Skip to content

fix: use "command -v" to find interpreter in $PATH#3150

Merged
aignas merged 1 commit intobazel-contrib:mainfrom
malt3:env_toolchain_command_lookup
Aug 7, 2025
Merged

fix: use "command -v" to find interpreter in $PATH#3150
aignas merged 1 commit intobazel-contrib:mainfrom
malt3:env_toolchain_command_lookup

Conversation

@malt3
Copy link
Contributor

@malt3 malt3 commented Aug 6, 2025

In some environments, which doesn't work correctly under Bazel, while command -v does.
I think the difference is that command is a shell builtin (and POSIX compliant), whereas which is not:

$ sh -c 'builtin command -v python3'
/usr/bin/python3

$ sh -c 'builtin which python3'
sh: line 1: builtin: which: not a shell builtin

While command -v performs fewer checks under the hood, it is more portable.

@malt3 malt3 requested review from aignas and rickeylev as code owners August 6, 2025 05:43
Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, LGTM, could you please add a note about this in the CHANGELOG.md please

In some environments, `which` doesn't work correctly under Bazel,
while `command -v` does.
I think the difference is that `command` is a shell builtin (and POSIX
compliant), whereas `which` is not:

```
$ sh -c 'builtin command -v python3'
/usr/bin/python3

$ sh -c 'builtin which python3'
sh: line 1: builtin: which: not a shell builtin
```

While `command -v` performs fewer checks under the hood, it is more portable.
@malt3 malt3 requested a review from aignas August 6, 2025 10:24
@aignas aignas added this pull request to the merge queue Aug 7, 2025
Merged via the queue into bazel-contrib:main with commit 32d7a24 Aug 7, 2025
2 checks passed
@malt3 malt3 deleted the env_toolchain_command_lookup branch August 7, 2025 05:37
malt3 added a commit to bazel-contrib/rules_img that referenced this pull request Aug 7, 2025
It interferes with the BCR publishing and a fix has been merged upstream: bazel-contrib/rules_python#3150
malt3 added a commit to bazel-contrib/rules_img that referenced this pull request Sep 9, 2025
Version 1.6.x and later contains this fix: bazel-contrib/rules_python#3150
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.

2 participants