bazelbuild/bazel · error

error: %s\n

Error message

error: %s\n

What it means

In xcode_locator.m, FindXcodes asks LaunchServices (LSCopyApplicationURLsForBundleIdentifier for 'com.apple.dt.Xcode') to enumerate installed Xcodes; if the call returns no array it bridges the CFError, prints 'error: <description>' to stderr, and returns nil, which fails Xcode detection for the Bazel/Xcode integration.

Source

Thrown at tools/osx/xcode_locator.m:137

// Searches for all available Xcodes in the system and returns a dictionary that
// maps version identifiers of any form (X, X.Y, and X.Y.Z) to the directory
// where the Xcode bundle lives.
//
// If there is a problem locating the Xcodes, prints one or more error messages
// and returns nil.
static NSMutableDictionary<NSString *, XcodeVersionEntry *> *FindXcodes()
  __attribute((ns_returns_retained)) {
  CFStringRef cfBundleID = CFSTR("com.apple.dt.Xcode");
  NSString *bundleID = (__bridge NSString *)cfBundleID;

  NSMutableDictionary<NSString *, XcodeVersionEntry *> *dict =
      [[NSMutableDictionary alloc] init];
  CFErrorRef cfError;
  NSArray *array = CFBridgingRelease(LSCopyApplicationURLsForBundleIdentifier(
      cfBundleID, &cfError));
  if (array == nil) {
    NSError *nsError = (__bridge NSError *)cfError;
    fprintf(stderr, "error: %s\n", nsError.description.UTF8String);
    return nil;
  }

  // Scan all bundles but delay returning in case of errors until we are
  // done. This is to let us log details about all the bundles that were
  // processed so that a faulty bundle doesn't hide useful information about
  // other bundles that were found.
  BOOL errors = NO;
  for (NSURL *url in array) {
    NSArray *contents = [
      [NSFileManager defaultManager] contentsOfDirectoryAtURL:url
                                   includingPropertiesForKeys:nil
                                                      options:0
                                                        error:nil];
    NSLog(@"Found bundle %@ in %@; contents on disk: %@",
          bundleID, url, contents);

    NSBundle *bundle = [NSBundle bundleWithURL:url];

View on GitHub (pinned to e6e199d060)

Solutions

  1. Install Xcode properly from .xip into /Applications and launch it once so it registers with LaunchServices.
  2. Run 'xcode-select -p' and 'xcodebuild -version' to confirm a healthy install, and sudo xcode-select -s /Applications/Xcode.app.
  3. Reset LaunchServices registration: /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user, then relaunch Xcode.
  4. Ensure the app bundle id is exactly com.apple.dt.Xcode (renamed or wrapper bundles will not match).
  5. On CI, prefer pre-provisioned images with Xcode registered rather than ad-hoc copies.

Example fix

# before: bazel build //ios:app  -> xcode_locator prints 'error: ...'
sudo xcode-select -s /Applications/Xcode.app
xcodebuild -version   # verify
bazel clean && bazel build //ios:app
Defensive patterns

Strategy: fallback

Validate before calling

// shell-level precheck before relying on xcode_locator
if ! xcode-select -p >/dev/null 2>&1 || ! xcodebuild -version >/dev/null 2>&1; then
  echo "Xcode not properly installed/selected" >&2; exit 1
fi

Prevention

When it happens

Trigger: Running xcode_locator on a machine where LaunchServices cannot resolve the Xcode bundle id: Xcode not installed, Xcode never launched/registered, a damaged LaunchServices database, or an incomplete .xip extraction that never registered with LaunchServices.

Common situations: Fresh macOS CI images with Xcode installed by unzipping rather than proper installation; corrupted LaunchServices after OS upgrades; Xcode betas installed under a different bundle identifier; environments where /Applications/Xcode.app was renamed.


AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14). Data as JSON: /api/errors/6943ee45d0f11c1b. Report an issue: GitHub.