Fix xcode-locator preferring some Xcode versions outside of /Applications

The current xcode-locator prefers Xcode versions in /Applications
over other versions, comments indicate this is to prefer
local versions over mounted versions. The check for whether Xcode
is in /Applications is only checking if the file path contains
"/Applications/".

This causes issues if Xcode installations can be found on disk that
contains "/Applications/" but are not rooted at /Applications,
e.g. when using TimeMachine these can be found at
/Volumes/MyPassportForMac/Backups.backupdb/.../Macintosh HD/Applications/Xcode.app
The Xcode from the backup can replace the Xcode actually at
/Applications/Xcode.app. This leads to compile errors later when using
that version of Xcode, e.g. "the rule is missing dependency
declarations" for files in the wrong Xcode path.

Fix by checking if the path starts with "/Applications/" instead of
just contains "/Applications/".

This will change behavior and potentially break users if the
"contains" check was relied on, e.g. if anybody expects
"/Users/me/Applications/Xcode.app" to be preferred over
"<network mount>/somewhere/Xcode.app". It's not clear that this was ever
intended to work like this and need to preserve this behavior.
If we wanted to be extra cautious, we could change this to 3 preference
tiers: first choose version in /Applications, then choose versions
containing "/Applications/" anywhere in the path, and finally choose
any other path to Xcode.

Closes #11678.

RELNOTES[INC]: Bazel now correctly prefers Xcode versions in `/Applications` over any other paths, which resolves an issue with accidentally picking up an Xcode version from a Time Machine backup or network disk. In the improbable case that you relied on the old behavior and Bazel now picks up Xcode from the wrong location, you can fix it by moving that Xcode version to /Applications.

PiperOrigin-RevId: 325424375
1 file changed
tree: 5ccd94c37933f946f2c39355de351e74b1a38fbc
  1. .bazelci/
  2. examples/
  3. scripts/
  4. site/
  5. src/
  6. third_party/
  7. tools/
  8. .bazelrc
  9. .gitattributes
  10. .gitignore
  11. AUTHORS
  12. BUILD
  13. CHANGELOG.md
  14. CODEOWNERS
  15. combine_distfiles.py
  16. combine_distfiles_to_tar.sh
  17. compile.sh
  18. CONTRIBUTING.md
  19. CONTRIBUTORS
  20. distdir.bzl
  21. ISSUE_TEMPLATE.md
  22. LICENSE
  23. README.md
  24. WORKSPACE
README.md

Bazel

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

  • Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.

  • One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.

  • Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.

  • Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.

Getting Started

Documentation

Contributing to Bazel

See CONTRIBUTING.md

Build status