Skip to content

Commit a99e08c

Browse files
Merge pull request #74 from SwiftPackageIndex/processing-env-variable
Inject SPI_PROCESSING into ShellOut commands
2 parents a09de5c + fe7d156 commit a99e08c

File tree

5 files changed

+50
-22
lines changed

5 files changed

+50
-22
lines changed

Package.resolved

Lines changed: 21 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version:6.0
22

33
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
44
//
@@ -18,12 +18,12 @@ import PackageDescription
1818

1919
let package = Package(
2020
name: "validator",
21-
platforms: [.macOS(.v10_15)],
21+
platforms: [.macOS(.v15)],
2222
products: [
2323
.executable(name: "validator", targets: ["validator"])
2424
],
2525
dependencies: [
26-
.package(url: "https://github.com/JohnSundell/ShellOut.git", from: "2.3.0"),
26+
.package(url: "https://github.com/SwiftPackageIndex/ShellOut.git", from: "3.0.0"),
2727
.package(url: "https://github.com/SwiftPackageIndex/CanonicalPackageURL.git", from: "0.0.6"),
2828
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"),
2929
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
@@ -45,5 +45,6 @@ let package = Package(
4545
.testTarget(name: "ValidatorTests",
4646
dependencies: ["ValidatorCore"],
4747
exclude: ["Fixtures"]),
48-
]
48+
],
49+
swiftLanguageModes: [.version("5")]
4950
)

Sources/ValidatorCore/Extensions/ShellOut+ext.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import ShellOut
1717

1818
extension ShellOutCommand {
1919
#if os(macOS)
20-
static let packageDump = ShellOutCommand(string: "/usr/bin/xcrun swift package dump-package")
20+
static let packageDump = ShellOutCommand(command: "/usr/bin/xcrun", arguments: ["swift", "package", "dump-package"])
2121
#else
22-
static let packageDump = ShellOutCommand(string: "swift package dump-package")
22+
static let packageDump = ShellOutCommand(command: "swift", arguments: ["package", "dump-package"])
2323
#endif
2424
}

Sources/ValidatorCore/Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ extension Package {
103103
}
104104
}
105105
do {
106-
guard let pkgJSON = try Current.shell.run(command: .packageDump, at: tempDir)
106+
guard let pkgJSON = try await Current.shell.run(command: .packageDump, at: tempDir)
107+
.stdout
107108
.data(using: .utf8) else {
108109
throw AppError.dumpPackageError("package dump did not return data")
109110
}

Sources/ValidatorCore/Shell.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,29 @@ import ShellOut
1717

1818

1919
struct Shell {
20-
var run: (ShellOutCommand, String, FileHandle?, FileHandle?) throws -> String
20+
var run: (ShellOutCommand, String, FileHandle?, FileHandle?) async throws -> (stdout: String, stderr: String)
2121

2222
@discardableResult
23-
func run(command: ShellOutCommand, at path: String = ".") throws -> String {
24-
return try run(command, path, nil, nil)
23+
func run(command: ShellOutCommand, at path: String = ".") async throws -> (stdout: String, stderr: String) {
24+
try await run(command, path, nil, nil)
2525
}
2626

27-
static let live: Self = .init(run: { cmd, path, stdout, stderr in
28-
try ShellOut.shellOut(to: cmd,
29-
at: path,
30-
outputHandle: stdout,
31-
errorHandle: stderr)
32-
})
27+
static var live: Self {
28+
.init(run: { cmd, path, stdout, stderr in
29+
try await ShellOut.shellOut(
30+
to: cmd,
31+
at: path,
32+
outputHandle: stdout,
33+
errorHandle: stderr,
34+
environment: ProcessInfo.processInfo.environment
35+
.merging(["SPI_PROCESSING": "1"], uniquingKeysWith: { $1 })
36+
)
37+
})
38+
}
3339

34-
static let mock: Self = .init(
35-
run: { _, _, _, _ in fatalError("not implemented") }
36-
)
40+
static var mock: Self {
41+
.init(
42+
run: { _, _, _, _ in fatalError("not implemented") }
43+
)
44+
}
3745
}

0 commit comments

Comments
 (0)