File tree Expand file tree Collapse file tree 4 files changed +18
-4
lines changed Expand file tree Collapse file tree 4 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -213,7 +213,8 @@ extension ParsableArguments {
213213 if messageInfo. shouldExitCleanly {
214214 print ( fullText)
215215 } else {
216- print ( fullText, to: & Platform. standardError)
216+ var errorOut = Platform . standardError
217+ print ( fullText, to: & errorOut)
217218 }
218219 }
219220 Platform . exit ( messageInfo. exitCode. rawValue)
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ extension ParsableCommand {
6363 _ arguments: [ String ] ? = nil
6464 ) throws -> ParsableCommand {
6565 var parser = CommandParser ( self )
66- let arguments = arguments ?? Array ( CommandLine . arguments . dropFirst ( ) )
66+ let arguments = arguments ?? Array ( CommandLine . _staticArguments . dropFirst ( ) )
6767 return try parser. parse ( arguments: arguments) . get ( )
6868 }
6969
Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ struct UsageGenerator {
1818
1919extension UsageGenerator {
2020 init ( definition: ArgumentSet ) {
21- let toolName = CommandLine . arguments [ 0 ] . split ( separator: " / " ) . last. map ( String . init) ?? " <command> "
21+ let toolName = CommandLine . _staticArguments [ 0 ]
22+ . split ( separator: " / " ) . last. map ( String . init) ?? " <command> "
2223 self . init ( toolName: toolName, definition: definition)
2324 }
2425
Original file line number Diff line number Diff line change 99//
1010//===----------------------------------------------------------------------===//
1111
12+ extension CommandLine {
13+ /// Accesses the command line arguments in a concurrency-safe way.
14+ ///
15+ /// Workaround for https://github.com/apple/swift/issues/66213
16+ static let _staticArguments : [ String ] =
17+ UnsafeBufferPointer ( start: unsafeArgv, count: Int ( argc) )
18+ . compactMap { String ( validatingUTF8: $0!)
19+ }
20+ }
21+
1222#if canImport(Glibc)
1323import Glibc
1424#elseif canImport(Musl)
@@ -103,7 +113,9 @@ extension Platform {
103113 }
104114
105115 /// The `stderr` output stream.
106- static var standardError = StandardError ( )
116+ static var standardError : StandardError {
117+ StandardError ( )
118+ }
107119}
108120
109121// MARK: Terminal size
You can’t perform that action at this time.
0 commit comments