-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix some warnings with ProcessEnvironmentBlock
#7364
Draft
MaxDesiatov
wants to merge
8
commits into
main
Choose a base branch
from
maxd/process-environment-block
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
53cc10e
Fix some warnings with `ProcessEnvironmentBlock`
MaxDesiatov 8e08c75
Fix remaining test suite build error
MaxDesiatov b244ed1
Merge branch 'main' of github.com:apple/swift-package-manager into ma…
MaxDesiatov 5b64324
Vendor `Git.swift`, make it SPI
MaxDesiatov f392d37
Merge branch 'main' of github.com:apple/swift-package-manager into ma…
MaxDesiatov 0f5bfaf
Fix build errors after merge
MaxDesiatov fa08cea
Hide more llbuild-specific APIs
MaxDesiatov 4b838cf
Merge branch 'maxd/hide-build-apis' of github.com:apple/swift-package…
MaxDesiatov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See http://swift.org/LICENSE.txt for license information | ||
See http://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import class Foundation.ProcessInfo | ||
import TSCBasic | ||
|
||
package enum Git { | ||
/// A shell command to run for Git. Can be either a name or a path. | ||
/// - Note: modification is not thread safe, designed for testing only | ||
package static var tool: String = "git\(executableFileSuffix)" | ||
|
||
/// Returns true if the git reference name is well formed. | ||
package static func checkRefFormat(ref: String) -> Bool { | ||
do { | ||
let result = try Process.popen(args: tool, "check-ref-format", "--allow-onelevel", ref) | ||
return result.exitStatus == .terminated(code: 0) | ||
} catch { | ||
return false | ||
} | ||
} | ||
|
||
private static var _gitEnvironment = ProcessEnv.block | ||
|
||
/// Returns the environment variables for launching the git subprocess. | ||
/// | ||
/// This contains the current environment with custom overrides for using | ||
/// git from swift build. | ||
/// - Note: modification is not thread safe, designed for testing only | ||
package static var environmentBlock: ProcessEnvironmentBlock { | ||
get { | ||
var env = Self._gitEnvironment | ||
|
||
// These variables are inserted into the environment when shelling out | ||
// to git if not already present. | ||
let underrideVariables: ProcessEnvironmentBlock = [ | ||
// Disable terminal prompts in git. This will make git error out and return | ||
// when it needs a user/pass etc instead of hanging the terminal (SR-3981). | ||
"GIT_TERMINAL_PROMPT": "0", | ||
|
||
// The above is env variable is not enough. However, ssh_config's batch | ||
// mode is made for this purpose. see: https://linux.die.net/man/5/ssh_config | ||
"GIT_SSH_COMMAND": "ssh -oBatchMode=yes", | ||
] | ||
|
||
for (key, value) in underrideVariables { | ||
// Skip this key is already present in the env. | ||
if env.keys.contains(key) { continue } | ||
|
||
env[key] = value | ||
} | ||
|
||
return env | ||
} | ||
set { | ||
Self._gitEnvironment = newValue | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we need to worry about this accidentally causing build issues?
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 we expose it anywhere outside of SwiftPM to any clients, at least not on purpose. IIUC corresponding TSC APIs were widely adopted instead. As soon as
package
support is merged in my other PR, I'll try usingpackage
visibility here to prevent any unintended adoption of this typealias in the future.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.
Could use SPI in the meantime, would also make it easy to remember all the places we want
package
😅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.
And can now use
package
.