Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions tools/osx/xcode_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ def _search_sdk_output(output, sdkname):
"""Returns the SDK version given xcodebuild stdout and an sdkname."""
return _search_string(output, "(%s" % sdkname, ")")

def _xcodebuild_path(repository_ctx):
"""Returns the xcodebuild path"""
developer_dir = repository_ctx.getenv("DEVELOPER_DIR")
if developer_dir:
xcodebuild_path = repository_ctx.path("{}/usr/bin/xcodebuild".format(developer_dir))
if xcodebuild_path.exists:
return str(xcodebuild_path)

xcodebuild_path = repository_ctx.which("xcodebuild")
if xcodebuild_path.exists:
return str(xcodebuild_path)

fail("xcodebuild can't be found neither in DEVELOPER_DIR nor by name")

def _xcode_version_output(repository_ctx, name, version, aliases, developer_dir, timeout):
"""Returns a string containing an xcode_version build target."""
build_contents = ""
Expand All @@ -54,7 +68,7 @@ def _xcode_version_output(repository_ctx, name, version, aliases, developer_dir,
decorated_aliases.append("'%s'" % alias)
repository_ctx.report_progress("Fetching SDK information for Xcode %s" % version)
xcodebuild_result = repository_ctx.execute(
["xcrun", "xcodebuild", "-version", "-sdk"],
["xcrun", _xcodebuild_path(repository_ctx), "-version", "-sdk"],
timeout,
{"DEVELOPER_DIR": developer_dir},
)
Expand Down Expand Up @@ -197,6 +211,10 @@ def _darwin_build_file(repository_ctx):
repository_ctx.report_progress("Fetching the default Xcode version")
env = repository_ctx.os.environ

xcrun_path = repository_ctx.which("xcrun")
if not xcrun_path.exists:
fail("Can't find installed xcrun")

if "BAZEL_OSX_EXECUTE_TIMEOUT" in env:
timeout = int(env["BAZEL_OSX_EXECUTE_TIMEOUT"])
else:
Expand All @@ -207,7 +225,7 @@ def _darwin_build_file(repository_ctx):
"-i",
"DEVELOPER_DIR={}".format(env.get("DEVELOPER_DIR", default = "")),
"xcrun",
"xcodebuild",
_xcodebuild_path(repository_ctx),
"-version",
], timeout)

Expand Down
14 changes: 12 additions & 2 deletions tools/osx/xcode_locator.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,18 @@ static void AddEntryToDictionary(
NSMutableDictionary<NSString *, XcodeVersionEntry *> *dict =
[[NSMutableDictionary alloc] init];
CFErrorRef cfError;
NSArray *array = CFBridgingRelease(LSCopyApplicationURLsForBundleIdentifier(
cfBundleID, &cfError));

// If the user sets the environment variable DEVELOPER_DIR, then that Xcode will be returned.
// Otherwise, the function returns a list of all discovered Xcodes on the host.
NSDictionary<NSString *, NSString *> *environmentVariables = [[NSProcessInfo processInfo] environment];
NSString *developer_dir_env = environmentVariables[@"DEVELOPER_DIR"];

NSArray *array = CFBridgingRelease(LSCopyApplicationURLsForBundleIdentifier(cfBundleID, &cfError));
if (developer_dir_env) {
NSURL *fileURL = [NSURL fileURLWithPath:developer_dir_env];
NSURL *xcodeURL = [[fileURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent];
array = @[xcodeURL];
}
if (array == nil) {
NSError *nsError = (__bridge NSError *)cfError;
fprintf(stderr, "error: %s\n", nsError.description.UTF8String);
Expand Down