Skip to content

Commit 41a4131

Browse files
committed
add basic test
1 parent f7ef53f commit 41a4131

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

tests/bootstrap_impls/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ sh_py_run_test(
2929
sh_src = "run_binary_zip_yes_test.sh",
3030
)
3131

32+
sh_py_run_test(
33+
name = "run_binary_relative_venv_symlinks_no_test",
34+
bootstrap_impl = "script",
35+
py_src = "bin.py",
36+
relative_venv_symlinks = "no",
37+
sh_src = "run_binary_relative_venv_symlinks_no_test.sh",
38+
target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT,
39+
)
40+
3241
sh_py_run_test(
3342
name = "run_binary_bootstrap_script_zip_yes_test",
3443
bootstrap_impl = "script",

tests/bootstrap_impls/bin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
print("PYTHONSAFEPATH:", os.environ.get("PYTHONSAFEPATH", "UNSET") or "EMPTY")
2323
print("sys.flags.safe_path:", sys.flags.safe_path)
2424
print("file:", __file__)
25+
print("sys.executable:", sys.executable)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# --- begin runfiles.bash initialization v3 ---
16+
# Copy-pasted from the Bazel Bash runfiles library v3.
17+
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
18+
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
19+
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
20+
source "$0.runfiles/$f" 2>/dev/null || \
21+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
22+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
23+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
24+
# --- end runfiles.bash initialization v3 ---
25+
set +e
26+
27+
bin=$(rlocation $BIN_RLOCATION)
28+
if [[ -z "$bin" ]]; then
29+
echo "Unable to locate test binary: $BIN_RLOCATION"
30+
exit 1
31+
fi
32+
actual=$($bin)
33+
34+
function expect_match() {
35+
local expected_pattern=$1
36+
local actual=$2
37+
if ! (echo "$actual" | grep "$expected_pattern" ) >/dev/null; then
38+
echo "expected to match: $expected_pattern"
39+
echo "===== actual START ====="
40+
echo "$actual"
41+
echo "===== actual END ====="
42+
echo
43+
touch EXPECTATION_FAILED
44+
return 1
45+
fi
46+
}
47+
48+
expect_match "sys.executable:.*tmp.*python3" "$actual"
49+
50+
venvs_root=$(mkdir -d)
51+
52+
actual=$(RULES_PYTHON_VENVS_ROOT=$venvs_root $bin)
53+
expect_match "sys.executable:.*$venvs_root" "$actual"
54+
55+
# Exit if any of the expects failed
56+
[[ ! -e EXPECTATION_FAILED ]]

tests/support/sh_py_run_test.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def _perform_transition_impl(input_settings, attr):
3333
settings["//command_line_option:extra_toolchains"] = attr.extra_toolchains
3434
if attr.python_version:
3535
settings["//python/config_settings:python_version"] = attr.python_version
36+
if attr.relative_venv_symlinks:
37+
settings["//python/config_settings:relative_venv_symlinks"] = attr.relative_venv_symlinks
3638
return settings
3739

3840
_perform_transition = transition(
@@ -41,12 +43,14 @@ _perform_transition = transition(
4143
"//python/config_settings:bootstrap_impl",
4244
"//command_line_option:extra_toolchains",
4345
"//python/config_settings:python_version",
46+
"//python/config_settings:relative_venv_symlinks",
4447
],
4548
outputs = [
4649
"//command_line_option:build_python_zip",
4750
"//command_line_option:extra_toolchains",
4851
"//python/config_settings:bootstrap_impl",
4952
"//python/config_settings:python_version",
53+
"//python/config_settings:relative_venv_symlinks",
5054
VISIBLE_FOR_TESTING,
5155
],
5256
)
@@ -93,6 +97,7 @@ def _py_reconfig_impl(ctx):
9397
def _make_reconfig_rule(**kwargs):
9498
attrs = {
9599
"bootstrap_impl": attr.string(),
100+
"relative_venv_symlinks": attr.string(),
96101
"build_python_zip": attr.string(default = "auto"),
97102
"extra_toolchains": attr.string_list(
98103
doc = """

0 commit comments

Comments
 (0)