Skip to content

Commit

Permalink
meson: do the macos sdk version comparison in meson
Browse files Browse the repository at this point in the history
Since we can no longer rely on distuils for a version comparison, let's
modify the macos-sdk-version script so it returns multiple potential
versions to meson. Then use meson's built-in version comparison to pick
the right one instead. This avoids the complication of needing certain
python packages installed since everything simply uses stdlib functions.
  • Loading branch information
Dudemanguy committed Oct 29, 2023
1 parent 5018726 commit 1888591
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
17 changes: 5 additions & 12 deletions TOOLS/macos-sdk-version.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
#!/usr/bin/env python3

# Logic copied from compiler_swift.py in the waf build. This checks for the sdk
# path, the sdk version, and the sdk build version. The sdk path is returned
# along with what is selected as the sdk version.
# This checks for the sdk path, the sdk version, and
# the sdk build version.

import re
import os
import string
import sys
from packaging import version
from shutil import which
from subprocess import check_output

def find_macos_sdk():
sdk = os.environ.get('MACOS_SDK', '')
sdk_version = os.environ.get('MACOS_SDK_VERSION', '0.0')
build_version = '0.0'
xcrun = which('xcrun')

if not xcrun:
return sdk,sdk_version
return sdk,sdk_version,build_version

if not sdk:
sdk = check_output([xcrun, '--sdk', 'macosx', '--show-sdk-path'],
Expand Down Expand Up @@ -55,13 +54,7 @@ def find_macos_sdk():
if not isinstance(sdk_version, str):
sdk_version = '10.10.0'

# pick the higher version, always pick sdk over build if newer
if version.parse(build_version) > version.parse(sdk_version):
return sdk,build_version
else:
return sdk,sdk_version

return sdk,sdk_version
return sdk,sdk_version,build_version

if __name__ == "__main__":
sdk_info = find_macos_sdk()
Expand Down
4 changes: 3 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,9 @@ macos_sdk_version = '0.0'
if darwin and macos_sdk_version_py.found()
macos_sdk_info = run_command(macos_sdk_version_py, check: true).stdout().split(',')
macos_sdk_path = macos_sdk_info[0].strip()
macos_sdk_version = macos_sdk_info[1]
# Always pick whichever version is higher.
macos_sdk_version = macos_sdk_info[1].version_compare('>' + macos_sdk_info[2]) ? \
macos_sdk_info[1] : macos_sdk_info[2]
endif

if macos_sdk_path != ''
Expand Down

0 comments on commit 1888591

Please sign in to comment.