aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar dannark <dannark@google.com>2018-06-12 09:28:45 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-12 09:30:48 -0700
commitf4b9ff40b8f1612571cc711560177af240d034d0 (patch)
tree2b2bf5415d7b4a0ab5db78d916cebfec0775f810 /src/test/shell
parent1b94e64ee8a1d385e92a8d9f4c9a06e2d99c82bf (diff)
Remap repository names inside load statements in BUILD files if the repository name is remapped.
For example if main/WORKSPACE contains: local_repository( name = "a", path = "../a", repo_mapping = {"@x" : "@y"}, ) a/BUILD load("@x//:sample.bzl", "sample") Then the load in a/BUILD will be resolved as "@y//:sample.bzl" RELNOTES: None PiperOrigin-RevId: 200227431
Diffstat (limited to 'src/test/shell')
-rwxr-xr-xsrc/test/shell/bazel/workspace_test.sh37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/test/shell/bazel/workspace_test.sh b/src/test/shell/bazel/workspace_test.sh
index 7addf93a08..a308c2adb0 100755
--- a/src/test/shell/bazel/workspace_test.sh
+++ b/src/test/shell/bazel/workspace_test.sh
@@ -381,4 +381,41 @@ EOF
expect_log "@flower//daisy:daisy"
}
+function test_repository_mapping_in_build_file_load() {
+ # Main repo assigns @x to @y within @a
+ mkdir -p main
+ cat > main/WORKSPACE <<EOF
+workspace(name = "main")
+
+local_repository(name = "a", path="../a", repo_mapping = {"@x" : "@y"})
+local_repository(name = "y", path="../y")
+EOF
+ touch main/BUILD
+
+ # Repository y is a substitute for x
+ mkdir -p y
+ touch y/WORKSPACE
+ touch y/BUILD
+ cat > y/symbol.bzl <<EOF
+Y_SYMBOL = "y_symbol"
+EOF
+
+ # Repository a refers to @x
+ mkdir -p a
+ touch a/WORKSPACE
+ cat > a/BUILD<<EOF
+load("@x//:symbol.bzl", "Y_SYMBOL")
+genrule(name = "a",
+ outs = ["result.txt"],
+ cmd = "echo %s > \$(location result.txt);" % (Y_SYMBOL)
+)
+EOF
+
+ cd main
+ bazel build --experimental_enable_repo_mapping @a//:a || fail "Expected build to succeed"
+ cat bazel-genfiles/external/a/result.txt
+ grep "y_symbol" bazel-genfiles/external/a/result.txt \
+ || fail "expected 'y_symbol' in $(cat bazel-genfiles/external/a/result.txt)"
+}
+
run_suite "workspace tests"