build: more reliable way of getting the Swift version from a string

Fixes #6212
This commit is contained in:
Akemi 2018-10-15 19:59:11 +02:00 committed by Jan Ekström
parent facc63b862
commit 6fbd933108
1 changed files with 4 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import re
from waflib import Utils
def __run(cmd):
@ -11,7 +12,9 @@ def __add_swift_flags(ctx):
ctx.env.SWIFT_FLAGS = ('-frontend -c -sdk %s -enable-objc-interop'
' -emit-objc-header -parse-as-library'
' -target x86_64-apple-macosx10.10') % (ctx.env.MACOS_SDK)
ctx.env.SWIFT_VERSION = __run([ctx.env.SWIFT, '-version']).split(' ')[3]
ver = re.compile("(?i)version\s?([\d.]+)")
ctx.env.SWIFT_VERSION = ver.search(__run([ctx.env.SWIFT, '-version'])).group(1)
major, minor = [int(n) for n in ctx.env.SWIFT_VERSION.split('.')[:2]]
# the -swift-version parameter is only supported on swift 3.1 and newer