aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Sergio Campama <kaipi@google.com>2017-01-20 15:48:33 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2017-01-23 09:49:56 +0000
commit9c390fbe4acee09c75034b94553deef7870df5a3 (patch)
tree864d09b09393377b1dc203fe7d4a7e8230319568
parent88eca6e4f3951fe0ee1be3306bfb85f560bc046a (diff)
Enables passing local as an execution requirement through the ExecutionInfoProvider.
-- PiperOrigin-RevId: 145084927 MOS_MIGRATED_REVID=145084927
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/test/TestTargetProperties.java12
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/test/SkylarkTestingModuleTest.java40
2 files changed, 44 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/TestTargetProperties.java b/src/main/java/com/google/devtools/build/lib/rules/test/TestTargetProperties.java
index c455933424..839a6fee73 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/test/TestTargetProperties.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/test/TestTargetProperties.java
@@ -78,7 +78,8 @@ public class TestTargetProperties {
size = TestSize.getTestSize(rule);
timeout = TestTimeout.getTestTimeout(rule);
tags = ruleContext.attributes().get("tags", Type.STRING_LIST);
- isLocal = TargetUtils.isLocalTestRule(rule) || TargetUtils.isExclusiveTestRule(rule);
+ boolean isTaggedLocal = TargetUtils.isLocalTestRule(rule)
+ || TargetUtils.isExclusiveTestRule(rule);
// We need to use method on ruleConfiguredTarget to perform validation.
isFlaky = ruleContext.attributes().get("flaky", Type.BOOLEAN);
@@ -86,15 +87,22 @@ public class TestTargetProperties {
Map<String, String> executionInfo = Maps.newLinkedHashMap();
executionInfo.putAll(TargetUtils.getExecutionInfo(rule));
- if (isLocal) {
+ if (isTaggedLocal) {
executionInfo.put("local", "");
}
+
+ boolean isRequestedLocalByProvider = false;
if (executionRequirements != null) {
// This will overwrite whatever TargetUtils put there, which might be confusing.
executionInfo.putAll(executionRequirements.getExecutionInfo());
+
+ // We also need to mark it as local if the execution requirements specifies it.
+ isRequestedLocalByProvider = executionRequirements.getExecutionInfo().containsKey("local");
}
this.executionInfo = ImmutableMap.copyOf(executionInfo);
+ isLocal = isTaggedLocal || isRequestedLocalByProvider;
+
language = TargetUtils.getRuleLanguage(rule);
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/test/SkylarkTestingModuleTest.java b/src/test/java/com/google/devtools/build/lib/rules/test/SkylarkTestingModuleTest.java
index 021a96340d..4cde8ce3b5 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/test/SkylarkTestingModuleTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/test/SkylarkTestingModuleTest.java
@@ -31,10 +31,10 @@ public class SkylarkTestingModuleTest extends BuildViewTestCase {
scratch.file(
"examples/rule/apple_rules.bzl",
"def my_rule_impl(ctx):",
- " exec_info = testing.ExecutionInfo({'requires-darwin': '1'})",
- " return [exec_info]",
+ " exec_info = testing.ExecutionInfo({'requires-darwin': '1'})",
+ " return [exec_info]",
"my_rule = rule(implementation = my_rule_impl,",
- " attrs = {},",
+ " attrs = {},",
")");
scratch.file(
"examples/apple_skylark/BUILD",
@@ -58,10 +58,10 @@ public class SkylarkTestingModuleTest extends BuildViewTestCase {
scratch.file(
"examples/rule/apple_rules.bzl",
"def my_rule_impl(ctx):",
- " test_env = testing.TestEnvironment({'XCODE_VERSION_OVERRIDE': '7.3.1'})",
- " return [test_env]",
+ " test_env = testing.TestEnvironment({'XCODE_VERSION_OVERRIDE': '7.3.1'})",
+ " return [test_env]",
"my_rule = rule(implementation = my_rule_impl,",
- " attrs = {},",
+ " attrs = {},",
")");
scratch.file(
"examples/apple_skylark/BUILD",
@@ -78,4 +78,32 @@ public class SkylarkTestingModuleTest extends BuildViewTestCase {
assertThat(provider.getEnvironment().get("XCODE_VERSION_OVERRIDE")).isEqualTo("7.3.1");
}
+
+ @Test
+ public void testExecutionInfoProviderCanMarkTestAsLocal() throws Exception {
+ scratch.file("examples/rule/BUILD");
+ scratch.file(
+ "examples/rule/apple_rules.bzl",
+ "def my_rule_test_impl(ctx):",
+ " exec_info = testing.ExecutionInfo({'local': ''})",
+ " ctx.file_action(ctx.outputs.executable, '', True)",
+ " return [exec_info]",
+ "my_rule_test = rule(implementation = my_rule_test_impl,",
+ " test = True,",
+ " attrs = {},",
+ ")");
+ scratch.file(
+ "examples/apple_skylark/BUILD",
+ "package(default_visibility = ['//visibility:public'])",
+ "load('/examples/rule/apple_rules', 'my_rule_test')",
+ "my_rule_test(",
+ " name = 'my_target',",
+ ")");
+
+ ConfiguredTarget skylarkTarget = getConfiguredTarget("//examples/apple_skylark:my_target");
+ TestRunnerAction testAction = (TestRunnerAction) getGeneratingAction(
+ TestProvider.getTestStatusArtifacts(skylarkTarget).get(0));
+
+ assertThat(testAction.getTestProperties().isLocal()).isTrue();
+ }
}