diff options
author | Dmitry Shevchenko <dmishe@google.com> | 2016-10-03 22:12:28 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2016-10-04 08:55:09 +0000 |
commit | deeeb31f8ba0f196fbc9ca2a177d59d57ea50b32 (patch) | |
tree | 999abbd9c868be741495a0fc63a3ac77b7d31deb /src/main/java/com/google/devtools | |
parent | 169e68f4f3fcc000cc4fedebf15a9ea9373784e4 (diff) |
Add a way to select non-default Xcode toolchain
* Adds a flag --xcode_toolchain which sets TOOLCHAINS env variable for xcrun.
* Updates swift_library to work with this flag when selecting Swift runtime location.
* By default the flag has a null value and is not set in env.
--
MOS_MIGRATED_REVID=135033093
Diffstat (limited to 'src/main/java/com/google/devtools')
4 files changed, 70 insertions, 17 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java index 5d2830a049..3d71ca5ad8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java @@ -227,6 +227,17 @@ public class AppleCommandLineOptions extends FragmentOptions { } } + @Option( + name = "xcode_toolchain", + defaultValue = "null", + category = "flags", + help = "The identifier of an Xcode toolchain to use for builds. Currently only the toolchains " + + "that ship with Xcode are supported. For example, in addition to the default toolchain" + + " Xcode 8 has 'com.apple.dt.toolchain.Swift_2_3' which can be used for building legacy" + + " Swift code." + ) + public String xcodeToolchain; + @Option(name = "apple_bitcode", converter = AppleBitcodeMode.Converter.class, // TODO(blaze-team): Default to embedded_markers when fully implemented. diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java index 59a6fc1403..e0d242703f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java @@ -84,6 +84,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { private final ImmutableList<String> tvosCpus; private final AppleBitcodeMode bitcodeMode; private final Label xcodeConfigLabel; + @Nullable private final String xcodeToolchain; @Nullable private final Label defaultProvisioningProfileLabel; private final boolean disableNativeSwiftRules; @@ -127,6 +128,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { this.xcodeConfigLabel = Preconditions.checkNotNull(appleOptions.xcodeVersionConfig, "xcodeConfigLabel"); this.defaultProvisioningProfileLabel = appleOptions.defaultProvisioningProfile; + this.xcodeToolchain = appleOptions.xcodeToolchain; this.disableNativeSwiftRules = appleOptions.disableNativeSwiftRules; } @@ -519,6 +521,17 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { return Joiner.on('-').join(components); } + /** Returns the identifier for an Xcode toolchain to use with tools. */ + @SkylarkCallable( + name = "xcode_toolchain", + doc = "Identifier for the custom Xcode toolchain to use in build or None if not specified", + allowReturnNones = true, + structField = true + ) + public String getXcodeToolchain() { + return xcodeToolchain; + } + /** * Whether the native Swift support should be disabled. Used to deprecate said functionality. */ diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java index fa16aaf3f9..8136e837ca 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java @@ -1445,9 +1445,22 @@ public final class CompilationSupport { } if (objcProvider.is(USES_SWIFT)) { - commandLine - .add("-L") - .add(AppleToolchain.swiftLibDir(appleConfiguration.getSingleArchPlatform())); + // Check if there's a swift library path already. If that's not the case - fall back to + // the default one. This is for backwards compatibility with Swift native rules. + // TODO(b/30281236): Remove when native Swift is deprecated. + boolean swiftLibDirSet = false; + for (String arg : objcProvider.get(ObjcProvider.LINKOPT)) { + if (arg.startsWith("-L") && arg.contains("usr/lib/swift")) { + swiftLibDirSet = true; + break; + } + } + + if (!swiftLibDirSet) { + commandLine + .add("-L") + .add(AppleToolchain.swiftLibDir(appleConfiguration.getSingleArchPlatform())); + } } for (String linkopt : attributes.linkopts()) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java index 009b3fddfe..4cf8e6264f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java @@ -1058,13 +1058,21 @@ public final class ReleaseBundlingSupport { return; } - CustomCommandLine.Builder commandLine = - CustomCommandLine.builder() - .addPath(intermediateArtifacts.swiftFrameworksFileZip().getExecPath()) - .add("Frameworks") - .add("--platform") - .add(platform.getLowerCaseNameInPlist()) - .addExecPath("--scan-executable", combinedArchBinary); + AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); + + CustomCommandLine.Builder commandLine = CustomCommandLine.builder(); + if (appleConfiguration.getXcodeToolchain() != null) { + commandLine.add("--toolchain").add(appleConfiguration.getXcodeToolchain()); + } + + commandLine + .add("--output_zip_path") + .addPath(intermediateArtifacts.swiftFrameworksFileZip().getExecPath()) + .add("--bundle_path") + .add("Frameworks") + .add("--platform") + .add(platform.getLowerCaseNameInPlist()) + .addExecPath("--scan-executable", combinedArchBinary); ruleContext.registerAction( ObjcRuleClasses.spawnAppleEnvActionBuilder(ruleContext, platform) @@ -1082,13 +1090,21 @@ public final class ReleaseBundlingSupport { return; } - CustomCommandLine.Builder commandLine = - CustomCommandLine.builder() - .addPath(intermediateArtifacts.swiftSupportZip().getExecPath()) - .add("SwiftSupport/" + platform.getLowerCaseNameInPlist()) - .add("--platform") - .add(platform.getLowerCaseNameInPlist()) - .addExecPath("--scan-executable", combinedArchBinary); + AppleConfiguration configuration = ruleContext.getFragment(AppleConfiguration.class); + + CustomCommandLine.Builder commandLine = CustomCommandLine.builder(); + if (configuration.getXcodeToolchain() != null) { + commandLine.add("--toolchain").add(configuration.getXcodeToolchain()); + } + + commandLine + .add("--output_zip_path") + .addPath(intermediateArtifacts.swiftSupportZip().getExecPath()) + .add("--bundle_path") + .add("SwiftSupport/" + platform.getLowerCaseNameInPlist()) + .add("--platform") + .add(platform.getLowerCaseNameInPlist()) + .addExecPath("--scan-executable", combinedArchBinary); ruleContext.registerAction( ObjcRuleClasses.spawnAppleEnvActionBuilder(ruleContext, platform) |