Allow overriding of skyfunctions in the skyframe executor and increase visibility of some classes / methods.
PiperOrigin-RevId: 269626190
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Rule.java b/src/main/java/com/google/devtools/build/lib/packages/Rule.java
index 052c2fe..97090c7 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Rule.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Rule.java
@@ -41,14 +41,14 @@
import java.util.Set;
/**
- * An instance of a build rule in the build language. A rule has a name, a
- * package to which it belongs, a class such as <code>cc_library</code>, and
- * set of typed attributes. The set of attribute names and types is a property
- * of the rule's class. The use of the term "class" here has nothing to do
- * with Java classes. All rules are implemented by the same Java classes, Rule
- * and RuleClass.
+ * An instance of a build rule in the build language. A rule has a name, a package to which it
+ * belongs, a class such as <code>cc_library</code>, and set of typed attributes. The set of
+ * attribute names and types is a property of the rule's class. The use of the term "class" here has
+ * nothing to do with Java classes. All rules are implemented by the same Java classes, Rule and
+ * RuleClass.
*
* <p>Here is a typical rule as it appears in a BUILD file:
+ *
* <pre>
* cc_library(name = 'foo',
* defines = ['-Dkey=value'],
@@ -56,7 +56,8 @@
* deps = ['bar'])
* </pre>
*/
-public final class Rule implements Target, DependencyFilter.AttributeInfoProvider {
+// Non-final only for mocking in tests. Do not subclass!
+public class Rule implements Target, DependencyFilter.AttributeInfoProvider {
/** Label predicate that allows every label. */
public static final Predicate<Label> ALL_LABELS = Predicates.alwaysTrue();
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index c00e171..1a993ba 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -462,9 +462,10 @@
// TODO(janakr): use this semaphore to bound memory usage for SkyFunctions besides
// ConfiguredTargetFunction that may have a large temporary memory blow-up.
Semaphore cpuBoundSemaphore = new Semaphore(ResourceUsage.getAvailableProcessors());
- // We use an immutable map builder for the nice side effect that it throws if a duplicate key
- // is inserted.
- ImmutableMap.Builder<SkyFunctionName, SkyFunction> map = ImmutableMap.builder();
+
+ // We don't check for duplicates in order to allow extraSkyfunctions to override existing
+ // entries.
+ Map<SkyFunctionName, SkyFunction> map = new HashMap<>();
map.put(SkyFunctions.PRECOMPUTED, new PrecomputedFunction());
map.put(SkyFunctions.CLIENT_ENVIRONMENT_VARIABLE, new ClientEnvironmentFunction(clientEnv));
map.put(SkyFunctions.ACTION_ENVIRONMENT_VARIABLE, new ActionEnvironmentFunction());
@@ -610,7 +611,7 @@
map.put(SkyFunctions.RESOLVED_FILE, new ResolvedFileFunction());
map.put(SkyFunctions.PLATFORM_MAPPING, new PlatformMappingFunction());
map.putAll(extraSkyFunctions);
- return map.build();
+ return ImmutableMap.copyOf(map);
}
protected boolean traverseTestSuites() {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java
index a4eeb4c..e06d4f3 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TransitiveBaseTraversalFunction.java
@@ -59,7 +59,7 @@
* target' aspects' dependencies via {@link #processDeps}. Finally, it calls {@link
* #computeSkyValue} with the {#code ProcessedTargets} to get the {@link SkyValue} to return.
*/
-abstract class TransitiveBaseTraversalFunction<ProcessedTargetsT> implements SkyFunction {
+public abstract class TransitiveBaseTraversalFunction<ProcessedTargetsT> implements SkyFunction {
/**
* Returns a {@link SkyKey} corresponding to the traversal of a target specified by {@code label}
* and its transitive dependencies.
@@ -333,10 +333,10 @@
}
/**
- * Used to declare all the exception types that can be wrapped in the exception thrown by
- * {@link TransitiveTraversalFunction#compute}.
+ * Used to declare all the exception types that can be wrapped in the exception thrown by {@link
+ * TransitiveTraversalFunction#compute}.
*/
- static class TransitiveBaseTraversalFunctionException extends SkyFunctionException {
+ public static class TransitiveBaseTraversalFunctionException extends SkyFunctionException {
/**
* Used to propagate an error from a direct target dependency to the target that depended on
* it.