summaryrefslogtreecommitdiffstats
path: root/waftools
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2019-04-13 20:44:42 +0200
committerJan Ekström <jeebjp@gmail.com>2019-07-21 18:13:07 +0300
commit76858ba91ce242ac8fb40f2787934e1e3e1fa51b (patch)
tree51f0aef33f4796ef9ae5ed1515bb46d83c921941 /waftools
parentbc014f2ad43d476730261d181475ec60e9dcdbae (diff)
downloadmpv-76858ba91ce242ac8fb40f2787934e1e3e1fa51b.tar.bz2
mpv-76858ba91ce242ac8fb40f2787934e1e3e1fa51b.tar.xz
build: add support for Swift toolchains not provided by Apple
the xcode-select tool only properly works with Apple provided toolchains but not with third party ones from swift.org. in the latter case the swift compiler executable is found in the proper path but the swift libs from the xcode or command line tools will be picked. this leads to a not wanted discrepancy of the swift compiler and libs and possible errors. instead of relying on the xcode-select tool search for the libs relative to the swift executable. that relative path seems to be the same for all toolchains. if for any reasons a swift executable is not found in the relative path, fall back to the old xcode-select method. furthermore, both static and dynamic libs will be searched for but only the former will be used for now. this is a preparation for the upcoming swift 5 migration.
Diffstat (limited to 'waftools')
-rw-r--r--waftools/detections/compiler_swift.py60
1 files changed, 48 insertions, 12 deletions
diff --git a/waftools/detections/compiler_swift.py b/waftools/detections/compiler_swift.py
index 7e4e3db41e..bdac0baf83 100644
--- a/waftools/detections/compiler_swift.py
+++ b/waftools/detections/compiler_swift.py
@@ -1,4 +1,5 @@
import re
+import os.path
from waflib import Utils
from distutils.version import StrictVersion
@@ -36,20 +37,55 @@ def __add_swift_library_linking_flags(ctx, swift_library):
])
def __find_swift_library(ctx):
- swift_library_paths = [
- 'Toolchains/XcodeDefault.xctoolchain/usr/lib/swift_static/macosx',
- 'usr/lib/swift_static/macosx'
- ]
- dev_path = __run(['xcode-select', '-p'])[1:]
+ swift_libraries = {}
+ #first search for swift libs relative to the swift compiler executable
+ swift_library_relative_paths = {
+ 'SWIFT_LIB_DYNAMIC': '../../lib/swift/macosx',
+ 'SWIFT_LIB_STATIC': '../../lib/swift_static/macosx'
+ }
- ctx.start_msg('Checking for Swift Library')
- for path in swift_library_paths:
- swift_library = ctx.root.find_dir([dev_path, path])
+ for lib_type, path in swift_library_relative_paths.items():
+ lib_path = os.path.join(ctx.env.SWIFT, path)
+ swift_library = ctx.root.find_dir(lib_path)
if swift_library is not None:
- ctx.end_msg(swift_library.abspath())
- __add_swift_library_linking_flags(ctx, swift_library.abspath())
- return
- ctx.end_msg(False)
+ swift_libraries[lib_type] = swift_library.abspath()
+
+ #fall back to xcode-select path
+ swift_library_paths = {
+ 'SWIFT_LIB_DYNAMIC': [
+ 'Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx',
+ 'usr/lib/swift/macosx'
+ ],
+ 'SWIFT_LIB_STATIC': [
+ 'Toolchains/XcodeDefault.xctoolchain/usr/lib/swift_static/macosx',
+ 'usr/lib/swift_static/macosx'
+ ]
+ }
+ dev_path = __run(['xcode-select', '-p'])[1:]
+
+ for lib_type, paths in swift_library_paths.items():
+ for path in paths:
+ if lib_type not in swift_libraries:
+ swift_library = ctx.root.find_dir([dev_path, path])
+ if swift_library is not None:
+ swift_libraries[lib_type] = swift_library.abspath()
+ break
+ else:
+ break
+
+ #check if library paths were found
+ ctx.start_msg('Checking for dynamic Swift Library')
+ if 'SWIFT_LIB_DYNAMIC' in swift_libraries:
+ ctx.end_msg(swift_libraries['SWIFT_LIB_DYNAMIC'])
+ else:
+ ctx.end_msg(False)
+
+ ctx.start_msg('Checking for static Swift Library')
+ if 'SWIFT_LIB_STATIC' in swift_libraries:
+ ctx.end_msg(swift_libraries['SWIFT_LIB_STATIC'])
+ __add_swift_library_linking_flags(ctx, swift_libraries['SWIFT_LIB_STATIC'])
+ else:
+ ctx.end_msg(False)
def __find_macos_sdk(ctx):
ctx.start_msg('Checking for macOS SDK')