Skip to content

Commit

Permalink
Enable Bzlmod in shell integration tests
Browse files Browse the repository at this point in the history
Working towards: bazelbuild#18958

Closes bazelbuild#19785

PiperOrigin-RevId: 573215173
Change-Id: I2b1f24d01f22966df76c6d5ccfaa6ef5cbbfd12f
  • Loading branch information
meteorcloudy authored and copybara-github committed Oct 13, 2023
1 parent 4064d78 commit 175a18d
Show file tree
Hide file tree
Showing 51 changed files with 261 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public static String convertStreamToString(InputStream is) throws Exception {
public void hello(String obj) throws Exception {
String greeting = "Hello";
try {
String greetFile = getRunfiles()
+ "/io_bazel/examples/java-starlark/src/main/resources/greeting.txt";
String greetFile =
getRunfiles() + "/_main/examples/java-starlark/src/main/resources/greeting.txt";
greeting = convertStreamToString(new FileInputStream(greetFile));
} catch (FileNotFoundException e) {
// use default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
// The repository isn't on the file system, there is nothing we can do.
throw new RepositoryFunctionException(
new IOException(
"to fix, run\n\tbazel fetch //...\nExternal repository "
"External repository "
+ repositoryName.getNameWithAt()
+ " not found and fetching repositories is disabled."),
Transience.TRANSIENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2709,7 +2709,7 @@ public RepositoryMapping getMainRepoMapping(
DetailedExitCode.of(
FailureDetail.newBuilder()
.setExternalRepository(FailureDetails.ExternalRepository.getDefaultInstance())
.setMessage("unknown error during computation of main repo mapping")
.setMessage("error during computation of main repo mapping: " + e.getMessage())
.build()),
e);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ msys*)
;;
esac

# TODO: cc_shared_library doesn't work well with Bzlmod.
disable_bzlmod

function test_starlark_cc() {
setup_tests src/main/starlark/tests/builtins_bzl/cc
mkdir -p "src/conditions"
Expand Down
3 changes: 2 additions & 1 deletion src/test/shell/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//:distdir_deps.bzl", "gen_workspace_stanza")
load("@rules_python//python:defs.bzl", "py_test")
load("//:distdir_deps.bzl", "gen_workspace_stanza")

package(default_visibility = ["//visibility:private"])

Expand Down Expand Up @@ -47,6 +47,7 @@ sh_library(
],
data = [
":testenv.sh",
"//src/test/tools/bzlmod:MODULE.bazel.lock",
"@bazel_tools//tools/bash/runfiles",
],
visibility = ["//visibility:public"],
Expand Down
2 changes: 2 additions & 0 deletions src/test/shell/bazel/bazel_coverage_hermetic_py_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ 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

# Fetch hermetic python and register toolchain.
function set_up() {
cat >>WORKSPACE <<EOF
Expand Down
4 changes: 2 additions & 2 deletions src/test/shell/bazel/bazel_coverage_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ import java.nio.channels.*;
import java.net.InetAddress;
public class CovTest extends TestCase {
private static Process startSubprocess(String arg) throws Exception {
String path = System.getenv("TEST_SRCDIR") + "/main/java/cov/Cov_deploy.jar";
String path = System.getenv("TEST_SRCDIR") + "/_main/java/cov/Cov_deploy.jar";
String[] command = {
// Run the deploy jar by invoking JVM because the integration tests
// cannot use the java launcher (b/29388516).
Expand Down Expand Up @@ -580,7 +580,7 @@ import java.nio.channels.*;
import java.net.InetAddress;
public class CovTest extends TestCase {
private static Process startSubprocess(String arg) throws Exception {
String path = System.getenv("TEST_SRCDIR") + "/main/java/cov/Cov_deploy.jar";
String path = System.getenv("TEST_SRCDIR") + "/_main/java/cov/Cov_deploy.jar";
String[] command = {
// Run the deploy jar by invoking JVM because the integration tests
// cannot use the java launcher (b/29388516).
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/bazel_hermetic_sandboxing_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function test_absolute_path() {
function test_symbolic_link() {
bazel build examples/hermetic:symbolic_link &> $TEST_log \
&& fail "Fail due to non hermetic sandbox: examples/hermetic:symbolic_link" || true
expect_log "cat: \/execroot\/main\/examples\/hermetic\/unknown_file.txt: No such file or directory"
expect_log "cat: \/execroot\/_main\/examples\/hermetic\/unknown_file.txt: No such file or directory"
}

# Test that the sandbox discover if the bazel python rule miss dependencies.
Expand Down
1 change: 1 addition & 0 deletions src/test/shell/bazel/bazel_java17_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fi
JAVA_TOOLS_ZIP_FILE_URL=${JAVA_TOOLS_ZIP_FILE_URL:-}
JAVA_TOOLS_PREBUILT_ZIP_FILE_URL=${JAVA_TOOLS_PREBUILT_ZIP_FILE_URL:-}

disable_bzlmod

function set_up() {
cat >>WORKSPACE <<EOF
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/bazel_rules_cc_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ filegroup(name = 'yolo')
EOF

cd rules_cc_can_be_overridden || fail "couldn't cd into workspace"
bazel build @rules_cc//:yolo &> $TEST_log || \
bazel build --noenable_bzlmod @rules_cc//:yolo &> $TEST_log || \
fail "Bazel failed to build @rules_cc"
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/bazel_rules_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def rules_java_toolchains():
EOF

cd rules_java_can_be_overridden || fail "couldn't cd into workspace"
bazel build @rules_java//:yolo &> $TEST_log || \
bazel build --noenable_bzlmod @rules_java//:yolo &> $TEST_log || \
fail "Bazel failed to build @rules_java"
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/shell/bazel/bazel_test_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ sh_test(
EOF

bazel test --test_output=all //foo &> $TEST_log || fail "Test failed"
expect_log "pwd: .*/foo.runfiles/bar$"
expect_log "pwd: .*/foo.runfiles/_main$"
expect_log "src: .*/foo.runfiles$"
expect_log "ws: bar$"
expect_log "ws: _main$"
}

function test_runfiles_java_runfiles_merges_env_vars() {
Expand Down Expand Up @@ -172,8 +172,8 @@ EOF
bazel test --test_env="${overridden}"=override --test_output=all \
//foo >& "${TEST_log}" || fail "Test failed"

expect_log "${overridden}: /.*/execroot/bar/override"
expect_log "${unchanged}: /.*/execroot/bar/bazel-out/[^/]\+-fastbuild/bin/foo/foo.runfiles"
expect_log "${overridden}: /.*/execroot/_main/override"
expect_log "${unchanged}: /.*/execroot/_main/bazel-out/[^/]\+-fastbuild/bin/foo/foo.runfiles"
}

function test_run_under_external_label_with_options() {
Expand Down
20 changes: 10 additions & 10 deletions src/test/shell/bazel/bazel_with_jdk_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,19 @@ EOF
--toolchain_resolution_debug=tools/jdk:runtime_toolchain_type \
--java_runtime_version=8 \
//java/main:JavaExample &>"${TEST_log}" || fail "Autodetecting a fake JDK version 8 and selecting it failed"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @local_jdk//:jdk"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @rules_java~.*~toolchains~local_jdk//:jdk"

bazel cquery \
--toolchain_resolution_debug=tools/jdk:runtime_toolchain_type \
--java_runtime_version=local_jdk_8 \
//java/main:JavaExample &>"${TEST_log}" || fail "Autodetecting a fake JDK version 8 and selecting it failed"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @local_jdk//:jdk"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @rules_java~.*~toolchains~local_jdk//:jdk"

bazel cquery \
--toolchain_resolution_debug=tools/jdk:runtime_toolchain_type \
--java_runtime_version=11 \
//java/main:JavaExample &>"${TEST_log}" || fail "Autodetecting a fake JDK version 8 and selecting it failed"
expect_not_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @local_jdk//:jdk"
expect_not_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @rules_java~.*~toolchains~local_jdk//:jdk"
}

# Bazel shall detect JDK version and configure it with "local_jdk_{version}" and "{version}" setting.
Expand All @@ -207,19 +207,19 @@ EOF
--toolchain_resolution_debug=tools/jdk:runtime_toolchain_type \
--java_runtime_version=11 \
//java/main:JavaExample &>"${TEST_log}" || fail "Autodetecting a fake JDK version 11 and selecting it failed"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @local_jdk//:jdk"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @rules_java~.*~toolchains~local_jdk//:jdk"

bazel cquery \
--toolchain_resolution_debug=tools/jdk:runtime_toolchain_type \
--java_runtime_version=local_jdk_11 \
//java/main:JavaExample &>"${TEST_log}" || fail "Autodetecting a fake JDK version 11 and selecting it failed"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @local_jdk//:jdk"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @rules_java~.*~toolchains~local_jdk//:jdk"

bazel cquery \
--toolchain_resolution_debug=tools/jdk:runtime_toolchain_type \
--java_runtime_version=17 \
//java/main:JavaExample &>"${TEST_log}" || fail "Autodetecting a fake JDK version 11 and selecting it failed"
expect_not_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @local_jdk//:jdk"
expect_not_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @rules_java~.*~toolchains~local_jdk//:jdk"
}

# Bazel shall detect JDK version and configure it with "local_jdk_{version}" and "{version}" setting.
Expand All @@ -242,19 +242,19 @@ EOF
--toolchain_resolution_debug=tools/jdk:runtime_toolchain_type \
--java_runtime_version=11 \
//java/main:JavaExample &>"${TEST_log}" || fail "Autodetecting a fake JDK version 11 and selecting it failed"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @local_jdk//:jdk"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @rules_java~.*~toolchains~local_jdk//:jdk"

bazel cquery \
--toolchain_resolution_debug=tools/jdk:runtime_toolchain_type \
--java_runtime_version=local_jdk_11 \
//java/main:JavaExample &>"${TEST_log}" || fail "Autodetecting a fake JDK version 11 and selecting it failed"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @local_jdk//:jdk"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @rules_java~.*~toolchains~local_jdk//:jdk"

bazel cquery \
--toolchain_resolution_debug=tools/jdk:runtime_toolchain_type \
--java_runtime_version=17 \
//java/main:JavaExample &>"${TEST_log}" || fail "Autodetecting a fake JDK version 11 and selecting it failed"
expect_not_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @local_jdk//:jdk"
expect_not_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @rules_java~.*~toolchains~local_jdk//:jdk"
}

# Failure to detect JDK version shall be handled gracefully.
Expand All @@ -277,7 +277,7 @@ EOF
--toolchain_resolution_debug=tools/jdk:runtime_toolchain_type \
//java/main:JavaExample &>"${TEST_log}" \
|| fail "Failed to resolve Java toolchain when version cannot be detected"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @local_jdk//:jdk"
expect_log "@bazel_tools//tools/jdk:runtime_toolchain_type -> toolchain @rules_java~.*~toolchains~local_jdk//:jdk"
}

# Bazel shall provide Java compilation toolchains that use local JDK.
Expand Down
2 changes: 2 additions & 0 deletions src/test/shell/bazel/bazel_workspaces_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ source "${CURRENT_DIR}/remote_helpers.sh" \

mock_rules_java_to_avoid_downloading

disable_bzlmod

# Sets up a workspace with the given commands inserted into the repository rule
# that will be executed when doing bazel build //:test
function set_workspace_command() {
Expand Down
8 changes: 4 additions & 4 deletions src/test/shell/bazel/cc_flags_supplier_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function test_legacy_make_variable() {
"''"

write_test_target
bazel build --cpu local --crosstool_top=//setup:toolchain //:display &> "$TEST_log" || fail "Build failed"
bazel build --extra_toolchains=//setup:cc-toolchain-local //:display &> "$TEST_log" || fail "Build failed"
expect_log "CC_FLAGS: -test-cflag1 -test-cflag2"
}

Expand All @@ -192,7 +192,7 @@ function test_sysroot() {
"'/sys/root'"

write_test_target
bazel build --cpu local --crosstool_top=//setup:toolchain //:display &> "$TEST_log" || fail "Build failed"
bazel build --extra_toolchains=//setup:cc-toolchain-local //:display &> "$TEST_log" || fail "Build failed"
expect_log "CC_FLAGS: --sysroot=/sys/root"
}

Expand All @@ -212,7 +212,7 @@ function test_feature_config() {
"''"

write_test_target
bazel build --cpu local --crosstool_top=//setup:toolchain //:display &> "$TEST_log" || fail "Build failed"
bazel build --extra_toolchains=//setup:cc-toolchain-local //:display &> "$TEST_log" || fail "Build failed"
expect_log "CC_FLAGS: foo bar baz"
}

Expand All @@ -232,7 +232,7 @@ function test_all_sources() {
"'/sys/root'"

write_test_target
bazel build --cpu local --crosstool_top=//setup:toolchain //:display &> "$TEST_log" || fail "Build failed"
bazel build --extra_toolchains=//setup:cc-toolchain-local //:display &> "$TEST_log" || fail "Build failed"
expect_log "CC_FLAGS: -test-cflag1 -test-cflag2 --sysroot=/sys/root foo bar baz"
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/cc_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ EOF
BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 bazel query 'deps(//:ok)' &>"$TEST_log" || \
fail "Should pass with fake toolchain"
expect_not_log "An error occurred during the fetch of repository 'local_config_cc'"
expect_log "@local_config_cc//:empty"
expect_log "@@bazel_tools~cc_configure_extension~local_config_cc//:empty"
}

function setup_workspace_layout_with_external_directory() {
Expand Down
2 changes: 2 additions & 0 deletions src/test/shell/bazel/check_external_files_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ if "$is_windows"; then
export MSYS2_ARG_CONV_EXCL="*"
fi

disable_bzlmod

function get_extrepourl() {
if $is_windows; then
echo "file:///$(cygpath -m $1)"
Expand Down
4 changes: 2 additions & 2 deletions src/test/shell/bazel/cross_repository_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ EOF

# These should now fail.
bazel query @bar//:bar >& $TEST_log && fail "build should fail"
expect_log "no such package '@bar//': The repository '@bar' could not be resolved"
expect_log "No repository visible as '@bar' from main repository"
bazel query @bar//subbar:subbar >& $TEST_log && fail "build should fail"
expect_log "no such package '@bar//subbar': The repository '@bar' could not be resolved"
expect_log "No repository visible as '@bar' from main repository"
}

# Test for https://github.com/bazelbuild/bazel/issues/2580
Expand Down
7 changes: 4 additions & 3 deletions src/test/shell/bazel/execroot_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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; }

function test_execroot_structure() {
function test_execroot_structure_without_bzlmod() {
ws_name="dooby_dooby_doo"
cat > WORKSPACE <<EOF
workspace(name = "$ws_name")
Expand All @@ -37,8 +37,8 @@ genrule(
)
EOF

bazel build -s //dir:use-srcs &> $TEST_log || fail "expected success"
execroot="$(bazel info execution_root)"
bazel build --noenable_bzlmod -s //dir:use-srcs &> $TEST_log || fail "expected success"
execroot="$(bazel info --noenable_bzlmod execution_root)"
test -e "$execroot/../${ws_name}"
ls -l bazel-out | tee out
assert_contains "$(dirname $execroot)/${ws_name}/bazel-out" out
Expand Down Expand Up @@ -172,6 +172,7 @@ EOF

function test_external_directory_globs() {
touch WORKSPACE
touch MODULE.bazel

mkdir -p external/a external/c
echo file_ab > external/a/b
Expand Down
3 changes: 2 additions & 1 deletion src/test/shell/bazel/external_correctness_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ genrule(
)""",
)
EOF
write_default_lockfile "m/MODULE.bazel.lock"
cd m
bazel "$batch_flag" build @r//:fg &> $TEST_log || \
fail "Expected build to succeed"
Expand All @@ -333,7 +334,7 @@ function test_top_level_dir_changes_nobatch() {

function test_non_extsietnt_repo_in_pattern() {
bazel build @non_existent_repo//... &> $TEST_log && fail "Expected build to fail"
expect_log "ERROR: No such repository '@non_existent_repo'"
expect_log "ERROR: No repository visible as '@non_existent_repo' from main repository"
}

run_suite "//external correctness tests"
4 changes: 2 additions & 2 deletions src/test/shell/bazel/external_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ EOF
# But it is required after a clean.
bazel clean --expunge || fail "Clean failed"
bazel build --fetch=false //zoo:ball-pit >& $TEST_log && fail "Expected build to fail"
expect_log "bazel fetch //..."
expect_log "fetching repositories is disabled"
}

function test_prefix_stripping_tar_gz() {
Expand Down Expand Up @@ -944,7 +944,7 @@ genrule(
)
EOF
bazel build :foo &> "$TEST_log" && fail "Expected failure" || true
expect_log "no such package '@foo//'"
expect_log "No repository visible as '@foo' from main repository"
}

function test_flip_flopping() {
Expand Down
Loading

0 comments on commit 175a18d

Please sign in to comment.