diff options
4 files changed, 41 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index e6a267c75f..8dcc65cca1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -474,17 +474,18 @@ public final class CcCommon { /** * Creates the feature configuration for a given rule. - * - * @param ruleContext the context of the rule we want the feature configuration for. + * + * @param ruleContext the context of the rule we want the feature configuration for. * @param ruleSpecificRequestedFeatures features that will be requested, and thus be always * enabled if the toolchain supports them. * @param ruleSpecificUnsupportedFeatures features that are not supported in the current context. * @return the feature configuration for the given {@code ruleContext}. */ - public static FeatureConfiguration configureFeatures(RuleContext ruleContext, + public static FeatureConfiguration configureFeatures( + RuleContext ruleContext, Set<String> ruleSpecificRequestedFeatures, - Set<String> ruleSpecificUnsupportedFeatures) { - CcToolchainProvider toolchain = CppHelper.getToolchain(ruleContext); + Set<String> ruleSpecificUnsupportedFeatures, + CcToolchainProvider toolchain) { ImmutableSet.Builder<String> unsupportedFeaturesBuilder = ImmutableSet.builder(); unsupportedFeaturesBuilder.addAll(ruleSpecificUnsupportedFeatures); if (!toolchain.supportsHeaderParsing()) { @@ -523,11 +524,24 @@ public final class CcCommon { /** * Creates a feature configuration for a given rule. - * - * @param ruleContext the context of the rule we want the feature configuration for. + * + * @param ruleContext the context of the rule we want the feature configuration for. + * @param toolchain the toolchain we want the feature configuration for. + * @return the feature configuration for the given {@code ruleContext}. + */ + public static FeatureConfiguration configureFeatures( + RuleContext ruleContext, CcToolchainProvider toolchain) { + return configureFeatures( + ruleContext, ImmutableSet.<String>of(), ImmutableSet.<String>of(), toolchain); + } + + /** + * Creates a feature configuration for a given rule. + * + * @param ruleContext the context of the rule we want the feature configuration for. * @return the feature configuration for the given {@code ruleContext}. */ public static FeatureConfiguration configureFeatures(RuleContext ruleContext) { - return configureFeatures(ruleContext, ImmutableSet.<String>of(), ImmutableSet.<String>of()); + return configureFeatures(ruleContext, CppHelper.getToolchain(ruleContext)); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java index 49a5a02cee..7483a61c33 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java @@ -781,7 +781,8 @@ public final class CppLinkAction extends AbstractAction { .setUseTestOnlyFlags(useTestOnlyFlags) .setNeedWholeArchive(needWholeArchive) .setParamFile(paramFile) - .setAllLTOArtifacts(isLTOIndexing ? null : allLTOArtifacts); + .setAllLTOArtifacts(isLTOIndexing ? null : allLTOArtifacts) + .setToolchain(toolchain); if (!isLTOIndexing) { linkCommandLineBuilder diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java index 64f779173d..48946b5c6b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java @@ -1013,6 +1013,7 @@ public final class LinkCommandLine extends CommandLine { @Nullable private Iterable<LTOBackendArtifacts> allLTOBackendArtifacts; @Nullable private Artifact paramFile; @Nullable private Artifact interfaceSoBuilder; + @Nullable private CcToolchainProvider toolchain; // This interface is needed to support tests that don't create a // ruleContext, in which case the configuration and action owner @@ -1040,7 +1041,11 @@ public final class LinkCommandLine extends CommandLine { FeatureConfiguration featureConfiguration = null; // The ruleContext can be null for some tests. if (ruleContext != null) { - featureConfiguration = CcCommon.configureFeatures(ruleContext); + if (toolchain != null) { + featureConfiguration = CcCommon.configureFeatures(ruleContext, toolchain); + } else { + featureConfiguration = CcCommon.configureFeatures(ruleContext); + } CcToolchainFeatures.Variables.Builder buildVariables = new CcToolchainFeatures.Variables.Builder(); CppConfiguration cppConfiguration = ruleContext.getFragment(CppConfiguration.class); @@ -1074,6 +1079,15 @@ public final class LinkCommandLine extends CommandLine { } /** + * Sets the toolchain to use for link flags. If this is not called, the toolchain + * is retrieved from the rule. + */ + public Builder setToolchain(CcToolchainProvider toolchain) { + this.toolchain = toolchain; + return this; + } + + /** * Sets the type of the link. It is an error to try to set this to {@link * LinkTargetType#INTERFACE_DYNAMIC_LIBRARY}. Note that all the static target types (see {@link * LinkTargetType#isStaticLibraryLink}) are equivalent, and there is no check that the output diff --git a/src/test/java/com/google/devtools/build/lib/util/GroupedListTest.java b/src/test/java/com/google/devtools/build/lib/util/GroupedListTest.java index f960a8e29d..13370fd9d3 100644 --- a/src/test/java/com/google/devtools/build/lib/util/GroupedListTest.java +++ b/src/test/java/com/google/devtools/build/lib/util/GroupedListTest.java @@ -125,7 +125,7 @@ public class GroupedListTest { assertFalse(groupedList.isEmpty()); Object compressed = groupedList.compress(); assertElementsEqual(compressed, allElts); - assertElementsEqualInGroups(GroupedList.create(compressed), elements); + assertElementsEqualInGroups(GroupedList.<String>create(compressed), elements); assertElementsEqualInGroups(groupedList, elements); } @@ -157,7 +157,7 @@ public class GroupedListTest { assertElementsEqual(compressed, allElts); // Get rid of empty list -- it was not stored in groupedList. elements.remove(1); - assertElementsEqualInGroups(GroupedList.create(compressed), elements); + assertElementsEqualInGroups(GroupedList.<String>create(compressed), elements); assertElementsEqualInGroups(groupedList, elements); } |