-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Package plugins don't work on Windows if the PATH environment variable isn't accessed with the right case #8126
base: main
Are you sure you want to change the base?
Conversation
@swift-ci please smoke test |
…e 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
5ad260a
to
fe1a671
Compare
env["Path"] = pluginLibraryPath | ||
} | ||
process.environment = env | ||
var env = Environment.current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Since the issue was not caught by a test, possibly because we don't execute tests against windows yet, would it be possible to check if a test already exists, and if not, please add one to ensure we don't regress - once the tests are enabled.
process.environment = env | ||
var env = Environment.current | ||
env.prependPath(key: .path, value: pluginLibraryPath) | ||
process.environment = .init(env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a new type introduced (I think in TSC?) to deal with the case (in)sensitivity of the environment. However, I do like this approach - it is simpler for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #7684
Builds of packages using package plugins may fail on Windows with the following error:
309 translates to 0x135, which maps to 0xc0000135 aka STATUS_DLL_NOT_FOUND.
This is due to the following code in DefaultPluginScriptRunner.swift:
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
[One line description of your change]
Motivation:
[Explain here the context, and why you're making that change. What is the problem you're trying to solve.]
Modifications:
[Describe the modifications you've done.]
Result:
[After your change, what will change.]