-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix environment related warnings #7684
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
Conversation
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 not convinced Environment
warrants its own module, I'd prefer to keep it in Basics
for now. It's unclear to me how that separation logic should be followed if at all. There's a lot of functionality in Basics
, a new module for each type (or functionality aspect) would require a dozen of new modules, which IMO overcomplicates things.
If you insist on moving it out of |
It seems like |
Main problem with that is a dependency on |
@swift-ci test |
@swift-ci test windows |
@compnerd would you have a moment to look how well this works for Windows compatibility? |
} | ||
} | ||
|
||
// FIXME: This should come from Foundation |
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 that this can come from Foundation. Foundation's API is not easy to change and the environment being case insensitive is not currently well handled there.
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.
The intent of the comment that this type should come from a common Swift ecosystem library and foundation seems like the most natural place.
} | ||
} | ||
|
||
package static var pathValueDelimiter: 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 think pathEntryDelimiter
is better - the variable is a set of key, value pairs which makes value a bit overloaded.
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.
Yeah, I can change the name to your suggestion
package static func set(key: EnvironmentKey, value: String?) throws { | ||
if let value = value { | ||
#if os(Windows) | ||
guard _putenv("\(key)=\(value)") == 0 else { |
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 is annoying - I don't know if we should use _putenv
or SetEnvironmentVariableW
. The former only adjusts the "C" functions view, the latter only changes the Win32 view. I suppose that we could call both?
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 can have it call both, in general I strongly dislike mutating the global environment anyways
for (key, value) in sorted { | ||
if first { | ||
first = false | ||
} else { | ||
description.append(", ") | ||
} | ||
description.append("\"") | ||
description.append(key.rawValue) | ||
description.append("=") | ||
description.append(value) | ||
description.append("\"") | ||
} |
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.
for (key, value) in sorted { | |
if first { | |
first = false | |
} else { | |
description.append(", ") | |
} | |
description.append("\"") | |
description.append(key.rawValue) | |
description.append("=") | |
description.append(value) | |
description.append("\"") | |
} | |
sorted.map { #""\#($0.rawValue)"="\#($1)""# }.joined(", ") |
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 avoided string interpolation and join to avoid intermediate allocations
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.
That said it really doesn't matter and I can use an easier to read method
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.
Curious if we have issues on the compiler repo tracking possible optimizer work that hypothetically could get rid of intermediate allocations here?
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.
Curious if we have issues on the compiler repo tracking possible optimizer work that hypothetically could get rid of intermediate allocations here?
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.
Thank you for making SwiftPM more environment friendly! 🙈
@swift-ci test windows |
@swift-ci test |
@swift-ci test windows |
1 similar comment
@swift-ci test windows |
looks like windows CI is failing to checkout Swift which is odd because the other checks are working |
@swift-ci test windows |
1 similar comment
@swift-ci test windows |
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.
Looks great, thank you! Could you please run swiftformat
on new files before merging?
@swift-ci test |
@swift-ci test windows |
Adds a new `Environment` type to replace TSCBasics EnvironmentVariables and ProcessEnvironmentBlock types. Updates points of use of the older APIs with the newer API and adds unit tests for `Environment`. (cherry picked from commit 74aea87)
Includes these PRs cherry-picked off `main` * #7605 * #7660 * #7667 * #7682 * #7687 * #7690 * #7684 * #7679 **Explanation**: Cherry-pick of recent NFC changes, which makes it easier to cherry-pick actual bug fixes onto 6.0 due to the reduced number of merge conflicts. **Scope**: broad, includes both modules graph and llbuild-related changes. **Risk**: low, the test suite is passing, no functional changes are included, and cherry-picked changes were incubated on `main` for some time. **Testing**: Existing automated test suite. **Issue**: N/A **Reviewers**: @xedin @MaxDesiatov @rauhul --------- Co-authored-by: Pavel Yaskevich <xedin@apache.org> Co-authored-by: Danny Mösch <danny.moesch@icloud.com> Co-authored-by: Rauhul Varma <rauhul@apple.com>
Adds a new
Environment
type to replace TSCBasics EnvironmentVariablesand ProcessEnvironmentBlock types. Updates points of use of the older
APIs with the newer API and adds unit tests for
Environment
.