diff options
author | Dudemanguy <random342@airmail.cc> | 2021-11-07 12:45:58 -0600 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2021-11-14 19:13:10 +0000 |
commit | c698575c5760d06b69cce4e92aed124a031f5a6c (patch) | |
tree | 480afedfe041373a8e18b62aeddf5ab29215d929 /TOOLS | |
parent | be536dd45ade36ca203221da6d5c61f9d9230a08 (diff) | |
download | mpv-c698575c5760d06b69cce4e92aed124a031f5a6c.tar.bz2 mpv-c698575c5760d06b69cce4e92aed124a031f5a6c.tar.xz |
TOOLS: add macos-swift-lib-directory.py script
Apple is great and forces us to do a lot of weird checks because they
randomly move the location of the swift libraries around. Make a
specific python script for checking various locations and write the
output to stdout for meson.
Diffstat (limited to 'TOOLS')
-rwxr-xr-x | TOOLS/macos-swift-lib-directory.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/TOOLS/macos-swift-lib-directory.py b/TOOLS/macos-swift-lib-directory.py new file mode 100755 index 0000000000..51e8cbe96f --- /dev/null +++ b/TOOLS/macos-swift-lib-directory.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +# Finds the macos swift library directory and prints the full path to stdout. +# First argument is the path to the swift executable. + +import os +import sys +from shutil import which +from subprocess import check_output + +def find_swift_lib(): + swift_lib_dir = os.environ.get('SWIFT_LIB_DYNAMIC', '') + if swift_lib_dir: + return swift_lib_dir + + # first check for lib dir relative to swift executable + xcode_dir = os.path.dirname(os.path.dirname(sys.argv[1])) + swift_lib_dir = os.path.join(xcode_dir, "lib", "swift", "macosx") + + if os.path.isdir(swift_lib_dir): + return swift_lib_dir + + # fallback to xcode-select path + xcode_select = which("xcode-select") + if not xcode_select: + sys.exit(1) + + xcode_path = check_output([xcode_select, "-p"], encoding="UTF-8") + + swift_lib_dir = os.path.join(xcode_path, "Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx") + if os.path.isdir(swift_lib_dir): + return swift_lib_dir + + # last resort if we still haven't found a path + swift_lib_dir = os.path.join(xcode_path, "usr/lib/swift/macosx") + if not os.path.isdir(swift_lib_dir): + sys.exit(1) + return swift_lib_dir + +if __name__ == "__main__": + swift_lib_dir = find_swift_lib() + sys.stdout.write(swift_lib_dir) |