-
Notifications
You must be signed in to change notification settings - Fork 4.4k
macOS: respect DEVELOPER_DIR for Xcode selection. #25657
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
Conversation
|
what's the motivation here to take precedence over xcode_version? in today's world the intent of the logic is that bazel does a lookup once to discover the current Xcode version (and that could take DEVELOPER_DIR into account) and then after that all invocations use that discover. The weird part about this is that separate actions could technically use different Xcode versions, for example in your example |
|
The motivation is to ensure that when My understanding is that the intent should be that if a user explicitly provides To illustrate the problem, consider this scenario:
The current implementation can result in an action that uses paths from both Xcode installations. Here's a concrete example, runnable with the attached example.zip file: This command will print the clang invocation, which includes both My change ensures that, in this scenario, only |
|
Right the intent in bazel instead today is that you never pass DEVELOPER_DIR to actions, and instead bazel handles passing that itself, which it does by determining the DEVELOPER_DIR when it starts to discover xcode versions (if that part isn't working we should fix that) the issue with changing this is that theoretically those could mismatch, and then things could end up with 2 values in other ways. put another way we could make bazel reject ever setting DEVELOPER_DIR / SDKROOT in action_env, since that should be a bazel implementation detail. |
keith
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 was missing a piece in order to fully understand this. The key is that if you have 2 different copies of the same Xcode version, and xcode-locator cannot differentiate.
I think we should land but clearly not recommend for folks, since most workflows should go through the normal discovery paths and then get DEVLEOPER_DIR set automatically.
the alternative to this would be to make xcode_autoconf take the DEVELOPER_DIR more literally, where today it only uses it to get the version and then look that up based on xcode-locator, but I think that path probably isn't worth it for this edge case.
|
@allevato would you be able to have a look at this PR? Thank you! |
This doesn't seem like a compelling case to support. Why do you intentionally have two copies of the same version? Or is the issue that you somehow have a duplicate and it's not getting distinguished? If the latter, that's an argument to improve xcode-locator. Otherwise, I'm very much against leaking external state (even intentionally via |
allevato
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'm not actually requesting changes here, I just want to have signal that I don't think we should do this)
|
Here's a direction to explore that might be viable (I haven't thought it all the way through, though). There shouldn't be a lot of places in Bazel's Java core where the So what if you could just pass the developer dir of the Xcode you want to use as that flag? I don't know if this would have any knock-on effects downstream, like with the |
We actually have multiple copies installed of the same Xcode version with different local changes potentially, requiring us to unambiguously set DEVELOPER_DIR.
Thanks for your direction, I also like the explicit nature of it more than my initial patch. I will try to update my change with your suggestions. |
On macOS, this change allows --xcode_version to accept a path to an Xcode developer directory (e.g. /Applications/Xcode2.app/Contents/Developer). If the value is not a valid version number, it is treated as the desired DEVELOPER_DIR and used verbatim, bypassing xcode-locator. This makes Xcode selection more explicit and avoids relying on environment variables or auto-detection.
bab0d03 to
5c77256
Compare
allevato
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.
@susinmotion This seems fine to me but I'd appreciate a second pair of eyes on it.
src/main/java/com/google/devtools/build/lib/exec/local/XcodeLocalEnvProvider.java
Show resolved
Hide resolved
allevato
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.
Yep! If @susinmotion is good, I'm good.
|
I have no power to merge it, though. |
|
@allevato who can help merging it? Thank you! |
|
@iancha1992 could you help merging this change? Thank you! |
On macOS, this change ensures that when `DEVELOPER_DIR` environment variable is used, it will be propagated to `/usr/bin/xcrun` to query the SDKROOT. This takes precedence over the `--xcode_version` flag when selecting the Xcode installation. This aligns with the intended use as documented in `man xcrun`: `The tool xcode-select(1) is used to set a system default for the active developer directory, and may be overridden by the DEVELOPER_DIR environment variable (see ENVIRONMENT).` To leverage this, developers must propagate the `DEVELOPER_DIR` environment variable to Bazel actions using `--action_env=DEVELOPER_DIR`. Closes bazelbuild#25657. PiperOrigin-RevId: 748404233 Change-Id: I52181098658d33e2bd2ec992ad1cd38d64abb293
|
@bazel-io fork 8.3.0 |
On macOS, this change ensures that when `DEVELOPER_DIR` environment variable is used, it will be propagated to `/usr/bin/xcrun` to query the SDKROOT. This takes precedence over the `--xcode_version` flag when selecting the Xcode installation. This aligns with the intended use as documented in `man xcrun`: `The tool xcode-select(1) is used to set a system default for the active developer directory, and may be overridden by the DEVELOPER_DIR environment variable (see ENVIRONMENT).` To leverage this, developers must propagate the `DEVELOPER_DIR` environment variable to Bazel actions using `--action_env=DEVELOPER_DIR`. Closes bazelbuild#25657. PiperOrigin-RevId: 748404233 Change-Id: I52181098658d33e2bd2ec992ad1cd38d64abb293
On macOS, this change ensures that when `DEVELOPER_DIR` environment variable is used, it will be propagated to `/usr/bin/xcrun` to query the SDKROOT. This takes precedence over the `--xcode_version` flag when selecting the Xcode installation. This aligns with the intended use as documented in `man xcrun`: `The tool xcode-select(1) is used to set a system default for the active developer directory, and may be overridden by the DEVELOPER_DIR environment variable (see ENVIRONMENT).` To leverage this, developers must propagate the `DEVELOPER_DIR` environment variable to Bazel actions using `--action_env=DEVELOPER_DIR`. Closes #25657. PiperOrigin-RevId: 748404233 Change-Id: I52181098658d33e2bd2ec992ad1cd38d64abb293 Commit d2e8c82 Co-authored-by: Benji Vos <bvos@apple.com>
On macOS, this change ensures that when `DEVELOPER_DIR` environment variable is used, it will be propagated to `/usr/bin/xcrun` to query the SDKROOT. This takes precedence over the `--xcode_version` flag when selecting the Xcode installation. This aligns with the intended use as documented in `man xcrun`: `The tool xcode-select(1) is used to set a system default for the active developer directory, and may be overridden by the DEVELOPER_DIR environment variable (see ENVIRONMENT).` To leverage this, developers must propagate the `DEVELOPER_DIR` environment variable to Bazel actions using `--action_env=DEVELOPER_DIR`. Closes bazelbuild#25657. PiperOrigin-RevId: 748404233 Change-Id: I52181098658d33e2bd2ec992ad1cd38d64abb293
On macOS, this change ensures that when
DEVELOPER_DIRenvironment variable is used, it will be propagated to/usr/bin/xcrunto query the SDKROOT. This takes precedence over the--xcode_versionflag when selecting the Xcode installation. This aligns with the intended use as documented inman xcrun:The tool xcode-select(1) is used to set a system default for the active developer directory, and may be overridden by the DEVELOPER_DIR environment variable (see ENVIRONMENT).To leverage this, developers must propagate the
DEVELOPER_DIRenvironment variable to Bazel actions using--action_env=DEVELOPER_DIR.