Skip to content

Commit

Permalink
Infer active Xcode for testing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
neonichu committed Feb 18, 2025
1 parent 09c975a commit 98972d6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Sources/SWBTestSupport/CoreTestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,19 @@ extension Core {
// When this code is being loaded directly via unit tests, find the running Xcode path.
//
// This is a "well known" launch parameter set in Xcode's schemes.
let developerPath = getEnvironmentVariable("XCODE_DEVELOPER_DIR_PATH").map(Path.init)
let developerPath: Path?
if let xcodeDeveloperDirPath = getEnvironmentVariable("XCODE_DEVELOPER_DIR_PATH").map(Path.init) {
developerPath = xcodeDeveloperDirPath
} else {
// In the context of auto-generated package schemes, try to infer the active Xcode.
let potentialDeveloperPath = getEnvironmentVariable("PATH")?.components(separatedBy: String(Path.pathEnvironmentSeparator)).first.map(Path.init)?.dirname.dirname
let versionInfo = potentialDeveloperPath?.dirname.join("version.plist")
if let versionInfo = versionInfo, (try? PropertyList.fromPath(versionInfo, fs: localFS))?.dictValue?["ProjectName"] == "IDEApplication" {
developerPath = potentialDeveloperPath
} else {
developerPath = nil
}
}

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

0 comments on commit 98972d6

Please sign in to comment.