Skip to content

Commit 6119192

Browse files
committed
Format repository
1 parent 1ed8aaa commit 6119192

File tree

753 files changed

+63542
-48241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

753 files changed

+63542
-48241
lines changed

.swift-format

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
2-
"version": 1,
3-
"lineLength": 10000,
4-
"indentation": {
5-
"spaces": 4
6-
},
7-
"rules": {
8-
},
9-
"tabWidth": 4
2+
"version": 1,
3+
"lineLength": 10000,
4+
"indentation": {
5+
"spaces": 4
6+
},
7+
"lineBreakBeforeEachArgument": true,
8+
"maximumBlankLines" : 1,
9+
"multiElementCollectionTrailingCommas" : true,
10+
"rules": {
11+
},
12+
"tabWidth": 4
1013
}

Package.swift

Lines changed: 147 additions & 82 deletions
Large diffs are not rendered by default.

Plugins/cmake-smoke-test/cmake-smoke-test.swift

Lines changed: 102 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct CMakeSmokeTest: CommandPlugin {
6666
}
6767

6868
var sharedSwiftFlags = [
69-
"-module-cache-path", moduleCachePath
69+
"-module-cache-path", moduleCachePath,
7070
]
7171

7272
if let sysrootPath {
@@ -79,15 +79,16 @@ struct CMakeSmokeTest: CommandPlugin {
7979
"-DTSC_DIR=\(swiftToolsSupportCoreBuildURL.appending(components: "cmake", "modules").filePath)",
8080
"-DSwiftDriver_DIR=\(swiftDriverBuildURL.appending(components: "cmake", "modules").filePath)",
8181
"-DSwiftSystem_DIR=\(swiftSystemBuildURL.appending(components: "cmake", "modules").filePath)",
82-
"-DSwiftToolsProtocols_DIR=\(swiftToolsProtocolsBuildURL.appending(components: "cmake", "modules").filePath)"
82+
"-DSwiftToolsProtocols_DIR=\(swiftToolsProtocolsBuildURL.appending(components: "cmake", "modules").filePath)",
8383
]
8484

85-
let sharedCMakeArgs = [
86-
"-G", "Ninja",
87-
"-DCMAKE_MAKE_PROGRAM=\(ninjaPath)",
88-
"-DCMAKE_BUILD_TYPE:=Debug",
89-
"-DCMAKE_Swift_FLAGS='\(sharedSwiftFlags.joined(separator: " "))'"
90-
] + cMakeProjectArgs + extraCMakeArgs
85+
let sharedCMakeArgs =
86+
[
87+
"-G", "Ninja",
88+
"-DCMAKE_MAKE_PROGRAM=\(ninjaPath)",
89+
"-DCMAKE_BUILD_TYPE:=Debug",
90+
"-DCMAKE_Swift_FLAGS='\(sharedSwiftFlags.joined(separator: " "))'",
91+
] + cMakeProjectArgs + extraCMakeArgs
9192

9293
Diagnostics.progress("Building swift-tools-support-core")
9394
try await Process.checkNonZeroExit(url: cmakeURL, arguments: sharedCMakeArgs + [swiftToolsSupportCoreURL.filePath], workingDirectory: swiftToolsSupportCoreBuildURL)
@@ -168,13 +169,13 @@ enum OS {
168169

169170
static func host() throws -> Self {
170171
#if os(macOS)
171-
return .macOS
172+
return .macOS
172173
#elseif os(Linux)
173-
return .linux
174+
return .linux
174175
#elseif os(Windows)
175-
return .windows
176+
return .windows
176177
#else
177-
throw Errors.unimplementedForHostOS
178+
throw Errors.unimplementedForHostOS
178179
#endif
179180
}
180181
}
@@ -211,100 +212,104 @@ extension Process {
211212
static func checkNonZeroExit(url: URL, arguments: [String], workingDirectory: URL, environment: [String: String]? = nil) async throws {
212213
try Diagnostics.progress("\(url.filePath) \(arguments.joined(separator: " "))")
213214
#if USE_PROCESS_SPAWNING_WORKAROUND && !os(Windows)
214-
Diagnostics.progress("Using process spawning workaround")
215-
// Linux workaround for https://github.com/swiftlang/swift-corelibs-foundation/issues/4772
216-
// Foundation.Process on Linux seems to inherit the Process.run()-calling thread's signal mask, creating processes that even have SIGTERM blocked
217-
// This manifests as CMake getting stuck when invoking 'uname' with incorrectly configured signal handlers.
218-
var fileActions = posix_spawn_file_actions_t()
219-
defer { posix_spawn_file_actions_destroy(&fileActions) }
220-
var attrs: posix_spawnattr_t = posix_spawnattr_t()
221-
defer { posix_spawnattr_destroy(&attrs) }
222-
posix_spawn_file_actions_init(&fileActions)
223-
try posix_spawn_file_actions_addchdir_np(&fileActions, workingDirectory.filePath)
224-
225-
posix_spawnattr_init(&attrs)
226-
posix_spawnattr_setpgroup(&attrs, 0)
227-
var noSignals = sigset_t()
228-
sigemptyset(&noSignals)
229-
posix_spawnattr_setsigmask(&attrs, &noSignals)
230-
231-
var mostSignals = sigset_t()
232-
sigemptyset(&mostSignals)
233-
for i in 1 ..< SIGSYS {
234-
if i == SIGKILL || i == SIGSTOP {
235-
continue
236-
}
237-
sigaddset(&mostSignals, i)
238-
}
239-
posix_spawnattr_setsigdefault(&attrs, &mostSignals)
240-
posix_spawnattr_setflags(&attrs, numericCast(POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK))
241-
var pid: pid_t = -1
242-
try withArrayOfCStrings([url.filePath] + arguments) { arguments in
243-
try withArrayOfCStrings((environment ?? [:]).map { key, value in "\(key)=\(value)" }) { environment in
244-
let spawnResult = try posix_spawn(&pid, url.filePath, /*file_actions=*/&fileActions, /*attrp=*/&attrs, arguments, nil);
245-
var exitCode: Int32 = -1
246-
var result = wait4(pid, &exitCode, 0, nil);
247-
while (result == -1 && errno == EINTR) {
248-
result = wait4(pid, &exitCode, 0, nil)
249-
}
250-
guard result != -1 else {
251-
throw Errors.miscError("wait failed")
215+
Diagnostics.progress("Using process spawning workaround")
216+
// Linux workaround for https://github.com/swiftlang/swift-corelibs-foundation/issues/4772
217+
// Foundation.Process on Linux seems to inherit the Process.run()-calling thread's signal mask, creating processes that even have SIGTERM blocked
218+
// This manifests as CMake getting stuck when invoking 'uname' with incorrectly configured signal handlers.
219+
var fileActions = posix_spawn_file_actions_t()
220+
defer { posix_spawn_file_actions_destroy(&fileActions) }
221+
var attrs: posix_spawnattr_t = posix_spawnattr_t()
222+
defer { posix_spawnattr_destroy(&attrs) }
223+
posix_spawn_file_actions_init(&fileActions)
224+
try posix_spawn_file_actions_addchdir_np(&fileActions, workingDirectory.filePath)
225+
226+
posix_spawnattr_init(&attrs)
227+
posix_spawnattr_setpgroup(&attrs, 0)
228+
var noSignals = sigset_t()
229+
sigemptyset(&noSignals)
230+
posix_spawnattr_setsigmask(&attrs, &noSignals)
231+
232+
var mostSignals = sigset_t()
233+
sigemptyset(&mostSignals)
234+
for i in 1..<SIGSYS {
235+
if i == SIGKILL || i == SIGSTOP {
236+
continue
252237
}
253-
guard exitCode == 0 else {
254-
throw Errors.miscError("exit code nonzero")
238+
sigaddset(&mostSignals, i)
239+
}
240+
posix_spawnattr_setsigdefault(&attrs, &mostSignals)
241+
posix_spawnattr_setflags(&attrs, numericCast(POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK))
242+
var pid: pid_t = -1
243+
try withArrayOfCStrings([url.filePath] + arguments) { arguments in
244+
try withArrayOfCStrings((environment ?? [:]).map { key, value in "\(key)=\(value)" }) { environment in
245+
let spawnResult = try posix_spawn(&pid, url.filePath, /*file_actions=*/ &fileActions, /*attrp=*/ &attrs, arguments, nil);
246+
var exitCode: Int32 = -1
247+
var result = wait4(pid, &exitCode, 0, nil);
248+
while (result == -1 && errno == EINTR) {
249+
result = wait4(pid, &exitCode, 0, nil)
250+
}
251+
guard result != -1 else {
252+
throw Errors.miscError("wait failed")
253+
}
254+
guard exitCode == 0 else {
255+
throw Errors.miscError("exit code nonzero")
256+
}
255257
}
256258
}
257-
}
258259
#else
259-
let process = Process()
260-
process.executableURL = url
261-
process.arguments = arguments
262-
process.currentDirectoryURL = workingDirectory
263-
process.environment = environment
264-
try await process.run()
265-
if process.terminationStatus != 0 {
266-
throw Errors.processError(terminationReason: process.terminationReason, terminationStatus: process.terminationStatus)
267-
}
260+
let process = Process()
261+
process.executableURL = url
262+
process.arguments = arguments
263+
process.currentDirectoryURL = workingDirectory
264+
process.environment = environment
265+
try await process.run()
266+
if process.terminationStatus != 0 {
267+
throw Errors.processError(terminationReason: process.terminationReason, terminationStatus: process.terminationStatus)
268+
}
268269
#endif
269270
}
270271
}
271272

272273
#if USE_PROCESS_SPAWNING_WORKAROUND && !os(Windows)
273-
func scan<S: Sequence, U>(_ seq: S, _ initial: U, _ combine: (U, S.Element) -> U) -> [U] {
274-
var result: [U] = []
275-
result.reserveCapacity(seq.underestimatedCount)
276-
var runningResult = initial
277-
for element in seq {
278-
runningResult = combine(runningResult, element)
279-
result.append(runningResult)
280-
}
281-
return result
282-
}
274+
func scan<S: Sequence, U>(_ seq: S, _ initial: U, _ combine: (U, S.Element) -> U) -> [U] {
275+
var result: [U] = []
276+
result.reserveCapacity(seq.underestimatedCount)
277+
var runningResult = initial
278+
for element in seq {
279+
runningResult = combine(runningResult, element)
280+
result.append(runningResult)
281+
}
282+
return result
283+
}
283284

284-
func withArrayOfCStrings<T>(
285-
_ args: [String],
286-
_ body: (UnsafePointer<UnsafeMutablePointer<Int8>?>) throws -> T
287-
) throws -> T {
288-
let argsCounts = Array(args.map { $0.utf8.count + 1 })
289-
let argsOffsets = [0] + scan(argsCounts, 0, +)
290-
let argsBufferSize = argsOffsets.last!
291-
var argsBuffer: [UInt8] = []
292-
argsBuffer.reserveCapacity(argsBufferSize)
293-
for arg in args {
294-
argsBuffer.append(contentsOf: arg.utf8)
295-
argsBuffer.append(0)
296-
}
297-
return try argsBuffer.withUnsafeMutableBufferPointer {
298-
(argsBuffer) in
299-
let ptr = UnsafeRawPointer(argsBuffer.baseAddress!).bindMemory(
300-
to: Int8.self, capacity: argsBuffer.count)
301-
var cStrings: [UnsafePointer<Int8>?] = argsOffsets.map { ptr + $0 }
302-
cStrings[cStrings.count - 1] = nil
303-
return try cStrings.withUnsafeMutableBufferPointer {
304-
let unsafeString = UnsafeMutableRawPointer($0.baseAddress!).bindMemory(
305-
to: UnsafeMutablePointer<Int8>?.self, capacity: $0.count)
306-
return try body(unsafeString)
285+
func withArrayOfCStrings<T>(
286+
_ args: [String],
287+
_ body: (UnsafePointer<UnsafeMutablePointer<Int8>?>) throws -> T
288+
) throws -> T {
289+
let argsCounts = Array(args.map { $0.utf8.count + 1 })
290+
let argsOffsets = [0] + scan(argsCounts, 0, +)
291+
let argsBufferSize = argsOffsets.last!
292+
var argsBuffer: [UInt8] = []
293+
argsBuffer.reserveCapacity(argsBufferSize)
294+
for arg in args {
295+
argsBuffer.append(contentsOf: arg.utf8)
296+
argsBuffer.append(0)
297+
}
298+
return try argsBuffer.withUnsafeMutableBufferPointer {
299+
(argsBuffer) in
300+
let ptr = UnsafeRawPointer(argsBuffer.baseAddress!).bindMemory(
301+
to: Int8.self,
302+
capacity: argsBuffer.count
303+
)
304+
var cStrings: [UnsafePointer<Int8>?] = argsOffsets.map { ptr + $0 }
305+
cStrings[cStrings.count - 1] = nil
306+
return try cStrings.withUnsafeMutableBufferPointer {
307+
let unsafeString = UnsafeMutableRawPointer($0.baseAddress!).bindMemory(
308+
to: UnsafeMutablePointer<Int8>?.self,
309+
capacity: $0.count
310+
)
311+
return try body(unsafeString)
312+
}
313+
}
307314
}
308-
}
309-
}
310315
#endif

Plugins/generate-windows-installer-component-groups/generate-windows-installer-component-groups.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ struct GenerateWindowsInstallerComponentGroups: CommandPlugin {
2525
continue
2626
}
2727
librariesComponent += #"""
28-
<Component>
29-
<File Source="$(ToolchainRoot)\usr\bin\\#(sourceModule.name).dll" />
30-
</Component>
28+
<Component>
29+
<File Source="$(ToolchainRoot)\usr\bin\\#(sourceModule.name).dll" />
30+
</Component>
3131
32-
"""#
32+
"""#
3333

3434
let resources = sourceModule.sourceFiles.filter { resource in resource.type == .resource && ["xcspec", "xcbuildrules"].contains(resource.url.pathExtension) }
3535
if !resources.isEmpty {
3636
groupRefs += #" <ComponentGroupRef Id="\#(sourceModule.name)Resources" />\#n"#
3737
directories += #" <Directory Id="_usr_share_pm_\#(sourceModule.name)" Name="SwiftBuild_\#(sourceModule.name).resources" />\#n"#
3838
resourcesComponents += #" <ComponentGroup Id="\#(sourceModule.name)Resources" Directory="_usr_share_pm_\#(sourceModule.name)">\#n"#
39-
for resource in resources {
39+
for resource in resources {
4040
resourcesComponents += #"""
41-
<Component>
42-
<File Source="$(ToolchainRoot)\usr\share\pm\SwiftBuild_\#(sourceModule.name).resources\\#(resource.url.lastPathComponent)" />
43-
</Component>
41+
<Component>
42+
<File Source="$(ToolchainRoot)\usr\share\pm\SwiftBuild_\#(sourceModule.name).resources\\#(resource.url.lastPathComponent)" />
43+
</Component>
4444
45-
"""#
45+
"""#
4646
}
4747
resourcesComponents += " </ComponentGroup>\n"
4848
}

Plugins/launch-xcode/launch-xcode.swift

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,37 @@ import Foundation
1717
struct LaunchXcode: CommandPlugin {
1818
func performCommand(context: PluginContext, arguments: [String]) async throws {
1919
#if !os(macOS)
20-
throw LaunchXcodeError.unsupportedPlatform
20+
throw LaunchXcodeError.unsupportedPlatform
2121
#else
22-
var args = ArgumentExtractor(arguments)
23-
var configuration: PackageManager.BuildConfiguration = .debug
24-
// --release
25-
if args.extractFlag(named: "release") > 0 {
26-
configuration = .release
27-
} else {
28-
// --configuration release
29-
let configurationOptions = args.extractOption(named: "configuration")
30-
if configurationOptions.contains("release") {
22+
var args = ArgumentExtractor(arguments)
23+
var configuration: PackageManager.BuildConfiguration = .debug
24+
// --release
25+
if args.extractFlag(named: "release") > 0 {
3126
configuration = .release
27+
} else {
28+
// --configuration release
29+
let configurationOptions = args.extractOption(named: "configuration")
30+
if configurationOptions.contains("release") {
31+
configuration = .release
32+
}
3233
}
33-
}
3434

35-
let buildResult = try packageManager.build(.all(includingTests: false), parameters: .init(configuration: configuration, echoLogs: true))
36-
guard buildResult.succeeded else { return }
37-
guard let buildServiceURL = buildResult.builtArtifacts.map({ $0.url }).filter({ $0.lastPathComponent == "SWBBuildServiceBundle" }).first else {
38-
throw LaunchXcodeError.buildServiceURLNotFound
39-
}
35+
let buildResult = try packageManager.build(.all(includingTests: false), parameters: .init(configuration: configuration, echoLogs: true))
36+
guard buildResult.succeeded else { return }
37+
guard let buildServiceURL = buildResult.builtArtifacts.map({ $0.url }).filter({ $0.lastPathComponent == "SWBBuildServiceBundle" }).first else {
38+
throw LaunchXcodeError.buildServiceURLNotFound
39+
}
4040

41-
print("Launching Xcode...")
42-
let process = Process()
43-
process.executableURL = URL(fileURLWithPath: "/usr/bin/open")
44-
process.arguments = ["-n", "-F", "-W", "--env", "XCBBUILDSERVICE_PATH=\(buildServiceURL.path())", "-b", "com.apple.dt.Xcode"]
45-
process.standardOutput = nil
46-
process.standardError = nil
47-
try await process.run()
48-
if process.terminationStatus != 0 {
49-
throw LaunchXcodeError.launchFailed
50-
}
41+
print("Launching Xcode...")
42+
let process = Process()
43+
process.executableURL = URL(fileURLWithPath: "/usr/bin/open")
44+
process.arguments = ["-n", "-F", "-W", "--env", "XCBBUILDSERVICE_PATH=\(buildServiceURL.path())", "-b", "com.apple.dt.Xcode"]
45+
process.standardOutput = nil
46+
process.standardError = nil
47+
try await process.run()
48+
if process.terminationStatus != 0 {
49+
throw LaunchXcodeError.launchFailed
50+
}
5151
#endif
5252
}
5353
}

0 commit comments

Comments
 (0)