Skip to content

Commit 0660812

Browse files
authored
Infer active Xcode for testing (#183)
Historically, we have been relying on `XCODE_DEVELOPER_DIR_PATH` being set to `DEVELOPER_DIR` in our schemes to find the active Xcode, but with auto-generated package schemes, this doesn't really work anymore. Try to infer the path from `PATH` instead which should be set when running in the context of Xcode.
1 parent 68b0a58 commit 0660812

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Sources/SWBTestSupport/CoreTestSupport.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,19 @@ extension Core {
5050
// When this code is being loaded directly via unit tests, find the running Xcode path.
5151
//
5252
// This is a "well known" launch parameter set in Xcode's schemes.
53-
let developerPath = getEnvironmentVariable("XCODE_DEVELOPER_DIR_PATH").map(Path.init)
53+
let developerPath: Path?
54+
if let xcodeDeveloperDirPath = getEnvironmentVariable("XCODE_DEVELOPER_DIR_PATH").map(Path.init) {
55+
developerPath = xcodeDeveloperDirPath
56+
} else {
57+
// In the context of auto-generated package schemes, try to infer the active Xcode.
58+
let potentialDeveloperPath = getEnvironmentVariable("PATH")?.components(separatedBy: String(Path.pathEnvironmentSeparator)).first.map(Path.init)?.dirname.dirname
59+
let versionInfo = potentialDeveloperPath?.dirname.join("version.plist")
60+
if let versionInfo = versionInfo, (try? PropertyList.fromPath(versionInfo, fs: localFS))?.dictValue?["ProjectName"] == "IDEApplication" {
61+
developerPath = potentialDeveloperPath
62+
} else {
63+
developerPath = nil
64+
}
65+
}
5466

5567
// Unset variables which may interfere with testing in Swift CI
5668
for variable in ["SWIFT_EXEC", "SWIFT_DRIVER_SWIFT_FRONTEND_EXEC", "SWIFT_DRIVER_SWIFT_EXEC"] {

0 commit comments

Comments
 (0)