Skip to content

Commit

Permalink
build: add check for macOS SDK version
Browse files Browse the repository at this point in the history
this provides an easy way to check for a specific macOS SDK version and
with that the availability of features.
  • Loading branch information
Akemi authored and jeeb committed Jul 21, 2019
1 parent 9a2c760 commit 850b303
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion waftools/checks/generic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import inflector
from distutils.version import StrictVersion
from waflib.ConfigSet import ConfigSet
from waflib import Utils

Expand All @@ -8,7 +9,7 @@
"check_pkg_config_cflags", "check_cc", "check_statement", "check_libs",
"check_headers", "compose_checks", "check_true", "any_version",
"load_fragment", "check_stub", "check_ctx_vars", "check_program",
"check_pkg_config_datadir"]
"check_pkg_config_datadir", "check_macos_sdk"]

any_version = None

Expand Down Expand Up @@ -186,3 +187,13 @@ def load_fragment(fragment):
fragment_code = fp.read()
fp.close()
return fragment_code

def check_macos_sdk(version):
def fn(ctx, dependency_identifier):
if ctx.env.MACOS_SDK_VERSION:
if StrictVersion(ctx.env.MACOS_SDK_VERSION) >= StrictVersion(version):
ctx.define(inflector.define_key(dependency_identifier), 1)
return True
return False

return fn
10 changes: 10 additions & 0 deletions waftools/detections/compiler_swift.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import string
import os.path
from waflib import Utils
from distutils.version import StrictVersion
Expand Down Expand Up @@ -116,9 +117,18 @@ def __find_swift_library(ctx):
def __find_macos_sdk(ctx):
ctx.start_msg('Checking for macOS SDK')
sdk = __run(['xcrun', '--sdk', 'macosx', '--show-sdk-path'])
sdk_build_version = __run(['xcrun', '--sdk', 'macosx', '--show-sdk-build-version' ])

if sdk:
ctx.end_msg(sdk)
ctx.env.MACOS_SDK = sdk

if sdk_build_version:
verRe = re.compile("(\d+)(\D+)(\d+)")
version_parts = verRe.search(sdk_build_version)
major = int(version_parts.group(1))-4
minor = string.ascii_lowercase.index(version_parts.group(2).lower())
ctx.env.MACOS_SDK_VERSION = '10.' + str(major) + '.' + str(minor)
else:
ctx.end_msg(False)

Expand Down

0 comments on commit 850b303

Please sign in to comment.