fix(build): safely append Homebrew paths to avoid overriding user toolchains#68
Merged
fix(build): safely append Homebrew paths to avoid overriding user toolchains#68
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates build.sh PATH handling so Homebrew tool directories are appended only when present and not already included, avoiding unintentional precedence over user-provided toolchains.
Changes:
- Replace unconditional Homebrew PATH prepending with conditional PATH appends for
/opt/homebrew/bin. - Add conditional PATH append for
/usr/local/binto support Intel Homebrew layouts while preserving existing PATH precedence.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+6
to
+9
| export PATH="$PATH:/opt/homebrew/bin" | ||
| fi | ||
| if [[ ":$PATH:" != *":/usr/local/bin:"* ]] && [ -d "/usr/local/bin" ]; then | ||
| export PATH="$PATH:/usr/local/bin" |
There was a problem hiding this comment.
Appending with export PATH="$PATH:/opt/homebrew/bin" (and similarly for /usr/local/bin) will introduce an empty PATH element if $PATH is empty/unset, which makes the current working directory searchable (PATH=":/opt/homebrew/bin"). Consider using a safe append pattern (e.g., only add the : when $PATH is non-empty) to avoid this security/behavior risk.
Suggested change
| export PATH="$PATH:/opt/homebrew/bin" | |
| fi | |
| if [[ ":$PATH:" != *":/usr/local/bin:"* ]] && [ -d "/usr/local/bin" ]; then | |
| export PATH="$PATH:/usr/local/bin" | |
| export PATH="${PATH:+$PATH:}/opt/homebrew/bin" | |
| fi | |
| if [[ ":$PATH:" != *":/usr/local/bin:"* ]] && [ -d "/usr/local/bin" ]; then | |
| export PATH="${PATH:+$PATH:}/usr/local/bin" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refines the previous
PATHinjection inbuild.shbased on PR review. Instead of globally prepending the Homebrew binary directories, they are now safely appended to thePATHonly if they exist and are not already present. This ensures that any custom user toolchains (like explicitcmakeorswiftpaths) take priority while safely falling back to native Homebrew paths on Apple Silicon.