-
Notifications
You must be signed in to change notification settings - Fork 124
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
TSCBasic: support case insensitivity for environment #447
Conversation
@swift-ci please test |
07b0569
to
010a72f
Compare
@swift-ci please test |
010a72f
to
9e8d570
Compare
@swift-ci please test |
@swift-ci please test |
9e7ac95
to
416729d
Compare
@swift-ci test |
This will need a complementary change in swift-driver, I'll whip that up in a bit. |
It may break SwiftPM and/or SourceKit-LSP too, that's why deprecation of the old API and introducing a new one may be preferable. |
Sure, the deprecation is something to consider, but this is a problem for Windows and needs to propagate. |
@swift-ci please test |
@swift-ci please test Linux platform |
e78f87f
to
fdfb719
Compare
@MaxDesiatov I'm no longer convinced that trying to do this is valuable and we should just expose this in all its nuance to all users. We will end up having to rebuild the full |
fdfb719
to
1fbfb9f
Compare
One more request here: this needs test cases to specify and verify all of the new API surface, since the original bug report doesn't provide self-contained reproducible test cases. Hence my confusion about desired behaviour in a different version of the change. |
I don't know about tests that would be useful here - this is providing the API surface that is necessary to build the dependencies - I don't think that this makes sense to provide tests for unless we just give up on the type representation and just force people to spell out the dictionary type. |
We have to verify that the new API surface works well in the first place. Tests codify a specification for the behavior and the API shape. For example, if you want to preserve string case sensitivity internally while allowing case insensitive lookup at the same time, as you mentioned in the other PR, tests should verify that this property holds, and will also guarantee that it doesn't regress in the future. |
fa6aae5
to
b2ddcca
Compare
|
||
/// Invalidate the cached env. | ||
public static func invalidateEnv() { | ||
_vars = ProcessInfo.processInfo.environment | ||
_vars = ProcessEnvironmentBlock(uniqueKeysWithValues: ProcessInfo.processInfo.environment.map { (CaseInsensitiveString($0.key), $0.value) }) |
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.
This has to be _block
to avoid the deprecation, doesn't it? Also the line is too long, so needs formatting adjustments
_vars = ProcessEnvironmentBlock(uniqueKeysWithValues: ProcessInfo.processInfo.environment.map { (CaseInsensitiveString($0.key), $0.value) }) | |
_block = ProcessEnvironmentBlock( | |
uniqueKeysWithValues: ProcessInfo.processInfo.environment.map { | |
(CaseInsensitiveString($0.key), $0.value) | |
} | |
) |
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.
I don't think it does, I don't see any deprecation warnings. Note that I left the backing store named _vars
. I can change it to _block
if you prefer.
} | ||
} | ||
#else | ||
public typealias ProcessEnvironmentBlock = [String:String] |
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.
I'm unsure if this is a good name, since AFAIU this is specific to Windows NT. Is there something more generic we could use instead?
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.
We already have a mixture of env
and environment
, I think that this is a reasonable alternative.
1978ba3
to
f57674f
Compare
f57674f
to
c23ba35
Compare
@swift-ci please test |
d988b94
to
90fd114
Compare
@swift-ci please test |
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.
This LGTM now, thank you for iterating on this 👍
Windows is case insensitive for the environment control block, which we did not honour. This causes issues when Swift is used with programs which are incorrectly cased (e.g. emacs). Introduce an explicit wrapper type for Windows to make the lookup case insensitive, canonicalising the name to lowercase. This allows us to treat Path and PATH identically (along with any other environment variable and case matching) which respects the Windows behaviour. Additionally, migrate away from the POSIX variants which do not handle the case properly to the Windows version which does. The introduced type `ProcessEnvironmentBlock` is just a typealias, allowing access to the dictionary itself which is important to preserve the behaviour for the clients. The `CaseInsensitiveString` is a case insensitive, case preserving string representation that allows us to recreate the environment on Windows as the environment is case insensitive, so it should not be possible to have conflicts when reading the Process Environment Block from the Process Execution Block. This is a partial resolution to environment variable handling as the tools need subsequent changes to adopt the new API. Fixes: swiftlang#446 Co-authored-by: Max Desiatov <[email protected]>
90fd114
to
8ded310
Compare
@swift-ci please test |
@swift-ci please test Windows platform |
1 similar comment
@swift-ci please test Windows platform |
Windows is case insensitive for the environment control block, which we did not honour. This causes issues when Swift is used with programs which are incorrectly cased (e.g. emacs). Introduce an explicit wrapper type for Windows to make the lookup case insensitive, canonicalising the name to lowercase. This allows us to treat
Path
andPATH
identically (along with any other environment variable and case matching) which respects the Windows behaviour. Additionally, migrate away from the POSIX variants which do not handle the case properly to the Windows version which does.Fixes: #446