diff options
author | 2015-11-06 21:04:42 +0000 | |
---|---|---|
committer | 2015-11-06 22:54:13 +0000 | |
commit | 7fdbd784e82a388a158aa10dde3e3d5ceddefeee (patch) | |
tree | e582f072b0edc6df373098786549787c16670959 /src/main/java/com/google/devtools | |
parent | 69a3f3621ea5c96edab39fde29fa1eb76d83006c (diff) |
Add xcrunwrapper to deal with DEVELOPER_DIR and SDKROOT.
Replace uses of $SDKROOT and $DEVELOPER_DIR values in compile paths with __DEVELOPER_DIR__ and __SDKROOT__ to that xcrunwrapper can deal with them appropriately.
RELNOTES:none
--
MOS_MIGRATED_REVID=107259512
Diffstat (limited to 'src/main/java/com/google/devtools')
8 files changed, 98 insertions, 38 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java index aa25b8e2bb..c784a1e3f8 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java @@ -339,6 +339,7 @@ public class BazelRuleClassProvider { builder.addRuleDefinition(new ObjcRuleClasses.SdkFrameworksDependerRule()); builder.addRuleDefinition(new ObjcRuleClasses.CompileDependencyRule()); builder.addRuleDefinition(new ObjcRuleClasses.ResourceToolsRule()); + builder.addRuleDefinition(new ObjcRuleClasses.XcrunRule()); builder.addRuleDefinition(new IosApplicationRule()); builder.addRuleDefinition(new IosExtensionBinaryRule()); builder.addRuleDefinition(new IosExtensionRule()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java index 9385885fd7..42deaf2e23 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java @@ -18,7 +18,6 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.ASSET_CATALO import static com.google.devtools.build.lib.rules.objc.ObjcProvider.BUNDLE_FILE; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STRINGS; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.XCASSETS_DIR; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.XCRUN; import com.google.common.base.Optional; import com.google.common.base.Verify; @@ -231,9 +230,10 @@ final class BundleSupport { .setCommandLine(ibActionsCommandLine(archiveRoot, zipOutput, storyboardInput)) .addOutput(zipOutput) .addInput(storyboardInput) - // TODO(dmaclach): Adding realpath here should not be required once + // TODO(dmaclach): Adding realpath and xcrunwrapper should not be required once // https://github.com/bazelbuild/bazel/issues/285 is fixed. .addInput(attributes.realpath()) + .addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable()) .build(ruleContext)); } } @@ -270,13 +270,14 @@ final class BundleSupport { .setExecutable(attributes.momcWrapper()) .addOutput(outputZip) .addInputs(datamodel.getInputs()) - // TODO(dmaclach): Adding realpath here should not be required once + // TODO(dmaclach): Adding realpath and xcrunwrapper should not be required once // https://github.com/google/bazel/issues/285 is fixed. .addInput(attributes.realpath()) - .setCommandLine(CustomCommandLine.builder() + .addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable()) + .setCommandLine(CustomCommandLine.builder() .addPath(outputZip.getExecPath()) .add(datamodel.archiveRootForMomczip()) - .add("-XD_MOMC_SDKROOT=" + IosSdkCommands.sdkDir(objcConfiguration)) + .add("-XD_MOMC_SDKROOT=" + IosSdkCommands.sdkDir()) .add("-XD_MOMC_IOS_TARGET_VERSION=" + bundling.getMinimumOsVersion()) .add("-MOMC_PLATFORMS") .add(objcConfiguration.getBundlingPlatform().getLowerCaseNameInPlist()) @@ -302,9 +303,10 @@ final class BundleSupport { .setCommandLine(ibActionsCommandLine(archiveRoot, zipOutput, original)) .addOutput(zipOutput) .addInput(original) - // TODO(dmaclach): Adding realpath here should not be required once + // TODO(dmaclach): Adding realpath and xcrunwrapper should not be required once // https://github.com/bazelbuild/bazel/issues/285 is fixed. .addInput(attributes.realpath()) + .addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable()) .build(ruleContext)); } } @@ -324,6 +326,7 @@ final class BundleSupport { .addPath(strings.getExecPath()) .build()) .addInput(strings) + .addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable()) .addOutput(bundled) .build(ruleContext)); } @@ -385,9 +388,10 @@ final class BundleSupport { .addTransitiveInputs(objcProvider.get(ASSET_CATALOG)) .addOutput(zipOutput) .addOutput(actoolPartialInfoplist) - // TODO(dmaclach): Adding realpath here should not be required once + // TODO(dmaclach): Adding realpath and xcrunwrapper should not be required once // https://github.com/google/bazel/issues/285 is fixed. .addInput(attributes.realpath()) + .addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable()) .setCommandLine(actoolzipCommandLine( objcProvider, zipOutput, 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 8c120e7aca..b48969568b 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 @@ -42,7 +42,6 @@ import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.NON_ARC_S import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.SRCS_TYPE; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.STRIP; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.SWIFT; -import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.XCRUN; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.intermediateArtifacts; import static java.nio.charset.StandardCharsets.ISO_8859_1; @@ -60,6 +59,7 @@ import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.ParameterFile; import com.google.devtools.build.lib.analysis.AnalysisEnvironment; +import com.google.devtools.build.lib.analysis.FilesToRunProvider; import com.google.devtools.build.lib.analysis.PrerequisiteArtifacts; import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleContext; @@ -117,6 +117,13 @@ public final class CompilationSupport { ImmutableList.of("-fprofile-arcs", "-ftest-coverage"); /** + * Returns the location of the xcrunwrapper tool. + */ + public static final FilesToRunProvider xcrunwrapper(RuleContext ruleContext) { + return ruleContext.getExecutablePrerequisite("$xcrunwrapper", Mode.HOST); + } + + /** * Files which can be instrumented along with the attributes in which they may occur and the * attributes along which they are propagated from dependencies (via * {@link InstrumentedFilesProvider}). @@ -397,7 +404,7 @@ public final class CompilationSupport { // TODO(bazel-team): Remote private headers from inputs once they're added to the provider. ruleContext.registerAction(ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) .setMnemonic("ObjcCompile") - .setExecutable(XCRUN) + .setExecutable(xcrunwrapper(ruleContext)) .setCommandLine(commandLine.build()) .addInput(sourceFile) .addInputs(additionalInputs.build()) @@ -445,7 +452,7 @@ public final class CompilationSupport { .add("-frontend") .add("-emit-object") .add("-target").add(IosSdkCommands.swiftTarget(objcConfiguration)) - .add("-sdk").add(IosSdkCommands.sdkDir(objcConfiguration)) + .add("-sdk").add(IosSdkCommands.sdkDir()) .add("-enable-objc-interop"); if (objcConfiguration.generateDebugSymbols()) { @@ -494,7 +501,7 @@ public final class CompilationSupport { ruleContext.registerAction( ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) .setMnemonic("SwiftCompile") - .setExecutable(XCRUN) + .setExecutable(xcrunwrapper(ruleContext)) .setCommandLine(commandLine.build()) .addInput(sourceFile) .addInputs(otherSwiftSources) @@ -527,7 +534,7 @@ public final class CompilationSupport { .add(SWIFT) .add("-frontend") .add("-emit-module") - .add("-sdk").add(IosSdkCommands.sdkDir(objcConfiguration)) + .add("-sdk").add(IosSdkCommands.sdkDir()) .add("-target").add(IosSdkCommands.swiftTarget(objcConfiguration)); if (objcConfiguration.generateDebugSymbols()) { @@ -563,7 +570,7 @@ public final class CompilationSupport { ruleContext.registerAction(ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) .setMnemonic("SwiftModuleMerge") - .setExecutable(XCRUN) + .setExecutable(xcrunwrapper(ruleContext)) .setCommandLine(commandLine.build()) .addInputs(moduleFiles.build()) .addTransitiveInputs(objcProvider.get(HEADER)) @@ -599,13 +606,13 @@ public final class CompilationSupport { actions.add(ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) .setMnemonic("ObjcLink") - .setExecutable(XCRUN) + .setExecutable(xcrunwrapper(ruleContext)) .setCommandLine(new CustomCommandLine.Builder() .add(LIBTOOL) .add("-static") .add("-filelist").add(objList.getExecPathString()) .add("-arch_only").add(objcConfiguration.getIosCpu()) - .add("-syslibroot").add(IosSdkCommands.sdkDir(objcConfiguration)) + .add("-syslibroot").add(IosSdkCommands.sdkDir()) .add("-o").add(archive.getExecPathString()) .build()) .addInputs(objFiles) @@ -623,12 +630,12 @@ public final class CompilationSupport { ImmutableList<Artifact> ccLibraries = ccLibraries(objcProvider); ruleContext.registerAction(ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) .setMnemonic("ObjcLink") - .setExecutable(XCRUN) + .setExecutable(xcrunwrapper(ruleContext)) .setCommandLine(new CustomCommandLine.Builder() .add(LIBTOOL) .add("-static") .add("-arch_only").add(objcConfiguration.getIosCpu()) - .add("-syslibroot").add(IosSdkCommands.sdkDir(objcConfiguration)) + .add("-syslibroot").add(IosSdkCommands.sdkDir()) .add("-o").add(archive.getExecPathString()) .addExecPaths(objcProvider.get(LIBRARY)) .addExecPaths(objcProvider.get(IMPORTED_LIBRARY)) @@ -780,6 +787,7 @@ public final class CompilationSupport { .addTransitiveInputs(objcProvider.get(FRAMEWORK_FILE)) .addInputs(ccLibraries) .addInputs(extraLinkInputs) + .addInput(xcrunwrapper(ruleContext).getExecutable()) .build(ruleContext)); if (objcConfiguration.shouldStripBinary()) { @@ -793,7 +801,7 @@ public final class CompilationSupport { ruleContext.registerAction( ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) .setMnemonic("ObjcBinarySymbolStrip") - .setExecutable(XCRUN) + .setExecutable(xcrunwrapper(ruleContext)) .setCommandLine(symbolStripCommandLine(stripArgs, binaryToLink, strippedBinary)) .addOutput(strippedBinary) .addInput(binaryToLink) @@ -825,7 +833,7 @@ public final class CompilationSupport { ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext); CustomCommandLine.Builder commandLine = CustomCommandLine.builder() - .addPath(XCRUN); + .addPath(xcrunwrapper(ruleContext).getExecutable().getExecPath()); if (objcProvider.is(USES_CPP)) { commandLine @@ -885,7 +893,7 @@ public final class CompilationSupport { PathFragment dsymPath = FileSystemUtils.removeExtension(dsymBundle.get().getExecPath()); commandLine .add("&&") - .addPath(XCRUN) + .addPath(xcrunwrapper(ruleContext).getExecutable().getExecPath()) .add(DSYMUTIL) .add(linkedBinary.getExecPathString()) .add("-o " + dsymPath) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosSdkCommands.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosSdkCommands.java index 73be677afc..2773894868 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosSdkCommands.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosSdkCommands.java @@ -32,7 +32,12 @@ import java.util.List; * Utility code for use when generating iOS SDK commands. */ public class IosSdkCommands { - public static final String DEVELOPER_DIR = "/Applications/Xcode.app/Contents/Developer"; + + // These next two strings are shared secrets with the xcrunwrapper.sh to allow + // expansion of DeveloperDir and SDKRoot and runtime, since they aren't known + // until compile time on any given build machine. + private static final String DEVELOPER_DIR = "__BAZEL_XCODE_DEVELOPER_DIR__"; + private static final String SDKROOT_DIR = "__BAZEL_XCODE_SDKROOT__"; // There is a handy reference to many clang warning flags at // http://nshipster.com/clang-diagnostics/ @@ -73,20 +78,42 @@ public class IosSdkCommands { return Platform.forArch(configuration.getIosCpu()).getNameInPlist(); } + /** + * Returns the platform directory inside of Xcode for a given configuration. + */ public static String platformDir(ObjcConfiguration configuration) { - return DEVELOPER_DIR + "/Platforms/" + getPlatformPlistName(configuration) + ".platform"; + return platformDir(getPlatformPlistName(configuration)); } - public static String sdkDir(ObjcConfiguration configuration) { - return platformDir(configuration) + "/Developer/SDKs/" - + getPlatformPlistName(configuration) + configuration.getIosSdkVersion() + ".sdk"; + /** + * Returns the platform directory inside of Xcode for a given platform name (e.g. iphoneos). + */ + public static String platformDir(String platformName) { + return DEVELOPER_DIR + "/Platforms/" + platformName + ".platform"; } - public static String frameworkDir(ObjcConfiguration configuration) { + /** + * Returns the platform directory inside of Xcode for a given configuration. + */ + public static String sdkDir() { + return SDKROOT_DIR; + } + + /** + * Returns the platform frameworks directory inside of Xcode for a given configuration. + */ + public static String platformDeveloperFrameworkDir(ObjcConfiguration configuration) { return platformDir(configuration) + "/Developer/Library/Frameworks"; } /** + * Returns the SDK frameworks directory inside of Xcode for a given configuration. + */ + public static String sdkDeveloperFrameworkDir() { + return sdkDir() + "/Developer/Library/Frameworks"; + } + + /** * Returns swift libraries path. */ public static String swiftLibDir(ObjcConfiguration configuration) { @@ -131,11 +158,11 @@ public class IosSdkCommands { return builder .add("-arch", configuration.getIosCpu()) - .add("-isysroot", sdkDir(configuration)) + .add("-isysroot", sdkDir()) // TODO(bazel-team): Pass framework search paths to Xcodegen. - .add("-F", sdkDir(configuration) + "/Developer/Library/Frameworks") + .add("-F", sdkDeveloperFrameworkDir()) // As of sdk8.1, XCTest is in a base Framework dir - .add("-F", frameworkDir(configuration)) + .add("-F", platformDeveloperFrameworkDir(configuration)) // Add custom (non-SDK) framework search paths. For each framework foo/bar.framework, // include "foo" as a search path. .addAll(Interspersing.beforeEach( diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java index 8055a7071d..64e211b9a5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommon.java @@ -499,10 +499,9 @@ public final class ObjcCommon { if (compilationAttributes.isPresent()) { CompilationAttributes attributes = compilationAttributes.get(); - ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(context); Iterable<PathFragment> sdkIncludes = Iterables.transform( Interspersing.prependEach( - IosSdkCommands.sdkDir(objcConfiguration) + "/usr/include/", + IosSdkCommands.sdkDir() + "/usr/include/", PathFragment.safePathStrings(attributes.sdkIncludes())), TO_PATH_FRAGMENT); objcProvider diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java index 03ea73d953..a52f69084e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java @@ -107,7 +107,7 @@ public class ObjcProtoLibraryRule implements RuleDefinition { return RuleDefinition.Metadata.builder() .name("objc_proto_library") .factoryClass(ObjcProtoLibrary.class) - .ancestors(BaseRuleClasses.RuleBase.class) + .ancestors(BaseRuleClasses.RuleBase.class, ObjcRuleClasses.XcrunRule.class) .build(); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java index febfe93c2b..7e296d8b73 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcRuleClasses.java @@ -65,7 +65,6 @@ public class ObjcRuleClasses { static final String DSYMUTIL = "dsymutil"; static final String LIPO = "lipo"; static final String STRIP = "strip"; - static final PathFragment XCRUN = new PathFragment("/usr/bin/xcrun"); private static final PathFragment JAVA = new PathFragment("/usr/bin/java"); @@ -482,7 +481,7 @@ public class ObjcRuleClasses { return RuleDefinition.Metadata.builder() .name("$objc_resources_rule") .type(RuleClassType.ABSTRACT) - .ancestors(ResourceToolsRule.class) + .ancestors(ResourceToolsRule.class, XcrunRule.class) .build(); } } @@ -711,7 +710,8 @@ public class ObjcRuleClasses { BaseRuleClasses.RuleBase.class, CompileDependencyRule.class, OptionsRule.class, - CoptsRule.class) + CoptsRule.class, + XcrunRule.class) .build(); } } @@ -907,7 +907,7 @@ public class ObjcRuleClasses { return RuleDefinition.Metadata.builder() .name("$objc_bundling_rule") .type(RuleClassType.ABSTRACT) - .ancestors(OptionsRule.class, ResourceToolsRule.class) + .ancestors(OptionsRule.class, ResourceToolsRule.class, XcrunRule.class) .build(); } } @@ -1042,5 +1042,25 @@ public class ObjcRuleClasses { .build(); } } + + /** + * Common attributes for {@code objc_*} rules that need to call xcrun. + */ + public static class XcrunRule implements RuleDefinition { + @Override + public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { + return builder + .add(attr("$xcrunwrapper", LABEL).cfg(HOST).exec() + .value(env.getLabel(Constants.TOOLS_REPOSITORY + "//tools/objc:xcrunwrapper"))) + .build(); + } + @Override + public Metadata getMetadata() { + return RuleDefinition.Metadata.builder() + .name("$objc_xcrun_rule") + .type(RuleClassType.ABSTRACT) + .build(); + } + } } 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 f11ec3f30b..54d6d7c741 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 @@ -511,7 +511,7 @@ public final class ReleaseBundlingSupport { .setMnemonic("ObjcCombiningArchitectures") .addTransitiveInputs(linkedBinaries) .addOutput(resultingLinkedBinary) - .setExecutable(ObjcRuleClasses.XCRUN) + .setExecutable(CompilationSupport.xcrunwrapper(ruleContext)) .setCommandLine(CustomCommandLine.builder() .add(ObjcRuleClasses.LIPO) .addExecPaths("-create", linkedBinaries) @@ -763,9 +763,10 @@ public final class ReleaseBundlingSupport { .setCommandLine(commandLine.build()) .addOutput(intermediateArtifacts.swiftFrameworksFileZip()) .addInput(intermediateArtifacts.combinedArchitectureBinary()) - // TODO(dmaclach): Adding realpath here should not be required once + // TODO(dmaclach): Adding realpath and xcrunwrapper should not be required once // https://github.com/google/bazel/issues/285 is fixed. .addInput(attributes.realpath()) + .addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable()) .build(ruleContext)); } |