aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-04-16 13:43:00 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-16 13:44:19 -0700
commit646f281496b9c46714f15813c32d2ca846ceb322 (patch)
tree5f115ee972721cee8cef6ebb64b7291e81fe2a38 /src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
parent559ffb7dd6578c961e775ba4901917ab8bffcb9d (diff)
Introduce tools attribute to ctx.actions.run and friends.
This will allow us to stop iterating all inputs in an expensive manner looking for tools so we can add their runfiles. If users specify the 'tools' attribute, it is assumed they know what they are doing and inputs will no longer be scanned for tools. RELNOTES: Introduce 'tools' attribute to ctx.actions.run. PiperOrigin-RevId: 193092258
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
index 4e656ce3d2..918dc6d6c7 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
@@ -38,6 +38,7 @@ import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction;
import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction.Substitution;
+import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
import com.google.devtools.build.lib.analysis.skylark.SkylarkActionFactory;
import com.google.devtools.build.lib.analysis.skylark.SkylarkCustomCommandLine;
import com.google.devtools.build.lib.analysis.skylark.SkylarkRuleContext;
@@ -408,6 +409,78 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
" command = ['dummy_command', '--arg'])");
}
+ private void setupToolInInputsTest(String... ruleImpl) throws Exception {
+ ImmutableList.Builder<String> lines = ImmutableList.builder();
+ lines.add("def _main_rule_impl(ctx):");
+ for (String line : ruleImpl) {
+ lines.add(" " + line);
+ }
+ lines.add(
+ "my_rule = rule(",
+ " _main_rule_impl,",
+ " attrs = { ",
+ " 'exe' : attr.label(executable = True, allow_files = True, cfg='host'),",
+ " },",
+ ")");
+ scratch.file("bar/bar.bzl", lines.build().toArray(new String[] {}));
+ scratch.file(
+ "bar/BUILD",
+ "load('//bar:bar.bzl', 'my_rule')",
+ "sh_binary(",
+ " name = 'mytool',",
+ " srcs = ['mytool.sh'],",
+ " data = ['file1.dat', 'file2.dat'],",
+ ")",
+ "my_rule(",
+ " name = 'my_rule',",
+ " exe = ':mytool',",
+ ")");
+ }
+
+ @Test
+ public void testCreateSpawnActionWithToolInInputsLegacy() throws Exception {
+ setupToolInInputsTest(
+ "output = ctx.actions.declare_file('bar.out')",
+ "ctx.actions.run_shell(",
+ " inputs = ctx.attr.exe.files,",
+ " outputs = [output],",
+ " command = 'boo bar baz',",
+ ")");
+ RuleConfiguredTarget target = (RuleConfiguredTarget) getConfiguredTarget("//bar:my_rule");
+ SpawnAction action = (SpawnAction) Iterables.getOnlyElement(target.getActions());
+ assertThat(action.getTools()).isNotEmpty();
+ }
+
+ @Test
+ public void testCreateSpawnActionWithToolAttribute() throws Exception {
+ setupToolInInputsTest(
+ "output = ctx.actions.declare_file('bar.out')",
+ "ctx.actions.run_shell(",
+ " inputs = [],",
+ " tools = ctx.attr.exe.files,",
+ " outputs = [output],",
+ " command = 'boo bar baz',",
+ ")");
+ RuleConfiguredTarget target = (RuleConfiguredTarget) getConfiguredTarget("//bar:my_rule");
+ SpawnAction action = (SpawnAction) Iterables.getOnlyElement(target.getActions());
+ assertThat(action.getTools()).isNotEmpty();
+ }
+
+ @Test
+ public void testCreateSpawnActionWithToolAttributeIgnoresToolsInInputs() throws Exception {
+ setupToolInInputsTest(
+ "output = ctx.actions.declare_file('bar.out')",
+ "ctx.actions.run_shell(",
+ " inputs = ctx.attr.exe.files,",
+ " tools = ctx.attr.exe.files,",
+ " outputs = [output],",
+ " command = 'boo bar baz',",
+ ")");
+ RuleConfiguredTarget target = (RuleConfiguredTarget) getConfiguredTarget("//bar:my_rule");
+ SpawnAction action = (SpawnAction) Iterables.getOnlyElement(target.getActions());
+ assertThat(action.getTools()).isNotEmpty();
+ }
+
@Test
public void testCreateFileAction() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");