SERVER-123515 make single source of truth for bazel binary in CI (#51229)

GitOrigin-RevId: bc4bf052301df5178c4aac5383679d1fead46cd4
This commit is contained in:
Daniel Moody 2026-04-07 13:45:20 -05:00 committed by MongoDB Bot
parent e88aa21206
commit c1e39887a7
10 changed files with 35 additions and 12 deletions

View File

@ -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(

View File

@ -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,

View File

@ -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

View File

@ -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.

View File

@ -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)"

View File

@ -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)"

View File

@ -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"

View File

@ -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!"

View File

@ -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"

View File

@ -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: