Skip to content

Commit

Permalink
Use xcrun to discover Apple SDK paths (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanderso authored Oct 12, 2024
1 parent 54a9a91 commit c8f93f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
7 changes: 3 additions & 4 deletions build/config/ios/ios_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ def main(argv):

for sdk in sdks:
command = [
'xcodebuild',
'-version',
'-sdk',
'xcrun',
'--sdk',
sdk,
'Path'
'--show-sdk-path',
]
sdk_output = run_command_with_retry(command, timeout=300)
if symlink_path:
Expand Down
35 changes: 8 additions & 27 deletions build/mac/find_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,14 @@ def main():
'|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| '
'if you are using Xcode 4.') % job.returncode)

sdk_command = ['xcodebuild',
'-showsdks',
'-json']
sdk_json_output = run_command_with_retry(sdk_command, timeout=300)
sdk_json = json.loads(sdk_json_output)

best_sdk = None
sdk_output = None

# Xcode can return the same version for different symlinked paths.
# Sort by path to keep the list stable between runs.
for properties in sorted(list(sdk_json), key=lambda d: d['sdkPath']):
# Filter out macOS DriverKit, watchOS, AppleTV, and other SDKs.
if properties.get('platform') != 'macosx' or 'driver' in properties.get('canonicalName'):
continue
sdk_version = properties['sdkVersion']
parsed_version = parse_version(sdk_version)
if (parsed_version >= parse_version(min_sdk_version) and
(not best_sdk or parsed_version < parse_version(best_sdk))):
best_sdk = sdk_version
sdk_output = properties['sdkPath']

if not best_sdk:
print(sdk_json_output)
raise Exception('No %s+ SDK found' % min_sdk_version)

# xcrun --sdk macosx --show-sdk-path
sdk_command = [
'xcrun',
'--sdk',
'macosx',
'--show-sdk-path',
]
sdk_output = run_command_with_retry(sdk_command, timeout=300)
if symlink_path:
sdks_path = os.path.join(symlink_path, 'SDKs')
symlink_target = os.path.join(sdks_path, os.path.basename(sdk_output))
Expand All @@ -125,7 +107,6 @@ def main():

if not options.as_gclient_hook:
print(sdk_output)
print(best_sdk)
return 0


Expand Down

0 comments on commit c8f93f2

Please sign in to comment.