From e377515c09eecda8bfb2e28493330b19dc373714 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 8 Aug 2024 04:17:36 -0700 Subject: [PATCH] Make sure external_* tests work with --enable_workspace=false A part of https://github.com/bazelbuild/bazel/pull/23087 Working towards: https://github.com/bazelbuild/bazel/issues/23023 PiperOrigin-RevId: 660778111 Change-Id: I98469a867733204aa6d2e428d36faba60fa91cb6 --- .../shell/bazel/external_correctness_test.sh | 54 +-- .../shell/bazel/external_integration_test.sh | 439 ++++++++++-------- .../shell/bazel/external_patching_test.sh | 72 ++- src/test/shell/bazel/external_path_test.sh | 53 ++- .../shell/bazel/external_remote_file_test.sh | 66 +-- .../bazel/external_starlark_execute_test.sh | 10 +- .../bazel/external_starlark_load_test.sh | 20 +- 7 files changed, 366 insertions(+), 348 deletions(-) diff --git a/src/test/shell/bazel/external_correctness_test.sh b/src/test/shell/bazel/external_correctness_test.sh index b09e052a8d7359..9d612a3d211a1e 100755 --- a/src/test/shell/bazel/external_correctness_test.sh +++ b/src/test/shell/bazel/external_correctness_test.sh @@ -25,7 +25,7 @@ function set_up() { # Set up empty remote repo. mkdir -p $REMOTE - touch $REMOTE/WORKSPACE + touch $REMOTE/REPO.bazel cat > $REMOTE/BUILD < $LOCAL/WORKSPACE < $LOCAL/MODULE.bazel < $TEST_log || fail "Build failed" - assert_contains "bazel-out/.*-fastbuild/.*/external/a/b/c" \ - "bazel-genfiles/external/a/b/c/d" + assert_contains "bazel-out/.*-fastbuild/.*/external/+_repo_rules+a/b/c" \ + "bazel-genfiles/external/+_repo_rules+a/b/c/d" } function test_package_group_in_external_repos() { REMOTE=$TEST_TMPDIR/r mkdir -p $REMOTE/v $REMOTE/a v a - touch $REMOTE/WORKSPACE + touch $REMOTE/REPO.bazel echo 'filegroup(name="rv", srcs=["//:fg"])' > $REMOTE/v/BUILD echo 'filegroup(name="ra", srcs=["//:fg"])' > $REMOTE/a/BUILD @@ -160,14 +161,14 @@ package_group(name="pg", packages=["//v"]) filegroup(name="fg", visibility=[":pg"]) EOF - echo "local_repository(name='r', path='$REMOTE')" > WORKSPACE + echo "local_repository(name='r', path='$REMOTE')" >> MODULE.bazel bazel build @r//v:rv >& $TEST_log || fail "Build failed" bazel build @r//a:ra >& $TEST_log && fail "Build succeeded" - expect_log "target '@@r//:fg' is not visible" + expect_log "target '@@+_repo_rules+r//:fg' is not visible" bazel build //a:ma >& $TEST_log && fail "Build succeeded" - expect_log "target '@@r//:fg' is not visible" + expect_log "target '@@+_repo_rules+r//:fg' is not visible" bazel build //v:mv >& $TEST_log && fail "Build succeeded" - expect_log "target '@@r//:fg' is not visible" + expect_log "target '@@+_repo_rules+r//:fg' is not visible" } @@ -176,7 +177,7 @@ function test_refs_btwn_repos() { REMOTE1=$TEST_TMPDIR/remote1 REMOTE2=$TEST_TMPDIR/remote2 mkdir -p $REMOTE1 $REMOTE2 - touch $REMOTE1/WORKSPACE $REMOTE2/WORKSPACE + touch $REMOTE1/REPO.bazel $REMOTE2/REPO.bazel cat > $REMOTE1/input < WORKSPACE <> MODULE.bazel < $TEST_log || fail "Build failed" - assert_contains 1.0 bazel-genfiles/external/remote2/x.out + assert_contains 1.0 bazel-genfiles/external/+_repo_rules+remote2/x.out } function test_visibility_attributes_in_external_repos() { REMOTE=$TEST_TMPDIR/r mkdir -p $REMOTE/v $REMOTE/r - touch $REMOTE/WORKSPACE + touch $REMOTE/REPO.bazel cat > $REMOTE/r/BUILD < WORKSPACE <> MODULE.bazel <& $TEST_log && fail "Build succeeded" - expect_log "target '@@r//r:fg1' is not visible" + expect_log "target '@@+_repo_rules+r//r:fg1' is not visible" } function test_select_in_external_repo() { REMOTE=$TEST_TMPDIR/r mkdir -p $REMOTE/a $REMOTE/c d - touch $REMOTE/WORKSPACE + touch $REMOTE/REPO.bazel cat > $REMOTE/a/BUILD <<'EOF' genrule( @@ -265,7 +266,7 @@ package(default_visibility=["//visibility:public"]) config_setting(name = "one", values = { "define": "ARG=one" }) EOF - cat > WORKSPACE <> MODULE.bazel < m/WORKSPACE <<'EOF' + cat > $(setup_module_dot_bazel "m/MODULE.bazel") <<'EOF' +new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository") new_local_repository( name = "r", path = "../r", @@ -310,18 +312,18 @@ genrule( )""", ) EOF - write_default_lockfile "m/MODULE.bazel.lock" + cd m bazel "$batch_flag" build @r//:fg &> $TEST_log || \ fail "Expected build to succeed" touch ../r/three bazel "$batch_flag" build @r//:fg &> $TEST_log || \ fail "Expected build to succeed" - assert_contains "external/r/three" bazel-genfiles/external/r/fg.out + assert_contains "external/+_repo_rules+r/three" bazel-genfiles/external/+_repo_rules+r/fg.out touch ../r/subdir/four bazel "$batch_flag" build @r//:fg &> $TEST_log || \ fail "Expected build to succeed" - assert_contains "external/r/subdir/four" bazel-genfiles/external/r/fg.out + assert_contains "external/+_repo_rules+r/subdir/four" bazel-genfiles/external/+_repo_rules+r/fg.out } function test_top_level_dir_changes_batch() { diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh index bf14e71adeeabc..a36fc10e29583c 100755 --- a/src/test/shell/bazel/external_integration_test.sh +++ b/src/test/shell/bazel/external_integration_test.sh @@ -32,7 +32,7 @@ java_binary( name = "ball-pit", srcs = ["BallPit.java"], main_class = "BallPit", - deps = ["//external:mongoose"], + deps = ["@endangered//jar"], ) EOF @@ -56,17 +56,17 @@ tear_down() { function zip_up() { repo2_zip=$TEST_TMPDIR/fox.zip - zip -0 -ry $repo2_zip WORKSPACE fox + zip -0 -ry $repo2_zip MODULE.bazel fox } function tar_gz_up() { repo2_zip=$TEST_TMPDIR/fox.tar.gz - tar czf $repo2_zip WORKSPACE fox + tar czf $repo2_zip MODULE.bazel fox } function tar_xz_up() { repo2_zip=$TEST_TMPDIR/fox.tar.xz - tar cJf $repo2_zip WORKSPACE fox + tar cJf $repo2_zip MODULE.bazel fox } # Test downloading a file from a repository. @@ -97,7 +97,7 @@ function http_archive_helper() { rm -rf $repo2 mkdir -p $repo2/fox cd $repo2 - create_workspace_with_default_repos WORKSPACE + setup_module_dot_bazel cat > fox/BUILD <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < zoo/female.sh <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <" cat "${marker_file}" echo "" @@ -343,8 +344,8 @@ function test_cached_across_server_restart() { function test_jar_download() { serve_jar - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) <<'EOF' -load("hang.bzl", "hang") + cat >> $(setup_module_dot_bazel) <<'EOF' +hang = use_repo_rule("//:hang.bzl", "hang") hang(name="hang") EOF @@ -453,7 +454,9 @@ function test_deferred_download_two_parallel_downloads() { startup_server "${server_dir}" - cat >> $(create_workspace_with_default_repos WORKSPACE) <<'EOF' + # TODO: https://github.com/bazelbuild/bazel/issues/23234 + # This test hangs after moving to MODULE.bazel + cat > WORKSPACE <<'EOF' load("defer.bzl", "defer") defer(name="defer") @@ -488,7 +491,7 @@ EOF touch BUILD # Start Bazel - bazel query @defer//:all >& $TEST_log & + bazel query --enable_workspace @defer//:all >& $TEST_log & local bazel_pid=$! # Wait until the .download() calls return @@ -512,8 +515,10 @@ EOF } function test_deferred_download_error() { - cat >> $(create_workspace_with_default_repos WORKSPACE) <<'EOF' -load("defer.bzl", "defer") + # TODO: https://github.com/bazelbuild/bazel/issues/23234 + # This test hangs after moving to MODULE.bazel + cat > WORKSPACE <<'EOF' +load("//:defer.bzl", "defer") defer(name="defer") EOF @@ -536,7 +541,7 @@ EOF touch BUILD # Start Bazel - bazel query @defer//:all >& $TEST_log && fail "Bazel unexpectedly succeeded" + bazel query --enable_workspace @defer//:all >& $TEST_log && fail "Bazel unexpectedly succeeded" expect_log "Error downloading.*doesnotexist" expect_not_log "survived wait" } @@ -555,9 +560,10 @@ function test_deferred_download_smoke() { startup_server "${server_dir}" - cat >> $(create_workspace_with_default_repos WORKSPACE) <<'EOF' + # TODO: https://github.com/bazelbuild/bazel/issues/23234 + # This test hangs after moving to MODULE.bazel + cat > WORKSPACE <<'EOF' load("defer.bzl", "defer") - defer(name="defer") EOF @@ -581,7 +587,7 @@ EOF touch BUILD # Start Bazel - bazel query @defer//:all-targets >& $TEST_log & + bazel query --enable_workspace @defer//:all-targets >& $TEST_log & local bazel_pid=$! # Wait until the .download() call returns @@ -606,8 +612,8 @@ EOF serve_file $test_file cd ${WORKSPACE_DIR} - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < zoo/female.sh <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < ext.bzl <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < $TEST_log || fail "Build failed" - assert_contains "abc" bazel-genfiles/external/x/catter.out + assert_contains "abc" bazel-genfiles/external/+_repo_rules+x/catter.out } function test_prefix_stripping_zip() { @@ -899,8 +914,8 @@ function test_prefix_stripping_zip() { local sha256=$(sha256sum x.zip | cut -f 1 -d ' ') serve_file x.zip - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < $TEST_log || fail "Build failed" - assert_contains "abc" bazel-genfiles/external/x/catter.out + assert_contains "abc" bazel-genfiles/external/+_repo_rules+x/catter.out } function test_prefix_stripping_existing_repo() { @@ -939,8 +954,8 @@ EOF local sha256=$(sha256sum x.zip | cut -f 1 -d ' ') serve_file x.zip - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < $TEST_log || fail "Build failed" - assert_contains "abc" bazel-genfiles/external/x/catter.out + assert_contains "abc" bazel-genfiles/external/+_repo_rules+x/catter.out } function test_adding_prefix_zip() { @@ -960,8 +975,8 @@ function test_adding_prefix_zip() { local sha256=$(sha256sum z.zip | cut -f 1 -d ' ') serve_file z.zip - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < $TEST_log || fail "Build failed" - assert_contains "abc" bazel-genfiles/external/ws/catter.out + assert_contains "abc" bazel-genfiles/external/+_repo_rules+ws/catter.out } function test_adding_and_stripping_prefix_zip() { @@ -991,8 +1006,8 @@ function test_adding_and_stripping_prefix_zip() { local sha256=$(sha256sum z.zip | cut -f 1 -d ' ') serve_file z.zip - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < $TEST_log || fail "Build failed" - assert_contains "abc" bazel-genfiles/external/ws/catter.out + assert_contains "abc" bazel-genfiles/external/+_repo_rules+ws/catter.out } function test_moving_build_file() { @@ -1022,8 +1037,8 @@ function test_moving_build_file() { local sha256=$(sha256sum x.tar.gz | cut -f 1 -d ' ') serve_file x.tar.gz - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < $TEST_log || fail "Build 1 failed" - assert_contains "abc" bazel-genfiles/external/x/catter.out + assert_contains "abc" bazel-genfiles/external/+_repo_rules+x/catter.out mv x.BUILD x.BUILD.new || fail "Moving x.BUILD failed" - sed 's/x.BUILD/x.BUILD.new/g' WORKSPACE > WORKSPACE.tmp || \ - fail "Editing WORKSPACE failed" - mv WORKSPACE.tmp WORKSPACE + sed 's/x.BUILD/x.BUILD.new/g' MODULE.bazel > MODULE.bazel.tmp || \ + fail "Editing MODULE.bazel failed" + mv MODULE.bazel.tmp MODULE.bazel bazel build @x//:catter &> $TEST_log || fail "Build 2 failed" - assert_contains "abc" bazel-genfiles/external/x/catter.out + assert_contains "abc" bazel-genfiles/external/+_repo_rules+x/catter.out } function test_changing_build_file() { @@ -1059,8 +1074,8 @@ function test_changing_build_file() { local sha256=$(sha256sum x.tar.gz | cut -f 1 -d ' ') serve_file x.tar.gz - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < WORKSPACE.tmp || \ - fail "Editing WORKSPACE failed" - mv WORKSPACE.tmp WORKSPACE + assert_contains "abc" bazel-genfiles/external/+_repo_rules+x/catter.out + sed 's/x.BUILD/x.BUILD.new/g' MODULE.bazel > MODULE.bazel.tmp || \ + fail "Editing MODULE.bazel failed" + mv MODULE.bazel.tmp MODULE.bazel bazel build @x//:catter &> $TEST_log || fail "Build 2 failed" - assert_contains "def" bazel-genfiles/external/x/catter.out + assert_contains "def" bazel-genfiles/external/+_repo_rules+x/catter.out } function test_android_sdk_basic_load() { @@ -1105,14 +1120,14 @@ android_sdk_repository( ) EOF - bazel query "//external:androidsdk" 2> "$TEST_log" > "$TEST_TMPDIR/queryout" \ + bazel query --enable_workspace "//external:androidsdk" 2> "$TEST_log" > "$TEST_TMPDIR/queryout" \ || fail "Expected success" cat "$TEST_TMPDIR/queryout" > "$TEST_log" expect_log "//external:androidsdk" } function test_use_bind_as_repository() { - cat >> $(create_workspace_with_default_repos WORKSPACE) <<'EOF' + cat > WORKSPACE <<'EOF' load("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") local_repository(name = 'foobar', path = 'foo') bind(name = 'foo', actual = '@foobar//:test') @@ -1129,12 +1144,13 @@ genrule( outs = ["foo.txt"], ) EOF - bazel build :foo &> "$TEST_log" && fail "Expected failure" || true + bazel build --enable_workspace :foo &> "$TEST_log" && fail "Expected failure" || true expect_log "No repository visible as '@foo' from main repository" } function test_bind_repo_mapping() { - cat >> $(create_workspace_with_default_repos WORKSPACE myws) <<'EOF' + cat > WORKSPACE <<'EOF' +workspace(name = "myws") load('//:foo.bzl', 'foo') foo() bind(name='bar', actual='@myws//:something') @@ -1146,14 +1162,14 @@ EOF cat > BUILD <<'EOF' filegroup(name='something', visibility=["//visibility:public"]) EOF - bazel build //external:foo //external:bar &> "$TEST_log" || fail "don't fail!" + bazel build --enable_workspace //external:foo //external:bar &> "$TEST_log" || fail "don't fail!" } function test_flip_flopping() { REPO_PATH=$TEST_TMPDIR/repo mkdir -p "$REPO_PATH" cd "$REPO_PATH" - create_workspace_with_default_repos WORKSPACE + setup_module_dot_bazel touch BUILD foo zip -r repo.zip * sha256=$(sha256sum repo.zip | head -c 64) @@ -1164,14 +1180,14 @@ function test_flip_flopping() { cd - cat > local_ws < remote_ws < $TEST_log || fail "Build failed" - test -L "$external_dir/repo" || fail "creating local symlink failed" - test -a "$external_dir/repo/bar" || fail "bar not found" - cp remote_ws WORKSPACE + test -L "$external_dir/+_repo_rules+repo" || fail "creating local symlink failed" + test -a "$external_dir/+_repo_rules+repo/bar" || fail "bar not found" + cp remote_ws MODULE.bazel bazel build @repo//:all &> $TEST_log || fail "Build failed" - test -d "$external_dir//repo" || fail "creating remote repo failed" - test -a "$external_dir/repo/foo" || fail "foo not found" + test -d "$external_dir/+_repo_rules+repo" || fail "creating remote repo failed" + test -a "$external_dir/+_repo_rules+repo/foo" || fail "foo not found" done shutdown_server @@ -1197,13 +1213,13 @@ function test_sha256_weird() { REPO_PATH=$TEST_TMPDIR/repo mkdir -p "$REPO_PATH" cd "$REPO_PATH" - create_workspace_with_default_repos WORKSPACE + setup_module_dot_bazel zip -r repo.zip * startup_server $PWD cd - - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < BUILD <<'EOF' package(default_visibility = ["//visibility:public"]) @@ -1467,8 +1483,8 @@ EOF rm -rf main mkdir main cd main - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < WORKSPACE < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) <<'EOF' -load("//:rule.bzl", "with_progress") + cat >> $(setup_module_dot_bazel) <<'EOF' +with_progress = use_repo_rule("//:rule.bzl", "with_progress") with_progress(name="foo") EOF cat > BUILD <<'EOF' @@ -2408,8 +2439,8 @@ function test_progress_reporting() { mkdir main cd main - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < "${TEST_log}" 2>&1 && fail "Expected failure" || : - expect_log '@ext.*badargument' + expect_log '@@+_repo_rules+ext.*badargument' } function test_prefix_suggestions() { @@ -2444,8 +2475,8 @@ function test_prefix_suggestions() { mkdir main cd main - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) <<'EOF' + cat > WORKSPACE <<'EOF' load("@nonexistent//path/to/package:file/to/import.bzl", "foo") foo() EOF touch BUILD - bazel build //... > "${TEST_log}" 2>&1 && fail "Expected failure" + bazel build --enable_workspace //... > "${TEST_log}" 2>&1 && fail "Expected failure" expect_log '@nonexistent//path/to/package:file/to/import.bzl' expect_log 'nonexistent.*repository.*WORKSPACE' @@ -2532,8 +2563,8 @@ function test_report_files_searched() { mkdir -p path/to/workspace cd path/to/workspace - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) <<'EOF' + cat > WORKSPACE <<'EOF' load("//:repos.bzl", "repos") repos() EOF @@ -2620,7 +2651,7 @@ def foo_repos(): ) EOF - bazel build @foo//... > "${TEST_log}" 2>&1 && fail "expected failure" + bazel build --enable_workspace @foo//... > "${TEST_log}" 2>&1 && fail "expected failure" inplace-sed -e "s?$WRKDIR/?WRKDIR/?g" -e "s?$TEST_TMPDIR/?TEST_TMPDIR/?g" "${TEST_log}" expect_log 'error.*repository.*foo' @@ -2696,7 +2727,7 @@ load("@a//:notabuildfile.bzl", "x") EOF touch BUILD - bazel build //... > "${TEST_log}" 2>&1 && fail "expected failure" || : + bazel build --enable_workspace //... > "${TEST_log}" 2>&1 && fail "expected failure" || : inplace-sed -e 's?$(pwd)/?PWD/?g' "${TEST_log}" expect_not_log '[iI]nternal [eE]rror' @@ -2738,7 +2769,7 @@ data_repo = repository_rule( ) EOF touch BUILD - cat >> $(create_workspace_with_default_repos WORKSPACE) <<'EOF' + cat > WORKSPACE <<'EOF' load("//:withimplicit.bzl", "data_repo") data_repo( @@ -2748,7 +2779,7 @@ data_repo( load("@data//:value.bzl", "value") EOF - bazel build //... > "${TEST_log}" 2>&1 && fail "expected failure" || : + bazel build --enable_workspace //... > "${TEST_log}" 2>&1 && fail "expected failure" || : inplace-sed -e 's?$(pwd)/?PWD/?g' "${TEST_log}" expect_log "you have to add.*this_repo_is_missing.*WORKSPACE" @@ -2787,8 +2818,8 @@ function test_overwrite_existing_workspace_build() { mkdir main cd main - cat > WORKSPACE < $(setup_module_dot_bazel) < external_build_file <<'EOF' @@ -2841,8 +2872,8 @@ function test_external_java_target_depends_on_external_resources() { mkdir -p $test_repo1/a mkdir -p $test_repo2 - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < $test_repo1/a/BUILD <<'EOF' package(default_visibility = ["//visibility:public"]) @@ -2873,7 +2904,7 @@ public class A { } EOF - touch $test_repo2/WORKSPACE + touch $test_repo2/REPO.bazel cat > $test_repo2/BUILD <<'EOF' package(default_visibility = ["//visibility:public"]) @@ -2891,8 +2922,6 @@ EOF } function test_query_external_packages() { - setup_skylib_support - mkdir -p external/nested mkdir -p not-external @@ -2916,6 +2945,9 @@ filegroup( ) EOF + # Remove tools directory set up by copy_tools_directory in testenv.sh + rm -rf tools/ + bazel query //... >& $TEST_log || fail "Expected build/run to succeed" expect_log "//not-external:b" expect_not_log "//external:a1" @@ -2930,8 +2962,6 @@ EOF } function test_query_external_all_targets() { - setup_skylib_support - mkdir -p external/nested mkdir -p not-external @@ -2951,6 +2981,9 @@ filegroup( EOF touch not-external/B + # Remove tools directory set up by copy_tools_directory in testenv.sh + rm -rf tools/ + bazel query //...:all-targets >& $TEST_log \ || fail "Expected build/run to succeed" expect_log "//not-external:b" @@ -2978,8 +3011,8 @@ function test_external_deps_skymeld() { rm -rf main mkdir main cd main - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < WORKSPACE < $(setup_module_dot_bazel) < ext-0.1.2/foo.sh <<'EOF' @@ -108,8 +108,8 @@ test_patch_file() { -echo Here be dragons... +echo There are dragons... EOF - cat > WORKSPACE < $(setup_module_dot_bazel) < BUILD <<'EOF' genrule( name = "foo", @@ -150,8 +149,8 @@ EOF || fail "expected the new patch to be applied" # Verify that changes to the patches attribute trigger enough rebuilding - cat > WORKSPACE < $(setup_module_dot_bazel) < patch_foo.sh - cat > WORKSPACE < $(setup_module_dot_bazel) <"${TEST_log}" 2>&1 && fail "expected failure" || : @@ -229,8 +226,8 @@ EOF echo There are dragons... EOF - cat > WORKSPACE < $(setup_module_dot_bazel) < BUILD <<'EOF' genrule( name = "foo", @@ -275,8 +271,8 @@ EOF mkdir main cd main - cat > WORKSPACE < $(setup_module_dot_bazel) < $TEST_log 2>&1 && fail "Expected to fail" expect_log "Error downloading \\[.*/remote.patch\\] to" @@ -327,8 +322,8 @@ EOF mkdir main cd main - cat > WORKSPACE < $(setup_module_dot_bazel) < BUILD <<'EOF' genrule( name = "foo", @@ -392,8 +386,8 @@ EOF -echo Here be dragons... +echo There are dragons... EOF - cat > WORKSPACE < $(setup_module_dot_bazel) < BUILD <<'EOF' genrule( name = "foo", @@ -434,8 +427,8 @@ EOF || fail "expected the new patch to be applied" # Verify that changes to the patches attribute trigger enough rebuilding - cat > WORKSPACE < $(setup_module_dot_bazel) < WORKSPACE < $(setup_module_dot_bazel) < BUILD <<'EOF' genrule( name = "local", @@ -532,8 +523,8 @@ EOF mkdir main cd main - cat > WORKSPACE < $(setup_module_dot_bazel) < BUILD <<'EOF' genrule( name = "local", @@ -600,8 +590,8 @@ EOF mkdir main cd main - cat > WORKSPACE < $(setup_module_dot_bazel) < BUILD <<'EOF' genrule( name = "local", @@ -669,8 +658,8 @@ EOF mkdir main cd main - cat > WORKSPACE < $(setup_module_dot_bazel) < BUILD <<'EOF' genrule( name = "local", @@ -726,8 +714,8 @@ EOF mkdir main cd main - cat > WORKSPACE < $(setup_module_dot_bazel) < BUILD <<'EOF' genrule( name = "local", @@ -793,8 +780,8 @@ index 1f4c41e..9d548ff 100644 2.18.0.rc1.244.gcf134e6275-goog EOF - cat > WORKSPACE < $(setup_module_dot_bazel) < BUILD <<'EOF' genrule( name = "foo", diff --git a/src/test/shell/bazel/external_path_test.sh b/src/test/shell/bazel/external_path_test.sh index 231e7e29adc1ce..16765ac98d1395 100755 --- a/src/test/shell/bazel/external_path_test.sh +++ b/src/test/shell/bazel/external_path_test.sh @@ -29,7 +29,7 @@ repo_with_local_include() { # Generate a repository, in the current working directory, with a target # //src:hello that includes a file via a local path. - create_workspace_with_default_repos WORKSPACE + setup_module_dot_bazel mkdir src cat > src/main.c <<'EOF' #include @@ -57,7 +57,7 @@ library_with_local_include() { # is a library with headers that include via paths relative to the root of # that repository - create_workspace_with_default_repos WORKSPACE + setup_module_dot_bazel mkdir lib cat > lib/lib.h <<'EOF' #include "lib/constants.h" @@ -115,8 +115,8 @@ test_local_paths_remote() { mkdir main cd main - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < main.c <<'EOF' #include "lib/lib.h" @@ -180,8 +179,8 @@ test_lib_paths_remote() { mkdir main cd main - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < withpath/BUILD <<'EOF' genrule( @@ -295,7 +295,6 @@ test_fixed_path_local() { mkdir main cd main - create_workspace_with_default_repos WORKSPACE repo_with_local_path_reference bazel build //withpath:it || fail "Expected success" @@ -314,8 +313,8 @@ DISABLED_test_fixed_path_remote() { mkdir main cd main - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < rule/BUILD <<'EOF' exports_files(["to_upper.sh"]) @@ -369,7 +369,6 @@ test_local_rules() { mkdir main cd main - create_workspace_with_default_repos WORKSPACE repo_with_local_implicit_dependencies mkdir call echo hello world > call/hello.txt @@ -398,8 +397,8 @@ test_remote_rules() { mkdir main cd main - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < rule/preamb.html <<'EOF' @@ -528,7 +528,6 @@ test_embedded_local() { cd "${WRKDIR}" mkdir main - create_workspace_with_default_repos WORKSPACE repo_with_embedded_paths mkdir call cat > call/plain.txt <<'EOF' @@ -560,8 +559,8 @@ test_embedded_remote() { mkdir main cd main - cat >> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) <> $(create_workspace_with_default_repos WORKSPACE) < $(setup_module_dot_bazel) < rule/BUILD <<'EOF' genrule( @@ -675,7 +675,7 @@ EOF repo_data_file() { # Create, in the current directory, an archive of a data repository containing - # //:file.txt, and add a corresponding entry to ./main/WORKSPACE. + # //:file.txt, and add a corresponding entry to ./main/MODULE.bazel. mkdir data cat > data/file.txt <<'EOF' Copyright ... @@ -685,15 +685,14 @@ exports_files(["file.txt"], visibility = ["//visibility:public"]) EOF tar cvf data.tar data rm -rf data - cat >> main/WORKSPACE <> $(setup_module_dot_bazel "main/MODULE.bazel") <> main/WORKSPACE <> $(setup_module_dot_bazel "main/MODULE.bazel") < hello_world-0.1.2/hello_world.c <<'EOF' @@ -117,25 +117,25 @@ cc_binary( ) EOF touch BUILD.bazel - touch WORKSPACE + touch REPO.bazel mkdir main cd main - cat > WORKSPACE <> $(setup_module_dot_bazel) < WORKSPACE <> $(setup_module_dot_bazel) < WORKSPACE <> $(setup_module_dot_bazel) < $TEST_log 2>&1 && fail "Expected to fail" expect_log "but wanted sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFY=" @@ -230,23 +230,23 @@ cc_binary( srcs = ["hello_world.c"], ) EOF - touch WORKSPACE + touch REPO.bazel mkdir main cd main - cat > WORKSPACE <> $(setup_module_dot_bazel) < WORKSPACE <> $(setup_module_dot_bazel) < $TEST_log 2>&1 && fail "Expected to fail" expect_log "Error in download: Cannot write outside of the repository directory" @@ -298,23 +298,23 @@ cc_binary( srcs = ["hello_world.c"], ) EOF - touch WORKSPACE + touch REPO.bazel mkdir main cd main - cat > WORKSPACE <> $(setup_module_dot_bazel) < $TEST_log 2>&1 && fail "Expected to fail" expect_log "Error in download: Cannot write outside of the repository directory" diff --git a/src/test/shell/bazel/external_starlark_execute_test.sh b/src/test/shell/bazel/external_starlark_execute_test.sh index b06729ec2a9cc9..5a971747e18589 100755 --- a/src/test/shell/bazel/external_starlark_execute_test.sh +++ b/src/test/shell/bazel/external_starlark_execute_test.sh @@ -40,8 +40,8 @@ def _impl(ctx): changing_repo = repository_rule(_impl) EOF - cat > WORKSPACE <<'EOF' -load("//:repo.bzl", "changing_repo") + cat > $(setup_module_dot_bazel) <<'EOF' +changing_repo = use_repo_rule("//:repo.bzl", "changing_repo") changing_repo(name="change") EOF @@ -53,7 +53,6 @@ genrule( cmd = "cp $< $@", ) EOF - write_default_lockfile "MODULE.bazel.lock" bazel build //:it cp `bazel info bazel-genfiles`/it.txt output cat output @@ -90,12 +89,11 @@ def _impl(ctx): waiting_repo = repository_rule(_impl) EOF - cat > WORKSPACE <<'EOF' -load("//:repo.bzl", "waiting_repo") + cat > $(setup_module_dot_bazel) <<'EOF' +waiting_repo = use_repo_rule("//:repo.bzl", "waiting_repo") waiting_repo(name="wait") EOF - write_default_lockfile "MODULE.bazel.lock" cat > BUILD <<'EOF' genrule( name = "it", diff --git a/src/test/shell/bazel/external_starlark_load_test.sh b/src/test/shell/bazel/external_starlark_load_test.sh index 4d1628f2b30063..e552671d5f847e 100755 --- a/src/test/shell/bazel/external_starlark_load_test.sh +++ b/src/test/shell/bazel/external_starlark_load_test.sh @@ -47,8 +47,8 @@ function run_external_starlark_load_test() { create_new_workspace external_repo=${new_workspace_dir} - cat > ${WORKSPACE_DIR}/WORKSPACE < ${WORKSPACE_DIR}/MODULE.bazel < $repo2/remote.bzl < WORKSPACE < MODULE.bazel < WORKSPACE < MODULE.bazel < $repo1/BUILD < $repo2/remote.bzl <