From a851658e0f3768dcfcf4bd59ea375968094abf5c Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 9 Aug 2024 00:45:40 -0700 Subject: [PATCH] Make sure all other shell/integration 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: 661158600 Change-Id: Ib16db0042ff40baaf15937f3320e3a32f5211b36 --- src/test/shell/integration/aquery_test.sh | 25 ++++---- .../shell/integration/bazel_aquery_test.sh | 11 ++-- src/test/shell/integration/bazel_java_test.sh | 64 +++++++++++++------ .../shell/integration/bazel_query_test.sh | 8 ++- .../integration/build_event_stream_test.sh | 9 ++- .../integration/configured_query_test.sh | 26 +++++--- src/test/shell/integration/exec_group_test.sh | 4 +- .../implicit_dependency_reporting_test.sh | 2 +- .../shell/integration/loading_phase_test.sh | 10 +-- .../integration/modify_execution_info_test.sh | 15 +---- src/test/shell/integration/prelude_test.sh | 8 +-- .../integration/py_args_escaping_test.sh | 6 +- .../shell/integration/python_stub_test.sh | 3 + src/test/shell/integration/python_test.sh | 1 + src/test/shell/integration/runfiles_test.sh | 11 ++-- src/test/shell/integration/sandboxing_test.sh | 4 +- ...configurations_external_workspaces_test.sh | 12 ++-- .../starlark_configurations_test.sh | 2 +- .../integration/stub_finds_runfiles_test.sh | 1 + .../target_compatible_with_test.sh | 10 +-- ...rget_compatible_with_test_external_repo.sh | 20 +++--- src/test/shell/integration/toolchain_test.sh | 60 +++++++++-------- .../integration/toolchain_transition_test.sh | 8 +-- src/test/shell/testenv.sh.tmpl | 3 + 24 files changed, 183 insertions(+), 140 deletions(-) diff --git a/src/test/shell/integration/aquery_test.sh b/src/test/shell/integration/aquery_test.sh index f8107509e321a6..fb68f28014898a 100755 --- a/src/test/shell/integration/aquery_test.sh +++ b/src/test/shell/integration/aquery_test.sh @@ -1219,14 +1219,14 @@ EOF bazel clean - bazel aquery --noenable_bzlmod --output=textproto --skyframe_state > output 2> "$TEST_log" \ + bazel aquery --output=textproto --skyframe_state > output 2> "$TEST_log" \ || fail "Expected success" cat output >> "$TEST_log" assert_not_contains "actions" output - bazel build --noenable_bzlmod --nobuild "//$pkg:foo" + bazel build --nobuild "//$pkg:foo" - bazel aquery --noenable_bzlmod --output=textproto --skyframe_state > output 2> "$TEST_log" \ + bazel aquery --output=textproto --skyframe_state > output 2> "$TEST_log" \ || fail "Expected success" cat output >> "$TEST_log" @@ -1255,9 +1255,9 @@ EOF QUERY="inputs('.*matching_in.java', outputs('.*matching_out', mnemonic('Genrule')))" bazel clean - bazel build --noenable_bzlmod --nobuild "//$pkg:foo" + bazel build --nobuild "//$pkg:foo" - bazel aquery --noenable_bzlmod --output=textproto --skyframe_state ${QUERY} > output 2> "$TEST_log" \ + bazel aquery --output=textproto --skyframe_state ${QUERY} > output 2> "$TEST_log" \ || fail "Expected success" cat output >> "$TEST_log" @@ -1277,14 +1277,14 @@ EOF bazel clean - bazel aquery --noenable_bzlmod --output=textproto --skyframe_state > output 2> "$TEST_log" \ + bazel aquery --output=textproto --skyframe_state > output 2> "$TEST_log" \ || fail "Expected success" cat output >> "$TEST_log" assert_not_contains "actions" output - bazel build --noenable_bzlmod --nobuild "//$pkg:foo" + bazel build --nobuild "//$pkg:foo" - bazel aquery --noenable_bzlmod --output=textproto --skyframe_state > output 2> "$TEST_log" \ + bazel aquery --output=textproto --skyframe_state > output 2> "$TEST_log" \ || fail "Expected success" cat output >> "$TEST_log" @@ -1308,14 +1308,14 @@ EOF bazel clean - bazel aquery --noenable_bzlmod --output=jsonproto --skyframe_state > output 2> "$TEST_log" \ + bazel aquery --output=jsonproto --skyframe_state > output 2> "$TEST_log" \ || fail "Expected success" cat output >> "$TEST_log" assert_not_contains "actions" output - bazel build --noenable_bzlmod --nobuild "//$pkg:foo" + bazel build --nobuild "//$pkg:foo" - bazel aquery --noenable_bzlmod --output=jsonproto --skyframe_state > output 2> "$TEST_log" \ + bazel aquery --output=jsonproto --skyframe_state > output 2> "$TEST_log" \ || fail "Expected success" cat output >> "$TEST_log" @@ -1336,7 +1336,7 @@ EOF bazel clean - bazel aquery --noenable_bzlmod --output=text --skyframe_state &> "$TEST_log" \ + bazel aquery --output=text --skyframe_state &> "$TEST_log" \ && fail "Expected failure" expect_log "--skyframe_state must be used with --output=proto\|textproto\|jsonproto. Invalid aquery output format: text" } @@ -1363,6 +1363,7 @@ EOF } function test_aquery_include_template_substitution_for_template_expand_of_py_binary() { + add_rules_python "MODULE.bazel" local pkg="${FUNCNAME[0]}" mkdir -p "$pkg" || fail "mkdir -p $pkg" cat > "$pkg/BUILD" <<'EOF' diff --git a/src/test/shell/integration/bazel_aquery_test.sh b/src/test/shell/integration/bazel_aquery_test.sh index 44fd9dc17d9619..cb21812068c162 100755 --- a/src/test/shell/integration/bazel_aquery_test.sh +++ b/src/test/shell/integration/bazel_aquery_test.sh @@ -55,13 +55,14 @@ function test_repo_mapping_manifest() { local pkg="${FUNCNAME[0]}" local pkg2="${FUNCNAME[0]}_pkg2" mkdir -p "$pkg" || fail "mkdir -p $pkg" - cat > "$pkg/WORKSPACE" < $(setup_module_dot_bazel "$pkg/MODULE.bazel") < "$pkg/BUILD" < "$pkg2/BUILD" <output 2> "$TEST_log" || fail "Expected success" cat output >> "$TEST_log" - assert_contains "^file_contents:.*pkg2,__main__,_main" output + assert_contains "^file_contents:.*pkg2,+_repo_rules+pkg2" output bazel aquery --output=text --include_file_write_contents "//:foo" | \ sed -nr '/Mnemonic: RepoMappingManifest/,/^ *$/p' >output \ @@ -92,7 +93,7 @@ EOF # Verify file contents if we can decode base64-encoded data. if which base64 >/dev/null; then sed -nr 's/^ *FileWriteContents: \[(.*)\]/echo \1 | base64 -d/p' output | \ - sh | tee -a "$TEST_log" | assert_contains "pkg2,__main__,_main" - + sh | tee -a "$TEST_log" | assert_contains "pkg2,+_repo_rules+pkg2" - fi } diff --git a/src/test/shell/integration/bazel_java_test.sh b/src/test/shell/integration/bazel_java_test.sh index c5b82bf53afe6b..47da103178b28a 100755 --- a/src/test/shell/integration/bazel_java_test.sh +++ b/src/test/shell/integration/bazel_java_test.sh @@ -51,13 +51,18 @@ EOF # Javabuilder shall be executed using JDK defined in java_toolchain's java_runtime attribute. # Java targets shall be executed using JDK matching --java_runtime_version version. function test_java_runtime() { - cat << EOF >> WORKSPACE -load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository") -local_java_repository( + add_rules_java "MODULE.bazel" + add_platforms "MODULE.bazel" + cat << EOF >> MODULE.bazel +_local_java_repository_rule = use_repo_rule("@rules_java//toolchains:local_java_repository.bzl", "_local_java_repository_rule") +_local_java_repository_rule( name = "host_javabase", + runtime_name = "host_javabase", java_home = "$PWD/foobar", version = "11", ) +register_toolchains("@host_javabase//:runtime_toolchain_definition") +register_toolchains("@host_javabase//:bootstrap_runtime_toolchain_definition") EOF mkdir java @@ -118,13 +123,18 @@ EOF # Javabuilder shall be executed using JDK defined in java_toolchain's java_runtime attribute, not tool_java_runtime. # Testing: Javabuilder in exec configuration. function test_exec_toolchain_java_runtime_not_set_from_tool_java_runtime_version() { - cat << EOF >> WORKSPACE -load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository") -local_java_repository( + add_rules_java "MODULE.bazel" + add_platforms "MODULE.bazel" + cat << EOF >> MODULE.bazel +_local_java_repository_rule = use_repo_rule("@rules_java//toolchains:local_java_repository.bzl", "_local_java_repository_rule") +_local_java_repository_rule( name = "host_javabase", + runtime_name = "host_javabase", java_home = "$PWD/foobar", version = "11", ) +register_toolchains("@host_javabase//:runtime_toolchain_definition") +register_toolchains("@host_javabase//:bootstrap_runtime_toolchain_definition") EOF mkdir -p java cat >> java/rule.bzl <> WORKSPACE -load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository") -local_java_repository( + add_rules_java "MODULE.bazel" + add_platforms "MODULE.bazel" + cat << EOF >> MODULE.bazel +_local_java_repository_rule = use_repo_rule("@rules_java//toolchains:local_java_repository.bzl", "_local_java_repository_rule") +_local_java_repository_rule( name = "javabase", + runtime_name = "javabase", java_home = "$PWD/zoo", version = "11", ) +register_toolchains("@javabase//:runtime_toolchain_definition") +register_toolchains("@javabase//:bootstrap_runtime_toolchain_definition") + +java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains") +use_repo(java_toolchains, "local_jdk") EOF mkdir -p zoo/bin @@ -273,28 +291,38 @@ function test_no_javabase() { # Tests non-existent java_home path. function test_no_java_home_path() { - cat << EOF >> WORKSPACE -load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository") -local_java_repository( - name = "javabase", - java_home = "$PWD/i-dont-exist", + add_rules_java "MODULE.bazel" + add_platforms "MODULE.bazel" + cat << EOF >> MODULE.bazel +_local_java_repository_rule = use_repo_rule("@rules_java//toolchains:local_java_repository.bzl", "_local_java_repository_rule") +_local_java_repository_rule( + name = "host_javabase", + runtime_name = "host_javabase", + java_home = "$PWD/idontexist", version = "11", ) +register_toolchains("@host_javabase//:runtime_toolchain_definition") +register_toolchains("@host_javabase//:bootstrap_runtime_toolchain_definition") EOF - bazel build @javabase//... >& $TEST_log && fail "Build with missing java_home should fail." + bazel build @host_javabase//... >& $TEST_log && fail "Build with missing java_home should fail." expect_log "The path indicated by the \"java_home\" attribute .* does not exist." } function test_genrule() { - cat << EOF >> WORKSPACE -load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository") -local_java_repository( + add_rules_java "MODULE.bazel" + add_platforms "MODULE.bazel" + cat << EOF >> MODULE.bazel +_local_java_repository_rule = use_repo_rule("@rules_java//toolchains:local_java_repository.bzl", "_local_java_repository_rule") +_local_java_repository_rule( name = "foo_javabase", + runtime_name = "foo_javabase", java_home = "$PWD/foo", version = "11", ) +register_toolchains("@foo_javabase//:runtime_toolchain_definition") +register_toolchains("@foo_javabase//:bootstrap_runtime_toolchain_definition") EOF mkdir -p foo/bin bar/bin diff --git a/src/test/shell/integration/bazel_query_test.sh b/src/test/shell/integration/bazel_query_test.sh index 86aa3c628c5a30..2d6b3e24b53bea 100755 --- a/src/test/shell/integration/bazel_query_test.sh +++ b/src/test/shell/integration/bazel_query_test.sh @@ -66,7 +66,7 @@ fi function set_up() { add_to_bazelrc "build --package_path=%workspace%" - setup_skylib_support + add_bazel_skylib "MODULE.bazel" } function tear_down() { @@ -498,6 +498,7 @@ EOF } function test_location_output_source_files() { + add_rules_python "MODULE.bazel" rm -rf foo mkdir -p foo cat > foo/BUILD < foo/BUILD < foo/BUILD < WORKSPACE <<'EOF' + cat > MODULE.bazel <<'EOF' +local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") local_repository( name = "notthere", path = "/nope", diff --git a/src/test/shell/integration/build_event_stream_test.sh b/src/test/shell/integration/build_event_stream_test.sh index 1d3532d2857cee..00495a59bf0216 100755 --- a/src/test/shell/integration/build_event_stream_test.sh +++ b/src/test/shell/integration/build_event_stream_test.sh @@ -26,7 +26,7 @@ add_to_bazelrc "build --experimental_build_event_upload_strategy=local" set -e function set_up() { - setup_skylib_support + add_bazel_skylib "MODULE.bazel" mkdir -p pkg touch pkg/somesourcefile @@ -1249,7 +1249,7 @@ filegroup( srcs = ["doesnotexist"], ) EOF - (bazel build --noenable_bzlmod --build_event_text_file="${TEST_log}" :badfilegroup \ + (bazel build --build_event_text_file="${TEST_log}" :badfilegroup \ && fail "Expected failure") || : # There should be precisely one event with target_completed as event id type (echo 'g/^id/+1p'; echo 'q') | ed "${TEST_log}" 2>&1 | tail -n +2 > event_id_types @@ -1259,7 +1259,7 @@ EOF [ `grep unconfigured_label event_id_types | wc -l` -eq 1 ] \ || fail "not precisely one unconfigured_label event id" - (bazel build -k --noenable_bzlmod --build_event_text_file="${TEST_log}" :badfilegroup :doesnotexist \ + (bazel build -k --build_event_text_file="${TEST_log}" :badfilegroup :doesnotexist \ && fail "Expected failure") || : # There should be precisely two events with target_completed as event id type (echo 'g/^id/+1p'; echo 'q') | ed "${TEST_log}" 2>&1 | tail -n +2 > event_id_types @@ -1493,7 +1493,7 @@ EOF # toolchain resolution and also the //external package. This way we don't need # to bother making careful assertions about these packages in our actual test # logic below. - bazel build --noenable_bzlmod --nobuild \ + bazel build --nobuild \ //just-to-get-packages-needed-for-toolchain-resolution:whatever \ >& "$TEST_log" || fail "Expected success" @@ -1535,7 +1535,6 @@ fail('bad') EOF bazel build \ - --noenable_bzlmod \ --nobuild \ --keep_going \ --build_event_text_file=bep.txt \ diff --git a/src/test/shell/integration/configured_query_test.sh b/src/test/shell/integration/configured_query_test.sh index 5e84246ac8f3b7..c8d0fdedca22b1 100755 --- a/src/test/shell/integration/configured_query_test.sh +++ b/src/test/shell/integration/configured_query_test.sh @@ -286,6 +286,7 @@ EOF function test_show_transitive_config_fragments() { local -r pkg=$FUNCNAME mkdir -p $pkg + add_rules_python "MODULE.bazel" cat > $pkg/BUILD <<'EOF' load("@rules_python//python:py_library.bzl", "py_library") @@ -359,6 +360,7 @@ EOF function test_show_transitive_config_fragments_alias() { local -r pkg=$FUNCNAME mkdir -p $pkg + add_rules_python "MODULE.bazel" cat > $pkg/BUILD <<'EOF' load("@rules_python//python:py_library.bzl", "py_library") @@ -420,6 +422,7 @@ EOF function test_show_transitive_config_fragments_host_deps() { local -r pkg=$FUNCNAME mkdir -p $pkg + add_rules_python "MODULE.bazel" cat > $pkg/BUILD <<'EOF' load("@rules_python//python:py_library.bzl", "py_library") @@ -451,6 +454,7 @@ EOF function test_show_transitive_config_fragments_through_output_file() { local -r pkg=$FUNCNAME mkdir -p $pkg + add_rules_python "MODULE.bazel" cat > $pkg/BUILD <<'EOF' load("@rules_python//python:py_library.bzl", "py_library") @@ -482,6 +486,7 @@ EOF function test_show_direct_config_fragments() { local -r pkg=$FUNCNAME mkdir -p $pkg + add_rules_python "MODULE.bazel" cat > $pkg/BUILD <<'EOF' load("@rules_python//python:py_library.bzl", "py_library") @@ -907,6 +912,7 @@ EOF function test_starlark_output_mode() { local -r pkg=$FUNCNAME mkdir -p $pkg + add_rules_python "MODULE.bazel" cat > $pkg/BUILD <<'EOF' load("@rules_python//python:py_library.bzl", "py_library") @@ -1041,6 +1047,7 @@ root_rule = rule( ) EOF + add_rules_python "MODULE.bazel" cat > $pkg/BUILD <<'EOF' load(":rules.bzl", "bool_flag", "list_flag", "root_rule") load("@rules_python//python:py_library.bzl", "py_library") @@ -1111,7 +1118,7 @@ EOF function test_starlark_build_options_invalid_arg() { local -r pkg=$FUNCNAME mkdir -p $pkg - + add_rules_python "MODULE.bazel" cat > $pkg/BUILD <<'EOF' load("@rules_python//python:py_library.bzl", "py_library") @@ -1389,13 +1396,14 @@ function test_bazelignore_error_cquery_nocrash() { local -r pkg=$FUNCNAME mkdir -p $pkg/repo - touch $pkg/repo/WORKSPACE + touch $pkg/repo/REPO.bazel cat > $pkg/repo/BUILD < $pkg/WORKSPACE < $pkg/MODULE.bazel <output \ 2>"$TEST_log" && fail "Expected failure" @@ -1421,8 +1429,9 @@ sh_library(name='japanese') EOF mkdir -p $dir/main - write_default_lockfile $dir/main/MODULE.bazel.lock - cat > $dir/main/WORKSPACE < $dir/main/MODULE.bazel < $dir/main/WORKSPACE < $dir/main/MODULE.bazel <> WORKSPACE <> ${TOOLCHAIN_REGISTRAION_FILE} <> WORKSPACE <> ${TOOLCHAIN_REGISTRAION_FILE} < rule.bzl <<'EOF' def _rule_impl(ctx): out = ctx.actions.declare_file(ctx.label.name + ".txt") diff --git a/src/test/shell/integration/loading_phase_test.sh b/src/test/shell/integration/loading_phase_test.sh index 15313edaddbf6e..8576f3b5b9d6c0 100755 --- a/src/test/shell/integration/loading_phase_test.sh +++ b/src/test/shell/integration/loading_phase_test.sh @@ -324,26 +324,26 @@ function test_no_package_loading_on_benign_workspace_file_changes() { echo 'workspace(name="wsname1")' > WORKSPACE echo 'sh_library(name="shname1")' > $pkg/foo/BUILD - bazel query --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \ + bazel query --enable_workspace --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \ || fail "Expected success" expect_log "Loading package: $pkg/foo" expect_log "//$pkg/foo:shname1" echo 'sh_library(name="shname2")' > $pkg/foo/BUILD - bazel query --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \ + bazel query --enable_workspace --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \ || fail "Expected success" expect_log "Loading package: $pkg/foo" expect_log "//$pkg/foo:shname2" # Test that comment changes do not cause package reloading echo '#benign comment' >> WORKSPACE - bazel query --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \ + bazel query --enable_workspace --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \ || fail "Expected success" expect_not_log "Loading package: $pkg/foo" expect_log "//$pkg/foo:shname2" echo 'workspace(name="wsname2")' > WORKSPACE - bazel query --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \ + bazel query --enable_workspace --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \ || fail "Expected success" expect_log "Loading package: $pkg/foo" expect_log "//$pkg/foo:shname2" @@ -467,7 +467,7 @@ function test_bazel_bin_is_not_a_package() { local -r pkg="${FUNCNAME[0]}" mkdir "$pkg" || fail "Could not mkdir $pkg" echo "filegroup(name = '$pkg')" > "$pkg/BUILD" - setup_skylib_support + add_bazel_skylib "MODULE.bazel" # Ensure bazel- is created. bazel build --symlink_prefix="foo_prefix-" "//$pkg" || fail "build failed" [[ -d "foo_prefix-bin" ]] || fail "bazel-bin was not created" diff --git a/src/test/shell/integration/modify_execution_info_test.sh b/src/test/shell/integration/modify_execution_info_test.sh index d627c99202c5d7..5038e426a6726b 100755 --- a/src/test/shell/integration/modify_execution_info_test.sh +++ b/src/test/shell/integration/modify_execution_info_test.sh @@ -151,20 +151,7 @@ Genrule=+requires-a,CppCompile=+requires-b,CppCompile=+requires-c \ function test_modify_execution_info_various_types() { if [[ "$PRODUCT_NAME" = "bazel" ]]; then - cat "$(rlocation "io_bazel/src/test/shell/integration/rules_proto_stanza.txt")" >>WORKSPACE - cat >> WORKSPACE << EOF -load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") -rules_proto_dependencies() -rules_proto_toolchains() - -# @com_google_protobuf//:protoc depends on @io_bazel//third_party/zlib. -new_local_repository( - name = "io_bazel", - path = "$(dirname $(dirname $(dirname $(rlocation io_bazel/third_party/zlib/BUILD))))", - build_file_content = "# Intentionally left empty.", - workspace_file_content = "workspace(name = 'io_bazel')", -) -EOF + add_rules_python "MODULE.bazel" fi local pkg="${FUNCNAME[0]}" mkdir -p "$pkg" || fail "mkdir -p $pkg" diff --git a/src/test/shell/integration/prelude_test.sh b/src/test/shell/integration/prelude_test.sh index 30aae9b7b80d00..7893adb665235b 100755 --- a/src/test/shell/integration/prelude_test.sh +++ b/src/test/shell/integration/prelude_test.sh @@ -28,7 +28,6 @@ set -e #### TESTS ############################################################# function test_prelude() { - create_workspace_with_default_repos WORKSPACE mkdir -p tools/build_rules touch tools/build_rules/BUILD @@ -53,7 +52,8 @@ EOF } function test_prelude_external_repository() { - cat > WORKSPACE << EOF + cat > MODULE.bazel << EOF +local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") local_repository( name = "imported_workspace", path = "$PWD/imported_workspace", @@ -77,7 +77,7 @@ genrule( EOF mkdir -p imported_workspace - touch imported_workspace/WORKSPACE + touch imported_workspace/REPO.bazel mkdir -p imported_workspace/tools/build_rules touch imported_workspace/tools/build_rules/BUILD @@ -100,7 +100,7 @@ EOF output=$(cat bazel-genfiles/gr.out) check_eq "outer from test_prelude_external_repository, outer workspace" "$output" "unexpected output in gr.out" - output=$(cat bazel-genfiles/external/imported_workspace/gr_inner.out) + output=$(cat bazel-genfiles/external/+_repo_rules+imported_workspace/gr_inner.out) check_eq "inner from test_prelude_external_repository, inner workspace" "$output" "unexpected output in gr_inner.out" } diff --git a/src/test/shell/integration/py_args_escaping_test.sh b/src/test/shell/integration/py_args_escaping_test.sh index 4c5c5378351554..9d6e58824d93b6 100755 --- a/src/test/shell/integration/py_args_escaping_test.sh +++ b/src/test/shell/integration/py_args_escaping_test.sh @@ -226,7 +226,7 @@ function assert_good_output_of_the_program_with_many_args() { function test_args_escaping() { local -r ws="$TEST_TMPDIR/${FUNCNAME[0]}" # unique workspace for this test mkdir -p "$ws" - create_workspace_with_default_repos "$ws/WORKSPACE" + setup_module_dot_bazel "$ws/MODULE.bazel" create_py_file_that_prints_args "$ws" create_build_file_with_many_args "$ws" @@ -248,7 +248,7 @@ function test_args_escaping() { function test_untokenizable_args() { local -r ws="$TEST_TMPDIR/${FUNCNAME[0]}" # unique workspace for this test mkdir -p "$ws" - create_workspace_with_default_repos "$ws/WORKSPACE" + setup_module_dot_bazel "$ws/MODULE.bazel" create_py_file_that_prints_args "$ws" create_build_file_for_untokenizable_args "$ws" @@ -263,7 +263,7 @@ function test_untokenizable_args() { function test_host_config() { local -r ws="$TEST_TMPDIR/${FUNCNAME[0]}" # unique workspace for this test mkdir -p "$ws" - create_workspace_with_default_repos "$ws/WORKSPACE" + setup_module_dot_bazel "$ws/MODULE.bazel" cat >"$ws/BUILD" <<'eof' load("//:rule.bzl", "run_host_configured") diff --git a/src/test/shell/integration/python_stub_test.sh b/src/test/shell/integration/python_stub_test.sh index de3f1e307792c1..f0893076288c13 100755 --- a/src/test/shell/integration/python_stub_test.sh +++ b/src/test/shell/integration/python_stub_test.sh @@ -70,6 +70,7 @@ use_fake_python_runtimes_for_testsuite # Tests that Python 2 or Python 3 is actually invoked. function test_python_version() { + add_rules_python "MODULE.bazel" mkdir -p test touch test/main3.py cat > test/BUILD << EOF @@ -91,6 +92,7 @@ EOF } function test_can_build_py_library_at_top_level_regardless_of_version() { + add_rules_python "MODULE.bazel" mkdir -p test cat > test/BUILD << EOF load("@rules_python//python:py_library.bzl", "py_library") @@ -113,6 +115,7 @@ EOF # capable of finding its runfiles directory by considering RUNFILES_DIR # and RUNFILES_MANIFEST_FILE set by the caller. function test_python_through_bash_without_runfile_links() { + add_rules_python "MODULE.bazel" mkdir -p python_through_bash cat > python_through_bash/BUILD << EOF diff --git a/src/test/shell/integration/python_test.sh b/src/test/shell/integration/python_test.sh index d2d5e28bcf9860..c3afe22a277db1 100755 --- a/src/test/shell/integration/python_test.sh +++ b/src/test/shell/integration/python_test.sh @@ -82,6 +82,7 @@ fi # * https://github.com/bazelbuild/bazel/issues/2394 # * https://bugs.python.org/issue28425 function test_python_binary_empty_files_in_runfiles_are_regular_files() { + add_rules_python "MODULE.bazel" mkdir -p test/mypackage cat > test/BUILD <<'EOF' load("@rules_python//python:py_test.bzl", "py_test") diff --git a/src/test/shell/integration/runfiles_test.sh b/src/test/shell/integration/runfiles_test.sh index 73e87d9cabdd1d..5526f1364923da 100755 --- a/src/test/shell/integration/runfiles_test.sh +++ b/src/test/shell/integration/runfiles_test.sh @@ -71,8 +71,6 @@ fi set -e -disable_bzlmod - function create_pkg() { local -r pkg=$1 mkdir -p $pkg @@ -149,6 +147,8 @@ EOF } function test_foo_runfiles() { + add_rules_python "MODULE.bazel" + local WORKSPACE_NAME=$TEST_WORKSPACE local -r pkg=$FUNCNAME create_pkg $pkg cat > BUILD << EOF @@ -379,8 +379,7 @@ function test_workspace_name_change() { # TODO(b/174761497): Re-enable the test outside of Bazel. [[ "${PRODUCT_NAME}" != bazel ]] && return 0 - # Rewrite the workspace name but leave the rest of WORKSPACE alone. - sed -ie 's,workspace(.*,workspace(name = "foo"),' WORKSPACE + echo 'workspace(name = "foo")' > WORKSPACE cat > BUILD < thing.cc < $TEST_log || fail "Build failed" + bazel build --noenable_bzlmod --enable_workspace //:thing $EXTRA_BUILD_FLAGS &> $TEST_log || fail "Build failed" [[ -d ${PRODUCT_NAME}-bin/thing${EXT}.runfiles/foo ]] || fail "foo not found" # Change workspace name to bar. sed -ie 's,workspace(.*,workspace(name = "bar"),' WORKSPACE - bazel build //:thing $EXTRA_BUILD_FLAGS &> $TEST_log || fail "Build failed" + bazel build --noenable_bzlmod --enable_workspace //:thing $EXTRA_BUILD_FLAGS &> $TEST_log || fail "Build failed" [[ -d ${PRODUCT_NAME}-bin/thing${EXT}.runfiles/bar ]] || fail "bar not found" [[ ! -d ${PRODUCT_NAME}-bin/thing${EXT}.runfiles/foo ]] \ || fail "Old foo still found" diff --git a/src/test/shell/integration/sandboxing_test.sh b/src/test/shell/integration/sandboxing_test.sh index 12e8fc47f21ef0..18622b1b89adf0 100755 --- a/src/test/shell/integration/sandboxing_test.sh +++ b/src/test/shell/integration/sandboxing_test.sh @@ -24,8 +24,6 @@ CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${CURRENT_DIR}/../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } -disable_bzlmod - function set_up() { add_to_bazelrc "build --spawn_strategy=sandboxed" add_to_bazelrc "build --genrule_strategy=sandboxed" @@ -352,6 +350,7 @@ EOF cat << 'EOF' >> examples/genrule/datafile this is a datafile EOF + local WORKSPACE_NAME=$TEST_WORKSPACE # The workspace name is initialized in testenv.sh; use that var rather than # hardcoding it here. The extra sed pass is so we can selectively expand that # one var while keeping the rest of the heredoc literal. @@ -1061,6 +1060,7 @@ EOF file_inode_a=$(awk '/The file inode is/ {print $5}' ${test_output}) local output_base="$(bazel info output_base)" + local WORKSPACE_NAME=$TEST_WORKSPACE local stashed_test_dir="${output_base}/sandbox/sandbox_stash/TestRunner/6/execroot/$WORKSPACE_NAME" touch $(find "$stashed_test_dir/$out_directory/" -name a.sh.runfiles -type d)"/$WORKSPACE_NAME/pkg/file4.txt" diff --git a/src/test/shell/integration/starlark_configurations_external_workspaces_test.sh b/src/test/shell/integration/starlark_configurations_external_workspaces_test.sh index a8723bb3c8adfb..11e7ce405f6131 100755 --- a/src/test/shell/integration/starlark_configurations_external_workspaces_test.sh +++ b/src/test/shell/integration/starlark_configurations_external_workspaces_test.sh @@ -127,12 +127,13 @@ EOF function test_set_flag_with_workspace_name() { + echo "workspace(name = '${WORKSPACE_NAME}')" > WORKSPACE local -r pkg=$FUNCNAME mkdir -p $pkg write_build_setting_bzl "@${WORKSPACE_NAME}" - bazel build //$pkg:my_drink --@//$pkg:type="coffee" \ + bazel build --enable_workspace //$pkg:my_drink --@//$pkg:type="coffee" \ > output 2>"$TEST_log" || fail "Expected success" expect_log "type=coffee" @@ -144,12 +145,12 @@ function test_reference_inner_repository_flags() { mkdir -p $subpkg ## set up outer repo - cat > $pkg/WORKSPACE < $(setup_module_dot_bazel "$pkg/MODULE.bazel") < $subpkg/BUILD < $subpkg/WORKSPACE < $(setup_module_dot_bazel "$subpkg/MODULE.bazel") <& "$TEST_log" && fail "Expected failure" expect_not_log "crashed due to an internal error" - expect_log "`cfg` must be set to a transition object initialized by the transition() function" + expect_log '`cfg` must be set to a transition object initialized by the transition() function' } function write_attr_list_transition() { diff --git a/src/test/shell/integration/stub_finds_runfiles_test.sh b/src/test/shell/integration/stub_finds_runfiles_test.sh index de7948c2cc1d6a..98e7a174057eda 100755 --- a/src/test/shell/integration/stub_finds_runfiles_test.sh +++ b/src/test/shell/integration/stub_finds_runfiles_test.sh @@ -35,6 +35,7 @@ fi #### HELPER FUNCTIONS ################################################## function set_up() { + add_rules_python "MODULE.bazel" mkdir -p pkg pkg/java cat > pkg/BUILD << 'EOF' load("@rules_python//python:py_binary.bzl", "py_binary") diff --git a/src/test/shell/integration/target_compatible_with_test.sh b/src/test/shell/integration/target_compatible_with_test.sh index 8e5b1628d7ac66..c3dc96eb0aaaa3 100755 --- a/src/test/shell/integration/target_compatible_with_test.sh +++ b/src/test/shell/integration/target_compatible_with_test.sh @@ -64,6 +64,7 @@ if "$is_windows"; then fi function set_up() { + add_platforms "MODULE.bazel" mkdir -p target_skipping || fail "couldn't create directory" cat > target_skipping/pass.sh <<'EOF' #!/bin/bash @@ -890,7 +891,7 @@ EOF # Validates that we can express targets being compatible with everything _but_ # A and B. function test_inverse_logic() { - setup_skylib_support + add_bazel_skylib "MODULE.bazel" # Not using 'EOF' because injecting skylib_package cat >> target_skipping/BUILD <> WORKSPACE <<'EOF' + cat >> MODULE.bazel <<'EOF' +local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") local_repository(name = 'build_bazel_apple_support', path = 'build_bazel_apple_support') EOF mkdir -p build_bazel_apple_support/platforms - touch build_bazel_apple_support/WORKSPACE + touch build_bazel_apple_support/REPO.bazel cat > build_bazel_apple_support/platforms/BUILD <<'EOF' package(default_visibility=["//visibility:public"]) platform( @@ -1237,7 +1239,7 @@ EOF # Validates that we successfully skip analysistest rule targets when they # depend on incompatible targets. function test_analysistest() { - setup_skylib_support + add_bazel_skylib "MODULE.bazel" # Not using 'EOF' because injecting skylib_package cat > target_skipping/analysistest.bzl < target_skipping/pass.sh < target_skipping/fail.sh < target_skipping/fail.sh < target_skipping/WORKSPACE <> target_skipping/WORKSPACE < $(setup_module_dot_bazel "target_skipping/MODULE.bazel") < target_skipping/third_party/test_repo/BUILD < "${TEST_log}" && fail "Bazel passed unexpectedly." - expect_log 'ERROR:.*Target @@test_repo//:bin is incompatible and cannot be built' + expect_log 'ERROR:.*Target @@+_repo_rules+test_repo//:bin is incompatible and cannot be built' expect_log '^ERROR: Build did NOT complete successfully' # Now look at the build event log. mv "${TEST_log}".build.json "${TEST_log}" expect_log '^ name: "PARSING_FAILURE"$' - expect_log 'Target @@test_repo//:bin is incompatible and cannot be built.' + expect_log 'Target @@+_repo_rules+test_repo//:bin is incompatible and cannot be built.' } # Regression test for https://github.com/bazelbuild/bazel/issues/12374 @@ -226,8 +224,8 @@ repo_rule = repository_rule( ) EOF - cat >> WORKSPACE <> MODULE.bazel <> WORKSPACE <> $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < $TEST_log && fail "Build failure expected" - expect_log "error parsing target pattern \"/:invalid:label:syntax\": invalid package name '/': package names may not start with '/'" + + if [[ $PRODUCT_NAME == "bazel" ]]; then + expect_log "Expected absolute target patterns (must begin with '//' or '@') for 'register_toolchains' argument, but got '/:invalid:label:syntax'" + else + expect_log "error parsing target pattern \"/:invalid:label:syntax\": invalid package name '/': package names may not start with '/'" + fi } function test_register_toolchain_error_invalid_target() { @@ -996,7 +1001,7 @@ function test_register_toolchain_error_invalid_target() { write_test_toolchain "${pkg}" write_test_rule "${pkg}" - cat > WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE <WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE <WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < "${pkg}/external/rules_foo/rule/rule.bzl" < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE < $TEST_log || fail "Build failed" - expect_log "foo_tool = " + expect_log "foo_tool = " } function test_exec_platform_order_with_mandatory_toolchains { @@ -2673,7 +2679,7 @@ platform( ) EOF # Register them in order. - cat >> WORKSPACE <> $TOOLCHAIN_REGISTRAION_FILE <> WORKSPACE <> $TOOLCHAIN_REGISTRAION_FILE < WORKSPACE < $TOOLCHAIN_REGISTRAION_FILE <>WORKSPACE <> $TOOLCHAIN_REGISTRAION_FILE <>WORKSPACE <> $TOOLCHAIN_REGISTRAION_FILE <