Skip to content

Commit 5339b1e

Browse files
patricearruda84MongoDB Bot
authored and
MongoDB Bot
committed
SERVER-103205: Remove Linux v4 cc mongo toolchain files. (#34989)
GitOrigin-RevId: 0b38fa0899548366c1d164b6525d9a90e30d1201
1 parent c9700d3 commit 5339b1e

9 files changed

+34
-1142
lines changed

MODULE.bazel.lock

-960
This file was deleted.

bazel/bazelisk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def resolve_latest_version(version_history, offset):
231231
if offset >= len(version_history):
232232
version = "latest-{}".format(offset) if offset else "latest"
233233
raise Exception(
234-
'Cannot resolve version "{}": There are only {} Bazel ' "releases.".format(
234+
'Cannot resolve version "{}": There are only {} Bazel releases.'.format(
235235
version, len(version_history)
236236
)
237237
)

bazel/config/configs.bzl

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ compiler_type = rule(
2626
# mongo_toolchain_version
2727
# =========
2828

29-
mongo_toolchain_version_values = ["v4", "v5"]
29+
mongo_toolchain_version_values = ["v5"]
3030

3131
mongo_toolchain_version_provider = provider(
32-
doc = "Select the mongo toolchain version (e.g.: v4)",
33-
fields = {"mongo_toolchain_version": "Choose one of [v4, v5]"},
32+
doc = "Select the mongo toolchain version (e.g.: v5)",
33+
fields = {"mongo_toolchain_version": "Choose one of " + ".".join(mongo_toolchain_version_values)},
3434
)
3535

3636
def mongo_toolchain_version_impl(ctx):
3737
mongo_toolchain_version_value = ctx.build_setting_value
3838
if mongo_toolchain_version_value not in mongo_toolchain_version_values:
39-
fail(str(ctx.label) + " mongo_toolchain_version allowed to take values {" + ", ".join(mongo_toolchain_version_value) + "} but was set to unallowed value " + mongo_toolchain_version_value)
39+
fail(str(ctx.label) + " mongo_toolchain_version allowed to take values {" + ", ".join(mongo_toolchain_version_values) + "} but was set to unallowed value " + mongo_toolchain_version_value)
4040
return mongo_toolchain_version_provider(mongo_toolchain_version = mongo_toolchain_version_value)
4141

4242
mongo_toolchain_version = rule(

bazel/toolchains/cc/mongo_linux/mongo_toolchain.bzl

+3-13
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ toolchain_download = repository_rule(
119119
doc = "Host architecture.",
120120
),
121121
"version": attr.string(
122-
values = ["v4", "v5"],
122+
values = ["v5"],
123123
doc = "Mongodbtoolchain version.",
124124
mandatory = True,
125125
),
@@ -135,20 +135,13 @@ toolchain_download = repository_rule(
135135
)
136136

137137
def setup_mongo_toolchains():
138-
toolchain_download(
139-
name = "mongo_toolchain_v4",
140-
version = "v4",
141-
flags_tpl = "//bazel/toolchains/cc/mongo_linux:mongo_toolchain_flags_v4.bzl",
142-
)
143-
144138
toolchain_download(
145139
name = "mongo_toolchain_v5",
146140
version = "v5",
147141
flags_tpl = "//bazel/toolchains/cc/mongo_linux:mongo_toolchain_flags_v5.bzl",
148142
)
149143

150144
native.register_toolchains(
151-
"@mongo_toolchain_v4//:all",
152145
"@mongo_toolchain_v5//:all",
153146
)
154147

@@ -170,11 +163,8 @@ def setup_mongo_toolchain_aliases():
170163
for target in toolchain_targets:
171164
selects[target] = {}
172165

173-
for version in ("v4", "v5"):
174-
toolchain_name = "mongo_toolchain_{}".format(version)
175-
option_name = "//bazel/config:mongo_toolchain_{}".format(version)
176-
for target in toolchain_targets:
177-
selects[target][option_name] = "@{}//:{}".format(toolchain_name, target)
166+
for target in toolchain_targets:
167+
selects[target]["//bazel/config:mongo_toolchain_v5"] = "@mongo_toolchain_v5//:{}".format(target)
178168

179169
for target, local_alias in toolchain_targets.items():
180170
native.alias(

bazel/toolchains/cc/mongo_linux/mongo_toolchain_flags_v4.bzl

-33
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain_version_v4.bzl", "TOOLCHAIN_MAP_V4")
21
load("//bazel/toolchains/cc/mongo_linux:mongo_toolchain_version_v5.bzl", "TOOLCHAIN_MAP_V5")
32

43
TOOLCHAIN_MAP = {
5-
"v4": TOOLCHAIN_MAP_V4,
64
"v5": TOOLCHAIN_MAP_V5,
75
}

bazel/toolchains/cc/mongo_linux/mongo_toolchain_version_v4.bzl

-116
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("//bazel/toolchains/cc:mongo_toolchain_version_v5.bzl", "TOOLCHAIN_MAP_V5")
2+
3+
TOOLCHAIN_MAP = {
4+
"v5": TOOLCHAIN_MAP_V5,
5+
}

buildscripts/mongo_toolchain.py

+21-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from pathlib import Path
55
from typing import Optional
66

7+
sys.path.append("bazel")
8+
from bazelisk import get_bazel_path, make_bazel_cmd
9+
710
# WARNING: this file is imported from outside of any virtual env so the main import block MUST NOT
811
# import any third-party non-std libararies. Libraries needed when running as a script can be
912
# conditionally imported below.
@@ -13,7 +16,7 @@
1316
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(os.path.realpath(__file__)))))
1417

1518

16-
SUPPORTED_VERSIONS = ("v4", "v5")
19+
SUPPORTED_VERSIONS = "v5"
1720

1821

1922
class MongoToolchainError(RuntimeError):
@@ -76,13 +79,20 @@ def _get_lib_dir_path(self) -> Path:
7679
return self._root_dir / "lib"
7780

7881

79-
def _run_command(cmd: str) -> str:
80-
return subprocess.check_output(cmd, shell=True, text=True).strip()
82+
def _execute_bazel(argv):
83+
bazel_cmd = make_bazel_cmd(get_bazel_path(), argv)
84+
cmd = f"{bazel_cmd['exec']} {' '.join(bazel_cmd['args'])}"
85+
return subprocess.check_output(
86+
cmd,
87+
env=bazel_cmd["env"],
88+
shell=True,
89+
text=True,
90+
).strip()
8191

8292

8393
def _fetch_bazel_toolchain(version: str) -> None:
8494
try:
85-
_run_command(f"bazel build --config=local @mongo_toolchain_{version}//:all")
95+
_execute_bazel(["build", "--config=local", f"@mongo_toolchain_{version}//:all"])
8696
except subprocess.CalledProcessError as e:
8797
raise MongoToolchainNotFoundError(
8898
f"Failed to fetch bazel toolchain: `{e.cmd}` exited with code {e.returncode}"
@@ -91,13 +101,12 @@ def _fetch_bazel_toolchain(version: str) -> None:
91101

92102
def _get_bazel_execroot() -> Path:
93103
try:
94-
execroot_str = _run_command("bazel info execution_root")
104+
execroot_str = _execute_bazel(["info", "execution_root"])
95105
except subprocess.CalledProcessError as e:
96106
raise MongoToolchainNotFoundError(
97107
f"Couldn't find bazel execroot: `{e.cmd}` exited with code {e.returncode}"
98108
)
99-
execroot = Path(execroot_str)
100-
return execroot
109+
return Path(execroot_str)
101110

102111

103112
def _get_bazel_toolchain_path(version: str) -> Path:
@@ -139,15 +148,15 @@ def get_mongo_toolchain(
139148
if toolchain_path is not None:
140149
return _get_toolchain_from_path(toolchain_path)
141150

142-
# If no version given, look in the environment or default to v4.
151+
# If no version given, look in the environment or default to v5.
143152
if version is None:
144-
version = os.environ.get("MONGO_TOOLCHAIN_VERSION", "v4")
153+
version = os.environ.get("MONGO_TOOLCHAIN_VERSION", "v5")
145154
assert version is not None
146155
if version not in SUPPORTED_VERSIONS:
147156
raise MongoToolchainNotFoundError(f"Unknown toolchain version {version}")
148157

149-
# If from_bazel is unspecified. Look in the environment or fall back to a default based on
150-
# the version (v4 -> not from bazel, v5 -> from bazel).
158+
# If from_bazel is unspecified, let's query from bazel where querying toolchain
159+
# version is supported since v5.
151160
def _parse_from_bazel_envvar(value: str) -> bool:
152161
v = value.lower()
153162
if v in ("true", "1"):
@@ -158,8 +167,7 @@ def _parse_from_bazel_envvar(value: str) -> bool:
158167
raise ValueError(f"Invalid value {value} for MONGO_TOOLCHAIN_FROM_BAZEL")
159168

160169
if from_bazel is None:
161-
from_bazel_default = "false" if version == "v4" else "true"
162-
from_bazel_value = os.environ.get("MONGO_TOOLCHAIN_FROM_BAZEL", from_bazel_default)
170+
from_bazel_value = os.environ.get("MONGO_TOOLCHAIN_FROM_BAZEL", "true")
163171
from_bazel = _parse_from_bazel_envvar(from_bazel_value)
164172

165173
if from_bazel:

0 commit comments

Comments
 (0)