diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java | 48 |
1 files changed, 32 insertions, 16 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 c9716a5902..b787ebcaf5 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 @@ -301,6 +301,7 @@ public abstract class CompilationSupport { protected final IntermediateArtifacts intermediateArtifacts; protected final boolean useDeps; protected final Map<String, NestedSet<Artifact>> outputGroupCollector; + protected final CcToolchainProvider toolchain; protected final boolean isTestRule; protected final boolean usePch; @@ -324,6 +325,7 @@ public abstract class CompilationSupport { CompilationAttributes compilationAttributes, boolean useDeps, Map<String, NestedSet<Artifact>> outputGroupCollector, + CcToolchainProvider toolchain, boolean isTestRule, boolean usePch) { this.ruleContext = ruleContext; @@ -336,6 +338,18 @@ public abstract class CompilationSupport { this.isTestRule = isTestRule; this.outputGroupCollector = outputGroupCollector; this.usePch = usePch; + // TODO(b/62143697): Remove this check once all rules are using the crosstool support. + if (ruleContext + .attributes() + .has(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, BuildType.LABEL)) { + if (toolchain == null) { + toolchain = CppHelper.getToolchainUsingDefaultCcToolchainAttribute(ruleContext); + } + this.toolchain = toolchain; + } else { + // Since the rule context doesn't have a toolchain at all, ignore any provided override. + this.toolchain = null; + } } /** Builder for {@link CompilationSupport} */ @@ -347,6 +361,7 @@ public abstract class CompilationSupport { private boolean useDeps = true; private Map<String, NestedSet<Artifact>> outputGroupCollector; private boolean isObjcLibrary = false; + private CcToolchainProvider toolchain; private boolean isTestRule = false; private boolean usePch = true; @@ -423,6 +438,17 @@ public abstract class CompilationSupport { } /** + * Sets {@link CcToolchainProvider} for the calling target. + * + * <p>This is needed if it can't correctly be inferred directly from the rule context. Setting + * to null causes the default to be used as if this was never called. + */ + public Builder setToolchainProvider(CcToolchainProvider toolchain) { + this.toolchain = toolchain; + return this; + } + + /** * Returns a {@link CompilationSupport} instance. This is either a {@link * CrosstoolCompilationSupport} or {@link LegacyCompilationSupport} depending on the value of * --experimental_objc_crosstool. @@ -458,6 +484,7 @@ public abstract class CompilationSupport { compilationAttributes, useDeps, outputGroupCollector, + toolchain, isTestRule, usePch); } else { @@ -468,6 +495,7 @@ public abstract class CompilationSupport { compilationAttributes, useDeps, outputGroupCollector, + toolchain, isTestRule, usePch); } @@ -490,7 +518,7 @@ public abstract class CompilationSupport { objcProvider, ExtraCompileArgs.NONE, ImmutableList.<PathFragment>of(), - maybeGetCcToolchain(), + toolchain, maybeGetFdoSupport()); } @@ -571,7 +599,7 @@ public abstract class CompilationSupport { return registerFullyLinkAction( objcProvider, outputArchive, - maybeGetCcToolchain(), + toolchain, maybeGetFdoSupport()); } @@ -629,7 +657,7 @@ public abstract class CompilationSupport { objcProvider, inputArtifacts, outputArchive, - maybeGetCcToolchain(), + toolchain, maybeGetFdoSupport()); } @@ -758,7 +786,7 @@ public abstract class CompilationSupport { common.getObjcProvider(), extraCompileArgs, priorityHeaders, - maybeGetCcToolchain(), + toolchain, maybeGetFdoSupport()); } return this; @@ -1444,18 +1472,6 @@ public abstract class CompilationSupport { } @Nullable - private CcToolchainProvider maybeGetCcToolchain() { - // TODO(rduan): Remove this check once all rules are using the crosstool support. - if (ruleContext - .attributes() - .has(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, BuildType.LABEL)) { - return CppHelper.getToolchainUsingDefaultCcToolchainAttribute(ruleContext); - } else { - return null; - } - } - - @Nullable private FdoSupportProvider maybeGetFdoSupport() { // TODO(rduan): Remove this check once all rules are using the crosstool support. if (ruleContext |