Skip to content

Commit b48ffb6

Browse files
committed
Format repository
1 parent c66f413 commit b48ffb6

File tree

751 files changed

+62889
-47612
lines changed

Some content is hidden

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

751 files changed

+62889
-47612
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: 146 additions & 81 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
@@ -63,7 +63,7 @@ struct CMakeSmokeTest: CommandPlugin {
6363
}
6464

6565
var sharedSwiftFlags = [
66-
"-module-cache-path", moduleCachePath
66+
"-module-cache-path", moduleCachePath,
6767
]
6868

6969
if let sysrootPath {
@@ -75,15 +75,16 @@ struct CMakeSmokeTest: CommandPlugin {
7575
"-DLLBuild_DIR=\(llbuildBuildURL.appending(components: "cmake", "modules").filePath)",
7676
"-DTSC_DIR=\(swiftToolsSupportCoreBuildURL.appending(components: "cmake", "modules").filePath)",
7777
"-DSwiftDriver_DIR=\(swiftDriverBuildURL.appending(components: "cmake", "modules").filePath)",
78-
"-DSwiftSystem_DIR=\(swiftSystemBuildURL.appending(components: "cmake", "modules").filePath)"
78+
"-DSwiftSystem_DIR=\(swiftSystemBuildURL.appending(components: "cmake", "modules").filePath)",
7979
]
8080

81-
let sharedCMakeArgs = [
82-
"-G", "Ninja",
83-
"-DCMAKE_MAKE_PROGRAM=\(ninjaPath)",
84-
"-DCMAKE_BUILD_TYPE:=Debug",
85-
"-DCMAKE_Swift_FLAGS='\(sharedSwiftFlags.joined(separator: " "))'"
86-
] + cMakeProjectArgs + extraCMakeArgs
81+
let sharedCMakeArgs =
82+
[
83+
"-G", "Ninja",
84+
"-DCMAKE_MAKE_PROGRAM=\(ninjaPath)",
85+
"-DCMAKE_BUILD_TYPE:=Debug",
86+
"-DCMAKE_Swift_FLAGS='\(sharedSwiftFlags.joined(separator: " "))'",
87+
] + cMakeProjectArgs + extraCMakeArgs
8788

8889
Diagnostics.progress("Building swift-tools-support-core")
8990
try await Process.checkNonZeroExit(url: cmakeURL, arguments: sharedCMakeArgs + [swiftToolsSupportCoreURL.filePath], workingDirectory: swiftToolsSupportCoreBuildURL)
@@ -159,13 +160,13 @@ enum OS {
159160

160161
static func host() throws -> Self {
161162
#if os(macOS)
162-
return .macOS
163+
return .macOS
163164
#elseif os(Linux)
164-
return .linux
165+
return .linux
165166
#elseif os(Windows)
166-
return .windows
167+
return .windows
167168
#else
168-
throw Errors.unimplementedForHostOS
169+
throw Errors.unimplementedForHostOS
169170
#endif
170171
}
171172
}
@@ -202,100 +203,104 @@ extension Process {
202203
static func checkNonZeroExit(url: URL, arguments: [String], workingDirectory: URL, environment: [String: String]? = nil) async throws {
203204
try Diagnostics.progress("\(url.filePath) \(arguments.joined(separator: " "))")
204205
#if USE_PROCESS_SPAWNING_WORKAROUND && !os(Windows)
205-
Diagnostics.progress("Using process spawning workaround")
206-
// Linux workaround for https://github.com/swiftlang/swift-corelibs-foundation/issues/4772
207-
// Foundation.Process on Linux seems to inherit the Process.run()-calling thread's signal mask, creating processes that even have SIGTERM blocked
208-
// This manifests as CMake getting stuck when invoking 'uname' with incorrectly configured signal handlers.
209-
var fileActions = posix_spawn_file_actions_t()
210-
defer { posix_spawn_file_actions_destroy(&fileActions) }
211-
var attrs: posix_spawnattr_t = posix_spawnattr_t()
212-
defer { posix_spawnattr_destroy(&attrs) }
213-
posix_spawn_file_actions_init(&fileActions)
214-
try posix_spawn_file_actions_addchdir_np(&fileActions, workingDirectory.filePath)
215-
216-
posix_spawnattr_init(&attrs)
217-
posix_spawnattr_setpgroup(&attrs, 0)
218-
var noSignals = sigset_t()
219-
sigemptyset(&noSignals)
220-
posix_spawnattr_setsigmask(&attrs, &noSignals)
221-
222-
var mostSignals = sigset_t()
223-
sigemptyset(&mostSignals)
224-
for i in 1 ..< SIGSYS {
225-
if i == SIGKILL || i == SIGSTOP {
226-
continue
227-
}
228-
sigaddset(&mostSignals, i)
229-
}
230-
posix_spawnattr_setsigdefault(&attrs, &mostSignals)
231-
posix_spawnattr_setflags(&attrs, numericCast(POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK))
232-
var pid: pid_t = -1
233-
try withArrayOfCStrings([url.filePath] + arguments) { arguments in
234-
try withArrayOfCStrings((environment ?? [:]).map { key, value in "\(key)=\(value)" }) { environment in
235-
let spawnResult = try posix_spawn(&pid, url.filePath, /*file_actions=*/&fileActions, /*attrp=*/&attrs, arguments, nil);
236-
var exitCode: Int32 = -1
237-
var result = wait4(pid, &exitCode, 0, nil);
238-
while (result == -1 && errno == EINTR) {
239-
result = wait4(pid, &exitCode, 0, nil)
240-
}
241-
guard result != -1 else {
242-
throw Errors.miscError("wait failed")
206+
Diagnostics.progress("Using process spawning workaround")
207+
// Linux workaround for https://github.com/swiftlang/swift-corelibs-foundation/issues/4772
208+
// Foundation.Process on Linux seems to inherit the Process.run()-calling thread's signal mask, creating processes that even have SIGTERM blocked
209+
// This manifests as CMake getting stuck when invoking 'uname' with incorrectly configured signal handlers.
210+
var fileActions = posix_spawn_file_actions_t()
211+
defer { posix_spawn_file_actions_destroy(&fileActions) }
212+
var attrs: posix_spawnattr_t = posix_spawnattr_t()
213+
defer { posix_spawnattr_destroy(&attrs) }
214+
posix_spawn_file_actions_init(&fileActions)
215+
try posix_spawn_file_actions_addchdir_np(&fileActions, workingDirectory.filePath)
216+
217+
posix_spawnattr_init(&attrs)
218+
posix_spawnattr_setpgroup(&attrs, 0)
219+
var noSignals = sigset_t()
220+
sigemptyset(&noSignals)
221+
posix_spawnattr_setsigmask(&attrs, &noSignals)
222+
223+
var mostSignals = sigset_t()
224+
sigemptyset(&mostSignals)
225+
for i in 1..<SIGSYS {
226+
if i == SIGKILL || i == SIGSTOP {
227+
continue
243228
}
244-
guard exitCode == 0 else {
245-
throw Errors.miscError("exit code nonzero")
229+
sigaddset(&mostSignals, i)
230+
}
231+
posix_spawnattr_setsigdefault(&attrs, &mostSignals)
232+
posix_spawnattr_setflags(&attrs, numericCast(POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK))
233+
var pid: pid_t = -1
234+
try withArrayOfCStrings([url.filePath] + arguments) { arguments in
235+
try withArrayOfCStrings((environment ?? [:]).map { key, value in "\(key)=\(value)" }) { environment in
236+
let spawnResult = try posix_spawn(&pid, url.filePath, /*file_actions=*/ &fileActions, /*attrp=*/ &attrs, arguments, nil);
237+
var exitCode: Int32 = -1
238+
var result = wait4(pid, &exitCode, 0, nil);
239+
while (result == -1 && errno == EINTR) {
240+
result = wait4(pid, &exitCode, 0, nil)
241+
}
242+
guard result != -1 else {
243+
throw Errors.miscError("wait failed")
244+
}
245+
guard exitCode == 0 else {
246+
throw Errors.miscError("exit code nonzero")
247+
}
246248
}
247249
}
248-
}
249250
#else
250-
let process = Process()
251-
process.executableURL = url
252-
process.arguments = arguments
253-
process.currentDirectoryURL = workingDirectory
254-
process.environment = environment
255-
try await process.run()
256-
if process.terminationStatus != 0 {
257-
throw Errors.processError(terminationReason: process.terminationReason, terminationStatus: process.terminationStatus)
258-
}
251+
let process = Process()
252+
process.executableURL = url
253+
process.arguments = arguments
254+
process.currentDirectoryURL = workingDirectory
255+
process.environment = environment
256+
try await process.run()
257+
if process.terminationStatus != 0 {
258+
throw Errors.processError(terminationReason: process.terminationReason, terminationStatus: process.terminationStatus)
259+
}
259260
#endif
260261
}
261262
}
262263

263264
#if USE_PROCESS_SPAWNING_WORKAROUND && !os(Windows)
264-
func scan<S: Sequence, U>(_ seq: S, _ initial: U, _ combine: (U, S.Element) -> U) -> [U] {
265-
var result: [U] = []
266-
result.reserveCapacity(seq.underestimatedCount)
267-
var runningResult = initial
268-
for element in seq {
269-
runningResult = combine(runningResult, element)
270-
result.append(runningResult)
271-
}
272-
return result
273-
}
265+
func scan<S: Sequence, U>(_ seq: S, _ initial: U, _ combine: (U, S.Element) -> U) -> [U] {
266+
var result: [U] = []
267+
result.reserveCapacity(seq.underestimatedCount)
268+
var runningResult = initial
269+
for element in seq {
270+
runningResult = combine(runningResult, element)
271+
result.append(runningResult)
272+
}
273+
return result
274+
}
274275

275-
func withArrayOfCStrings<T>(
276-
_ args: [String],
277-
_ body: (UnsafePointer<UnsafeMutablePointer<Int8>?>) throws -> T
278-
) throws -> T {
279-
let argsCounts = Array(args.map { $0.utf8.count + 1 })
280-
let argsOffsets = [0] + scan(argsCounts, 0, +)
281-
let argsBufferSize = argsOffsets.last!
282-
var argsBuffer: [UInt8] = []
283-
argsBuffer.reserveCapacity(argsBufferSize)
284-
for arg in args {
285-
argsBuffer.append(contentsOf: arg.utf8)
286-
argsBuffer.append(0)
287-
}
288-
return try argsBuffer.withUnsafeMutableBufferPointer {
289-
(argsBuffer) in
290-
let ptr = UnsafeRawPointer(argsBuffer.baseAddress!).bindMemory(
291-
to: Int8.self, capacity: argsBuffer.count)
292-
var cStrings: [UnsafePointer<Int8>?] = argsOffsets.map { ptr + $0 }
293-
cStrings[cStrings.count - 1] = nil
294-
return try cStrings.withUnsafeMutableBufferPointer {
295-
let unsafeString = UnsafeMutableRawPointer($0.baseAddress!).bindMemory(
296-
to: UnsafeMutablePointer<Int8>?.self, capacity: $0.count)
297-
return try body(unsafeString)
276+
func withArrayOfCStrings<T>(
277+
_ args: [String],
278+
_ body: (UnsafePointer<UnsafeMutablePointer<Int8>?>) throws -> T
279+
) throws -> T {
280+
let argsCounts = Array(args.map { $0.utf8.count + 1 })
281+
let argsOffsets = [0] + scan(argsCounts, 0, +)
282+
let argsBufferSize = argsOffsets.last!
283+
var argsBuffer: [UInt8] = []
284+
argsBuffer.reserveCapacity(argsBufferSize)
285+
for arg in args {
286+
argsBuffer.append(contentsOf: arg.utf8)
287+
argsBuffer.append(0)
288+
}
289+
return try argsBuffer.withUnsafeMutableBufferPointer {
290+
(argsBuffer) in
291+
let ptr = UnsafeRawPointer(argsBuffer.baseAddress!).bindMemory(
292+
to: Int8.self,
293+
capacity: argsBuffer.count
294+
)
295+
var cStrings: [UnsafePointer<Int8>?] = argsOffsets.map { ptr + $0 }
296+
cStrings[cStrings.count - 1] = nil
297+
return try cStrings.withUnsafeMutableBufferPointer {
298+
let unsafeString = UnsafeMutableRawPointer($0.baseAddress!).bindMemory(
299+
to: UnsafeMutablePointer<Int8>?.self,
300+
capacity: $0.count
301+
)
302+
return try body(unsafeString)
303+
}
304+
}
298305
}
299-
}
300-
}
301306
#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)