aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2016-03-21 16:20:06 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-03-21 18:39:21 +0000
commit6f15335deac0c04cfae11623efbe745f11e177ff (patch)
tree6782a0a789abcb2e97d45c9624bbb306a0e8106a /src/test/shell
parenta15c426bc5dfe9aa16f22553657dee60ccf1b5f5 (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/shell')
-rwxr-xr-xsrc/test/shell/bazel/external_skylark_load_test.sh113
-rwxr-xr-xsrc/test/shell/bazel/skylark_repository_test.sh3
2 files changed, 113 insertions, 3 deletions
diff --git a/src/test/shell/bazel/external_skylark_load_test.sh b/src/test/shell/bazel/external_skylark_load_test.sh
index 5f221c088e..bd8318ad87 100755
--- a/src/test/shell/bazel/external_skylark_load_test.sh
+++ b/src/test/shell/bazel/external_skylark_load_test.sh
@@ -123,6 +123,117 @@ function test_load_skylark_from_external_repo_with_repo_relative_label_load() {
"LOCAL!"
}
-run_suite "Test Skylark loads from/in external repositories"
+function test_skylark_repository_relative_label() {
+ repo2=$TEST_TMPDIR/repo2
+ mkdir -p $repo2
+ touch $repo2/WORKSPACE $repo2/BUILD
+ cat > $repo2/remote.bzl <<EOF
+def _impl(ctx):
+ print(Label("//foo:bar"))
+
+remote_rule = rule(
+ implementation = _impl,
+)
+EOF
+
+ cat > WORKSPACE <<EOF
+local_repository(
+ name = "r",
+ path = "$repo2",
+)
+EOF
+ cat > BUILD <<EOF
+load('@r//:remote.bzl', 'remote_rule')
+
+remote_rule(name = 'local')
+EOF
+
+ bazel build //:local &> $TEST_log || fail "Building local failed"
+ expect_log "@r//foo:bar"
+ cat > $repo2/remote.bzl <<EOF
+def _impl(ctx):
+ print(Label("//foo:bar", relative_to_caller_repository = True))
+
+remote_rule = rule(
+ implementation = _impl,
+)
+EOF
+ bazel build //:local &> $TEST_log || fail "Building local failed"
+ expect_log "//foo:bar"
+}
+
+# Going one level deeper: if we have:
+# local/
+# BUILD
+# r1/
+# BUILD
+# r2/
+# BUILD
+# remote.bzl
+# If //foo in local depends on //bar in r1, which is a Skylark rule
+# defined in r2/remote.bzl, then a Label in remote.bzl should either
+# resolve to @r2//whatever or @r1//whatever.
+function test_skylark_repository_nested_relative_label() {
+ repo1=$TEST_TMPDIR/repo1
+ repo2=$TEST_TMPDIR/repo2
+ mkdir -p $repo1 $repo2
+
+ # local
+ cat > WORKSPACE <<EOF
+local_repository(
+ name = "r1",
+ path = "$repo1",
+)
+local_repository(
+ name = "r2",
+ path = "$repo2",
+)
+EOF
+ cat > BUILD <<'EOF'
+genrule(
+ name = "foo",
+ srcs = ["@r1//:bar"],
+ outs = ["foo.out"],
+ cmd = "echo '$(SRCS)' > $@",
+)
+EOF
+ # r1
+ touch $repo1/WORKSPACE
+ cat > $repo1/BUILD <<EOF
+load('@r2//:remote.bzl', 'remote_rule')
+
+remote_rule(
+ name = 'bar',
+ visibility = ["//visibility:public"]
+)
+EOF
+
+ # r2
+ touch $repo2/WORKSPACE $repo2/BUILD
+ cat > $repo2/remote.bzl <<EOF
+def _impl(ctx):
+ print(Label("//foo:bar"))
+
+remote_rule = rule(
+ implementation = _impl,
+)
+EOF
+
+ bazel build //:foo &> $TEST_log || fail "Building local failed"
+ expect_log "@r2//foo:bar"
+
+ cat > $repo2/remote.bzl <<EOF
+def _impl(ctx):
+ print(Label("//foo:bar", relative_to_caller_repository = True))
+
+remote_rule = rule(
+ implementation = _impl,
+)
+EOF
+ bazel build //:foo &> $TEST_log || fail "Building local failed"
+ expect_log "@r1//foo:bar"
+}
+
+run_suite "Test Skylark loads from/in external repositories"
diff --git a/src/test/shell/bazel/skylark_repository_test.sh b/src/test/shell/bazel/skylark_repository_test.sh
index 16f52abb6a..a79feb72e3 100755
--- a/src/test/shell/bazel/skylark_repository_test.sh
+++ b/src/test/shell/bazel/skylark_repository_test.sh
@@ -305,9 +305,8 @@ EOF
function test_skylark_repository_which_and_execute() {
setup_skylark_repository
- bazel info
-
# Test we are using the client environment, not the server one
+ bazel info &> /dev/null # Start up the server.
echo "#!/bin/bash" > bin.sh
echo "exit 0" >> bin.sh
chmod +x bin.sh