Add a method `ActionLookupKey#mayOwnShareableActions` that corresponds with the logic to determine whether to create a shareable `ActionLookupData`. PiperOrigin-RevId: 417444843
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionLookupData.java b/src/main/java/com/google/devtools/build/lib/actions/ActionLookupData.java index 4e4282c..573689c 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionLookupData.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionLookupData.java
@@ -36,11 +36,9 @@ * only be called once per {@code (actionLookupKey, actionIndex)} pair. */ public static ActionLookupData create(ActionLookupKey actionLookupKey, int actionIndex) { - // If the label is null, this is not a typical action (it may be the build info action or a - // coverage action, for example). Don't try to share it. - return actionLookupKey.getLabel() == null - ? createUnshareable(actionLookupKey, actionIndex) - : new ActionLookupData(actionLookupKey, actionIndex); + return actionLookupKey.mayOwnShareableActions() + ? new ActionLookupData(actionLookupKey, actionIndex) + : createUnshareable(actionLookupKey, actionIndex); } /**
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionLookupKey.java b/src/main/java/com/google/devtools/build/lib/actions/ActionLookupKey.java index c7b0095..6c609d4 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionLookupKey.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionLookupKey.java
@@ -38,4 +38,19 @@ */ @Nullable BuildConfigurationKey getConfigurationKey(); + + /** + * Returns {@code true} if this key <em>may</em> own shareable actions, as determined by {@link + * ActionLookupData#valueIsShareable}. + * + * <p>Returns {@code false} for some non-standard keys such as the build info key and coverage + * report key. + * + * <p>A return of {@code true} still requires checking {@link ActionLookupData#valueIsShareable} + * to determine whether the individual action can be shared - notably, for a test target, + * compilation actions are shareable, but test actions are not. + */ + default boolean mayOwnShareableActions() { + return getLabel() != null; + } }