aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/shell
diff options
context:
space:
mode:
authorGravatar Danna Kelmer <dannark@google.com>2018-07-16 09:13:09 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-16 09:14:25 -0700
commit3149beb6543c50f381f91f9645f2a4da43d20c0c (patch)
tree941d788d6d52cb9dab7ab39ecabc544b3f89974d /src/test/shell
parent7e703eca32b834edc677a926c2d440e49ffdadc2 (diff)
Add implicit mapping from "@mainrepo" to "@". This fixes the issue where referencing the main repository using its name caused bazel to treat it as a separate external repository.
Closes #5586. Fixes #3115. RELNOTES: None PiperOrigin-RevId: 204752150
Diffstat (limited to 'src/test/shell')
-rwxr-xr-xsrc/test/shell/bazel/workspace_test.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/test/shell/bazel/workspace_test.sh b/src/test/shell/bazel/workspace_test.sh
index 22b7a4741b..72915a8b27 100755
--- a/src/test/shell/bazel/workspace_test.sh
+++ b/src/test/shell/bazel/workspace_test.sh
@@ -560,4 +560,66 @@ EOF
|| fail "Expected build to succeed"
}
+function test_mainrepo_name_is_not_different_repo() {
+ # Repository a refers to @x
+ mkdir -p mainrepo
+ echo "workspace(name = 'mainrepo')" > mainrepo/WORKSPACE
+ cat > mainrepo/BUILD<<EOF
+load("//:def.bzl", "a")
+load("@mainrepo//:def.bzl", "a")
+EOF
+ cat > mainrepo/def.bzl<<EOF
+print("def.bzl loaded")
+a = 1
+EOF
+
+ cd mainrepo
+ bazel query //... &>"$TEST_log" || fail "Expected query to succeed"
+ expect_log "def.bzl loaded."
+ expect_not_log "external"
+}
+
+function test_mainrepo_name_remapped_properly() {
+ mkdir -p mainrepo
+ touch mainrepo/BUILD
+ cat > mainrepo/WORKSPACE<<EOF
+workspace(name = "mainrepo")
+local_repository(
+ name = "a",
+ path = "../a"
+)
+EOF
+ cat > mainrepo/def.bzl<<EOF
+print ("def.bzl loaded")
+x = 10
+EOF
+
+ mkdir -p a
+ touch a/WORKSPACE
+ echo "load('@mainrepo//:def.bzl', 'x')"> a/BUILD
+
+ # the bzl file should be loaded from the main workspace and
+ # not as an external repository
+ cd mainrepo
+ bazel query @a//... &>"$TEST_log" || fail "Expected query to succeed"
+ expect_log "def.bzl loaded"
+ expect_not_log "external"
+
+ cd ..
+ cat > mainrepo/WORKSPACE<<EOF
+workspace(name = "mainrepo")
+local_repository(
+ name = "a",
+ path = "../a",
+ repo_mapping = {"@mainrepo" : "@newname"}
+)
+EOF
+
+ # now that @mainrepo doesn't exist within workspace "a",
+ # the query should fail
+ cd mainrepo
+ bazel query --experimental_enable_repo_mapping @a//... &>"$TEST_log" \
+ && fail "Failure expected" || true
+}
+
run_suite "workspace tests"