Skip to content

Commit

Permalink
Make sure all other shell/bazel tests work with --enable_workspace=false
Browse files Browse the repository at this point in the history
A part of #23087

Working towards: #23023

PiperOrigin-RevId: 661156778
Change-Id: I7783ce606869dcc3b5f21cee765f196ba3b365cd
  • Loading branch information
meteorcloudy authored and copybara-github committed Aug 9, 2024
1 parent d7feff5 commit 7c7aafa
Show file tree
Hide file tree
Showing 38 changed files with 331 additions and 347 deletions.
6 changes: 4 additions & 2 deletions src/main/starlark/tests/builtins_bzl/builtin_test_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
# implementation can rely on release Bazel, we can add the tests directly.

function setup_tests() {
add_rules_testing_to_workspace "WORKSPACE"
setup_skylib_support
add_rules_testing "MODULE.bazel"
add_bazel_skylib "MODULE.bazel"
add_rules_python "MODULE.bazel"
add_platforms "MODULE.bazel"
src=$(get_runfiles_dir $1)
dest="${2:-$1}"
if [ ! -e "$src" ]; then
Expand Down
5 changes: 3 additions & 2 deletions src/test/shell/bazel/allowlist_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ source "${CURRENT_DIR}/../integration_test_setup.sh" \
# repo structure:
# ${WORKSPACE_DIR}/
# vinegar/
# WORKSPACE
# MODULE.bazel
# local_repository
# rules.bzl
# rule_with_external_dep
Expand Down Expand Up @@ -73,7 +73,8 @@ EOF

cd ${WORKSPACE_DIR}
mkdir -p vinegar
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 = 'secret_ingredient', path = "${repo2}")
EOF
cat > vinegar/rules.bzl <<EOF
Expand Down
5 changes: 5 additions & 0 deletions src/test/shell/bazel/apple/bazel_apple_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ function set_up() {
XCODE_VERSION=$(xcodebuild -version | grep ^Xcode | cut -d' ' -f2)

create_new_workspace

cat > $(setup_module_dot_bazel) <<EOF
xcode_configure = use_extension("@bazel_tools//tools/osx:xcode_configure.bzl", "xcode_configure_extension")
use_repo(xcode_configure, "local_config_xcode")
EOF
}

function test_host_xcodes() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/shell/bazel/archive_contents_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ test_tar_utf8() {
FILE_URL="file://${WRKDIR}/ext.tar"
fi

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 = "ext",
Expand Down
14 changes: 8 additions & 6 deletions src/test/shell/bazel/bazel_build_event_stream_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ function set_up() {
FILE_URL="file://${PWD}/remote_file"
fi

cat > WORKSPACE <<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
cat > MODULE.bazel <<EOF
http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(name="remote", urls=["${FILE_URL}"])
EOF
cat > pkg/BUILD <<'EOF'
Expand Down Expand Up @@ -152,8 +152,8 @@ function test_query() {
function test_fetch_failure() {
# We expect that if a build is failing due to an error fetching an external
# repository, we get a reasonable attribution of the root cause.
cat > WORKSPACE <<'EOF'
load("//:failing_repo.bzl", "failing")
cat > MODULE.bazel <<'EOF'
failing = use_repo_rule("//:failing_repo.bzl", "failing")
failing(name="remote")
EOF
Expand Down Expand Up @@ -184,9 +184,11 @@ EOF
bazel build -k --build_event_text_file=$TEST_log //pkg:main //pkg:main2 \
&& fail "expected failure" || :

expect_log 'label: "//external:remote"'
# TODO: https://github.com/bazelbuild/bazel/issues/23240
# Create a new event id type that doesn't use "//external"
expect_log 'label: "//external:+_repo_rules+remote"'
expect_log 'description:.*This is the error message'
expect_not_log 'label.*@remote//file'
expect_not_log 'label.*@+_repo_rules+remote//file'
}

function test_residue_in_run_bep(){
Expand Down
12 changes: 6 additions & 6 deletions src/test/shell/bazel/bazel_embedded_starlark_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test_pkg_tar() {
rm -rf main
mkdir main
cd main
create_workspace_with_default_repos WORKSPACE
setup_module_dot_bazel
echo Hello World > foo.txt
echo Hello World, again > bar.txt
cat > BUILD <<'EOF'
Expand All @@ -51,7 +51,7 @@ test_pkg_tar_quoting() {
rm -rf main out
mkdir main
cd main
create_workspace_with_default_repos WORKSPACE
setup_module_dot_bazel
mkdir data
echo 'with equal' > data/'foo=bar'
echo 'like an option' > data/--foo
Expand Down Expand Up @@ -85,8 +85,8 @@ EOF
EXTREPODIR=`pwd`
mkdir main
cd main
cat >> $(create_workspace_with_default_repos WORKSPACE) <<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
cat > $(setup_module_dot_bazel) <<EOF
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name="ext",
urls=["file://${EXTREPODIR}/ext.zip"],
Expand Down Expand Up @@ -128,8 +128,8 @@ EOF

mkdir main
cd main
cat >> $(create_workspace_with_default_repos WORKSPACE) <<EOF
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
cat > $(setup_module_dot_bazel) <<EOF
new_git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
new_git_repository(
name="ext",
remote="file://${EXTREPODIR}/extgit/.git",
Expand Down
5 changes: 4 additions & 1 deletion src/test/shell/bazel/bazel_example_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ javabase=${javabase%/bin/java}

function set_up() {
copy_examples
create_workspace_with_default_repos "WORKSPACE" "io_bazel"
cat > MODULE.bazel <<EOF
module(name="io_bazel")
EOF
add_rules_java "MODULE.bazel"
}

#
Expand Down
13 changes: 7 additions & 6 deletions src/test/shell/bazel/bazel_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,8 @@ EOF
}

function test_auto_bazel_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 = "other_repo",
path = "other_repo",
Expand Down Expand Up @@ -1814,7 +1815,7 @@ public class Test {
EOF

mkdir -p other_repo
touch other_repo/WORKSPACE
touch other_repo/REPO.bazel

mkdir -p other_repo/pkg
cat > other_repo/pkg/BUILD.bazel <<'EOF'
Expand Down Expand Up @@ -1900,14 +1901,14 @@ EOF
expect_log "in pkg/Library.java: ''"

bazel run @other_repo//pkg:binary &>"$TEST_log" || fail "Run should succeed"
expect_log "in external/other_repo/pkg/Binary.java: 'other_repo'"
expect_log "in external/other_repo/pkg/Library2.java: 'other_repo'"
expect_log "in external/other_repo/pkg/Binary.java: '+_repo_rules+other_repo'"
expect_log "in external/other_repo/pkg/Library2.java: '+_repo_rules+other_repo'"
expect_log "in pkg/Library.java: ''"

bazel test --test_output=streamed \
@other_repo//pkg:test &>"$TEST_log" || fail "Test should succeed"
expect_log "in external/other_repo/pkg/Test.java: 'other_repo'"
expect_log "in external/other_repo/pkg/Library2.java: 'other_repo'"
expect_log "in external/other_repo/pkg/Test.java: '+_repo_rules+other_repo'"
expect_log "in external/other_repo/pkg/Library2.java: '+_repo_rules+other_repo'"
expect_log "in pkg/Library.java: ''"
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/shell/bazel/bazel_java_test_defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ EOF

# VANILLA_TOOLCHAIN_CONFIGURATION shall use VanillaJavaBuilder and not override any JDK internal compiler classes.
function test_default_java_toolchain_vanillaToolchain() {
add_rules_java MODULE.bazel
cat >> MODULE.bazel <<EOF
java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
use_repo(java_toolchains, "local_jdk")
EOF
cat > BUILD <<EOF
load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain", "VANILLA_TOOLCHAIN_CONFIGURATION")
default_java_toolchain(
Expand Down
15 changes: 7 additions & 8 deletions src/test/shell/bazel/bazel_java_tools_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ function set_up() {
if "$is_windows"; then
java_tools_prebuilt_zip_file_url="file:///${java_tools_prebuilt_rlocation}"
fi
cat > WORKSPACE <<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
EOF
cat $(rlocation io_bazel/src/tests/shell/bazel/rules_license_stanza.txt) >> WORKSPACE
cat >> WORKSPACE <<EOF
cat > $(setup_module_dot_bazel) <<EOF
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "local_java_tools",
urls = ["${java_tools_zip_file_url}"]
Expand All @@ -87,11 +84,13 @@ http_archive(
name = "local_java_tools_prebuilt",
urls = ["${java_tools_prebuilt_zip_file_url}"]
)
EOF
cat $(rlocation io_bazel/src/tests/shell/bazel/rules_license_stanza.txt) >> WORKSPACE
cat > MODULE.bazel <<EOF
bazel_dep(name = "abseil-cpp", version = "20240116.2", repo_name = "com_google_absl")
EOF
# Dependencies of java_tools
add_platforms "MODULE.bazel"
add_rules_cc "MODULE.bazel"
add_rules_proto "MODULE.bazel"
add_rules_license "MODULE.bazel"
}

function expect_path_in_java_tools() {
Expand Down
Loading

0 comments on commit 7c7aafa

Please sign in to comment.