From 1e258d2a7a5221613047e5cee0aaec5b56045d2b Mon Sep 17 00:00:00 2001 From: John Cater Date: Mon, 1 Mar 2021 05:59:44 -0800 Subject: [PATCH] Allow exec groups to inherit from the rule or other exec groups. Work towards #12006. Add a "test" exec group for TestRunnerActions. This will allow users to set {"test.key", "value"} inside their exec properties and {"key", "value"} will propagate as to just TestRunnerActions. This addresses user request #10799 This is a rollforward of c1ae939e2e27c928dc87ca64280948d93fdb056a, which was reverted in c266ac966761c4b3d8a408a03e407505c93effdd. Closes #13119. PiperOrigin-RevId: 360168649 --- .../devtools/build/lib/analysis/BaseRuleClasses.java | 3 +++ .../build/lib/analysis/test/TestActionBuilder.java | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java index 22722a54ccc625..2797298788ae6a 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java @@ -147,6 +147,8 @@ public static LabelLateBoundDefault getCoverageOutputGenerat return runUnder != null ? runUnder.getLabel() : null; }); + public static final String TEST_RUNNER_EXEC_GROUP = "test"; + /** * A base rule for all test rules. */ @@ -154,6 +156,7 @@ public static final class TestBaseRule implements RuleDefinition { @Override public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) { return builder + .addExecGroup(TEST_RUNNER_EXEC_GROUP) .requiresConfigurationFragments(TestConfiguration.class) // TestConfiguration only needed to create TestAction and TestProvider // Only necessary at top-level and can be skipped if trimmed. diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java b/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java index 89dcd09c239217..ecb2f35a6a1795 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java @@ -14,12 +14,14 @@ package com.google.devtools.build.lib.analysis.test; +import static com.google.devtools.build.lib.analysis.BaseRuleClasses.TEST_RUNNER_EXEC_GROUP; import static com.google.devtools.build.lib.packages.BuildType.LABEL; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.devtools.build.lib.actions.ActionInput; +import com.google.devtools.build.lib.actions.ActionOwner; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.ArtifactRoot; import com.google.devtools.build.lib.actions.RunfilesSupplier; @@ -147,6 +149,11 @@ private boolean isPersistentTestRunner() { && persistentTestRunnerRunfiles != null; } + private ActionOwner getOwner() { + ActionOwner owner = ruleContext.getActionOwner(TEST_RUNNER_EXEC_GROUP); + return owner == null ? ruleContext.getActionOwner() : owner; + } + /** * Creates a test action and artifacts for the given rule. The test action will use the specified * executable and runfiles. @@ -403,7 +410,7 @@ private TestParams createTestAction(int shards) boolean splitCoveragePostProcessing = testConfiguration.splitCoveragePostProcessing(); TestRunnerAction testRunnerAction = new TestRunnerAction( - ruleContext.getActionOwner(), + getOwner(), inputs, testRunfilesSupplier, testActionExecutable,