1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
#!/usr/bin/env python
# swift.py
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ------------------------------------------------------------------------------
import os
import os.path
import subprocess
configurations = ['Ninja-DebugAssert', 'Ninja-ReleaseAssert',
'Ninja-RelWithDebInfoAssert'] # TODO: add more configurations
def getSwiftCompiler():
"""Returns the swift compiler in effect the test suite is running with."""
env_var = "SWIFTC"
if env_var in os.environ:
return os.environ[env_var]
else:
lldb_root_path = os.path.join(
os.path.dirname(__file__), "..", "..", "..", "..", "..")
lldb_parent_path = os.path.join(lldb_root_path, "..")
candidates = []
candidates.append(
os.path.join(
lldb_root_path,
"llvm-build/DebugPresubmission/swift-macosx-x86_64/bin/swiftc"))
candidates.append(
os.path.join(
lldb_root_path,
"PrebuiltSwiftlang/swift-macosx-x86_64/bin/swiftc"))
candidates.append(
os.path.join(
lldb_root_path,
"llvm-build/ReleaseAssert/swift-macosx-x86_64/bin/swiftc"))
candidates.append(
os.path.join(
lldb_root_path,
"llvm-build/Release+Asserts/swift-macosx-x86_64/bin/swiftc"))
candidates.append(
os.path.join(
lldb_root_path,
"llvm-build/DebugAssert/swift-macosx-x86_64/bin/swiftc"))
candidates.append(
os.path.join(
lldb_root_path,
"llvm-build/Debug+Asserts/swift-macosx-x86_64/bin/swiftc"))
candidates.append(
os.path.join(
lldb_root_path,
"llvm-build/Debug/swift-macosx-x86_64/bin/swiftc"))
for configuration in configurations:
candidates.append(
os.path.join(
lldb_parent_path,
'build',
configuration,
'swift-linux-x86_64/bin/swiftc'))
candidates.append(
os.path.join(
lldb_parent_path,
'build',
configuration,
'swift-macosx-x86_64/bin/swiftc'))
for candidate in candidates:
if os.path.exists(candidate):
os.environ[env_var] = os.path.join(
os.path.realpath(
os.path.dirname(candidate)),
os.path.basename(candidate))
return os.environ[env_var]
# Give up and just return "swiftc"...
return "swiftc"
swift_sdk_root = None
def getSwiftSDKRoot():
"""Returns the SDK root to be used for compiling Swift/ObjC interop code."""
global swift_sdk_root
if swift_sdk_root is None:
import platform
if "SDKROOT" in os.environ:
swift_sdk_root = os.environ["SDKROOT"]
if "SWIFTSDKROOT" in os.environ:
swift_sdk_root = os.environ["SWIFTSDKROOT"]
elif platform.system() == 'Darwin':
try:
sdk_path = subprocess.check_output(
'xcrun -sdk macosx --show-sdk-path', shell=True)
if sdk_path[-1] == '\n':
sdk_path = sdk_path[0:-1]
if os.path.isdir(sdk_path):
swift_sdk_root = sdk_path
except:
pass
if swift_sdk_root is None:
swift_sdk_root = "/"
return swift_sdk_root
def getSwiftLibraryPath():
"""Returns the swift library include path for the linker for the swift the test suite is running with."""
env_var = "SWIFTLIBS"
if env_var in os.environ:
return os.environ[env_var]
else:
lldb_root_path = os.path.join(
os.path.dirname(__file__), "..", "..", "..", "..", "..")
lldb_parent_path = os.path.join(lldb_root_path, "..")
candidates = []
candidates.append(
os.path.join(
lldb_root_path,
"llvm-build/DebugPresubmission/swift-macosx-x86_64/lib/swift"))
candidates.append(
os.path.join(
lldb_root_path,
"PrebuiltSwiftlang/swift-macosx-x86_64/lib/swiftc"))
candidates.append(
os.path.join(
lldb_root_path,
"llvm-build/ReleaseAssert/swift-macosx-x86_64/lib/swiftc"))
candidates.append(
os.path.join(
lldb_root_path,
"llvm-build/DebugAssert/swift-macosx-x86_64/lib/swiftc"))
candidates.append(
os.path.join(
lldb_root_path,
"llvm-build/Debug/swift-macosx-x86_64/lib/swiftc"))
for configuration in configurations:
candidates.append(
os.path.join(
lldb_parent_path,
'build',
configuration,
'swift-linux-x86_64/lib/swift'))
candidates.append(
os.path.join(
lldb_parent_path,
'build',
configuration,
'swift-macosx-x86_64/lib/swift'))
for candidate in candidates:
if os.path.exists(candidate):
os.environ[env_var] = os.path.join(
os.path.realpath(
os.path.dirname(candidate)),
os.path.basename(candidate))
return os.environ[env_var]
# Give up and just return "/usr/lib/swift"...
return "/usr/lib/swift"
|