Skip to content

Commit 3a33a8d

Browse files
committed
Stop using system-wide Python for Bazel
Instead we rely on the hermetic Python toolchain installed via https://github.com/bazelbuild/rules_python. Most of the py_* targets already work fine with it. This commit also replaces workspace_status_command so that it does not require system-wide Python installation and instead use a simple Bash script on Linux/macOS and a PowerShell script on Windows.
1 parent 7ef46ae commit 3a33a8d

File tree

9 files changed

+27
-52
lines changed

9 files changed

+27
-52
lines changed

.bazelrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
try-import .bazelrc.local
22

33
# Ensure Windows support is accurate.
4+
45
startup --windows_enable_symlinks
56
build --enable_runfiles
67

@@ -31,7 +32,10 @@ build --action_env=PATH
3132

3233
# For build stamping
3334

34-
build --workspace_status_command=scripts/build-info.py
35+
build --enable_platform_specific_config
36+
build:linux --workspace_status_command=scripts/build-info.sh
37+
build:macos --workspace_status_command=scripts/build-info.sh
38+
build:windows --workspace_status_command="powershell.exe scripts/build-info.ps1"
3539

3640
# Make sure we get something helpful when tests fail
3741

BUILD.bazel

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
load("//common:browsers.bzl", "chrome_data", "firefox_data")
22
load("//java:browsers.bzl", "chrome_jvm_flags", "firefox_jvm_flags")
33
load("//java:defs.bzl", "artifact")
4-
load("@rules_python//python:defs.bzl", "py_runtime_pair")
54

65
filegroup(
76
name = "license",
@@ -12,29 +11,6 @@ filegroup(
1211
visibility = ["//visibility:public"],
1312
)
1413

15-
py_runtime(
16-
name = "py3_runtime",
17-
interpreter_path = select({
18-
"@platforms//os:macos": "/usr/bin/python3",
19-
"@platforms//os:linux": "/usr/bin/python",
20-
"@platforms//os:windows": "C:\\Python310\\python",
21-
}),
22-
python_version = "PY3",
23-
stub_shebang = "#!/usr/bin/python3",
24-
)
25-
26-
py_runtime_pair(
27-
name = "py_runtime_pair",
28-
py2_runtime = None,
29-
py3_runtime = ":py3_runtime",
30-
)
31-
32-
toolchain(
33-
name = "py_toolchain",
34-
toolchain = ":py_runtime_pair",
35-
toolchain_type = "@rules_python//python:toolchain_type",
36-
)
37-
3814
alias(
3915
name = "grid",
4016
actual = "//java/src/org/openqa/selenium/grid:executable-grid",

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ CrazyFun::Mappings::RakeMappings.new.add_all(crazy_fun)
8585

8686
# If it looks like a bazel target, build it with bazel
8787
rule /\/\/.*/ do |task|
88-
task.out = Bazel.execute('build', %w[--workspace_status_command scripts/build-info.py], task.name)
88+
task.out = Bazel.execute('build', task.name)
8989
end
9090

9191
# Spoof tasks to get CI working with bazel

WORKSPACE

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@ workspace(
22
name = "selenium",
33
)
44

5-
load("//common/private:env.bzl", "env")
6-
7-
env(
8-
name = "python_version",
9-
env_var = ["PYTHON_VERSION"],
10-
)
11-
12-
load("@python_version//:defs.bzl", "PYTHON_VERSION")
13-
14-
register_toolchains(":py_toolchain")
15-
165
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
176

187
http_archive(
@@ -57,7 +46,7 @@ load("@rules_python//python:repositories.bzl", "python_register_toolchains")
5746

5847
python_register_toolchains(
5948
name = "python_toolchain",
60-
python_version = PYTHON_VERSION,
49+
python_version = "3.8",
6150
)
6251

6352
load("@python_toolchain//:defs.bzl", "interpreter")

py/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ py_binary(
264264
"//common/devtools/chromium/" + n + ":js_protocol",
265265
],
266266
outs = ["selenium/webdriver/common/devtools/" + n],
267-
cmd = "python3 $(location :generate) $(location //common/devtools/chromium/" + n + ":browser_protocol) $(location //common/devtools/chromium/" + n + ":js_protocol) $@",
267+
cmd = "$(location :generate) $(location //common/devtools/chromium/" + n + ":browser_protocol) $(location //common/devtools/chromium/" + n + ":js_protocol) $@",
268268
tools = [
269269
":generate",
270270
],

rake_tasks/bazel/task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def needed?
55
end
66

77
def invoke(*_args, &block)
8-
self.out = Bazel::execute("build", ["--workspace_status_command=\"#{py_exe} scripts/build-info.py\""], name, &block)
8+
self.out = Bazel::execute("build", name, &block)
99

1010
block&.call(cmd_out)
1111
end

scripts/build-info.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$revision = (git rev-parse --short HEAD)
2+
$dirtyout = (git status --porcelain --untracked-files=no)
3+
if ($dirtyout -eq $null) {
4+
$dirty = ""
5+
} else {
6+
$dirty = "*"
7+
}
8+
echo "STABLE_GIT_REVISION $revision$dirty"

scripts/build-info.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

scripts/build-info.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
revision=$(git rev-parse --short HEAD)
4+
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
5+
dirty="*"
6+
else
7+
dirty=""
8+
fi
9+
10+
echo "STABLE_GIT_REVISION $revision$dirty"

0 commit comments

Comments
 (0)