Skip to content

Commit e9316f0

Browse files
rickeylevcopybara-github
authored andcommitted
python: Don't require python binary for Bazel tests.
This fixes the failures on MacOS after the recent upgrade to CI. When `//src/test/py/baze:runfiles_test` sets `--incompatible_use_python_toolchains=false`, it eventuallys tries to search `PATH` for `python`. This is because it falls back to the `--python_path` flag, which has a computed default of "python". Since new Mac versions no longer provide Python 2, this doesn't work. To fix, enable Python toolchains. Comments indicate they were only disabled because Python 3 wasn't available on the Mac CI machines at the time. For pywrapper_test: this was failing because it copies system utilities (e.g `/usr/bin/which`) to another location and tries to run them. For newer MacOS versions, this results in a failure due AMFI (a security mechanism, see https://theevilbit.github.io/posts/amfi_launch_constraints/) To fix, instead of copying the binary, write a wrapper that re-execs the original binary. Work towards #16526, #8169 PiperOrigin-RevId: 507526814 Change-Id: Ifaacc30cb155af30af606254eb7ffcd9304478f6
1 parent 02b1b78 commit e9316f0

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/test/py/bazel/runfiles_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ def _AssertRunfilesLibraryInBazelToolsRepo(self, family, lang_name):
4747
self.AssertExitCode(exit_code, 0, stderr)
4848
bazel_bin = stdout[0]
4949

50-
# TODO(brandjon): (Issue #8169) Make this test compatible with Python
51-
# toolchains. Blocked on the fact that there's no PY3 environment on our Mac
52-
# workers (bazelbuild/continuous-integration#578).
5350
exit_code, _, stderr = self.RunBazel([
5451
"build",
5552
"--verbose_failures",
56-
"--incompatible_use_python_toolchains=false",
5753
"//foo:runfiles-" + family
5854
])
5955
self.AssertExitCode(exit_code, 0, stderr)

tools/python/pywrapper_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ def setup_tool(self, cmd):
8686
path = which(cmd)
8787
self.assertIsNotNone(
8888
path, msg="Could not locate '%s' command on PATH" % cmd)
89-
self.CopyFile(path, os.path.join("dir", cmd), executable=True)
89+
# On recent MacOs versions, copying the coreutils tools elsewhere doesn't
90+
# work -- they simply fail with "Killed: 9". To workaround that, just
91+
# re-exec the actual binary.
92+
self.ScratchFile("dir/" + cmd,
93+
["#!/bin/sh", 'exec {} "$@"'.format(cmd)],
94+
executable=True)
9095

9196
def locate_runfile(self, runfile_path):
9297
resolved_path = self.Rlocation(runfile_path)

0 commit comments

Comments
 (0)