Skip to content

Commit 8177868

Browse files
authored
Merge pull request #18673 from ahoppen/swift-syntax-xcode
[swiftSyntax] Fix issue where swiftc was not found when swiftSyntax is build via Xcode
2 parents be0e164 + 3534733 commit 8177868

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

tools/SwiftSyntax/SwiftcInvocation.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct SwiftcRunner {
146146
/// - lib/
147147
/// - swift/
148148
/// - ${target}/
149-
/// - ${arch}/ (only on !Darwin)
149+
/// - ${arch}/ (only on !Darwin and if launched from Xcode)
150150
/// - libswiftSwiftSyntax.[dylib|so]
151151
/// ```
152152
static func locateSwiftc() -> URL? {
@@ -156,9 +156,13 @@ struct SwiftcRunner {
156156
.deletingLastPathComponent()
157157
.deletingLastPathComponent()
158158
.deletingLastPathComponent()
159-
#if !os(macOS)
160-
swiftcURL = swiftcURL.deletingLastPathComponent()
161-
#endif
159+
160+
if swiftcURL.lastPathComponent == "lib" {
161+
// We are still one level to deep because we started in ${arch},
162+
// not ${target}, see comment above). Traverse one more level upwards
163+
swiftcURL = swiftcURL.deletingLastPathComponent()
164+
}
165+
162166
swiftcURL = swiftcURL.appendingPathComponent("bin")
163167
.appendingPathComponent("swiftc")
164168
guard FileManager.default.fileExists(atPath: swiftcURL.path) else {

tools/swift-swiftsyntax-test/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ do {
8686
}
8787
exit(0)
8888
} catch {
89-
printerr(error.localizedDescription)
89+
printerr("\(error)")
9090
printerr("Run swift-swiftsyntax-test -help for more help.")
9191
exit(1)
9292
}

0 commit comments

Comments
 (0)