diff options
author | Kristina Chodorow <kchodorow@google.com> | 2016-03-21 16:20:06 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2016-03-21 18:39:21 +0000 |
commit | 6f15335deac0c04cfae11623efbe745f11e177ff (patch) | |
tree | 6782a0a789abcb2e97d45c9624bbb306a0e8106a /src/test/java | |
parent | a15c426bc5dfe9aa16f22553657dee60ccf1b5f5 (diff) |
Make labels in .bzl files in remote repos resolve relative to their repo
For example, if you have a BUILD file that does:
load('@foo//bar:baz.bzl', 'my_rule')
my_rule(...)
If baz.bzl uses Label('//whatever'), this change makes //whatever resolve to
@foo//whatever. Previous to this change, it would be resolved to the repository
the BUILD file using my_rule was in.
RELNOTES[INC]: Labels in .bzl files in remote repositories will be resolved
relative to their repository (instead of the repository the Skylark rule is
used in).
--
MOS_MIGRATED_REVID=117720181
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java | 32 |
1 files changed, 31 insertions, 1 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 113ba745c3..61a6ba8d31 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 @@ -789,7 +789,6 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { @Test public void testRelativeLabelInExternalRepository() throws Exception { - scratch.file("BUILD"); scratch.file("external_rule.bzl", "def _impl(ctx):", " return", @@ -800,6 +799,37 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { " }", ")"); + scratch.file("BUILD", + "filegroup(name='dep')"); + + scratch.file("/r/a/BUILD", + "load('/external_rule', 'external_rule')", + "external_rule(name='r')"); + + scratch.overwriteFile("WORKSPACE", + "local_repository(name='r', path='/r')"); + + invalidatePackages(); + SkylarkRuleContext context = createRuleContext("@r//a:r"); + Label depLabel = (Label) evalRuleContextCode(context, "ruleContext.attr.internal_dep.label"); + assertThat(depLabel).isEqualTo(Label.parseAbsolute("//:dep")); + } + + @Test + public void testCallerRelativeLabelInExternalRepository() throws Exception { + scratch.file("BUILD"); + scratch.file("external_rule.bzl", + "def _impl(ctx):", + " return", + "external_rule = rule(", + " implementation = _impl,", + " attrs = {", + " 'internal_dep': attr.label(", + " default = Label('//:dep', relative_to_caller_repository = True)", + " )", + " }", + ")"); + scratch.file("/r/BUILD", "filegroup(name='dep')"); |