diff options
21 files changed, 227 insertions, 50 deletions
diff --git a/.gitignore b/.gitignore index 8e407e6513..b998082598 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ /tools/objc/realpath /tools/objc/StdRedirect.dylib /tools/objc/swiftstdlibtoolwrapper.sh +/tools/objc/xcrunwrapper.sh diff --git a/compile.sh b/compile.sh index 56ca3da74a..7352c767ca 100755 --- a/compile.sh +++ b/compile.sh @@ -103,6 +103,7 @@ if [ $DO_TOOLS_COMPILATION ]; then bazel_bootstrap //src/tools/xcode/ibtoolwrapper:ibtoolwrapper tools/objc/ibtoolwrapper.sh 0755 bazel_bootstrap //src/tools/xcode/momcwrapper:momcwrapper tools/objc/momcwrapper.sh 0755 bazel_bootstrap //src/tools/xcode/swiftstdlibtoolwrapper:swiftstdlibtoolwrapper tools/objc/swiftstdlibtoolzip.sh 0755 + bazel_bootstrap //src/tools/xcode/xcrunwrapper:xcrunwrapper tools/objc/xcrunwrapper.sh 0755 bazel_bootstrap //src/objc_tools/bundlemerge:bundlemerge_deploy.jar \ tools/objc/precomp_bundlemerge_deploy.jar bazel_bootstrap //src/objc_tools/plmerge:plmerge_deploy.jar \ 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)); } diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index a9164cf420..c1b548a1d4 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -28,6 +28,7 @@ filegroup( "//src/tools/xcode/realpath", "//src/tools/xcode/stdredirect:StdRedirect.dylib", "//src/tools/xcode/swiftstdlibtoolwrapper", + "//src/tools/xcode/xcrunwrapper", "//third_party/iossim", ], "//conditions:default": [], diff --git a/src/test/shell/bazel/test-setup.sh b/src/test/shell/bazel/test-setup.sh index 9bad3731b9..d5393e7c5a 100755 --- a/src/test/shell/bazel/test-setup.sh +++ b/src/test/shell/bazel/test-setup.sh @@ -326,6 +326,7 @@ function setup_objc_test_support() { [ -e tools/objc/precomp_xcodegen_deploy.jar ] || ln -sv ${xcodegen_path} tools/objc/precomp_xcodegen_deploy.jar [ -e tools/objc/StdRedirect.dylib ] || ln -sv ${stdredirect_path} tools/objc/StdRedirect.dylib [ -e tools/objc/swiftstdlibtoolwrapper.sh ] || ln -sv ${swiftstdlibtoolwrapper_path} tools/objc/swiftstdlibtoolwrapper.sh + [ -e tools/objc/xcrunwrapper.sh ] || ln -sv ${xcrunwrapper_path} tools/objc/xcrunwrapper.sh [ -e tools/objc/realpath ] || ln -sv ${realpath_path} tools/objc/realpath [ -e tools/objc/environment_plist.sh ] || ln -sv ${environment_plist_path} tools/objc/environment_plist.sh diff --git a/src/test/shell/bazel/testenv.sh b/src/test/shell/bazel/testenv.sh index bf6b548f9a..7f2fc6514d 100755 --- a/src/test/shell/bazel/testenv.sh +++ b/src/test/shell/bazel/testenv.sh @@ -63,6 +63,7 @@ xcodegen_path="${TEST_SRCDIR}/src/objc_tools/xcodegen/xcodegen_deploy.jar" stdredirect_path="${TEST_SRCDIR}/src/tools/xcode/stdredirect/StdRedirect.dylib" realpath_path="${TEST_SRCDIR}/src/tools/xcode/realpath/realpath" environment_plist_path="${TEST_SRCDIR}/src/tools/xcode/environment/environment_plist.sh" +xcrunwrapper_path="${TEST_SRCDIR}/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh" # Test data testdata_path=${TEST_SRCDIR}/src/test/shell/bazel/testdata diff --git a/src/tools/xcode/actoolwrapper/actoolwrapper.sh b/src/tools/xcode/actoolwrapper/actoolwrapper.sh index 1a05fd7b69..28aef05474 100755 --- a/src/tools/xcode/actoolwrapper/actoolwrapper.sh +++ b/src/tools/xcode/actoolwrapper/actoolwrapper.sh @@ -21,7 +21,7 @@ set -eu -REALPATH=$0.runfiles/external/bazel_tools/tools/objc/realpath +REALPATH="$0.runfiles/external/bazel_tools/tools/objc/realpath" if [ ! -e $REALPATH ]; then REALPATH=tools/objc/realpath fi @@ -54,6 +54,11 @@ for i in $@; do LASTARG="$i" done +WRAPPER="$0.runfiles/external/bazel_tools/tools/objc/xcrunwrapper.sh" +if [ ! -e $WRAPPER ]; then + WRAPPER=tools/objc/xcrunwrapper.sh +fi + # If we are running into problems figuring out actool issues, there are a couple # of env variables that may help. Both of the following must be set to work. # IBToolDebugLogFile=<OUTPUT FILE PATH> @@ -63,7 +68,7 @@ done # helps. # Yes IBTOOL appears to be correct here due to actool and ibtool being based # on the same codebase. -/usr/bin/xcrun actool --errors --warnings --notices \ +$WRAPPER actool --errors --warnings --notices \ --compress-pngs --output-format human-readable-text \ --compile "$TEMPDIR" "${TOOLARGS[@]}" diff --git a/src/tools/xcode/ibtoolwrapper/ibtoolwrapper.sh b/src/tools/xcode/ibtoolwrapper/ibtoolwrapper.sh index 89faeded2f..346744f3d7 100755 --- a/src/tools/xcode/ibtoolwrapper/ibtoolwrapper.sh +++ b/src/tools/xcode/ibtoolwrapper/ibtoolwrapper.sh @@ -25,7 +25,7 @@ set -eu -REALPATH=$0.runfiles/external/bazel_tools/tools/objc/realpath +REALPATH="$0.runfiles/external/bazel_tools/tools/objc/realpath" if [ ! -e $REALPATH ]; then REALPATH=tools/objc/realpath fi @@ -54,6 +54,11 @@ for i in $@; do fi done +WRAPPER="$0.runfiles/external/bazel_tools/tools/objc/xcrunwrapper.sh" +if [ ! -e $WRAPPER ]; then + WRAPPER=tools/objc/xcrunwrapper.sh +fi + # If we are running into problems figuring out ibtool issues, there are a couple # of env variables that may help. Both of the following must be set to work. # IBToolDebugLogFile=<OUTPUT FILE PATH> @@ -61,7 +66,7 @@ done # you may also see if # IBToolNeverDeque=1 # helps. -/usr/bin/xcrun ibtool --errors --warnings --notices \ +$WRAPPER ibtool --errors --warnings --notices \ --auto-activate-custom-fonts --output-format human-readable-text \ --compile "$FULLPATH" "${TOOLARGS[@]}" diff --git a/src/tools/xcode/momcwrapper/momcwrapper.sh b/src/tools/xcode/momcwrapper/momcwrapper.sh index 29c39d0b69..fc846637e0 100755 --- a/src/tools/xcode/momcwrapper/momcwrapper.sh +++ b/src/tools/xcode/momcwrapper/momcwrapper.sh @@ -22,7 +22,7 @@ set -eu -REALPATH=$0.runfiles/external/bazel_tools/tools/objc/realpath +REALPATH="$0.runfiles/external/bazel_tools/tools/objc/realpath" if [ ! -e $REALPATH ]; then REALPATH=tools/objc/realpath fi @@ -33,7 +33,12 @@ shift 2 TEMPDIR=$(mktemp -d -t momcZippingOutput) trap "rm -rf \"$TEMPDIR\"" EXIT -/usr/bin/xcrun momc "$@" "$TEMPDIR/$NAME" +WRAPPER="$0.runfiles/external/bazel_tools/tools/objc/xcrunwrapper.sh" +if [ ! -e $WRAPPER ]; then + WRAPPER=tools/objc/xcrunwrapper.sh +fi + +$WRAPPER momc "$@" "$TEMPDIR/$NAME" # Need to push/pop tempdir so it isn't the current working directory # when we remove it via the EXIT trap. diff --git a/src/tools/xcode/swiftstdlibtoolwrapper/swiftstdlibtoolwrapper.sh b/src/tools/xcode/swiftstdlibtoolwrapper/swiftstdlibtoolwrapper.sh index 90520b5d2b..ed7d47122d 100755 --- a/src/tools/xcode/swiftstdlibtoolwrapper/swiftstdlibtoolwrapper.sh +++ b/src/tools/xcode/swiftstdlibtoolwrapper/swiftstdlibtoolwrapper.sh @@ -21,7 +21,7 @@ set -eu -REALPATH=$0.runfiles/external/bazel_tools/tools/objc/realpath +REALPATH="$0.runfiles/external/bazel_tools/tools/objc/realpath" if [ ! -e $REALPATH ]; then REALPATH=tools/objc/realpath fi @@ -33,7 +33,12 @@ trap "rm -rf \"$TEMPDIR\"" EXIT FULLPATH="$TEMPDIR/Frameworks" -/usr/bin/xcrun swift-stdlib-tool --copy --verbose --destination "$FULLPATH" "$@" +WRAPPER="$0.runfiles/external/bazel_tools/tools/objc/xcrunwrapper.sh" +if [ ! -e $WRAPPER ]; then + WRAPPER=tools/objc/xcrunwrapper.sh +fi + +$WRAPPER swift-stdlib-tool --copy --verbose --destination "$FULLPATH" "$@" # Need to push/pop tempdir so it isn't the current working directory # when we remove it via the EXIT trap. diff --git a/src/tools/xcode/xcrunwrapper/BUILD b/src/tools/xcode/xcrunwrapper/BUILD new file mode 100644 index 0000000000..e8ea8594a8 --- /dev/null +++ b/src/tools/xcode/xcrunwrapper/BUILD @@ -0,0 +1,11 @@ +package(default_visibility = ["//src/test:__subpackages__"]) + +filegroup( + name = "srcs", + srcs = glob(["**"]), +) + +sh_binary( + name = "xcrunwrapper", + srcs = ["xcrunwrapper.sh"], +) diff --git a/src/tools/xcode/xcrunwrapper/README b/src/tools/xcode/xcrunwrapper/README new file mode 100644 index 0000000000..d76642186e --- /dev/null +++ b/src/tools/xcode/xcrunwrapper/README @@ -0,0 +1,7 @@ +xcrunwrapper runs the command passed to it using xcrun. + +It replaces __DEVELOPER_DIR__ with $DEVELOPER_DIR (or reasonable default) +and __SDKROOT__ with a valid path based on SDKROOT (or reasonable default). + +xcrun only runs on Darwin, so xcrunwrapper only runs on Darwin. + diff --git a/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh b/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh new file mode 100755 index 0000000000..dfb36aa4ef --- /dev/null +++ b/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# +# Copyright 2015 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# xcrunwrapper runs the command passed to it using xcrun. +# It replaces __BAZEL_XCODE_DEVELOPER_DIR__ with $DEVELOPER_DIR (or reasonable +# default) and __BAZEL_XCODE_SDKROOT__ with a valid path based on SDKROOT (or +# reasonable default). +# These values (__BAZEL_XCODE_*) are a shared secret withIosSdkCommands.java. + +set -eu + +# Pick values for DEVELOPER_DIR and SDKROOT as appropriate (if they weren't set) + +WRAPPER_DEVDIR="${DEVELOPER_DIR:-}" +if [[ -z "${WRAPPER_DEVDIR}" ]] ; then + WRAPPER_DEVDIR="$(xcode-select -p)" +fi + +# TODO(blaze-team): Remove this once all build environments are setting SDKROOT +# for us. +WRAPPER_SDKROOT="${SDKROOT:-}" +if [[ -z "${WRAPPER_SDKROOT:-}" ]] ; then + WRAPPER_SDK=iphonesimulator + for ARG in "$@" ; do + case "${ARG}" in + armv6|armv7|armv7s|arm64) + WRAPPER_SDK=iphoneos + ;; + i386|x86_64) + WRAPPER_SDK=iphonesimulator + ;; + esac + done + WRAPPER_SDKROOT="$(/usr/bin/xcrun --show-sdk-path --sdk ${WRAPPER_SDK})" +fi + +UPDATEDARGS=() +for ARG in "$@" ; do + ARG="${ARG//__BAZEL_XCODE_DEVELOPER_DIR__/${WRAPPER_DEVDIR}}" + ARG="${ARG//__BAZEL_XCODE_SDKROOT__/${WRAPPER_SDKROOT}}" + UPDATEDARGS+=("${ARG}") +done + +/usr/bin/xcrun "${UPDATEDARGS[@]}" diff --git a/tools/objc/BUILD b/tools/objc/BUILD index 897eac6ec9..8870a5ba44 100644 --- a/tools/objc/BUILD +++ b/tools/objc/BUILD @@ -54,25 +54,42 @@ filegroup( sh_binary( name = "ibtoolwrapper", srcs = [":ibtoolwrapper.sh"], - data = [":realpath"], + data = [ + ":realpath", + ":xcrunwrapper", + ], ) sh_binary( name = "actoolwrapper", srcs = [":actoolwrapper.sh"], - data = [":realpath"], + data = [ + ":realpath", + ":xcrunwrapper", + ], ) sh_binary( name = "momcwrapper", srcs = [":momcwrapper.sh"], - data = [":realpath"], + data = [ + ":realpath", + ":xcrunwrapper", + ], ) sh_binary( name = "swiftstdlibtoolwrapper", srcs = [":swiftstdlibtoolwrapper.sh"], - data = [":realpath"], + data = [ + ":realpath", + ":xcrunwrapper", + ], +) + +sh_binary( + name = "xcrunwrapper", + srcs = [":xcrunwrapper.sh"], ) # TODO(bazel-team): Open-source the script once J2ObjC support is open-sourced. |