-
-
Notifications
You must be signed in to change notification settings - Fork 216
[Fix] Detect homebrew directory #3615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] Detect homebrew directory #3615
Conversation
📝 WalkthroughWalkthroughDynamic Homebrew prefix detection is added to both the Darwin Python build config and the Meson build. Each attempts to run Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer
participant Meson as meson.build
participant System as shell
Note over Meson: Configure (non-Windows)
Dev->>Meson: meson setup
Meson->>System: which brew
alt brew found
Meson->>System: brew --prefix
alt success & valid path
System-->>Meson: prefix path
Note right of Meson: set homebrew_prefix to returned path
else failure
Note right of Meson: keep default /opt/homebrew
end
else brew not found
Note right of Meson: keep default /opt/homebrew
end
Meson->>Meson: populate bases with include/lib using homebrew_prefix
sequenceDiagram
autonumber
actor Build as Build process
participant Config as buildconfig/config_darwin.py
participant System as shell
Build->>Config: import/execute config
Config->>System: brew --prefix
alt success & valid path
System-->>Config: prefix path
Config->>Config: set incdirs/libdirs = {prefix}/include,{prefix}/lib
else failure
Note right of Config: use existing fallbacks (non-Homebrew/SDL2 paths)
end
Build-->>Build: use resolved dirs
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
meson.build (1)
285-294: LGTM! Consider adding optional validation for robustness.The dynamic Homebrew prefix detection logic is sound. The fallback to
/opt/homebrewand the use ofcheck: falsewith returncode verification ensure graceful handling whenbrewis unavailable or fails.For added robustness, consider validating that the detected prefix is a valid directory path:
if brew_cmd.found() result = run_command(brew_cmd, '--prefix', check: false) if result.returncode() == 0 - homebrew_prefix = result.stdout().strip() + detected_prefix = result.stdout().strip() + if detected_prefix != '' and fs.is_dir(detected_prefix) + homebrew_prefix = detected_prefix + endif endif endifThis prevents edge cases where
brew --prefixmight return unexpected output, though the existingfs.exists()checks at lines 304 and 313 already provide safety by skipping invalid paths.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
buildconfig/config_darwin.py(2 hunks)meson.build(1 hunks)
🧰 Additional context used
🪛 Flake8 (7.3.0)
buildconfig/config_darwin.py
[error] 151-151: continuation line under-indented for hanging indent
(E121)
[error] 151-151: block comment should start with '# '
(E265)
[error] 155-155: block comment should start with '# '
(E265)
🪛 Ruff (0.14.0)
buildconfig/config_darwin.py
143-143: Starting a process with a partial executable path
(S607)
🔇 Additional comments (4)
buildconfig/config_darwin.py (3)
5-5: LGTM!The subprocess imports are necessary for dynamic Homebrew prefix detection and are used appropriately in the code below.
140-146: LGTM!The dynamic Homebrew prefix detection is implemented correctly:
- Gracefully handles both missing
brewcommand and execution failures- Appropriate use of
DEVNULLto suppress error output- Falls back to the conventional
/opt/homebrewdefaultNote: The static analysis S607 warning about using a partial executable path is a false positive. Invoking
brewfrom PATH is the standard and correct approach.
147-148: LGTM!The detected Homebrew prefix is correctly integrated into include and library search paths, while preserving existing fallback paths for robustness.
Also applies to: 156-156
meson.build (1)
296-296: LGTM! Clean integration of the detected prefix.The
baseslist now correctly uses the dynamically detectedhomebrew_prefixinstead of the hardcoded value, enabling builds with Homebrew installed at non-standard locations.
oddbookworm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! 🎉
There is one change I see offhand that I would like to see
ankith26
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for contributing! 🎉
I would have approved this PR even you had left out the buildconfig/config_darwin.py changes. But now that you've already implemented it, it's fine to have it too.
I don't have a mac to test out the changes but the code seems fine, and I'm assuming you already tested it out on a mac.
oddbookworm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll accept @ankith26's that the changes in config_darwin.py don't need further modification. Thanks for the contribution! 🎉
No longer assumes homebrew is at
/opt/homebrewand attempts to find its prefix. Resorts to the default install directory (/opt/homebrew) if it cannot be found or an error occurs.