Skip to content

Commit d29f36d

Browse files
[Build] Allow Python version to be set by ENV VAR
1 parent 04f7d00 commit d29f36d

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

‎.bazelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,42 @@ build --flag_alias=pin_browsers=//common:pin_browsers
44
build --flag_alias=headless=//common:headless
55

66
# Set the default java toolchain
7+
78
build --java_runtime_version=remotejdk_11
89
build --tool_java_language_version=11
910

1011
# We target java 8 by default
12+
1113
build --javacopt="--release 8"
1214

1315
# Require java dependencies to be used and first-order
16+
1417
build --experimental_strict_java_deps=strict
1518
build --explicit_java_test_deps
1619

1720
# Ensure builds are unpolluted by the user env
21+
1822
build --incompatible_strict_action_env
1923

2024
# Except for the PATH environment variable
25+
2126
build --action_env=PATH
2227

2328
# For build stamping
29+
2430
build --workspace_status_command=scripts/build-info.py
2531

2632
# Make sure we get something helpful when tests fail
33+
2734
build --verbose_failures
2835
build --test_output=errors
2936

3037
# Tests need to be able to open sockets on localhost
38+
3139
build --noexperimental_sandbox_default_allow_network
3240

3341
# pass environment variables to the test environment
42+
3443
build --test_env=CI
3544
build --test_env=DASHBOARD_URL
3645
build --test_env=DISPLAY
@@ -41,6 +50,7 @@ build --test_env=MOZ_HEADLESS
4150
build --test_env=PATH # Remove once browser pinning works
4251
build --test_env=SELENIUM_BROWSER
4352
build --test_env=TRAVIS
53+
build --test_env=PYTHON_VERSION
4454

4555
test --test_timeout=1800
4656

‎WORKSPACE

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ workspace(
66
},
77
)
88

9+
load("//common/private:env.bzl", "env")
10+
env(
11+
name = "python_version",
12+
env_var=["PYTHON_VERSION"]
13+
)
14+
load("@python_version//:defs.bzl", "PYTHON_VERSION")
15+
16+
917
register_toolchains(":py_toolchain")
1018

1119
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
@@ -61,7 +69,7 @@ load("@rules_python//python:repositories.bzl", "python_register_toolchains")
6169

6270
python_register_toolchains(
6371
name = "python_toolchain",
64-
python_version = "3.9",
72+
python_version = PYTHON_VERSION,
6573
)
6674

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

‎common/private/env.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def _env_impl(rctx):
2+
rctx.file("BUILD.bazel") # So we can refer to the defs.bzl file we're about to create
3+
defs = ["%s = %s" % (k, repr(rctx.os.environ.get(k, "3.8"))) for k in rctx.attr.env_var]
4+
rctx.file("defs.bzl", "\n".join(defs))
5+
6+
env = repository_rule(
7+
implementation = _env_impl,
8+
attrs = {
9+
"env_var": attr.string_list(),
10+
},
11+
)

0 commit comments

Comments
 (0)