Skip to content

Commit

Permalink
python: Don't require python binary for Bazel tests.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rickeylev authored and hvadehra committed Feb 14, 2023
1 parent 79bb67b commit 325b08d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/test/py/bazel/runfiles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,9 @@ def _AssertRunfilesLibraryInBazelToolsRepo(self, family, lang_name):
self.AssertExitCode(exit_code, 0, stderr)
bazel_bin = stdout[0]

# TODO(brandjon): (Issue #8169) Make this test compatible with Python
# toolchains. Blocked on the fact that there's no PY3 environment on our Mac
# workers (bazelbuild/continuous-integration#578).
exit_code, _, stderr = self.RunBazel([
"build",
"--verbose_failures",
"--incompatible_use_python_toolchains=false",
"//foo:runfiles-" + family
])
self.AssertExitCode(exit_code, 0, stderr)
Expand Down
7 changes: 6 additions & 1 deletion tools/python/pywrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ def setup_tool(self, cmd):
path = which(cmd)
self.assertIsNotNone(
path, msg="Could not locate '%s' command on PATH" % cmd)
self.CopyFile(path, os.path.join("dir", cmd), executable=True)
# On recent MacOs versions, copying the coreutils tools elsewhere doesn't
# work -- they simply fail with "Killed: 9". To workaround that, just
# re-exec the actual binary.
self.ScratchFile("dir/" + cmd,
["#!/bin/sh", 'exec {} "$@"'.format(cmd)],
executable=True)

def locate_runfile(self, runfile_path):
resolved_path = self.Rlocation(runfile_path)
Expand Down

0 comments on commit 325b08d

Please sign in to comment.