diff --git a/.bazelrc b/.bazelrc index f9d706b6832..c71d7a893c8 100644 --- a/.bazelrc +++ b/.bazelrc @@ -505,9 +505,6 @@ common:fission --remote_download_regex=.*\.dwo$ # Avoid failing builds when BES metadata fails to upload. common --bes_upload_mode=fully_async -# Default Mongo Version if a version is not specified. -common --define=MONGO_VERSION=8.2.0-alpha - # Default distmod if not specified. common --define=MONGO_DISTMOD="" @@ -523,6 +520,9 @@ try-import %workspace%/.bazelrc.evergreen # local default dev settings try-import %workspace%/.bazelrc.common_bes +# local default dev settings +try-import %workspace%/.bazelrc.mongo_variables + # local git version info try-import %workspace%/.bazelrc.git diff --git a/.gitignore b/.gitignore index cd5e71d0d10..cce677acd8f 100644 --- a/.gitignore +++ b/.gitignore @@ -291,6 +291,8 @@ buildozer .bazelrc.gitinfo .bazelrc.workstation .bazelrc.common_bes +.bazelrc.mongo_variables +.bazelrc.mongo_version .bazelrc.compiledb .bazelrc.sync .compiledb diff --git a/BUILD.bazel b/BUILD.bazel index 5350268b5bd..7c3ca9dc411 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -220,13 +220,13 @@ mongo_install( "//conditions:default": ["//src/mongo/db:mongod"], }), package_extract_name = select({ - "//bazel/config:build_enterprise_linux_enabled": "mongodb-linux-{TARGET_CPU}-enterprise-{MONGO_DISTMOD}-{MONGO_VERSION}", - "//bazel/config:build_enterprise_linux_disabled": "mongodb-linux-{TARGET_CPU}-{MONGO_DISTMOD}-{MONGO_VERSION}", - "//bazel/config:build_enterprise_windows_enabled": "mongodb-win32-{TARGET_CPU}-enterprise-{MONGO_DISTMOD}-{MONGO_VERSION}", - "//bazel/config:build_enterprise_windows_disabled": "mongodb-win32-{TARGET_CPU}-{MONGO_DISTMOD}-{MONGO_VERSION}", - "//bazel/config:build_enterprise_mac_enabled": "mongodb-macos-{TARGET_CPU}-enterprise-{MONGO_DISTMOD}-{MONGO_VERSION}", - "//bazel/config:build_enterprise_mac_disabled": "mongodb-macos-{TARGET_CPU}-{MONGO_DISTMOD}-{MONGO_VERSION}", - "//conditions:default": "mongodb-{TARGET_CPU}-{MONGO_DISTMOD}-{MONGO_VERSION}", + "//bazel/config:build_enterprise_linux_enabled": "mongodb-linux-{MONGO_ARCH}-enterprise-{MONGO_DISTMOD}-{MONGO_VERSION}", + "//bazel/config:build_enterprise_linux_disabled": "mongodb-linux-{MONGO_ARCH}-{MONGO_DISTMOD}-{MONGO_VERSION}", + "//bazel/config:build_enterprise_windows_enabled": "mongodb-win32-{MONGO_ARCH}-enterprise-{MONGO_DISTMOD}-{MONGO_VERSION}", + "//bazel/config:build_enterprise_windows_disabled": "mongodb-win32-{MONGO_ARCH}-{MONGO_DISTMOD}-{MONGO_VERSION}", + "//bazel/config:build_enterprise_mac_enabled": "mongodb-macos-{MONGO_ARCH}-enterprise-{MONGO_DISTMOD}-{MONGO_VERSION}", + "//bazel/config:build_enterprise_mac_disabled": "mongodb-macos-{MONGO_ARCH}-{MONGO_DISTMOD}-{MONGO_VERSION}", + "//conditions:default": "mongodb-{MONGO_ARCH}-{MONGO_DISTMOD}-{MONGO_VERSION}", }), publish_debug_in_stripped = select({ "@platforms//os:windows": True, diff --git a/bazel/wrapper_hook/BUILD.bazel b/bazel/wrapper_hook/BUILD.bazel index ff83f4303f8..27292c4cacf 100644 --- a/bazel/wrapper_hook/BUILD.bazel +++ b/bazel/wrapper_hook/BUILD.bazel @@ -10,6 +10,7 @@ py_library( "install_modules.py", "lint.py", "plus_interface.py", + "set_mongo_variables.py", "wrapper_debug.py", "wrapper_hook.py", ], diff --git a/bazel/wrapper_hook/compiledb.py b/bazel/wrapper_hook/compiledb.py index 084775c6b7e..92ca5c1b936 100644 --- a/bazel/wrapper_hook/compiledb.py +++ b/bazel/wrapper_hook/compiledb.py @@ -11,6 +11,8 @@ import sys REPO_ROOT = pathlib.Path(__file__).parent.parent.parent sys.path.append(str(REPO_ROOT)) +from bazel.wrapper_hook.set_mongo_variables import write_mongo_variables_bazelrc + def run_pty_command(cmd): stdout = None @@ -43,6 +45,9 @@ def run_pty_command(cmd): def generate_compiledb(bazel_bin, persistent_compdb, enterprise): + + # compiledb ignores command line args so just make a version rc file in anycase + write_mongo_variables_bazelrc([]) if persistent_compdb: info_proc = subprocess.run( [bazel_bin, "info", "output_base"], capture_output=True, text=True diff --git a/bazel/wrapper_hook/set_mongo_variables.py b/bazel/wrapper_hook/set_mongo_variables.py new file mode 100644 index 00000000000..bc3abf5afe2 --- /dev/null +++ b/bazel/wrapper_hook/set_mongo_variables.py @@ -0,0 +1,45 @@ +import hashlib +import os +import pathlib +import platform +import subprocess + +ARCH_NORMALIZE_MAP = { + "amd64": "x86_64", + "x86_64": "x86_64", + "arm64": "aarch64", + "aarch64": "aarch64", + "ppc64le": "ppc64le", + "s390x": "s390x", +} + +def get_mongo_arch(args): + arch = platform.machine().lower() + if arch in ARCH_NORMALIZE_MAP: + return ARCH_NORMALIZE_MAP[arch] + else: + return arch + +def get_mongo_version(args): + proc = subprocess.run(["git", "describe", "--abbrev=0"], capture_output=True, text=True) + return proc.stdout.strip()[1:] + +def write_mongo_variables_bazelrc(args): + mongo_version = get_mongo_version(args) + mongo_arch = get_mongo_arch(args) + + repo_root = pathlib.Path(os.path.abspath(__file__)).parent.parent.parent + version_file = os.path.join(repo_root, ".bazelrc.mongo_variables") + existing_hash = "" + if os.path.exists(version_file): + with open(version_file, encoding="utf-8") as f: + existing_hash = hashlib.md5(f.read().encode()).hexdigest() + + bazelrc_contents = f""" +common --define=MONGO_ARCH={mongo_arch} +common --define=MONGO_VERSION={mongo_version} +""" + current_hash = hashlib.md5(bazelrc_contents.encode()).hexdigest() + if existing_hash != current_hash: + with open(version_file, "w", encoding="utf-8") as f: + f.write(bazelrc_contents) diff --git a/bazel/wrapper_hook/wrapper_hook.py b/bazel/wrapper_hook/wrapper_hook.py index 8e2f5ac9204..4f67f1afd8b 100644 --- a/bazel/wrapper_hook/wrapper_hook.py +++ b/bazel/wrapper_hook/wrapper_hook.py @@ -22,6 +22,7 @@ def main(): from bazel.wrapper_hook.engflow_check import engflow_auth from bazel.wrapper_hook.generate_common_bes_bazelrc import write_workstation_bazelrc from bazel.wrapper_hook.plus_interface import check_bazel_command_type, test_runner_interface + from bazel.wrapper_hook.set_mongo_variables import write_mongo_variables_bazelrc # This is used to autogenerate a BUILD.bazel that creates # Filegroups for select tags - used to group targets for installing @@ -42,6 +43,8 @@ def main(): write_workstation_bazelrc(args) + write_mongo_variables_bazelrc(args) + args = test_runner_interface( sys.argv[1:], autocomplete_query=os.environ.get("MONGO_AUTOCOMPLETE_QUERY") == "1", diff --git a/buildscripts/package_test.py b/buildscripts/package_test.py index bb8b00418cc..e454b5fa1ef 100644 --- a/buildscripts/package_test.py +++ b/buildscripts/package_test.py @@ -249,6 +249,16 @@ VERSIONS_TO_SKIP: Set[str] = set( ) DISABLED_TESTS: Set[Tuple[str, str]] = set() +VALID_TAR_DIRECTORY_ARCHITECTURES = [ + "linux-aarch64", + "linux-x86_64", + "linux-ppc64le", + "linux-s390x", + "macos-aarch64", + "macos-x86_64", + "windows-x86_64", +] + @dataclasses.dataclass class Test: @@ -523,6 +533,12 @@ def get_edition_alias(edition_name: str) -> str: return "org" return edition_name +def validate_top_level_directory(tar_name: str): + command = f"tar -tf {tar_name} | head -n 1 | awk -F/ '{{print $1}}'" + proc = subprocess.run(command, capture_output=True, shell=True, text=True) + top_level_directory = proc.stdout.strip() + if all(os_arch not in top_level_directory for os_arch in VALID_TAR_DIRECTORY_ARCHITECTURES): + raise Exception(f"Found an unexpected os-arch pairing as the top level directory. Top level directory: {top_level_directory}") arches: Set[str] = set() oses: Set[str] = set() @@ -663,6 +679,8 @@ if args.command == "branch": ) ) + validate_top_level_directory("mongo-binaries.tgz") + if not args.skip_enterprise_check: logging.info( "Checking the source files used to build the binaries, use --skip-enterprise-check to skip this check."