From 1fc49593f67583ce6dff884ef9132f77d3d8a676 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 11 Feb 2023 07:00:34 +0000 Subject: [PATCH 1/3] Make toolchain acceptance tests work with latest Bazel build CI pipeline. The latest Bazel build continous integration testing pipeline sets several flags and environment variables that end up interfering with each other: * `--sandbox_tmpfs_path=/tmp` * `--test_env=USE_BAZEL_VERSION` * `USE_BAZEL_VERSION=/tmp/` * And Bazelisk is used to run Bazel What happens is `USE_BAZEL_VERSION` points to Bazel in /tmp, but then the `--sandbox_tmpfs_path` flag prevents it from being readable. Later, when a test wants to run Bazel, Bazelisk is invoked. It is able to see that it should use a custom Bazel binary because of `--test_env`, but then can't read the file because of `--sandbox_tmpfs_path`, so then fails. To fix, make the test runner that will run `bazel` unset `USE_BAZEL_VERSION` so Bazelisk doesn't try to use it. This also exposed an issue with Bazelisk demanding a cache directory be specified, so set that environment variable to the test's temp dir to keep Bazelisk happy. Fixes #856 --- .../toolchains/run_acceptance_test.py.tmpl | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/python/tests/toolchains/run_acceptance_test.py.tmpl b/python/tests/toolchains/run_acceptance_test.py.tmpl index b3071a7b3c..14367d14f8 100644 --- a/python/tests/toolchains/run_acceptance_test.py.tmpl +++ b/python/tests/toolchains/run_acceptance_test.py.tmpl @@ -23,9 +23,8 @@ class TestPythonVersion(unittest.TestCase): os.chdir("%test_location%") rules_python_path = os.path.join(os.environ["TEST_SRCDIR"], "rules_python") + test_tmpdir = os.environ["TEST_TMPDIR"] if %is_windows%: - test_tmpdir = os.environ["TEST_TMPDIR"] - home = os.path.join(test_tmpdir, "HOME") os.mkdir(home) os.environ["HOME"] = home @@ -34,6 +33,16 @@ class TestPythonVersion(unittest.TestCase): os.mkdir(local_app_data) os.environ["LocalAppData"] = local_app_data + # Bazelisk requires a cache directory be set + os.environ["XDG_CACHE_HOME"] = os.path.join(test_tmpdir, "xdg-cache-home") + + # Unset this so this this works when called by Bazel's latest Bazel build + # pipeline. It sets the following combination, which interfer with each other: + # * --sandbox_tmpfs_path=/tmp + # * --test_env=USE_BAZEL_VERSION + # * USE_BAZEL_VERSION=/tmp/ + os.environ.pop("USE_BAZEL_VERSION", None) + with open(".bazelrc", "w") as bazelrc: bazelrc.write( os.linesep.join( @@ -47,8 +56,11 @@ class TestPythonVersion(unittest.TestCase): ) def test_match_toolchain(self): - stream = os.popen("bazel run @python//:python3 -- --version") - output = stream.read().strip() + output = subprocess.check_output( + f"bazel run @python//:python3 -- --version", + shell = True, # Shell needed to look up via PATH + text=True, + ).strip() self.assertEqual(output, "Python %python_version%") subprocess.run("bazel test //...", shell=True, check=True) From 733d53ee87b5f61dc12677b5a1e665b290ea8de0 Mon Sep 17 00:00:00 2001 From: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com> Date: Sat, 11 Feb 2023 04:42:33 -0800 Subject: [PATCH 2/3] Update python/tests/toolchains/run_acceptance_test.py.tmpl --- python/tests/toolchains/run_acceptance_test.py.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tests/toolchains/run_acceptance_test.py.tmpl b/python/tests/toolchains/run_acceptance_test.py.tmpl index 14367d14f8..5ae5c57495 100644 --- a/python/tests/toolchains/run_acceptance_test.py.tmpl +++ b/python/tests/toolchains/run_acceptance_test.py.tmpl @@ -36,7 +36,7 @@ class TestPythonVersion(unittest.TestCase): # Bazelisk requires a cache directory be set os.environ["XDG_CACHE_HOME"] = os.path.join(test_tmpdir, "xdg-cache-home") - # Unset this so this this works when called by Bazel's latest Bazel build + # Unset this so this works when called by Bazel's latest Bazel build # pipeline. It sets the following combination, which interfer with each other: # * --sandbox_tmpfs_path=/tmp # * --test_env=USE_BAZEL_VERSION From af617b2216dbf47795ebef8ba5ab0a06cf1a8a0a Mon Sep 17 00:00:00 2001 From: Thulio Ferraz Assis <3149049+f0rmiga@users.noreply.github.com> Date: Sat, 11 Feb 2023 04:42:38 -0800 Subject: [PATCH 3/3] Update python/tests/toolchains/run_acceptance_test.py.tmpl --- python/tests/toolchains/run_acceptance_test.py.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tests/toolchains/run_acceptance_test.py.tmpl b/python/tests/toolchains/run_acceptance_test.py.tmpl index 5ae5c57495..150e1a99df 100644 --- a/python/tests/toolchains/run_acceptance_test.py.tmpl +++ b/python/tests/toolchains/run_acceptance_test.py.tmpl @@ -37,7 +37,7 @@ class TestPythonVersion(unittest.TestCase): os.environ["XDG_CACHE_HOME"] = os.path.join(test_tmpdir, "xdg-cache-home") # Unset this so this works when called by Bazel's latest Bazel build - # pipeline. It sets the following combination, which interfer with each other: + # pipeline. It sets the following combination, which interfere with each other: # * --sandbox_tmpfs_path=/tmp # * --test_env=USE_BAZEL_VERSION # * USE_BAZEL_VERSION=/tmp/