From 15843b74fcc86b91263c7fd863fb62dea618dfac Mon Sep 17 00:00:00 2001 From: Dave MacLachlan Date: Tue, 6 Oct 2015 21:11:18 +0000 Subject: Move several commands over to using xcrun instead of hardcoding tooling locations. -- MOS_MIGRATED_REVID=104797906 --- .../build/lib/rules/objc/CompilationSupport.java | 52 +++++++++++++--------- .../build/lib/rules/objc/ObjcRuleClasses.java | 19 ++++---- .../lib/rules/objc/ReleaseBundlingSupport.java | 3 +- 3 files changed, 41 insertions(+), 33 deletions(-) (limited to 'src') 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 1c92409383..d3ad0e17d7 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 @@ -37,10 +37,12 @@ import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.CLANG_PLU import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.COMPILABLE_SRCS_TYPE; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.DSYMUTIL; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.HEADERS; +import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.LIBTOOL; import static com.google.devtools.build.lib.rules.objc.ObjcRuleClasses.NON_ARC_SRCS_TYPE; 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; @@ -304,7 +306,8 @@ public final class CompilationSupport { coverageFlags.addAll(CLANG_COVERAGE_FLAGS); gcnoFiles.add(intermediateArtifacts.gcnoFile(sourceFile)); } - CustomCommandLine.Builder commandLine = new CustomCommandLine.Builder(); + CustomCommandLine.Builder commandLine = new CustomCommandLine.Builder() + .add(CLANG); if (ObjcRuleClasses.CPP_SOURCES.matches(sourceFile.getExecPath())) { commandLine.add("-stdlib=libc++"); } @@ -368,7 +371,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(CLANG) + .setExecutable(XCRUN) .setCommandLine(commandLine.build()) .addInput(sourceFile) .addInputs(additionalInputs.build()) @@ -410,6 +413,7 @@ public final class CompilationSupport { ImmutableSet otherSwiftSources = otherSwiftSourcesBuilder.build(); CustomCommandLine.Builder commandLine = new CustomCommandLine.Builder() + .add(SWIFT) .add("-frontend") .add("-emit-object") .add("-target").add(IosSdkCommands.swiftTarget(objcConfiguration)) @@ -451,7 +455,7 @@ public final class CompilationSupport { ruleContext.registerAction( ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) .setMnemonic("SwiftCompile") - .setExecutable(SWIFT) + .setExecutable(XCRUN) .setCommandLine(commandLine.build()) .addInput(sourceFile) .addInputs(otherSwiftSources) @@ -479,24 +483,25 @@ public final class CompilationSupport { } } - CustomCommandLine.Builder commandLine = new CustomCommandLine.Builder(); - commandLine.add("-frontend"); - commandLine.add("-emit-module"); - commandLine.add("-sdk").add(IosSdkCommands.sdkDir(objcConfiguration)); - commandLine.add("-target").add(IosSdkCommands.swiftTarget(objcConfiguration)); + CustomCommandLine.Builder commandLine = new CustomCommandLine.Builder() + .add(SWIFT) + .add("-frontend") + .add("-emit-module") + .add("-sdk").add(IosSdkCommands.sdkDir(objcConfiguration)) + .add("-target").add(IosSdkCommands.swiftTarget(objcConfiguration)); if (objcConfiguration.generateDebugSymbols()) { commandLine.add("-g"); } - commandLine.add("-module-name").add(getModuleName()); - commandLine.add("-parse-as-library"); - commandLine.addExecPaths(moduleFiles.build()); - commandLine.addExecPath("-o", intermediateArtifacts.swiftModule()); - commandLine.addExecPath("-emit-objc-header-path", intermediateArtifacts.swiftHeader()); + commandLine.add("-module-name").add(getModuleName()) + .add("-parse-as-library") + .addExecPaths(moduleFiles.build()) + .addExecPath("-o", intermediateArtifacts.swiftModule()) + .addExecPath("-emit-objc-header-path", intermediateArtifacts.swiftHeader()); ruleContext.registerAction(ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) .setMnemonic("SwiftModuleMerge") - .setExecutable(SWIFT) + .setExecutable(XCRUN) .setCommandLine(commandLine.build()) .addInputs(moduleFiles.build()) .addOutput(intermediateArtifacts.swiftModule()) @@ -530,8 +535,9 @@ public final class CompilationSupport { actions.add(ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) .setMnemonic("ObjcLink") - .setExecutable(ObjcRuleClasses.LIBTOOL) + .setExecutable(XCRUN) .setCommandLine(new CustomCommandLine.Builder() + .add(LIBTOOL) .add("-static") .add("-filelist").add(objList.getExecPathString()) .add("-arch_only").add(objcConfiguration.getIosCpu()) @@ -553,8 +559,9 @@ public final class CompilationSupport { ImmutableList ccLibraries = ccLibraries(objcProvider); ruleContext.registerAction(ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) .setMnemonic("ObjcLink") - .setExecutable(ObjcRuleClasses.LIBTOOL) + .setExecutable(XCRUN) .setCommandLine(new CustomCommandLine.Builder() + .add(LIBTOOL) .add("-static") .add("-arch_only").add(objcConfiguration.getIosCpu()) .add("-syslibroot").add(IosSdkCommands.sdkDir(objcConfiguration)) @@ -722,7 +729,7 @@ public final class CompilationSupport { ruleContext.registerAction( ObjcRuleClasses.spawnOnDarwinActionBuilder(ruleContext) .setMnemonic("ObjcBinarySymbolStrip") - .setExecutable(STRIP) + .setExecutable(XCRUN) .setCommandLine(symbolStripCommandLine(stripArgs, binaryToLink, strippedBinary)) .addOutput(strippedBinary) .addInput(binaryToLink) @@ -741,6 +748,7 @@ public final class CompilationSupport { private static CommandLine symbolStripCommandLine( Iterable extraFlags, Artifact unstrippedArtifact, Artifact strippedArtifact) { return CustomCommandLine.builder() + .add(STRIP) .add(extraFlags) .addExecPath("-o", strippedArtifact) .addPath(unstrippedArtifact.getExecPath()) @@ -752,14 +760,15 @@ public final class CompilationSupport { ImmutableList ccLibraries) { ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext); - CustomCommandLine.Builder commandLine = CustomCommandLine.builder(); + CustomCommandLine.Builder commandLine = CustomCommandLine.builder() + .addPath(XCRUN); if (objcProvider.is(USES_CPP)) { commandLine - .addPath(CLANG_PLUSPLUS) + .add(CLANG_PLUSPLUS) .add("-stdlib=libc++"); } else { - commandLine.addPath(CLANG); + commandLine.add(CLANG); } // Do not perform code stripping on tests because XCTest binary is linked not as an executable @@ -812,7 +821,8 @@ public final class CompilationSupport { PathFragment dsymPath = FileSystemUtils.removeExtension(dsymBundle.get().getExecPath()); commandLine .add("&&") - .addPath(DSYMUTIL) + .addPath(XCRUN) + .add(DSYMUTIL) .add(linkedBinary.getExecPathString()) .add("-o " + dsymPath) .add("&& zipped_bundle=${PWD}/" + dsymBundle.get().getShellEscapedExecPathString()) 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 082603d5a9..d0b9406c25 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 @@ -57,17 +57,14 @@ import com.google.devtools.build.lib.vfs.PathFragment; * Shared rule classes and associated utility code for Objective-C rules. */ public class ObjcRuleClasses { - - // TODO(danielwh): Replace these with actual Artifact references - private static final String BIN_DIR = - IosSdkCommands.DEVELOPER_DIR + "/Toolchains/XcodeDefault.xctoolchain/usr/bin"; - static final PathFragment CLANG = new PathFragment(BIN_DIR + "/clang"); - static final PathFragment CLANG_PLUSPLUS = new PathFragment(BIN_DIR + "/clang++"); - static final PathFragment SWIFT = new PathFragment(BIN_DIR + "/swift"); - static final PathFragment LIBTOOL = new PathFragment(BIN_DIR + "/libtool"); - static final PathFragment DSYMUTIL = new PathFragment(BIN_DIR + "/dsymutil"); - static final PathFragment LIPO = new PathFragment(BIN_DIR + "/lipo"); - static final PathFragment STRIP = new PathFragment(BIN_DIR + "/strip"); + static final String CLANG = "clang"; + static final String CLANG_PLUSPLUS = "clang++"; + static final String SWIFT = "swift"; + static final String LIBTOOL = "libtool"; + 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"); 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 8d43907cd6..ee4c26a074 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 @@ -508,8 +508,9 @@ public final class ReleaseBundlingSupport { .setMnemonic("ObjcCombiningArchitectures") .addTransitiveInputs(linkedBinaries) .addOutput(resultingLinkedBinary) - .setExecutable(ObjcRuleClasses.LIPO) + .setExecutable(ObjcRuleClasses.XCRUN) .setCommandLine(CustomCommandLine.builder() + .add(ObjcRuleClasses.LIPO) .addExecPaths("-create", linkedBinaries) .addExecPath("-o", resultingLinkedBinary) .build()) -- cgit v1.2.3