2021-11-07 18:45:58 +00:00
|
|
|
#!/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
|
|
|
|
|
2024-09-21 10:47:30 +00:00
|
|
|
|
2021-11-07 18:45:58 +00:00
|
|
|
def find_swift_lib():
|
2024-09-15 00:55:28 +00:00
|
|
|
swift_lib_dir = os.environ.get("SWIFT_LIB_DYNAMIC", "")
|
2021-11-07 18:45:58 +00:00
|
|
|
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")
|
|
|
|
|
2024-09-15 00:43:15 +00:00
|
|
|
swift_lib_dir = os.path.join(
|
|
|
|
xcode_path,
|
2024-09-15 12:08:30 +00:00
|
|
|
"Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx",
|
2024-09-15 00:43:15 +00:00
|
|
|
)
|
2021-11-07 18:45:58 +00:00
|
|
|
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)
|