diff options
author | 2016-04-25 13:25:40 +0000 | |
---|---|---|
committer | 2016-04-25 17:46:48 +0000 | |
commit | 83b2123d5671a579cb63eff8aefcc60de8355516 (patch) | |
tree | dabccb1a9bd89f6f3f6e082efe1ff4a8d06151cc /src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java | |
parent | c78052c7ae8176d9266e3e277009d5b24763a0a2 (diff) |
Add mechanism to crosstool language to specify action-specific execution requirements. Uses this mechanism to configure c/c++ compilation and linking for darwin execution from the crosstool.
--
MOS_MIGRATED_REVID=120701108
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java | 50 |
1 files changed, 46 insertions, 4 deletions
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 b0a1b7d825..154ecf6f75 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 @@ -38,6 +38,7 @@ import com.google.devtools.build.lib.actions.extra.ExtraActionInfo; import com.google.devtools.build.lib.analysis.AnalysisEnvironment; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; +import com.google.devtools.build.lib.analysis.actions.ExecutionInfoSpecifier; import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.collect.CollectionUtils; @@ -50,6 +51,7 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import com.google.devtools.build.lib.packages.RuleErrorConsumer; +import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; import com.google.devtools.build.lib.rules.cpp.Link.LinkStaticness; import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType; import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; @@ -76,7 +78,7 @@ import javax.annotation.Nullable; * Action that represents a linking step. */ @ThreadCompatible -public final class CppLinkAction extends AbstractAction { +public final class CppLinkAction extends AbstractAction implements ExecutionInfoSpecifier { /** * An abstraction for creating intermediate and output artifacts for C++ linking. * @@ -107,10 +109,16 @@ public final class CppLinkAction extends AbstractAction { private static final String LINK_GUID = "58ec78bd-1176-4e36-8143-439f656b181d"; private static final String FAKE_LINK_GUID = "da36f819-5a15-43a9-8a45-e01b60e10c8b"; + /** + * The name of this action for the purpose of crosstool features/action_configs + */ + private static final String ACTION_NAME = "cpp-link"; + private final CppConfiguration cppConfiguration; private final LibraryToLink outputLibrary; private final LibraryToLink interfaceOutputLibrary; - + private final ImmutableSet<String> executionRequirements; + private final LinkCommandLine linkCommandLine; /** True for cc_fake_binary targets. */ @@ -155,7 +163,8 @@ public final class CppLinkAction extends AbstractAction { boolean fake, boolean isLTOIndexing, Iterable<LTOBackendArtifacts> allLTOBackendArtifacts, - LinkCommandLine linkCommandLine) { + LinkCommandLine linkCommandLine, + ImmutableSet<String> executionRequirements) { super(owner, inputs, outputs); this.mandatoryInputs = inputs; this.cppConfiguration = cppConfiguration; @@ -165,6 +174,7 @@ public final class CppLinkAction extends AbstractAction { this.isLTOIndexing = isLTOIndexing; this.allLTOBackendArtifacts = allLTOBackendArtifacts; this.linkCommandLine = linkCommandLine; + this.executionRequirements = executionRequirements; } private static Iterable<LinkerInput> filterLinkerInputs(Iterable<LinkerInput> inputs) { @@ -243,6 +253,15 @@ public final class CppLinkAction extends AbstractAction { return outputLibrary.getArtifact().getPath(); } + @Override + public Map<String, String> getExecutionInfo() { + ImmutableMap.Builder<String, String> result = ImmutableMap.<String, String>builder(); + for (String requirement : executionRequirements) { + result.put(requirement, ""); + } + return result.build(); + } + @VisibleForTesting public List<String> getRawLinkArgv() { return linkCommandLine.getRawLinkArgv(); @@ -405,6 +424,8 @@ public final class CppLinkAction extends AbstractAction { f.addString(fake ? FAKE_LINK_GUID : LINK_GUID); f.addString(getCppConfiguration().getLdExecutable().getPathString()); f.addStrings(linkCommandLine.arguments()); + f.addStrings(executionRequirements); + // TODO(bazel-team): For correctness, we need to ensure the invariant that all values accessed // during the execution phase are also covered by the key. Above, we add the argv to the key, // which covers most cases. Unfortunately, the extra action and fake support methods above also @@ -518,6 +539,7 @@ public final class CppLinkAction extends AbstractAction { private PathFragment runtimeSolibDir; protected final BuildConfiguration configuration; private final CppConfiguration cppConfiguration; + private FeatureConfiguration featureConfiguration; // Morally equivalent with {@link Context}, except these are mutable. // Keep these in sync with {@link Context}. @@ -870,6 +892,17 @@ public final class CppLinkAction extends AbstractAction { analysisEnvironment.registerAction(parameterFileWriteAction); } + // If the crosstool uses action_configs to configure cc compilation, collect execution info + // from there, otherwise, use no execution info. + // TODO(b/27903698): Assert that the crosstool has an action_config for this action. + ImmutableSet<String> executionRequirements = ImmutableSet.of(); + if (featureConfiguration != null) { + if (featureConfiguration.actionIsConfigured(ACTION_NAME)) { + executionRequirements = + featureConfiguration.getToolForAction(ACTION_NAME).getExecutionRequirements(); + } + } + return new CppLinkAction( getOwner(), inputsBuilder.deduplicate().build(), @@ -880,7 +913,8 @@ public final class CppLinkAction extends AbstractAction { fake, isLTOIndexing, allLTOArtifacts, - linkCommandLine); + linkCommandLine, + executionRequirements); } /** @@ -954,6 +988,14 @@ public final class CppLinkAction extends AbstractAction { this.crosstoolInputs = inputs; return this; } + + /** + * Sets the feature configuration for the action. + */ + public Builder setFeatureConfiguration(FeatureConfiguration featureConfiguration) { + this.featureConfiguration = featureConfiguration; + return this; + } /** * This is the LTO indexing step, rather than the real link. |