diff options
author | 2016-02-10 12:29:25 +0000 | |
---|---|---|
committer | 2016-02-10 16:34:42 +0000 | |
commit | ee9e688c3df0d5c67f8bc7a2cc1d4a0a06229c66 (patch) | |
tree | 91d7b03d5db9e467a9d5c56a97efaf7c51ab90ca /src/test | |
parent | de3e9d5c1feec29149bac6ac0e1d9f3c65e00332 (diff) |
Make implicit attribute label lookup consistent.
Previously, as of 0c8049f5fc866d785dd83769fa6c38ecf771ba96, these labels
were treated as relative to the repository of the rule in some places
but not others.
From the other commit's message:
They [implicit attribute defaults] now all point to @bazel_tools anyway,
so there is no need [to special-case them].
--
Change-Id: If337eb2579ae613ba09cab0e0c927691922c0a39
Reviewed-on: https://bazel-review.googlesource.com/#/c/2783/
MOS_MIGRATED_REVID=114313341
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java index e46c55fddf..a75c93ff57 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java @@ -659,6 +659,41 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { } @Test + public void testLabelAttributeDefault() throws Exception { + scratch.file( + "my_rule.bzl", + "def _impl(ctx):", + " return", + "my_rule = rule(", + " implementation = _impl,", + " attrs = {", + " 'explicit_dep': attr.label(default = Label('//:dep')),", + " '_implicit_dep': attr.label(default = Label('//:dep')),", + " 'explicit_dep_list': attr.label_list(default = [Label('//:dep')]),", + " '_implicit_dep_list': attr.label_list(default = [Label('//:dep')]),", + " }", + ")"); + + scratch.file( + "BUILD", "filegroup(name='dep')", "load('/my_rule', 'my_rule')", "my_rule(name='r')"); + + invalidatePackages(); + SkylarkRuleContext context = createRuleContext("@//:r"); + Label explicitDepLabel = + (Label) evalRuleContextCode(context, "ruleContext.attr.explicit_dep.label"); + assertThat(explicitDepLabel).isEqualTo(Label.parseAbsolute("@//:dep")); + Label implicitDepLabel = + (Label) evalRuleContextCode(context, "ruleContext.attr._implicit_dep.label"); + assertThat(implicitDepLabel).isEqualTo(Label.parseAbsolute("@//:dep")); + Label explicitDepListLabel = + (Label) evalRuleContextCode(context, "ruleContext.attr.explicit_dep_list[0].label"); + assertThat(explicitDepListLabel).isEqualTo(Label.parseAbsolute("@//:dep")); + Label implicitDepListLabel = + (Label) evalRuleContextCode(context, "ruleContext.attr._implicit_dep_list[0].label"); + assertThat(implicitDepListLabel).isEqualTo(Label.parseAbsolute("@//:dep")); + } + + @Test public void testRelativeLabelInExternalRepository() throws Exception { scratch.file("BUILD"); scratch.file("external_rule.bzl", |