Skip to content

Commit fe1a671

Browse files
committed
Package plugins don't work on Windows if the PATH environment variable isn't accessed with the right case
Builds of packages using package plugins may fail on Windows with the following error: ``` error: plugin process ended by an uncaught signal: 309 <command: C:\foo\.build\plugins\cache\myplugin.exe>, <output: > ``` 309 translates to 0x135, which maps to 0xc0000135 aka STATUS_DLL_NOT_FOUND. This is due to the following code in DefaultPluginScriptRunner.swift: ```swift #if os(Windows) let pluginLibraryPath = self.toolchain.swiftPMLibrariesLocation.pluginLibraryPath.pathString var env = ProcessInfo.processInfo.environment if let Path = env["Path"] { env["Path"] = "\(pluginLibraryPath);\(Path)" } else { env["Path"] = pluginLibraryPath } process.environment = env #endif ``` Environment variable names are case-insensitive on Windows. On a real Windows host, it tends to be spelled "Path". In a Windows Container (Docker), it tends to be spelled "PATH". The code will end up clearing out the other paths from the PATH environment variable in the else case because Path != PATH. We need to access the path here in a case-insensitive manner -- use the existing Environment abstraction for this, which handles Windows case sensitivity concerns. Closes #8125
1 parent cb829d8 commit fe1a671

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Sources/Workspace/DefaultPluginScriptRunner.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,9 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
467467
process.environment = ProcessInfo.processInfo.environment
468468
#if os(Windows)
469469
let pluginLibraryPath = self.toolchain.swiftPMLibrariesLocation.pluginLibraryPath.pathString
470-
var env = ProcessInfo.processInfo.environment
471-
if let Path = env["Path"] {
472-
env["Path"] = "\(pluginLibraryPath);\(Path)"
473-
} else {
474-
env["Path"] = pluginLibraryPath
475-
}
476-
process.environment = env
470+
var env = Environment.current
471+
env.prependPath(key: .path, value: pluginLibraryPath)
472+
process.environment = .init(env)
477473
#endif
478474
process.currentDirectoryURL = workingDirectory.asURL
479475

0 commit comments

Comments
 (0)