C++: Remove usages of rule context from CcCompilationHelper
The Starlark API won't take the rule context. Here we replace usages of rule context in CcCompilationHelper with other fields. We still pass the context to CcCompilationHelper because this will be done incrementally over several CLs.
RELNOTES:none
PiperOrigin-RevId: 231939377
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index 4e00092..5b2dbf4 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -751,10 +751,7 @@
return getUniqueDirectoryArtifact(uniqueDirectorySuffix, relative, getBinOrGenfilesDirectory());
}
- /**
- * Creates an artifact in a directory that is unique to the rule, thus guaranteeing that it never
- * clashes with artifacts created by other rules.
- */
+ @Override
public Artifact getUniqueDirectoryArtifact(
String uniqueDirectory, PathFragment relative, ArtifactRoot root) {
return getDerivedArtifact(getUniqueDirectory(uniqueDirectory).getRelative(relative), root);
@@ -1402,10 +1399,7 @@
return outs.get(0);
}
- /**
- * Returns an artifact with a given file extension. All other path components
- * are the same as in {@code pathFragment}.
- */
+ @Override
public final Artifact getRelatedArtifact(PathFragment pathFragment, String extension) {
PathFragment file = FileSystemUtils.replaceExtension(pathFragment, extension);
return getDerivedArtifact(file, getConfiguration().getBinDirectory(rule.getRepository()));
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/ActionConstructionContext.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/ActionConstructionContext.java
index ce9c327..5fed24e9 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/ActionConstructionContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/ActionConstructionContext.java
@@ -73,6 +73,12 @@
Artifact getImplicitOutputArtifact(ImplicitOutputsFunction function) throws InterruptedException;
/**
+ * Returns an artifact with a given file extension. All other path components are the same as in
+ * {@code pathFragment}.
+ */
+ Artifact getRelatedArtifact(PathFragment pathFragment, String extension);
+
+ /**
* Creates an artifact in a directory that is unique to the rule, thus guaranteeing that it never
* clashes with artifacts created by other rules.
*
@@ -89,6 +95,13 @@
Artifact getUniqueDirectoryArtifact(String uniqueDirectorySuffix, PathFragment relative);
/**
+ * Creates an artifact in a directory that is unique to the rule, thus guaranteeing that it never
+ * clashes with artifacts created by other rules.
+ */
+ Artifact getUniqueDirectoryArtifact(
+ String uniqueDirectory, PathFragment relative, ArtifactRoot root);
+
+ /**
* Returns a path fragment qualified by the rule name and unique fragment to
* disambiguate artifacts produced from the source file appearing in
* multiple rules.
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
index 9853f7b..df507ac 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
@@ -610,7 +610,8 @@
return false;
}
if (targetUnchecked == Runtime.NONE) {
- return InstrumentedFilesCollector.shouldIncludeLocalSources(ruleContext);
+ return InstrumentedFilesCollector.shouldIncludeLocalSources(
+ ruleContext.getConfiguration(), ruleContext.getLabel(), ruleContext.isTestTarget());
}
TransitiveInfoCollection target = (TransitiveInfoCollection) targetUnchecked;
return (target.get(InstrumentedFilesInfo.SKYLARK_CONSTRUCTOR) != null)
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesCollector.java b/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesCollector.java
index e10f4fc..4bd6348 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesCollector.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/test/InstrumentedFilesCollector.java
@@ -158,7 +158,8 @@
// Local sources.
NestedSet<Artifact> localSources = NestedSetBuilder.emptySet(Order.STABLE_ORDER);
- if (shouldIncludeLocalSources(ruleContext)) {
+ if (shouldIncludeLocalSources(
+ ruleContext.getConfiguration(), ruleContext.getLabel(), ruleContext.isTestTarget())) {
NestedSetBuilder<Artifact> localSourcesBuilder = NestedSetBuilder.stableOrder();
for (TransitiveInfoCollection dep :
getAllPrerequisites(ruleContext, spec.sourceAttributes)) {
@@ -205,15 +206,6 @@
}
/**
- * Return whether the sources of the rule in {@code ruleContext} should be instrumented based on
- * the --instrumentation_filter and --instrument_test_targets config settings.
- */
- public static boolean shouldIncludeLocalSources(RuleContext ruleContext) {
- return shouldIncludeLocalSources(ruleContext.getConfiguration(), ruleContext.getLabel(),
- ruleContext.isTestTarget());
- }
-
- /**
* Return whether the sources included by {@code target} (a {@link TransitiveInfoCollection}
* representing a rule) should be instrumented according the --instrumentation_filter and
* --instrument_test_targets settings in {@code config}.
@@ -224,8 +216,12 @@
target.getProvider(TestProvider.class) != null);
}
- private static boolean shouldIncludeLocalSources(BuildConfiguration config, Label label,
- boolean isTest) {
+ /**
+ * Return whether the sources of the rule in {@code ruleContext} should be instrumented based on
+ * the --instrumentation_filter and --instrument_test_targets config settings.
+ */
+ public static boolean shouldIncludeLocalSources(
+ BuildConfiguration config, Label label, boolean isTest) {
return ((config.shouldInstrumentTestTargets() || !isTest)
&& config.getInstrumentationFilter().isIncluded(label.toString()));
}