SERVER-98995 Fail the build if the user is not using Bazelisk (#30857)
GitOrigin-RevId: bb5a2b01e3371d97a3e469c379d88ad3268ce594
This commit is contained in:
parent
5d3aa942f5
commit
57bd7f5ff4
3
.bazelrc
3
.bazelrc
@ -396,3 +396,6 @@ try-import %workspace%/.bazelrc.git
|
||||
|
||||
# Used for build profiles and any settings a user wants to consistently use
|
||||
try-import %workspace%/.bazelrc.local
|
||||
|
||||
# Flag as built with bazelisk
|
||||
try-import %workspace%/.bazelrc.bazelisk
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -282,6 +282,7 @@ buildozer
|
||||
.bazelrc.gitinfo
|
||||
.bazelrc.workstation
|
||||
.bazelrc.xcode
|
||||
.bazelrc.bazelisk
|
||||
*.bazel_info_for_ninja.txt
|
||||
.ninja_last_command_line_targets.txt
|
||||
bazel/coverity/analysis/BUILD.bazel
|
||||
|
||||
@ -2444,3 +2444,35 @@ selects.config_setting_group(
|
||||
":linux_gcc_fission",
|
||||
],
|
||||
)
|
||||
|
||||
# --------------------------------------
|
||||
# running_through_bazelisk
|
||||
# --------------------------------------
|
||||
|
||||
bool_flag(
|
||||
name = "running_through_bazelisk",
|
||||
build_setting_default = False,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "running_through_bazelisk_enabled",
|
||||
flag_values = {
|
||||
"//bazel/config:running_through_bazelisk": "True",
|
||||
},
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "x86_64_or_arm64",
|
||||
match_any = [
|
||||
"@platforms//cpu:aarch64",
|
||||
"@platforms//cpu:x86_64",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "running_through_bazelisk_x86_64_or_arm64",
|
||||
match_all = [
|
||||
":x86_64_or_arm64",
|
||||
":running_through_bazelisk_enabled",
|
||||
],
|
||||
)
|
||||
|
||||
@ -1283,6 +1283,20 @@ PGO_PROFILE_FLAGS = select({
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
# Hack to throw an error if the user isn't running bazel through bazelisk,
|
||||
# since we want to make sure the hook inside of tools/bazel gets run.
|
||||
RUNNING_THROUGH_BAZELISK_CHECK = select({
|
||||
"//bazel/config:running_through_bazelisk_x86_64_or_arm64": [],
|
||||
"@platforms//cpu:s390x": [],
|
||||
"@platforms//cpu:ppc": [],
|
||||
}, no_match_error = """
|
||||
Error:
|
||||
This repository must be built through bazelisk, please uninstall your current bazel
|
||||
installation and then run:
|
||||
|
||||
python buildscripts/install_bazel.py
|
||||
""")
|
||||
|
||||
MONGO_GLOBAL_INCLUDE_DIRECTORIES = [
|
||||
"-Isrc",
|
||||
"-I$(GENDIR)/src",
|
||||
@ -1354,7 +1368,8 @@ MONGO_GLOBAL_COPTS = (
|
||||
SASL_WINDOWS_COPTS +
|
||||
COVERAGE_FLAGS +
|
||||
PGO_PROFILE_FLAGS +
|
||||
SHARED_ARCHIVE_COPTS
|
||||
SHARED_ARCHIVE_COPTS +
|
||||
RUNNING_THROUGH_BAZELISK_CHECK
|
||||
)
|
||||
|
||||
MONGO_GLOBAL_LINKFLAGS = (
|
||||
|
||||
@ -645,6 +645,12 @@ def bazel_build_thread_func(env, log_dir: str, verbose: bool, ninja_generate: bo
|
||||
print("Starting bazel build thread...")
|
||||
run_bazel_command(env, bazel_cmd)
|
||||
|
||||
# This is used to detect if a user is running under bazelisk, delete this since
|
||||
# the SCons integration sets up bazelisk internally, but we want to trigger failures
|
||||
# afterwards if the user calls a non-bazelisk bazel directly.
|
||||
if os.path.exists(".bazelrc.bazelisk"):
|
||||
os.remove(".bazelrc.bazelisk")
|
||||
|
||||
|
||||
def create_bazel_builder(builder: SCons.Builder.Builder) -> SCons.Builder.Builder:
|
||||
return SCons.Builder.Builder(
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
# Whenever Bazel is invoked, it first calls this script setting "BAZEL_REAL" to the path of the real Bazel binary.
|
||||
# Use this file as a wrapper for any logic that should run before bazel itself is executed.
|
||||
|
||||
@ -67,4 +69,6 @@ fi
|
||||
|
||||
printf '%s\n' "${bazelrc_xcode_lines[@]}" > .bazelrc.xcode
|
||||
|
||||
echo "common --//bazel/config:running_through_bazelisk" > .bazelrc.bazelisk
|
||||
|
||||
exec "$bazel_real" "$@"
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
@echo off
|
||||
echo common --//bazel/config:running_through_bazelisk > .bazelrc.bazelisk
|
||||
"%BAZEL_REAL%" %*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user