Skip to content

Update .swift-format rules #205

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

Merged
merged 2 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 100,
"maximumBlankLines" : 1,
Expand Down
7 changes: 5 additions & 2 deletions Sources/AsyncProcess/FileContentStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -432,7 +434,8 @@ where Base: AsyncSequence, Base.Element == ByteBuffer {
}

public init(
_ underlying: Base, dropTerminator: Bool,
_ underlying: Base,
dropTerminator: Bool,
maximumAllowableBufferSize: Int,
dropLastChunkIfNoNewline: Bool
) {
Expand Down
8 changes: 6 additions & 2 deletions Sources/AsyncProcess/ProcessExecutor+Convenience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions Sources/AsyncProcess/ProcessExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
34 changes: 26 additions & 8 deletions Sources/GeneratorCLI/GeneratorCLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ struct GeneratorCLI: AsyncParsableCommand {

logger.info(
"Generator run finished successfully.",
metadata: ["elapsedTime": .string(elapsed.intervalString)])
metadata: ["elapsedTime": .string(elapsed.intervalString)]
)
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)

Expand All @@ -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 {
Expand Down Expand Up @@ -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
)
}
}
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
]
}
}

Expand All @@ -74,7 +76,8 @@ extension SwiftSDKGenerator {
"Using downloaded artifacts in these locations.",
metadata: [
"paths": .array(results.map(\.path.metadataValue))
])
]
)
}

func downloadUbuntuPackages(
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -191,7 +200,8 @@ extension SwiftSDKGenerator {
metadata: [
"url": .string(url.absoluteString),
"size": .string(byteCountFormatter.string(fromByteCount: Int64(bytes))),
])
]
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ extension SwiftSDKGenerator {
"""
`toolchainBinDirPath`, `sdkDirPath`, and `toolsetPath` are at unexpected locations that prevent computing \
relative paths
""")
"""
)
}

var metadata = SwiftSDKMetadataV4.TripleProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Expand Down
13 changes: 9 additions & 4 deletions Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)))
)
}
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -51,7 +53,8 @@ struct DownloadArtifactQuery: Query {
byteCountFormatter
.string(fromByteCount: Int64(total))
)
""")
"""
)
} else {
logger.debug(
"\(artifact.remoteURL.lastPathComponent) \(byteCountFormatter.string(fromByteCount: Int64(progress.receivedBytes)))"
Expand Down
Loading