diff --git a/buildscripts/gather_failed_tests.py b/buildscripts/gather_failed_tests.py index 6a08c8219ed..46eb9dd022a 100644 --- a/buildscripts/gather_failed_tests.py +++ b/buildscripts/gather_failed_tests.py @@ -8,6 +8,10 @@ from pathlib import Path import typer +def _bazel_binary() -> str: + return os.environ.get("BAZEL_BINARY", "bazel") + + def process_bep(bep_path): failed_tests = [] successful_tests = [] @@ -36,7 +40,7 @@ def _relink_binaries_with_symbols(failed_test_labels: list[str]): bazel_build_flags.append("--remote_download_outputs=toplevel") - relink_command = ["bazel", "build", *bazel_build_flags, *failed_test_labels] + relink_command = [_bazel_binary(), "build", *bazel_build_flags, *failed_test_labels] print(f"Running command: {' '.join(relink_command)}") subprocess.run( diff --git a/buildscripts/generate_result_tasks.py b/buildscripts/generate_result_tasks.py index 1caaf97d23b..cc96f0f5439 100644 --- a/buildscripts/generate_result_tasks.py +++ b/buildscripts/generate_result_tasks.py @@ -47,6 +47,10 @@ NIGHTLY_PROJECT_CONFIG = "etc/evergreen_nightly.yml" app = typer.Typer(pretty_exceptions_show_locals=False) +def _bazel_binary() -> str: + return os.environ.get("BAZEL_BINARY", "bazel") + + def make_results_task(target: str) -> Task: commands = [ FunctionCall("fetch remote test results", {"test_label": target}), @@ -352,7 +356,7 @@ def query_targets( query = f"({' + '.join(tag_queries)}) - {excluded}" cmd = ( - ["bazel", "cquery"] + [_bazel_binary(), "cquery"] + flags_list + [ query, diff --git a/evergreen/bazel_coverage.sh b/evergreen/bazel_coverage.sh index 1634d404539..6863e7a03c9 100644 --- a/evergreen/bazel_coverage.sh +++ b/evergreen/bazel_coverage.sh @@ -10,6 +10,7 @@ # Needed for evergreen scripts that use evergreen expansions and utility methods. DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" . "$DIR/prelude.sh" +. "$DIR/bazel_evergreen_shutils.sh" cd src @@ -19,9 +20,8 @@ set -o verbose # Use `eval` to force evaluation of the environment variables in the echo statement: eval echo "Execution environment: Args: ${args} Target: ${target}" -# We only support explicitly limited arch for code coverage, so there -# are fewer conditionals here than elsewhere in more general utilities. -BAZEL_BINARY=bazel +BAZEL_BINARY="$(bazel_evergreen_shutils::bazel_get_binary_path)" +export BAZEL_BINARY # Print command being run to file that can be uploaded echo "python buildscripts/install_bazel.py" >bazel-invocation.txt diff --git a/evergreen/bazel_evergreen_shutils.sh b/evergreen/bazel_evergreen_shutils.sh index e597b05c195..fccb6e1db46 100644 --- a/evergreen/bazel_evergreen_shutils.sh +++ b/evergreen/bazel_evergreen_shutils.sh @@ -281,7 +281,9 @@ bazel_evergreen_shutils::retry_bazel_cmd() { local timeout_str="$(bazel_evergreen_shutils::timeout_prefix "${evergreen_remote_exec:-}")" # Get command log path for usage afterwards - last_command_log_path=$(bazel info command_log) + # Use the selected Bazel binary so PPC/s390x don't fall back to a different + # bazel on PATH with different JDK behavior. + last_command_log_path=$("$BAZEL_BINARY" info command_log 2>/dev/null || true) # Everything else is the Bazel subcommand + flags (and possibly redirections/pipes). # We *intentionally* keep it as raw words and reassemble to a single string for eval. diff --git a/evergreen/bazel_run.sh b/evergreen/bazel_run.sh index 1c5b3ad7ff4..245b8b3c49f 100644 --- a/evergreen/bazel_run.sh +++ b/evergreen/bazel_run.sh @@ -23,6 +23,7 @@ bazel_evergreen_shutils::export_ssl_paths_if_needed eval echo "Execution environment: Args: ${args} Target: ${target} redact_args: ${redact_args}" BAZEL_BINARY="$(bazel_evergreen_shutils::bazel_get_binary_path)" +export BAZEL_BINARY # Build LOCAL_ARG for run-mode LOCAL_ARG="$(bazel_evergreen_shutils::compute_local_arg run)" diff --git a/evergreen/bazel_test.sh b/evergreen/bazel_test.sh index 6dba17bdd1f..ad0879b5556 100644 --- a/evergreen/bazel_test.sh +++ b/evergreen/bazel_test.sh @@ -21,6 +21,7 @@ bazel_evergreen_shutils::export_ssl_paths_if_needed eval echo "Execution environment: Targets: ${targets}" BAZEL_BINARY="$(bazel_evergreen_shutils::bazel_get_binary_path)" +export BAZEL_BINARY # Mode-specific LOCAL_ARG and release flag LOCAL_ARG="$(bazel_evergreen_shutils::compute_local_arg test)" diff --git a/evergreen/coverity_build.sh b/evergreen/coverity_build.sh index 32aba7e9015..00a4324f211 100644 --- a/evergreen/coverity_build.sh +++ b/evergreen/coverity_build.sh @@ -1,6 +1,7 @@ #!/bin/env bash DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" . "$DIR/prelude.sh" +. "$DIR/bazel_evergreen_shutils.sh" cd src @@ -15,6 +16,8 @@ fi activate_venv export MONGO_WRAPPER_OUTPUT_ALL=1 +BAZEL_BINARY="$(bazel_evergreen_shutils::bazel_get_binary_path)" +export BAZEL_BINARY # number of parallel jobs to use for build. # Even with scale=0 (the default), bc command adds decimal digits in case of multiplication. Division by 1 gives us a whole number with scale=0 coverity_config_dir="$workdir/coverity/config" @@ -29,7 +32,7 @@ trap 'rm -f "$compiledb_target_pattern_file" "$query_stderr_file"' EXIT echo "Generating compile_commands.json for Coverity capture" echo "Resolving mongo_compiledb targets under //:install-core" query_command=( - bazel + "$BAZEL_BINARY" $bazel_cache cquery $build_config @@ -53,7 +56,7 @@ if [ ! -s "$compiledb_target_pattern_file" ]; then fi build_compiledb_command=( - bazel + "$BAZEL_BINARY" $bazel_cache build $build_config @@ -65,9 +68,9 @@ echo "${build_compiledb_command[@]}" echo "Setting up clang-tidy IDE files" -bazel $bazel_cache run $build_config //:setup_clang_tidy +"$BAZEL_BINARY" $bazel_cache run $build_config //:setup_clang_tidy -compiledb_output_base="$(bazel $bazel_cache info output_base)" +compiledb_output_base="$("$BAZEL_BINARY" $bazel_cache info output_base)" repo_python="" python_candidates=( "$compiledb_output_base/external/_main~setup_mongo_python_toolchains~py_host/dist/bin/python3" diff --git a/evergreen/crypt_run_tests.sh b/evergreen/crypt_run_tests.sh index 568407927a9..61a6f52862a 100755 --- a/evergreen/crypt_run_tests.sh +++ b/evergreen/crypt_run_tests.sh @@ -5,6 +5,7 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" . "$DIR/prelude.sh" +. "$DIR/bazel_evergreen_shutils.sh" cd src @@ -16,6 +17,8 @@ if [ "$(uname)" != "Linux" ]; then exit 0 fi +BAZEL_BINARY="$(bazel_evergreen_shutils::bazel_get_binary_path)" + EXTRACT_DIR="bazel-bin/install" # EXTRACT_DIR is typically a Bazel symlink tree; dereference to the real path up front. if command -v realpath >/dev/null 2>&1; then @@ -85,5 +88,5 @@ $UNITTEST_PATH echo "Mongo Crypt Shared Library unit test succeeded!" echo "Running Mongo Crypt Shared Library debuggability test" -MONGO_WRAPPER_OUTPUT_ALL=1 bazel run gdb -- "$UNITTEST_PATH" --batch -ex "source ${EXTRACT_DIR}/crypt_debuggability_test.py" +MONGO_WRAPPER_OUTPUT_ALL=1 "$BAZEL_BINARY" run gdb -- "$UNITTEST_PATH" --batch -ex "source ${EXTRACT_DIR}/crypt_debuggability_test.py" echo "Mongo Crypt Shared Library shared library debuggability test succeeded!" diff --git a/evergreen/resmoke_tests_execute_bazel.sh b/evergreen/resmoke_tests_execute_bazel.sh index 6fa3c453660..899d1082d97 100644 --- a/evergreen/resmoke_tests_execute_bazel.sh +++ b/evergreen/resmoke_tests_execute_bazel.sh @@ -16,6 +16,7 @@ set -o verbose bazel_evergreen_shutils::activate_and_cd_src BAZEL_BINARY=$(bazel_evergreen_shutils::bazel_get_binary_path) +export BAZEL_BINARY ci_flags="--//bazel/resmoke:in_evergreen" diff --git a/evergreen/validate_compile_commands.py b/evergreen/validate_compile_commands.py index 96d2e7f5b47..fe01e456074 100644 --- a/evergreen/validate_compile_commands.py +++ b/evergreen/validate_compile_commands.py @@ -25,6 +25,10 @@ MONGO_TIDY_PLUGIN_CANDIDATES = frozenset( ) +def _get_bazel_binary() -> str: + return os.environ.get("BAZEL_BINARY", "bazel") + + def _get_workspace_dir() -> str: workspace_dir = os.environ.get("BUILD_WORKSPACE_DIRECTORY") if workspace_dir: @@ -43,7 +47,7 @@ def _ensure_compiledb_exists(compdb_path: str) -> None: "Attempting to run " f"'bazel build {' '.join(COMPILEDB_GENERATION_TARGETS)}' to generate it.\n" ) - subprocess.run(["bazel", "build", *COMPILEDB_GENERATION_TARGETS], check=True) + subprocess.run([_get_bazel_binary(), "build", *COMPILEDB_GENERATION_TARGETS], check=True) def _mongo_tidy_checks_supported_platform() -> bool: