diff options
author | 2017-03-15 21:02:29 +0000 | |
---|---|---|
committer | 2017-03-16 08:37:13 +0000 | |
commit | e6ff1090f70d1ddbf69b205216c216c5e052afc8 (patch) | |
tree | a1ea164f384bfbe9b6afdd4cd96a0966ae3807d6 | |
parent | 1e07d099f26fde981c58ef4e2cd3e5c88fe89851 (diff) |
Header thinning feature now ships the appropriate Apple SDK with header scanner tool to ensure that the correct headers are detected without building any assumptions into the tool.
--
PiperOrigin-RevId: 150238621
MOS_MIGRATED_REVID=150238621
4 files changed, 55 insertions, 3 deletions
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 adad227027..36fc313b11 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 @@ -1171,6 +1171,8 @@ public abstract class CompilationSupport { } FilesToRunProvider headerScannerTool = getHeaderThinningToolExecutable(); + PrerequisiteArtifacts appleSdks = + ruleContext.getPrerequisiteArtifacts(ObjcRuleClasses.APPLE_SDK_ATTRIBUTE, Mode.TARGET); ListMultimap<ImmutableList<String>, ObjcHeaderThinningInfo> objcHeaderThinningInfoByCommandLine = groupActionsByCommandLine(headerThinningInfo); // Register a header scanning spawn action for each unique set of command line arguments @@ -1178,8 +1180,22 @@ public abstract class CompilationSupport { SpawnAction.Builder builder = new SpawnAction.Builder() .setMnemonic("ObjcHeaderScanning") - .setExecutable(headerScannerTool); - CustomCommandLine.Builder cmdLine = CustomCommandLine.builder(); + .setExecutable(headerScannerTool) + .addInputs(appleSdks.list()); + CustomCommandLine.Builder cmdLine = + CustomCommandLine.builder() + .add("--arch") + .add(appleConfiguration.getSingleArchitecture().toLowerCase()) + .add("--platform") + .add(appleConfiguration.getSingleArchPlatform().getLowerCaseNameInPlist()) + .add("--sdk_version") + .add( + appleConfiguration + .getSdkVersionForPlatform(appleConfiguration.getSingleArchPlatform()) + .toStringWithMinimumComponents(2)) + .add("--xcode_version") + .add(appleConfiguration.getXcodeVersion().toStringWithMinimumComponents(2)) + .add("--"); for (ObjcHeaderThinningInfo info : objcHeaderThinningInfoByCommandLine.get(args)) { cmdLine.addJoinPaths( ":", diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java index 15a775a4c7..71266797eb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java @@ -305,6 +305,17 @@ public class ObjcCommandLineOptions extends FragmentOptions { ) public Label objcHeaderScannerTool; + @Option( + name = "apple_sdk", + defaultValue = "null", + category = "undocumented", + converter = LabelConverter.class, + help = + "Location of target that will provide the appropriate Apple SDK for the current build " + + "configuration." + ) + public Label appleSdk; + @Override public FragmentOptions getHost(boolean fallback) { ObjcCommandLineOptions host = (ObjcCommandLineOptions) super.getHost(fallback); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java index ec93b71ada..da9fd874b7 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java @@ -82,6 +82,7 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment { private final HeaderDiscovery.DotdPruningMode dotdPruningPlan; private final boolean experimentalHeaderThinning; private final Label objcHeaderScannerTool; + private final Label appleSdk; private final boolean generateXcodeProject; ObjcConfiguration(ObjcCommandLineOptions objcOptions, BuildConfiguration.Options options, @@ -123,6 +124,7 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment { : HeaderDiscovery.DotdPruningMode.DO_NOT_USE; this.experimentalHeaderThinning = objcOptions.experimentalObjcHeaderThinning; this.objcHeaderScannerTool = objcOptions.objcHeaderScannerTool; + this.appleSdk = objcOptions.appleSdk; this.generateXcodeProject = objcOptions.generateXcodeProject; } @@ -365,6 +367,11 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment { return objcHeaderScannerTool; } + /** Returns the label for the Apple SDK for current build configuration. */ + public Label getAppleSdk() { + return appleSdk; + } + /** * Returns {@code true} if an xcodegen project should be added to a target's files to 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 80ea4c0a4d..887535b8ef 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 @@ -70,8 +70,10 @@ public class ObjcRuleClasses { * Name of the attribute used for implicit dependency on the libtool wrapper. */ public static final String LIBTOOL_ATTRIBUTE = "$libtool"; - /** Name of the attribute used for implicit dependency on the header_scanner wrapper. */ + /** Name of the attribute used for implicit dependency on the header_scanner tool. */ public static final String HEADER_SCANNER_ATTRIBUTE = ":header_scanner"; + /** Name of attribute used for implicit dependency on the apple SDKs. */ + public static final String APPLE_SDK_ATTRIBUTE = ":apple_sdk"; static final String CLANG = "clang"; static final String CLANG_PLUSPLUS = "clang++"; @@ -764,6 +766,22 @@ public class ObjcRuleClasses { .getObjcHeaderScannerTool(); } })) + .add( + attr(APPLE_SDK_ATTRIBUTE, LABEL) + .value( + new LateBoundLabel<BuildConfiguration>(ObjcConfiguration.class) { + @Override + public Label resolve( + Rule rule, AttributeMap attributes, BuildConfiguration configuration) { + ObjcConfiguration objcConfiguration = + configuration.getFragment(ObjcConfiguration.class); + // Apple SDKs are currently only used by ObjC header thinning feature + if (objcConfiguration.useExperimentalHeaderThinning()) { + return objcConfiguration.getAppleSdk(); + } + return null; + } + })) .build(); } @Override |