diff --git a/.swift-format b/.swift-format index e345c2e..3b4cc63 100644 --- a/.swift-format +++ b/.swift-format @@ -9,7 +9,7 @@ }, "lineBreakAroundMultilineExpressionChainComponents" : false, "lineBreakBeforeControlFlowKeywords" : false, - "lineBreakBeforeEachArgument" : false, + "lineBreakBeforeEachArgument" : true, "lineBreakBeforeEachGenericRequirement" : false, "lineLength" : 100, "maximumBlankLines" : 1, diff --git a/Sources/AsyncProcess/FileContentStream.swift b/Sources/AsyncProcess/FileContentStream.swift index c0ee126..4999b8f 100644 --- a/Sources/AsyncProcess/FileContentStream.swift +++ b/Sources/AsyncProcess/FileContentStream.swift @@ -256,7 +256,9 @@ private final class ReadIntoAsyncChannelHandler: ChannelDuplexHandler { extension FileHandle { func fileContentStream(eventLoop: EventLoop) throws -> FileContentStream { let asyncBytes = try FileContentStream( - fileDescriptor: self.fileDescriptor, eventLoop: eventLoop) + fileDescriptor: self.fileDescriptor, + eventLoop: eventLoop + ) try self.close() return asyncBytes } @@ -432,7 +434,8 @@ where Base: AsyncSequence, Base.Element == ByteBuffer { } public init( - _ underlying: Base, dropTerminator: Bool, + _ underlying: Base, + dropTerminator: Bool, maximumAllowableBufferSize: Int, dropLastChunkIfNoNewline: Bool ) { diff --git a/Sources/AsyncProcess/ProcessExecutor+Convenience.swift b/Sources/AsyncProcess/ProcessExecutor+Convenience.swift index 00c6607..59e0302 100644 --- a/Sources/AsyncProcess/ProcessExecutor+Convenience.swift +++ b/Sources/AsyncProcess/ProcessExecutor+Convenience.swift @@ -324,7 +324,10 @@ extension ProcessExecutor { } var allInfo = ProcessExitReasonAndOutput( - exitReason: .exit(-1), standardOutput: nil, standardError: nil) + exitReason: .exit(-1), + standardOutput: nil, + standardError: nil + ) while let next = try await group.next() { switch next { case let .exitReason(exitReason): @@ -467,7 +470,8 @@ extension ProcessExecutor { try await self.runCollectingOutput( group: group, executable: executable, - arguments, standardInput: EOFSequence(), + arguments, + standardInput: EOFSequence(), collectStandardOutput: collectStandardOutput, collectStandardError: collectStandardError, perStreamCollectionLimitBytes: perStreamCollectionLimitBytes, diff --git a/Sources/AsyncProcess/ProcessExecutor.swift b/Sources/AsyncProcess/ProcessExecutor.swift index 80429a6..4fe211d 100644 --- a/Sources/AsyncProcess/ProcessExecutor.swift +++ b/Sources/AsyncProcess/ProcessExecutor.swift @@ -159,7 +159,8 @@ public final actor ProcessExecutor { private let _standardOutput: ChunkSequence private let _standardError: ChunkSequence private let processIsRunningApproximation = ManagedAtomic( - RunningStateApproximation.neverStarted.rawValue) + RunningStateApproximation.neverStarted.rawValue + ) private let processOutputConsumptionApproximation = ManagedAtomic(UInt8(0)) private let processPid = ManagedAtomic(pid_t(0)) private let ownsStandardOutputWriteHandle: Bool @@ -568,7 +569,10 @@ public final actor ProcessExecutor { // At this point, the process is running, we should therefore have a process ID (unless we're already dead). let childPid = p.processIdentifier _ = self.processPid.compareExchange( - expected: 0, desired: childPid, ordering: .sequentiallyConsistent) + expected: 0, + desired: childPid, + ordering: .sequentiallyConsistent + ) assert(childPid != 0 || !p.isRunning) self.logger.debug( "running command", diff --git a/Sources/GeneratorCLI/GeneratorCLI.swift b/Sources/GeneratorCLI/GeneratorCLI.swift index 82667af..cef47dc 100644 --- a/Sources/GeneratorCLI/GeneratorCLI.swift +++ b/Sources/GeneratorCLI/GeneratorCLI.swift @@ -71,7 +71,8 @@ struct GeneratorCLI: AsyncParsableCommand { logger.info( "Generator run finished successfully.", - metadata: ["elapsedTime": .string(elapsed.intervalString)]) + metadata: ["elapsedTime": .string(elapsed.intervalString)] + ) } } @@ -167,7 +168,8 @@ extension GeneratorCLI { if let arch = hostArch { let target = Triple(arch: arch, vendor: current.vendor!, os: current.os!) appLogger.warning( - "deprecated: Please use `--host \(target.triple)` instead of `--host-arch \(arch)`") + "deprecated: Please use `--host \(target.triple)` instead of `--host-arch \(arch)`" + ) return target } return current @@ -219,7 +221,8 @@ extension GeneratorCLI { if let arch = generatorOptions.targetArch { let target = Triple(arch: arch, vendor: nil, os: .linux, environment: .gnu) appLogger.warning( - "deprecated: Please use `--target \(target.triple)` instead of `--target-arch \(arch)`") + "deprecated: Please use `--target \(target.triple)` instead of `--target-arch \(arch)`" + ) } return Triple(arch: hostTriple.arch!, vendor: nil, os: .linux, environment: .gnu) } @@ -240,7 +243,9 @@ extension GeneratorCLI { let linuxDistributionVersion = self.linuxDistributionVersion ?? linuxDistributionDefaultVersion let linuxDistribution = try LinuxDistribution( - name: linuxDistributionName, version: linuxDistributionVersion) + name: linuxDistributionName, + version: linuxDistributionVersion + ) let hostTriple = try self.generatorOptions.deriveHostTriple() let targetTriple = self.deriveTargetTriple(hostTriple: hostTriple) @@ -259,7 +264,10 @@ extension GeneratorCLI { logger: loggerWithLevel(from: self.generatorOptions) ) try await GeneratorCLI.run( - recipe: recipe, targetTriple: targetTriple, options: self.generatorOptions) + recipe: recipe, + targetTriple: targetTriple, + options: self.generatorOptions + ) } func isInvokedAsDefaultSubcommand() -> Bool { @@ -316,7 +324,10 @@ extension GeneratorCLI { ) let targetTriple = self.deriveTargetTriple() try await GeneratorCLI.run( - recipe: recipe, targetTriple: targetTriple, options: self.generatorOptions) + recipe: recipe, + targetTriple: targetTriple, + options: self.generatorOptions + ) } } } @@ -327,12 +338,19 @@ extension Duration { let date = Date(timeInterval: TimeInterval(self.components.seconds), since: reference) let components = Calendar.current.dateComponents( - [.hour, .minute, .second], from: reference, to: date) + [.hour, .minute, .second], + from: reference, + to: date + ) if let hours = components.hour, hours > 0 { #if !canImport(Darwin) && compiler(<6.0) return String( - format: "%02d:%02d:%02d", hours, components.minute ?? 0, components.second ?? 0) + format: "%02d:%02d:%02d", + hours, + components.minute ?? 0, + components.second ?? 0 + ) #else return self.formatted() #endif diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift index e1386ac..3942662 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift @@ -136,7 +136,8 @@ extension SwiftSDKGenerator { if isOptional && !doesFileExist(at: fromPath) { logger.debug( "Optional package path ignored since it does not exist", - metadata: ["packagePath": .string(fromPath.string)]) + metadata: ["packagePath": .string(fromPath.string)] + ) continue } diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift index ad84680..0807fe0 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Download.swift @@ -31,7 +31,8 @@ extension FilePath { extension SwiftSDKGenerator { func downloadArtifacts( - _ client: some HTTPClientProtocol, _ engine: QueryEngine, + _ client: some HTTPClientProtocol, + _ engine: QueryEngine, downloadableArtifacts: inout DownloadableArtifacts, itemsToDownload: @Sendable (DownloadableArtifacts) -> [DownloadableArtifacts.Item] ) async throws { @@ -58,7 +59,8 @@ extension SwiftSDKGenerator { for item in itemsToDownload(downloadableArtifacts) { group.addTask { try await engine[ - DownloadArtifactQuery(artifact: item, httpClient: client, logger: self.logger)] + DownloadArtifactQuery(artifact: item, httpClient: client, logger: self.logger) + ] } } @@ -74,7 +76,8 @@ extension SwiftSDKGenerator { "Using downloaded artifacts in these locations.", metadata: [ "paths": .array(results.map(\.path.metadataValue)) - ]) + ] + ) } func downloadUbuntuPackages( @@ -93,7 +96,8 @@ extension SwiftSDKGenerator { """ The `xz` utility was not found in `PATH`. \ Consider installing it for more efficient downloading of package lists. - """) + """ + ) } async let mainPackages = try await client.parseUbuntuPackagesList( @@ -137,7 +141,9 @@ extension SwiftSDKGenerator { } logger.info( - "Downloading Ubuntu packages...", metadata: ["packageCount": .stringConvertible(urls.count)]) + "Downloading Ubuntu packages...", + metadata: ["packageCount": .stringConvertible(urls.count)] + ) try await inTemporaryDirectory { fs, tmpDir in let downloadedFiles = try await self.downloadFiles(from: urls, to: tmpDir, client, engine) await report(downloadedFiles: downloadedFiles) @@ -160,8 +166,11 @@ extension SwiftSDKGenerator { $0.addTask { let downloadedFilePath = try await engine[ DownloadFileQuery( - remoteURL: url, localDirectory: directory, httpClient: client - )] + remoteURL: url, + localDirectory: directory, + httpClient: client + ) + ] let filePath = downloadedFilePath.path guard let fileSize = try FileManager.default.attributesOfItem( @@ -191,7 +200,8 @@ extension SwiftSDKGenerator { metadata: [ "url": .string(url.absoluteString), "size": .string(byteCountFormatter.string(fromByteCount: Int64(bytes))), - ]) + ] + ) } } } diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift index fa95b6b..e5c9cf6 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Entrypoint.swift @@ -51,7 +51,10 @@ extension SwiftSDKGenerator { try await self.createDirectoryIfNeeded(at: pathsConfiguration.artifactsCachePath) let swiftSDKProduct = try await recipe.makeSwiftSDK( - generator: self, engine: engine, httpClient: client) + generator: self, + engine: engine, + httpClient: client + ) let toolsetJSONPath = try await self.generateToolsetJSON(recipe: recipe) diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Fixup.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Fixup.swift index 3161b5e..493db05 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Fixup.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Fixup.swift @@ -58,7 +58,8 @@ extension SwiftSDKGenerator { func symlinkClangHeaders() throws { let swiftStaticClangPath = self.pathsConfiguration.toolchainDirPath.appending( - "usr/lib/swift_static/clang") + "usr/lib/swift_static/clang" + ) if !doesFileExist(at: swiftStaticClangPath) { logger.info("Symlinking clang headers...") try self.createSymlink( diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Metadata.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Metadata.swift index 9a27475..e35ae01 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Metadata.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Metadata.swift @@ -63,7 +63,8 @@ extension SwiftSDKGenerator { """ `toolchainBinDirPath`, `sdkDirPath`, and `toolsetPath` are at unexpected locations that prevent computing \ relative paths - """) + """ + ) } var metadata = SwiftSDKMetadataV4.TripleProperties( diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Unpack.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Unpack.swift index 563936f..f4c953c 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Unpack.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Unpack.swift @@ -103,7 +103,8 @@ extension SwiftSDKGenerator { try await inTemporaryDirectory { fs, tmpDir in try await fs.unpack(file: targetSwiftPackagePath, into: tmpDir) try await fs.copyTargetSwift( - from: tmpDir.appending(relativePathToRoot).appending("usr"), sdkDirPath: sdkDirPath + from: tmpDir.appending(relativePathToRoot).appending("usr"), + sdkDirPath: sdkDirPath ) } } diff --git a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift index 06a9b27..b14b61c 100644 --- a/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift +++ b/Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift @@ -72,7 +72,8 @@ public actor SwiftSDKGenerator { return Triple("\(cpu)-unknown-linux-gnu") #else fatalError( - "Triple detection not implemented for the platform that this generator was built on.") + "Triple detection not implemented for the platform that this generator was built on." + ) #endif } @@ -195,7 +196,8 @@ public actor SwiftSDKGenerator { if isSymlink { let path = url.path try result.append( - (FilePath(path), FilePath(self.fileManager.destinationOfSymbolicLink(atPath: url.path)))) + (FilePath(path), FilePath(self.fileManager.destinationOfSymbolicLink(atPath: url.path))) + ) } } @@ -235,7 +237,9 @@ public actor SwiftSDKGenerator { func gunzip(file: FilePath, into directoryPath: FilePath) async throws { try await Shell.run( - #"cd "\#(directoryPath)" && gzip -d "\#(file)""#, shouldLogCommands: self.isVerbose) + #"cd "\#(directoryPath)" && gzip -d "\#(file)""#, + shouldLogCommands: self.isVerbose + ) } func untar( @@ -264,7 +268,8 @@ public actor SwiftSDKGenerator { let lsOutput = try await Shell.readStdout(cmd) logger.debug( "Files unpacked from deb file", - metadata: ["cmd": .string(cmd), "output": .string(lsOutput)]) + metadata: ["cmd": .string(cmd), "output": .string(lsOutput)] + ) } try await Shell.run( diff --git a/Sources/SwiftSDKGenerator/PlatformModels/LinuxDistribution.swift b/Sources/SwiftSDKGenerator/PlatformModels/LinuxDistribution.swift index 0152478..5385057 100644 --- a/Sources/SwiftSDKGenerator/PlatformModels/LinuxDistribution.swift +++ b/Sources/SwiftSDKGenerator/PlatformModels/LinuxDistribution.swift @@ -35,7 +35,9 @@ public enum LinuxDistribution: Hashable, Sendable { self = .noble default: throw GeneratorError.unknownLinuxDistribution( - name: LinuxDistribution.Name.ubuntu.rawValue, version: version) + name: LinuxDistribution.Name.ubuntu.rawValue, + version: version + ) } } diff --git a/Sources/SwiftSDKGenerator/Queries/DownloadArtifactQuery.swift b/Sources/SwiftSDKGenerator/Queries/DownloadArtifactQuery.swift index e81d2c3..adc8eb5 100644 --- a/Sources/SwiftSDKGenerator/Queries/DownloadArtifactQuery.swift +++ b/Sources/SwiftSDKGenerator/Queries/DownloadArtifactQuery.swift @@ -25,9 +25,11 @@ struct DownloadArtifactQuery: Query { func run(engine: QueryEngine) async throws -> FilePath { logger.info( "Downloading remote artifact not available in local cache", - metadata: ["remoteUrl": .string(self.artifact.remoteURL.absoluteString)]) + metadata: ["remoteUrl": .string(self.artifact.remoteURL.absoluteString)] + ) let stream = self.httpClient.streamDownloadProgress( - from: self.artifact.remoteURL, to: self.artifact.localPath + from: self.artifact.remoteURL, + to: self.artifact.localPath ) .removeDuplicates(by: didProgressChangeSignificantly) ._throttle(for: .seconds(1)) @@ -51,7 +53,8 @@ struct DownloadArtifactQuery: Query { byteCountFormatter .string(fromByteCount: Int64(total)) ) - """) + """ + ) } else { logger.debug( "\(artifact.remoteURL.lastPathComponent) \(byteCountFormatter.string(fromByteCount: Int64(progress.receivedBytes)))" diff --git a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift index 7d58357..923462d 100644 --- a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift +++ b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift @@ -225,7 +225,8 @@ public struct LinuxRecipe: SwiftSDKRecipe { ) async throws -> SwiftSDKProduct { if self.linuxDistribution.name == .rhel && self.mainTargetTriple.archName == "armv7" { throw GeneratorError.distributionDoesNotSupportArchitecture( - self.linuxDistribution, targetArchName: self.mainTargetTriple.archName + self.linuxDistribution, + targetArchName: self.mainTargetTriple.archName ) } @@ -268,7 +269,8 @@ public struct LinuxRecipe: SwiftSDKRecipe { switch self.hostSwiftSource { case let .localPackage(filePath): try await generator.rsync( - from: filePath.appending("usr"), to: generator.pathsConfiguration.toolchainDirPath + from: filePath.appending("usr"), + to: generator.pathsConfiguration.toolchainDirPath ) case .remoteTarball: try await generator.unpackHostSwift( @@ -287,7 +289,8 @@ public struct LinuxRecipe: SwiftSDKRecipe { ) case let .localPackage(filePath): try await generator.copyTargetSwift( - from: filePath.appending("usr"), sdkDirPath: sdkDirPath + from: filePath.appending("usr"), + sdkDirPath: sdkDirPath ) case .remoteTarball: try await generator.unpackTargetSwiftPackage( @@ -314,7 +317,9 @@ public struct LinuxRecipe: SwiftSDKRecipe { // so they don't need this file. if self.versionsConfiguration.swiftVersion.hasAnyPrefix(from: ["5.9", "5.10", "6.0"]) { try await generator.generateSDKSettingsFile( - sdkDirPath: sdkDirPath, distribution: linuxDistribution) + sdkDirPath: sdkDirPath, + distribution: linuxDistribution + ) } if self.hostSwiftSource != .preinstalled { @@ -329,7 +334,8 @@ public struct LinuxRecipe: SwiftSDKRecipe { } let autolinkExtractPath = generator.pathsConfiguration.toolchainBinDirPath.appending( - "swift-autolink-extract") + "swift-autolink-extract" + ) if await !generator.doesFileExist(at: autolinkExtractPath) { logger.info("Fixing `swift-autolink-extract` symlink...") diff --git a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/SwiftSDKRecipe.swift b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/SwiftSDKRecipe.swift index c10f008..5161519 100644 --- a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/SwiftSDKRecipe.swift +++ b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/SwiftSDKRecipe.swift @@ -25,7 +25,8 @@ public struct SwiftSDKProduct { public protocol SwiftSDKRecipe: Sendable { /// Update the given toolset with platform specific options func applyPlatformOptions( - toolset: inout Toolset, targetTriple: Triple + toolset: inout Toolset, + targetTriple: Triple ) func applyPlatformOptions( metadata: inout SwiftSDKMetadataV4.TripleProperties, @@ -41,7 +42,9 @@ public protocol SwiftSDKRecipe: Sendable { /// The main entrypoint of the recipe to make a Swift SDK func makeSwiftSDK( - generator: SwiftSDKGenerator, engine: QueryEngine, httpClient: some HTTPClientProtocol + generator: SwiftSDKGenerator, + engine: QueryEngine, + httpClient: some HTTPClientProtocol ) async throws -> SwiftSDKProduct } diff --git a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift index dc3cb58..ca2b598 100644 --- a/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift +++ b/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift @@ -63,7 +63,8 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe { toolset.swiftCompiler?.extraCLIOptions?.append( contentsOf: ccOptions.flatMap { ["-Xcc", $0] - }) + } + ) // Tell the C and C++ compilers to enable those features toolset.cCompiler = Toolset.ToolProperties(extraCLIOptions: ccOptions) toolset.cxxCompiler = Toolset.ToolProperties(extraCLIOptions: ccOptions) @@ -89,7 +90,8 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe { var relativeToolchainDir = paths.toolchainDirPath guard relativeToolchainDir.removePrefix(paths.swiftSDKRootPath) else { fatalError( - "The toolchain bin directory path must be a subdirectory of the Swift SDK root path.") + "The toolchain bin directory path must be a subdirectory of the Swift SDK root path." + ) } metadata.swiftStaticResourcesPath = relativeToolchainDir.appending("usr/lib/swift_static").string @@ -109,7 +111,9 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe { if let hostSwiftPackage { hostTriples = [hostSwiftPackage.triple] try await generator.rsync( - from: hostSwiftPackage.path.appending("usr"), to: pathsConfiguration.toolchainDirPath) + from: hostSwiftPackage.path.appending("usr"), + to: pathsConfiguration.toolchainDirPath + ) logger.info("Removing unused toolchain components...") let liblldbNames: [String] = try await { @@ -133,18 +137,23 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe { } else { // Simply copy the target Swift package into the SDK bundle when building host-agnostic SDK. try await generator.createDirectoryIfNeeded( - at: pathsConfiguration.toolchainDirPath.appending("usr")) + at: pathsConfiguration.toolchainDirPath.appending("usr") + ) try await generator.copy( - from: targetSwiftLibPath, to: pathsConfiguration.toolchainDirPath.appending("usr/lib")) + from: targetSwiftLibPath, + to: pathsConfiguration.toolchainDirPath.appending("usr/lib") + ) } let autolinkExtractPath = generator.pathsConfiguration.toolchainBinDirPath.appending( - "swift-autolink-extract") + "swift-autolink-extract" + ) // WebAssembly object file requires `swift-autolink-extract` if await !generator.doesFileExist(at: autolinkExtractPath), await generator.doesFileExist( - at: generator.pathsConfiguration.toolchainBinDirPath.appending("swift")) + at: generator.pathsConfiguration.toolchainBinDirPath.appending("swift") + ) { logger.info("Fixing `swift-autolink-extract` symlink...") try await generator.createSymlink(at: autolinkExtractPath, pointingTo: "swift") @@ -191,7 +200,9 @@ public struct WebAssemblyRecipe: SwiftSDKRecipe { continue } try await generator.rsync( - from: distributionPath.appending(pathWithinPackage), to: pathWithinSwiftSDK) + from: distributionPath.appending(pathWithinPackage), + to: pathWithinSwiftSDK + ) } } } diff --git a/Sources/SwiftSDKGenerator/SystemUtils/ByteBuffer+Utils.swift b/Sources/SwiftSDKGenerator/SystemUtils/ByteBuffer+Utils.swift index 7dca815..3f440e4 100644 --- a/Sources/SwiftSDKGenerator/SystemUtils/ByteBuffer+Utils.swift +++ b/Sources/SwiftSDKGenerator/SystemUtils/ByteBuffer+Utils.swift @@ -17,7 +17,8 @@ import NIOCore extension ByteBuffer { public func unzip(zipPath: String, isVerbose: Bool) async throws -> ByteBuffer? { let result = try await ProcessExecutor.runCollectingOutput( - executable: zipPath, ["-cd"], + executable: zipPath, + ["-cd"], standardInput: [self].async, collectStandardOutput: true, collectStandardError: false, diff --git a/Sources/SwiftSDKGenerator/SystemUtils/HTTPClient+Download.swift b/Sources/SwiftSDKGenerator/SystemUtils/HTTPClient+Download.swift index b11d02e..a693d5d 100644 --- a/Sources/SwiftSDKGenerator/SystemUtils/HTTPClient+Download.swift +++ b/Sources/SwiftSDKGenerator/SystemUtils/HTTPClient+Download.swift @@ -26,7 +26,8 @@ public protocol HTTPClientProtocol: Sendable { /// NOTE: The client will be shutdown after the operation completes, so it /// should not be stored or used outside of the operation. static func with( - http1Only: Bool, _ body: @Sendable (any HTTPClientProtocol) async throws -> Result + http1Only: Bool, + _ body: @Sendable (any HTTPClientProtocol) async throws -> Result ) async throws -> Result /// Download a file from the given URL to the given path. @@ -71,10 +72,12 @@ extension FilePath: @unchecked Sendable {} extension HTTPClient: HTTPClientProtocol { public static func with( - http1Only: Bool, _ body: @Sendable (any HTTPClientProtocol) async throws -> Result + http1Only: Bool, + _ body: @Sendable (any HTTPClientProtocol) async throws -> Result ) async throws -> Result { var configuration = HTTPClient.Configuration( - redirectConfiguration: .follow(max: 5, allowCycles: false)) + redirectConfiguration: .follow(max: 5, allowCycles: false) + ) if http1Only { configuration.httpVersion = .http1Only } @@ -111,7 +114,8 @@ extension FilePath: @unchecked Sendable {} reportHead: { task, responseHead in if responseHead.status != .ok { task.fail( - reason: GeneratorError.fileDownloadFailed(url, responseHead.status.description)) + reason: GeneratorError.fileDownloadFailed(url, responseHead.status.description) + ) } } ) @@ -160,7 +164,9 @@ extension FilePath: @unchecked Sendable {} case let .success(finalProgress): continuation.yield( DownloadProgress( - totalBytes: finalProgress.totalBytes, receivedBytes: finalProgress.receivedBytes) + totalBytes: finalProgress.totalBytes, + receivedBytes: finalProgress.receivedBytes + ) ) continuation.finish() } @@ -175,7 +181,8 @@ extension FilePath: @unchecked Sendable {} struct OfflineHTTPClient: HTTPClientProtocol { static func with( - http1Only: Bool, _ body: @Sendable (any HTTPClientProtocol) async throws -> Result + http1Only: Bool, + _ body: @Sendable (any HTTPClientProtocol) async throws -> Result ) async throws -> Result { let client = OfflineHTTPClient() return try await body(client) @@ -200,11 +207,15 @@ struct OfflineHTTPClient: HTTPClientProtocol { status: NIOHTTP1.HTTPResponseStatus, body: NIOCore.ByteBuffer? ) { throw FileOperationError.downloadFailed( - URL(string: url)!, "Cannot fetch file with offline client") + URL(string: url)!, + "Cannot fetch file with offline client" + ) } public func head(url: String, headers: NIOHTTP1.HTTPHeaders) async throws -> Bool { throw FileOperationError.downloadFailed( - URL(string: url)!, "Cannot fetch file with offline client") + URL(string: url)!, + "Cannot fetch file with offline client" + ) } } diff --git a/Sources/SwiftSDKGenerator/SystemUtils/which.swift b/Sources/SwiftSDKGenerator/SystemUtils/which.swift index 040a746..c856b46 100644 --- a/Sources/SwiftSDKGenerator/SystemUtils/which.swift +++ b/Sources/SwiftSDKGenerator/SystemUtils/which.swift @@ -20,7 +20,9 @@ import Foundation /// - Returns: The path to the executable if found, otherwise nil. func which(_ executableName: String) async throws -> String? { let result = try await ProcessExecutor.runCollectingOutput( - executable: "/usr/bin/which", [executableName], collectStandardOutput: true, + executable: "/usr/bin/which", + [executableName], + collectStandardOutput: true, collectStandardError: false, environment: ProcessInfo.processInfo.environment ) diff --git a/Tests/AsyncProcessTests/AsyncByteBufferLineSequenceTests.swift b/Tests/AsyncProcessTests/AsyncByteBufferLineSequenceTests.swift index 4f56cf0..d2d693e 100644 --- a/Tests/AsyncProcessTests/AsyncByteBufferLineSequenceTests.swift +++ b/Tests/AsyncProcessTests/AsyncByteBufferLineSequenceTests.swift @@ -44,7 +44,8 @@ final class AsyncByteBufferLineSequenceTests: XCTestCase { for n in 0..<100 { let inputs: [ByteBuffer] = [ByteBuffer(repeating: 0, count: n)] let lines = try await Array( - inputs.async.splitIntoLines(dropLastChunkIfNoNewline: true).strings) + inputs.async.splitIntoLines(dropLastChunkIfNoNewline: true).strings + ) XCTAssertEqual([], lines) } } diff --git a/Tests/AsyncProcessTests/IntegrationTests.swift b/Tests/AsyncProcessTests/IntegrationTests.swift index 50d3c8a..922e37a 100644 --- a/Tests/AsyncProcessTests/IntegrationTests.swift +++ b/Tests/AsyncProcessTests/IntegrationTests.swift @@ -31,7 +31,8 @@ final class IntegrationTests: XCTestCase { func testTheBasicsWork() async throws { let exe = ProcessExecutor( group: self.group, - executable: "/bin/sh", ["-c", "exit 0"], + executable: "/bin/sh", + ["-c", "exit 0"], standardInput: EOFSequence(), logger: self.logger ) @@ -50,7 +51,8 @@ final class IntegrationTests: XCTestCase { for exitCode in UInt8.min...UInt8.max { let exe = ProcessExecutor( group: self.group, - executable: "/bin/sh", ["-c", "exit \(exitCode)"], + executable: "/bin/sh", + ["-c", "exit \(exitCode)"], standardInput: EOFSequence(), logger: self.logger ) @@ -77,7 +79,8 @@ final class IntegrationTests: XCTestCase { for signal in signalsToTest { let exe = ProcessExecutor( group: self.group, - executable: "/bin/sh", ["-c", "kill -\(signal) $$"], + executable: "/bin/sh", + ["-c", "kill -\(signal) $$"], standardInput: EOFSequence(), logger: self.logger ) @@ -99,7 +102,8 @@ final class IntegrationTests: XCTestCase { let input = AsyncStream.justMakeIt(elementType: ByteBuffer.self) let exe = ProcessExecutor( group: self.group, - executable: "/bin/cat", ["-nu"], // sh", ["-c", "while read -r line; do echo $line; done"], + executable: "/bin/cat", + ["-nu"], // sh", ["-c", "while read -r line; do echo $line; done"], standardInput: input.consumer, logger: self.logger ) @@ -209,7 +213,8 @@ final class IntegrationTests: XCTestCase { let input = AsyncStream.justMakeIt(elementType: ByteBuffer.self) let exe = ProcessExecutor( group: self.group, - executable: "/bin/sh", [], + executable: "/bin/sh", + [], standardInput: input.consumer, logger: self.logger ) @@ -531,7 +536,9 @@ final class IntegrationTests: XCTestCase { standardInput: EOFSequence(), logger: recordedLogger, logConfiguration: OutputLoggingSettings( - logLevel: .critical, to: .metadata(logMessage: "msg", key: "key")) + logLevel: .critical, + to: .metadata(logMessage: "msg", key: "key") + ) ).throwIfNonZero() XCTAssert(sharedRecorder.recordedMessages.allSatisfy { $0.level == .critical }) XCTAssert(sharedRecorder.recordedMessages.allSatisfy { $0.message == "msg" }) @@ -611,7 +618,8 @@ final class IntegrationTests: XCTestCase { func testBasicRunMethodWorks() async throws { try await ProcessExecutor.run( group: self.group, - executable: "/bin/dd", ["if=/dev/zero", "bs=\(1024 * 1024)", "count=100"], + executable: "/bin/dd", + ["if=/dev/zero", "bs=\(1024 * 1024)", "count=100"], standardInput: EOFSequence(), logger: self.logger ).throwIfNonZero() @@ -620,7 +628,8 @@ final class IntegrationTests: XCTestCase { func testCollectJustStandardOutput() async throws { let allInfo = try await ProcessExecutor.runCollectingOutput( group: self.group, - executable: "/bin/dd", ["if=/dev/zero", "bs=\(1024 * 1024)", "count=1"], + executable: "/bin/dd", + ["if=/dev/zero", "bs=\(1024 * 1024)", "count=1"], standardInput: EOFSequence(), collectStandardOutput: true, collectStandardError: false, @@ -690,7 +699,8 @@ final class IntegrationTests: XCTestCase { do { let result = try await ProcessExecutor.runCollectingOutput( group: self.group, - executable: "/bin/dd", ["if=/dev/zero", "bs=\(1024 * 1024)", "count=1"], + executable: "/bin/dd", + ["if=/dev/zero", "bs=\(1024 * 1024)", "count=1"], standardInput: EOFSequence(), collectStandardOutput: true, collectStandardError: false, @@ -769,7 +779,8 @@ final class IntegrationTests: XCTestCase { func testAPIsWithoutELGOrLoggerArguments() async throws { let exe = ProcessExecutor( - executable: "/bin/sh", ["-c", "true"], + executable: "/bin/sh", + ["-c", "true"], standardInput: EOFSequence(), standardOutput: .discard, standardError: .discard @@ -777,7 +788,8 @@ final class IntegrationTests: XCTestCase { try await exe.run().throwIfNonZero() try await ProcessExecutor.run( - executable: "/bin/sh", ["-c", "true"], + executable: "/bin/sh", + ["-c", "true"], standardInput: EOFSequence() ).throwIfNonZero() @@ -807,7 +819,8 @@ final class IntegrationTests: XCTestCase { func testAPIsWithoutELGStandardInputOrLoggerArguments() async throws { let exe = ProcessExecutor( - executable: "/bin/sh", ["-c", "true"], + executable: "/bin/sh", + ["-c", "true"], standardOutput: .discard, standardError: .discard ) @@ -965,7 +978,8 @@ final class IntegrationTests: XCTestCase { ) { group in group.addTask { [logger = self.logger!] in try await ProcessExecutor.run( - executable: "/bin/sleep", ["100000"], + executable: "/bin/sleep", + ["100000"], logger: logger ) } diff --git a/Tests/GeneratorEngineTests/EngineTests.swift b/Tests/GeneratorEngineTests/EngineTests.swift index 5a3a95d..c3851e7 100644 --- a/Tests/GeneratorEngineTests/EngineTests.swift +++ b/Tests/GeneratorEngineTests/EngineTests.swift @@ -24,7 +24,9 @@ private let decoder = JSONDecoder() extension AsyncFileSystem { fileprivate func read( - _ path: FilePath, bufferLimit: Int = 10 * 1024 * 1024, as: V.Type + _ path: FilePath, + bufferLimit: Int = 10 * 1024 * 1024, + as: V.Type ) async throws -> V { let data = try await self.withOpenReadableFile(path) { var data = Data() diff --git a/Tests/SwiftSDKGeneratorTests/EndToEndTests.swift b/Tests/SwiftSDKGeneratorTests/EndToEndTests.swift index b067fd7..de885b6 100644 --- a/Tests/SwiftSDKGeneratorTests/EndToEndTests.swift +++ b/Tests/SwiftSDKGeneratorTests/EndToEndTests.swift @@ -19,7 +19,9 @@ import XCTest extension FileManager { func withTemporaryDirectory( - logger: Logger, cleanup: Bool = true, body: (URL) async throws -> T + logger: Logger, + cleanup: Bool = true, + body: (URL) async throws -> T ) async throws -> T { // Create a temporary directory using a UUID. Throws if the directory already exists. // The docs suggest using FileManager.url(for: .itemReplacementDirectory, ...) to create a temporary directory, @@ -74,7 +76,8 @@ func buildSDK(_ logger: Logger, scratchPath: String, withArguments runArguments: let installCommand = try XCTUnwrap( generatorOutput.split(separator: "\n").first { $0.contains("swift experimental-sdk install") - }) + } + ) let bundleName = try XCTUnwrap( FilePath(String(XCTUnwrap(installCommand.split(separator: " ").last))).components.last @@ -83,7 +86,8 @@ func buildSDK(_ logger: Logger, scratchPath: String, withArguments runArguments: logger.info("Checking installed Swift SDKs") let installedSDKs = try await Shell.readStdout("swift experimental-sdk list").components( - separatedBy: "\n") + separatedBy: "\n" + ) // Make sure this bundle hasn't been installed already. if installedSDKs.contains(bundleName) { @@ -136,10 +140,12 @@ final class RepeatedBuildTests: XCTestCase { do { try await Shell.run("docker ps") possibleArguments.append( - "--with-docker --linux-distribution-name rhel --linux-distribution-version ubi9") + "--with-docker --linux-distribution-name rhel --linux-distribution-version ubi9" + ) } catch { self.logger.warning( - "Docker CLI does not seem to be working, skipping tests that involve Docker.") + "Docker CLI does not seem to be working, skipping tests that involve Docker." + ) } for runArguments in possibleArguments { @@ -235,7 +241,9 @@ func buildTestcase(_ logger: Logger, testcase: String, bundleName: String, tempD let testPackageURL = tempDir.appendingPathComponent("swift-sdk-generator-test") let testPackageDir = FilePath(testPackageURL.path) try FileManager.default.createDirectory( - atPath: testPackageDir.string, withIntermediateDirectories: true) + atPath: testPackageDir.string, + withIntermediateDirectories: true + ) logger.info("Creating test project \(testPackageDir)") try await Shell.run("swift package --package-path \(testPackageDir) init --type executable") @@ -277,7 +285,8 @@ func buildTestcase(_ logger: Logger, testcase: String, bundleName: String, tempD logger.info("Test project built successfully") logger.info( - "Building test project in 6.0-\(containerVersion) container with static-swift-stdlib") + "Building test project in 6.0-\(containerVersion) container with static-swift-stdlib" + ) buildOutput = try await Shell.readStdout( """ docker run --rm -v \(testPackageDir):/src \ @@ -330,7 +339,10 @@ func buildTestcases(config: SDKConfiguration) async throws { let bundleName = try await FileManager.default.withTemporaryDirectory(logger: logger) { tempDir in try await buildSDK( - logger, scratchPath: tempDir.path, withArguments: config.sdkGeneratorArguments) + logger, + scratchPath: tempDir.path, + withArguments: config.sdkGeneratorArguments + ) } logger.info("Built Swift SDK") @@ -345,7 +357,10 @@ func buildTestcases(config: SDKConfiguration) async throws { do { try await FileManager.default.withTemporaryDirectory(logger: logger) { tempDir in try await buildTestcase( - logger, testcase: testcase, bundleName: bundleName, tempDir: tempDir + logger, + testcase: testcase, + bundleName: bundleName, + tempDir: tempDir ) } } catch { @@ -469,13 +484,15 @@ final class Swift59_RHELEndToEndTests: XCTestCase { func testAmazonLinux2Aarch64FromContainer() async throws { try skipSlow() try await buildTestcases( - config: config.withArchitecture("aarch64").withContainerImageSuffix("amazonlinux2")) + config: config.withArchitecture("aarch64").withContainerImageSuffix("amazonlinux2") + ) } func testAmazonLinux2X86_64FromContainer() async throws { try skipSlow() try await buildTestcases( - config: config.withArchitecture("x86_64").withContainerImageSuffix("amazonlinux2")) + config: config.withArchitecture("x86_64").withContainerImageSuffix("amazonlinux2") + ) } } @@ -501,25 +518,29 @@ final class Swift510_RHELEndToEndTests: XCTestCase { func testAmazonLinux2Aarch64FromContainer() async throws { try skipSlow() try await buildTestcases( - config: config.withArchitecture("aarch64").withContainerImageSuffix("amazonlinux2")) + config: config.withArchitecture("aarch64").withContainerImageSuffix("amazonlinux2") + ) } func testAmazonLinux2X86_64FromContainer() async throws { try skipSlow() try await buildTestcases( - config: config.withArchitecture("x86_64").withContainerImageSuffix("amazonlinux2")) + config: config.withArchitecture("x86_64").withContainerImageSuffix("amazonlinux2") + ) } func testFedora39Aarch64FromContainer() async throws { try skipSlow() try await buildTestcases( - config: config.withArchitecture("aarch64").withContainerImageSuffix("fedora39")) + config: config.withArchitecture("aarch64").withContainerImageSuffix("fedora39") + ) } func testFedora39X86_64FromContainer() async throws { try skipSlow() try await buildTestcases( - config: config.withArchitecture("x86_64").withContainerImageSuffix("fedora39")) + config: config.withArchitecture("x86_64").withContainerImageSuffix("fedora39") + ) } } @@ -545,24 +566,28 @@ final class Swift60_RHELEndToEndTests: XCTestCase { func testAmazonLinux2Aarch64FromContainer() async throws { try skipSlow() try await buildTestcases( - config: config.withArchitecture("aarch64").withContainerImageSuffix("amazonlinux2")) + config: config.withArchitecture("aarch64").withContainerImageSuffix("amazonlinux2") + ) } func testAmazonLinux2X86_64FromContainer() async throws { try skipSlow() try await buildTestcases( - config: config.withArchitecture("x86_64").withContainerImageSuffix("amazonlinux2")) + config: config.withArchitecture("x86_64").withContainerImageSuffix("amazonlinux2") + ) } func testFedora39Aarch64FromContainer() async throws { try skipSlow() try await buildTestcases( - config: config.withArchitecture("aarch64").withContainerImageSuffix("fedora39")) + config: config.withArchitecture("aarch64").withContainerImageSuffix("fedora39") + ) } func testFedora39X86_64FromContainer() async throws { try skipSlow() try await buildTestcases( - config: config.withArchitecture("x86_64").withContainerImageSuffix("fedora39")) + config: config.withArchitecture("x86_64").withContainerImageSuffix("fedora39") + ) } } diff --git a/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/LinuxRecipeTests.swift b/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/LinuxRecipeTests.swift index 656600e..01bef70 100644 --- a/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/LinuxRecipeTests.swift +++ b/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/LinuxRecipeTests.swift @@ -32,8 +32,10 @@ final class LinuxRecipeTests: XCTestCase { hostTriple: hostTriple, linuxDistribution: .init(name: .ubuntu, version: "22.04"), swiftVersion: swiftVersion, - swiftBranch: nil, lldVersion: "", - withDocker: withDocker, fromContainerImage: fromContainerImage, + swiftBranch: nil, + lldVersion: "", + withDocker: withDocker, + fromContainerImage: fromContainerImage, hostSwiftPackagePath: hostSwiftPackagePath, targetSwiftPackagePath: targetSwiftPackagePath, includeHostToolchain: includeHostToolchain, @@ -77,7 +79,8 @@ final class LinuxRecipeTests: XCTestCase { let recipe = try self.createRecipe(swiftVersion: testCase.swiftVersion) var toolset = Toolset(rootPath: nil) recipe.applyPlatformOptions( - toolset: &toolset, targetTriple: testCase.targetTriple + toolset: &toolset, + targetTriple: testCase.targetTriple ) XCTAssertEqual(toolset.swiftCompiler?.extraCLIOptions, testCase.expectedSwiftCompilerOptions) XCTAssertEqual(toolset.linker?.path, testCase.expectedLinkerPath) @@ -90,7 +93,8 @@ final class LinuxRecipeTests: XCTestCase { let recipe = try self.createRecipe(includeHostToolchain: false) var toolset = Toolset(rootPath: "swift.xctoolchain") recipe.applyPlatformOptions( - toolset: &toolset, targetTriple: Triple("x86_64-unknown-linux-gnu") + toolset: &toolset, + targetTriple: Triple("x86_64-unknown-linux-gnu") ) XCTAssertEqual(toolset.rootPath, nil) XCTAssertEqual( @@ -98,14 +102,18 @@ final class LinuxRecipeTests: XCTestCase { [ "-Xlinker", "-R/usr/lib/swift/linux/", "-use-ld=lld", - ]) + ] + ) XCTAssertEqual(toolset.cxxCompiler?.extraCLIOptions, ["-lstdc++"]) XCTAssertEqual(toolset.librarian?.path, "llvm-ar") XCTAssert(toolset.linker == nil) } func runItemsToDownloadTestCase( - recipe: LinuxRecipe, includesHostLLVM: Bool, includesTargetSwift: Bool, includesHostSwift: Bool + recipe: LinuxRecipe, + includesHostLLVM: Bool, + includesTargetSwift: Bool, + includesHostSwift: Bool ) throws { let pathsConfiguration = PathsConfiguration( sourceRoot: ".", @@ -159,7 +167,10 @@ final class LinuxRecipeTests: XCTestCase { ( // Remote target tarball with preinstalled toolchain recipe: try createRecipe( - hostTriple: hostTriple, swiftVersion: "5.9", includeHostToolchain: false), + hostTriple: hostTriple, + swiftVersion: "5.9", + includeHostToolchain: false + ), includesHostLLVM: false, includesTargetSwift: true, includesHostSwift: false @@ -218,7 +229,10 @@ final class LinuxRecipeTests: XCTestCase { ( // Remote target tarball with preinstalled toolchain recipe: try createRecipe( - hostTriple: hostTriple, swiftVersion: "5.9", includeHostToolchain: false), + hostTriple: hostTriple, + swiftVersion: "5.9", + includeHostToolchain: false + ), includesTargetSwift: true, includesHostSwift: false ), diff --git a/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/WebAssemblyRecipe.swift b/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/WebAssemblyRecipe.swift index 080a13b..228f4f5 100644 --- a/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/WebAssemblyRecipe.swift +++ b/Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/WebAssemblyRecipe.swift @@ -32,7 +32,8 @@ final class WebAssemblyRecipeTests: XCTestCase { let recipe = self.createRecipe() var toolset = Toolset(rootPath: nil) recipe.applyPlatformOptions( - toolset: &toolset, targetTriple: Triple("wasm32-unknown-wasi") + toolset: &toolset, + targetTriple: Triple("wasm32-unknown-wasi") ) XCTAssertEqual(toolset.swiftCompiler?.extraCLIOptions, ["-static-stdlib"]) XCTAssertNil(toolset.cCompiler) @@ -44,7 +45,8 @@ final class WebAssemblyRecipeTests: XCTestCase { let recipe = self.createRecipe() var toolset = Toolset(rootPath: nil) recipe.applyPlatformOptions( - toolset: &toolset, targetTriple: Triple("wasm32-unknown-wasip1-threads") + toolset: &toolset, + targetTriple: Triple("wasm32-unknown-wasip1-threads") ) XCTAssertEqual( toolset.swiftCompiler?.extraCLIOptions, @@ -69,6 +71,7 @@ final class WebAssemblyRecipeTests: XCTestCase { toolset.linker?.extraCLIOptions, [ "--import-memory", "--export-memory", "--shared-memory", "--max-memory=1073741824", - ]) + ] + ) } }