Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
dd1d29c
Use Subprocess for process management
cmcgee1024 Aug 13, 2025
ae3f8fc
Add awaits to Linux platform and reformat
cmcgee1024 Aug 13, 2025
a3f187f
Remove tcsetgrp code because child processes run in the parent proces…
cmcgee1024 Aug 14, 2025
9587560
Use the common standard input in case someone wants to run interactiv…
cmcgee1024 Aug 14, 2025
1051196
Split out process handling from the core Platform functions
cmcgee1024 Aug 14, 2025
97a23f0
Cleanup imports
cmcgee1024 Aug 14, 2025
9579809
Merge branch 'main' of https://github.com/swiftlang/swiftly into adop…
cmcgee1024 Oct 28, 2025
7e553fa
Fix compile errors with the new Subprocess version
cmcgee1024 Oct 28, 2025
23a63df
Disable problematic traits
cmcgee1024 Oct 28, 2025
88c3fa9
Merge branch 'main' of https://github.com/swiftlang/swiftly into adop…
cmcgee1024 Oct 28, 2025
27ea36b
Remove Platform.run methods in favour of more direct Subprocess usages
cmcgee1024 Oct 31, 2025
48c1b25
Rigorously check statuses and echo commands in build swiftly release …
cmcgee1024 Oct 31, 2025
a0829bf
Merge branch 'main' of https://github.com/swiftlang/swiftly into adop…
cmcgee1024 Oct 31, 2025
2c4b130
Make the command echo less verbose
cmcgee1024 Oct 31, 2025
fc7beea
Remove unnecessary duplicate imports of System and SystemPackage
cmcgee1024 Oct 31, 2025
7186f09
Remove unnecessary system imports for MacOS and redundant qualificati…
cmcgee1024 Oct 31, 2025
3ed18b6
Rework output methods to allow quiet and async sequence variants
cmcgee1024 Nov 1, 2025
2e9f202
Short fixes
cmcgee1024 Nov 1, 2025
4d7afee
Fix compile error
cmcgee1024 Nov 1, 2025
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
85 changes: 56 additions & 29 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:6.0
// swift-tools-version:6.2

import PackageDescription

Expand Down Expand Up @@ -31,6 +31,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.7.2"),
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.8.2"),
.package(url: "https://github.com/apple/swift-system", from: "1.4.2"),
.package(url: "https://github.com/swiftlang/swift-subprocess", exact: "0.2.1", traits: []),
// This dependency provides the correct version of the formatter so that you can run `swift run swiftformat Package.swift Plugins/ Sources/ Tests/`
.package(url: "https://github.com/nicklockwood/SwiftFormat", exact: "0.49.18"),
],
Expand Down Expand Up @@ -67,6 +68,7 @@ let package = Package(
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
.product(name: "OpenAPIAsyncHTTPClient", package: "swift-openapi-async-http-client"),
.product(name: "SystemPackage", package: "swift-system"),
.product(name: "Subprocess", package: "swift-subprocess"),
],
swiftSettings: swiftSettings,
plugins: ["GenerateCommandModels"]
Expand Down
50 changes: 32 additions & 18 deletions Sources/LinuxPlatform/Linux.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import Subprocess
import SwiftlyCore
import SystemPackage

Expand Down Expand Up @@ -263,7 +264,13 @@ public struct Linux: Platform {
}

if requireSignatureValidation {
guard (try? self.runProgram("gpg", "--version", quiet: true)) != nil else {
let result = try await run(
.name("gpg"),
arguments: ["--version"],
output: .discarded
)

if !result.terminationStatus.isSuccess {
var msg = "gpg is not installed. "
if let manager {
msg += """
Expand All @@ -283,11 +290,9 @@ public struct Linux: Platform {
try await fs.withTemporary(files: tmpFile) {
try await ctx.httpClient.getGpgKeys().download(to: tmpFile)
if let mockedHomeDir = ctx.mockedHomeDir {
var env = ProcessInfo.processInfo.environment
env["GNUPGHOME"] = (mockedHomeDir / ".gnupg").string
try await sys.gpg()._import(key: tmpFile).run(self, env: env, quiet: true)
try await sys.gpg()._import(key: tmpFile).run(environment: .inherit.updating(["GNUPGHOME": (mockedHomeDir / ".gnupg").string]), quiet: true)
} else {
try await sys.gpg()._import(key: tmpFile).run(self, quiet: true)
try await sys.gpg()._import(key: tmpFile).run(quiet: true)
}
}
}
Expand Down Expand Up @@ -315,7 +320,12 @@ public struct Linux: Platform {
do {
switch manager {
case "apt-get":
if let pkgList = try await self.runProgramOutput("dpkg", "-l", package) {
let result = try await run(.name("dpkg"), arguments: ["-l", package], output: .string(limit: 100 * 1024))
if !result.terminationStatus.isSuccess {
return false
}

if let pkgList = result.standardOutput {
// The package might be listed but not in an installed non-error state.
//
// Look for something like this:
Expand All @@ -329,8 +339,8 @@ public struct Linux: Platform {
}
return false
case "yum":
try self.runProgram("yum", "list", "installed", package, quiet: true)
return true
let result = try await run(.name("yum"), arguments: ["list", "installed", package], output: .discarded)
return result.terminationStatus.isSuccess
default:
return true
}
Expand Down Expand Up @@ -390,7 +400,15 @@ public struct Linux: Platform {
tmpDir / String(name)
}

try self.runProgram((tmpDir / "swiftly").string, "init")
let config = Configuration(
executable: .path(tmpDir / "swiftly"),
arguments: ["init"]
)

let result = try await run(config, output: .standardOutput, error: .standardError)
if !result.terminationStatus.isSuccess {
throw RunProgramError(terminationStatus: result.terminationStatus, config: config)
}
}
}

Expand Down Expand Up @@ -424,11 +442,9 @@ public struct Linux: Platform {
await ctx.message("Verifying toolchain signature...")
do {
if let mockedHomeDir = ctx.mockedHomeDir {
var env = ProcessInfo.processInfo.environment
env["GNUPGHOME"] = (mockedHomeDir / ".gnupg").string
try await sys.gpg().verify(detached_signature: sigFile, signed_data: archive).run(self, env: env, quiet: false)
try await sys.gpg().verify(detached_signature: sigFile, signed_data: archive).run(environment: .inherit.updating(["GNUPGHOME": (mockedHomeDir / ".gnupg").string]), quiet: false)
} else {
try await sys.gpg().verify(detached_signature: sigFile, signed_data: archive).run(self, quiet: !verbose)
try await sys.gpg().verify(detached_signature: sigFile, signed_data: archive).run(quiet: !verbose)
}
} catch {
throw SwiftlyError(message: "Signature verification failed: \(error).")
Expand All @@ -453,11 +469,9 @@ public struct Linux: Platform {
await ctx.message("Verifying swiftly signature...")
do {
if let mockedHomeDir = ctx.mockedHomeDir {
var env = ProcessInfo.processInfo.environment
env["GNUPGHOME"] = (mockedHomeDir / ".gnupg").string
try await sys.gpg().verify(detached_signature: sigFile, signed_data: archive).run(self, env: env, quiet: false)
try await sys.gpg().verify(detached_signature: sigFile, signed_data: archive).run(environment: .inherit.updating(["GNUPGHOME": (mockedHomeDir / ".gnupg").string]), quiet: false)
} else {
try await sys.gpg().verify(detached_signature: sigFile, signed_data: archive).run(self, quiet: !verbose)
try await sys.gpg().verify(detached_signature: sigFile, signed_data: archive).run(quiet: !verbose)
}
} catch {
throw SwiftlyError(message: "Signature verification failed: \(error).")
Expand Down Expand Up @@ -611,7 +625,7 @@ public struct Linux: Platform {

public func getShell() async throws -> String {
let userName = ProcessInfo.processInfo.userName
if let entry = try await sys.getent(database: "passwd", key: userName).entries(self).first {
if let entry = try await sys.getent(database: "passwd", key: userName).entries().first {
if let shell = entry.last { return shell }
}

Expand Down
Loading