Skip to content

Commit

Permalink
Disable WORKSPACE for a couple of straggler repo tests
Browse files Browse the repository at this point in the history
Fixes #23241.
Fixes #23234.
  • Loading branch information
Wyverald committed Sep 10, 2024
1 parent aed6a40 commit 035706c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
41 changes: 22 additions & 19 deletions src/test/shell/bazel/check_external_files_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ if "$is_windows"; then
export MSYS2_ARG_CONV_EXCL="*"
fi

# TODO: https://github.com/bazelbuild/bazel/issues/23241
disable_bzlmod

function get_extrepourl() {
if $is_windows; then
echo "file:///$(cygpath -m $1)"
Expand All @@ -81,8 +78,8 @@ setup_remote() {

mkdir main
cd main
cat >> "WORKSPACE" <<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
cat >> "MODULE.bazel" <<EOF
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name="remote",
strip_prefix="remote",
Expand All @@ -98,14 +95,14 @@ setup_local() {
mkdir local_rep
(
cd local_rep
touch WORKSPACE
touch REPO.bazel
echo 'genrule(name="g", outs=["go"], cmd="echo GO > $@")' > BUILD
)

mkdir main
cd main
cat >> "WORKSPACE" <<EOF
load("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
cat >> "MODULE.bazel" <<EOF
local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
local_repository(
name="local_rep",
path="../local_rep",
Expand All @@ -117,12 +114,12 @@ test_check_external_files() {
setup_remote
bazel build @remote//:g >& "$TEST_log" || fail "Expected build to succeed"

echo "broken file" > bazel-main/external/remote/BUILD
echo "broken file" > bazel-main/external/+_repo_rules+remote/BUILD
# The --noexperimental_check_external_repository_files flag doesn't notice the file is broken
bazel build --noexperimental_check_external_repository_files @remote//:g >& "$TEST_log" || fail "Expected build to succeed"

bazel build @remote//:g >& "$TEST_log" && fail "Expected build to fail" || true
expect_log "no such target '@@remote//:g'"
expect_log "no such target '@@+_repo_rules+remote//:g'"
}

test_check_all_flags_fast() {
Expand All @@ -133,7 +130,7 @@ test_check_all_flags_fast() {
instances=$(grep -c "$msg" "$(bazel info server_log)")
[[ $instances -eq 1 ]] || fail "Should have only been 1 instance, got $instances"

echo "broken file" > bazel-main/external/remote/BUILD
echo "broken file" > bazel-main/external/+_repo_rules+remote/BUILD

bazel build \
--noexperimental_check_external_repository_files \
Expand All @@ -159,7 +156,7 @@ run_local_repository_isnt_affected() {
$extra_args \
@local_rep//:g >& "$TEST_log" && fail "Expected build to fail" || true
bazel build --noexperimental_check_external_repository_files @local_rep//:g >& "$TEST_log" && fail "Expected build to fail" || true
expect_log "no such target '@@local_rep//:g'"
expect_log "no such target '@@+_repo_rules+local_rep//:g'"
}

test_local_repository_isnt_affected() {
Expand All @@ -175,11 +172,18 @@ run_override_repository_isnt_affected() {
shift

setup_local
echo > WORKSPACE
# intentionally put a wrong path in MODULE.bazel
cat > "MODULE.bazel" <<EOF
local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
local_repository(
name="local_rep",
path="../local_repkasjdf",
)
EOF
bazel build @local_rep//:g >& "$TEST_log" && fail "Expected build to fail" || true
expect_log "no such package '@@local_rep//'"
expect_log "but it does not exist or is not a directory"

argv="--override_repository=local_rep=$(pwd)/../local_rep"
argv="--override_repository=+_repo_rules+local_rep=$(pwd)/../local_rep"
bazel build "$argv" $extra_args @local_rep//:g >& "$TEST_log" || fail "Expected build to succeed"

echo "broken file" > ../local_rep/BUILD
Expand All @@ -189,7 +193,7 @@ run_override_repository_isnt_affected() {
"$argv" \
$extra_args \
@local_rep//:g >& "$TEST_log" && fail "Expected build to fail" || true
expect_log "no such target '@@local_rep//:g'"
expect_log "no such target '@@+_repo_rules+local_rep//:g'"
}

test_override_repository_isnt_affected() {
Expand All @@ -207,7 +211,6 @@ test_no_fetch_then_fetch() {
--noexperimental_check_output_files \
--watchfs \
@remote//:g >& "$TEST_log" && fail "Expected build to fail" || true
expect_log "no such package"
expect_log "fetching repositories is disabled"
bazel build \
--fetch \
Expand All @@ -225,7 +228,7 @@ test_no_build_doesnt_break_the_cache() {
--noexperimental_check_output_files \
--watchfs \
@remote//:g >& "$TEST_log" || fail "Expected build to pass"
[[ ! -f bazel-main/external/remote/BUILD ]] || fail "external files shouldn't have been made"
[[ ! -f bazel-main/external/+_repo_rules+remote/BUILD ]] || fail "external files shouldn't have been made"
bazel build \
--noexperimental_check_external_repository_files \
--noexperimental_check_output_files \
Expand All @@ -236,7 +239,7 @@ test_no_build_doesnt_break_the_cache() {
test_symlink_outside_still_checked() {
mkdir main
cd main
touch WORKSPACE
touch MODULE.bazel
echo 'sh_test(name = "symlink", srcs = ["symlink.sh"])' > BUILD

mkdir ../foo
Expand Down
27 changes: 9 additions & 18 deletions src/test/shell/bazel/external_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,8 @@ function test_deferred_download_two_parallel_downloads() {

startup_server "${server_dir}"

# TODO: https://github.com/bazelbuild/bazel/issues/23234
# This test hangs after moving to MODULE.bazel
cat > WORKSPACE <<'EOF'
load("defer.bzl", "defer")
cat > $(setup_module_dot_bazel) <<'EOF'
defer = use_repo_rule("//:defer.bzl", "defer")
defer(name="defer")
EOF

Expand Down Expand Up @@ -491,7 +488,7 @@ EOF
touch BUILD

# Start Bazel
bazel query --enable_workspace @defer//:all >& $TEST_log &
bazel query @defer//:all >& $TEST_log &
local bazel_pid=$!

# Wait until the .download() calls return
Expand All @@ -515,11 +512,8 @@ EOF
}

function test_deferred_download_error() {
# TODO: https://github.com/bazelbuild/bazel/issues/23234
# This test hangs after moving to MODULE.bazel
cat > WORKSPACE <<'EOF'
load("//:defer.bzl", "defer")
cat > $(setup_module_dot_bazel) <<'EOF'
defer = use_repo_rule("//:defer.bzl", "defer")
defer(name="defer")
EOF

Expand All @@ -532,7 +526,6 @@ def _defer_impl(rctx):
deferred.wait()
print("survived wait")
rctx.file("WORKSPACE", "")
rctx.file("BUILD", "filegroup(name='f', srcs=glob(['**']))")
defer = repository_rule(implementation = _defer_impl)
Expand All @@ -541,7 +534,7 @@ EOF
touch BUILD

# Start Bazel
bazel query --enable_workspace @defer//:all >& $TEST_log && fail "Bazel unexpectedly succeeded"
bazel query @defer//:all >& $TEST_log && fail "Bazel unexpectedly succeeded"
expect_log "Error downloading.*doesnotexist"
expect_not_log "survived wait"
}
Expand All @@ -560,10 +553,8 @@ function test_deferred_download_smoke() {

startup_server "${server_dir}"

# TODO: https://github.com/bazelbuild/bazel/issues/23234
# This test hangs after moving to MODULE.bazel
cat > WORKSPACE <<'EOF'
load("defer.bzl", "defer")
cat > $(setup_module_dot_bazel) <<'EOF'
defer = use_repo_rule("//:defer.bzl", "defer")
defer(name="defer")
EOF

Expand All @@ -587,7 +578,7 @@ EOF
touch BUILD

# Start Bazel
bazel query --enable_workspace @defer//:all-targets >& $TEST_log &
bazel query @defer//:all-targets >& $TEST_log &
local bazel_pid=$!

# Wait until the .download() call returns
Expand Down

0 comments on commit 035706c

Please sign in to comment.