aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java
diff options
context:
space:
mode:
authorGravatar Florian Weikert <fwe@google.com>2017-01-30 14:42:50 +0000
committerGravatar Yun Peng <pcloudy@google.com>2017-01-30 15:35:42 +0000
commitba40525a033d4170534abb47d200fce7fe637527 (patch)
tree56341b92423cfeec3ce0d403de243fb5a4bdaf95 /src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java
parent855fbe9ee447b7b37fd8c73dbc047d69b7ceffcf (diff)
Fix the translation of names of implicit or latebound attributes to their Skylark equivalent (from '$attr' and ':attr' to '_attr').
This CL eliminates duplicate code and makes sure that attribute names in SkylarkClassObjects are properly translated. -- PiperOrigin-RevId: 145986380 MOS_MIGRATED_REVID=145986380
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java55
1 files changed, 49 insertions, 6 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java
index fb86314aaa..60da09e1e9 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkIntegrationTest.java
@@ -691,20 +691,20 @@ public class SkylarkIntegrationTest extends BuildViewTestCase {
" ftb = depset(files)",
" return struct(runfiles = ctx.runfiles(), files = ftb)",
"",
- "def output_func(attr1, attr2):",
- " if attr2 != None: return {}",
- " return {'o': attr1 + '.txt'}",
+ "def output_func(public_attr, _private_attr):",
+ " if _private_attr != None: return {}",
+ " return {'o': public_attr + '.txt'}",
"",
"custom_rule = rule(implementation = custom_rule_impl,",
- " attrs = {'attr1': attr.string(),",
- " 'attr2': attr.label()},",
+ " attrs = {'public_attr': attr.string(),",
+ " '_private_attr': attr.label()},",
" outputs = output_func)");
scratch.file(
"test/skylark/BUILD",
"load('/test/skylark/extension', 'custom_rule')",
"",
- "custom_rule(name = 'cr', attr1 = 'bar')");
+ "custom_rule(name = 'cr', public_attr = 'bar')");
ConfiguredTarget target = getConfiguredTarget("//test/skylark:cr");
@@ -715,6 +715,49 @@ public class SkylarkIntegrationTest extends BuildViewTestCase {
}
@Test
+ public void testRuleClassImplicitOutputFunctionDependingOnComputedAttribute() throws Exception {
+ scratch.file(
+ "test/skylark/extension.bzl",
+ "def custom_rule_impl(ctx):",
+ " files = [ctx.outputs.o]",
+ " ctx.action(",
+ " outputs = files,",
+ " command = 'echo')",
+ " ftb = depset(files)",
+ " return struct(runfiles = ctx.runfiles(), files = ftb)",
+ "",
+ "def attr_func(public_attr):",
+ " return public_attr",
+ "",
+ "def output_func(_private_attr):",
+ " return {'o': _private_attr.name + '.txt'}",
+ "",
+ "custom_rule = rule(implementation = custom_rule_impl,",
+ " attrs = {'public_attr': attr.label(),",
+ " '_private_attr': attr.label(default = attr_func)},",
+ " outputs = output_func)",
+ "",
+ "def empty_rule_impl(ctx):",
+ " pass",
+ "",
+ "empty_rule = rule(implementation = empty_rule_impl)");
+
+ scratch.file(
+ "test/skylark/BUILD",
+ "load('/test/skylark/extension', 'custom_rule', 'empty_rule')",
+ "",
+ "empty_rule(name = 'foo')",
+ "custom_rule(name = 'cr', public_attr = '//test/skylark:foo')");
+
+ ConfiguredTarget target = getConfiguredTarget("//test/skylark:cr");
+
+ assertThat(
+ ActionsTestUtil.baseArtifactNames(
+ target.getProvider(FileProvider.class).getFilesToBuild()))
+ .containsExactly("foo.txt");
+ }
+
+ @Test
public void testRuleClassImplicitOutputs() throws Exception {
scratch.file(
"test/skylark/extension.bzl",