Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swift build fixes #5516

Merged
merged 3 commits into from
Feb 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 11 additions & 10 deletions waftools/detections/compiler_swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ def __run(cmd):
stdout=Utils.subprocess.PIPE,
stderr=Utils.subprocess.PIPE,
shell=True)
output = cmd.stdout.read().strip()
output = cmd.stdout.read().decode().strip()
return output
except Exception:
return ""

def __add_swift_flags(ctx):
ctx.env.SWIFT_FLAGS = ('-frontend -c -sdk %s -enable-objc-interop -emit-objc-header'
' -emit-module -parse-as-library') % (ctx.env.MACOS_SDK)
swift_version = __run(ctx.env.SWIFT + ' -version').split(' ')[3].split('.')
major, minor, sub = [int(n) for n in swift_version]
swift_version = __run(ctx.env.SWIFT + ' -version').split(' ')[3].split('.')[:2]
major, minor = [int(n) for n in swift_version]

# the -swift-version parameter is only supported on swift 3.1 and newer
if major >= 3 and minor >= 1 or major >= 4:
Expand Down Expand Up @@ -44,28 +44,29 @@ def __find_swift_library(ctx):
ctx.end_msg(swift_library)
__add_swift_library_linking_flags(ctx, swift_library)
return
ctx.end_msg(None, "RED")
ctx.end_msg(False)

def __find_macos_sdk(ctx):
ctx.start_msg('Checking for macOS SDK')
sdk = __run('xcrun --sdk macosx --show-sdk-path')
if sdk != "":
if sdk:
ctx.end_msg(sdk)
ctx.env.MACOS_SDK = sdk
else:
ctx.end_msg(None, "RED")
ctx.end_msg(False)

def __find_swift_compiler(ctx):
ctx.start_msg('Checking for swift (Swift compiler)')
swift = __run('xcrun -find swift')
if swift != "":
if swift:
ctx.end_msg(swift)
ctx.env.SWIFT = swift
__add_swift_flags(ctx)
__find_swift_library(ctx)
else:
ctx.end_msg(None, "RED")
ctx.end_msg(False)

def configure(ctx):
__find_macos_sdk(ctx)
__find_swift_compiler(ctx)
if ctx.env.DEST_OS == "darwin":
__find_macos_sdk(ctx)
__find_swift_compiler(ctx)