Skip to content

Search PATH when .pex is invoked at a relative path with no /#299

Open
chrisnovakovic wants to merge 1 commit intoplease-build:masterfrom
chrisnovakovic:pex-preamble-relative-path
Open

Search PATH when .pex is invoked at a relative path with no /#299
chrisnovakovic wants to merge 1 commit intoplease-build:masterfrom
chrisnovakovic:pex-preamble-relative-path

Conversation

@chrisnovakovic
Copy link
Copy Markdown
Contributor

In the preamble, mimic a shell's PATH searching behaviour when determining the path to the .pex file if it was invoked via a relative path name containing no / characters.

Assuming the output of a hypothetical python_binary with the run-time interpreter search path python3 has been copied to /usr/bin/out.pex, this will cause the Python interpreter to be invoked using the arguments on the right-hand side when the .pex file is invoked using the argument on the left-hand side:

  • /abs/path/out.pex -> python3 /abs/path/out.pex
  • rel/path/out.pex -> python3 rel/path/out.pex
  • out.pex -> python3 /usr/bin/out.pex

Fixes #298.

In the preamble, mimic a shell's `PATH` searching behaviour when
determining the path to the .pex file if it was invoked via a relative
path name containing no `/` characters.

Assuming the output of a hypothetical `python_binary` with the run-time
interpreter search path `python3` has been copied to `/usr/bin/out.pex`,
this will cause the Python interpreter to be invoked using the arguments
on the right-hand side when the .pex file is invoked using the argument
on the left-hand side:

- `/abs/path/out.pex` -> `python3 /abs/path/out.pex`
- `rel/path/out.pex` -> `python3 rel/path/out.pex`
- `out.pex` -> `python3 /usr/bin/out.pex`

Fixes please-build#298.
@chrisnovakovic
Copy link
Copy Markdown
Contributor Author

I've also written a regression test for this, but it won't pass until this PR gets merged and a new version of please_pex is released.


// Construct a candidate path by concatenating the next directory in PATH and the file name
// we were given.
if (dir_start == dir_end) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear on what this case is handling, so probably deserves a comment. Empty path entry meaning resolve relative to the current working directory?

}

FREE(*res_path);
} while (*dir_end++ == ':');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear on how we avoid an out-of-bounds memory access in all of this. I'm sure I'm just missing something, but would appreciate a pointer (pun intended)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.pex files aren't runnable when invoked off the PATH

2 participants