Skip to content

Commit 4d9b1b7

Browse files
committed
Fix OS X integration tests
1 parent b5fd2de commit 4d9b1b7

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

Sources/swift-build/UserToolchain.swift

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,51 @@
66

77
See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9-
*/
9+
*/
1010

1111
import protocol Build.Toolchain
1212
import struct Utility.Path
1313
import enum Multitool.Error
1414
import POSIX
1515

16+
#if os(OSX)
17+
private let whichClangArgs = ["xcrun", "--find", "clang"]
18+
#else
19+
private let whichClangArgs = ["which", "clang"]
20+
#endif
21+
1622
struct UserToolchain: Toolchain {
1723
let SWIFT_EXEC: String
1824
let clang: String
1925
let sysroot: String?
2026

2127
#if os(OSX)
22-
/**
23-
On OS X we do not support running in situations where xcrun fails.
24-
*/
25-
init() throws {
26-
SWIFT_EXEC = try getenv("SWIFT_EXEC") ?? POSIX.popen(["xcrun", "--find", "swiftc"]).chomp()
27-
clang = try getenv("CC") ?? POSIX.popen(["xcrun", "--find", "clang"]).chomp()
28-
sysroot = try getenv("SYSROOT") ?? POSIX.popen(["xcrun", "--sdk", "macosx", "--show-sdk-path"]).chomp()
29-
30-
guard !SWIFT_EXEC.isEmpty && !clang.isEmpty && !sysroot!.isEmpty else {
31-
throw Multitool.Error.InvalidToolchain
32-
}
33-
}
34-
3528
var platformArgs: [String] {
3629
return ["-target", "x86_64-apple-macosx10.10", "-sdk", sysroot!]
3730
}
38-
3931
#else
32+
let platformArgs: [String] = []
33+
#endif
4034

4135
init() throws {
4236
do {
4337
SWIFT_EXEC = getenv("SWIFT_EXEC")
44-
// see if user has put something earlier in the path
45-
?? (try? POSIX.popen(["which", "swiftc"]))?.chomp().abspath()
4638
// use the swiftc installed alongside ourselves
4739
?? Path.join(Process.arguments[0], "../swiftc").abspath()
48-
clang = try getenv("CC") ?? popen(["which", "clang"]).chomp().abspath()
49-
sysroot = nil
40+
41+
clang = try getenv("CC") ?? POSIX.popen(whichClangArgs).chomp()
42+
43+
#if os(OSX)
44+
sysroot = try getenv("SYSROOT") ?? POSIX.popen(["xcrun", "--sdk", "macosx", "--show-sdk-path"]).chomp()
45+
#else
46+
sysroot = nil
47+
#endif
48+
49+
guard !SWIFT_EXEC.isEmpty && !clang.isEmpty && (sysroot == nil || !sysroot!.isEmpty) else {
50+
throw Multitool.Error.InvalidToolchain
51+
}
5052
} catch POSIX.Error.ExitStatus {
5153
throw Multitool.Error.InvalidToolchain
5254
}
53-
guard !SWIFT_EXEC.isEmpty && !clang.isEmpty else {
54-
throw Multitool.Error.InvalidToolchain
55-
}
56-
5755
}
58-
59-
let platformArgs: [String] = []
60-
#endif
6156
}

0 commit comments

Comments
 (0)