Skip to content

Commit 66fd776

Browse files
committed
Prepare SPM Targets for Process migration by specifying that callee should use TSCBasic.Process
1 parent 4cf8e7e commit 66fd776

22 files changed

+126
-126
lines changed

Sources/Basics/Archiver+Zip.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public struct ZipArchiver: Archiver, Cancellable {
4747
}
4848

4949
#if os(Windows)
50-
let process = Process(arguments: ["tar.exe", "xf", archivePath.pathString, "-C", destinationPath.pathString])
50+
let process = TSCBasic.Process(arguments: ["tar.exe", "xf", archivePath.pathString, "-C", destinationPath.pathString])
5151
#else
52-
let process = Process(arguments: ["unzip", archivePath.pathString, "-d", destinationPath.pathString])
52+
let process = TSCBasic.Process(arguments: ["unzip", archivePath.pathString, "-d", destinationPath.pathString])
5353
#endif
5454
guard let registrationKey = self.cancellator.register(process) else {
5555
throw StringError("cancellation")
@@ -77,9 +77,9 @@ public struct ZipArchiver: Archiver, Cancellable {
7777
}
7878

7979
#if os(Windows)
80-
let process = Process(arguments: ["tar.exe", "tf", path.pathString])
80+
let process = TSCBasic.Process(arguments: ["tar.exe", "tf", path.pathString])
8181
#else
82-
let process = Process(arguments: ["unzip", "-t", path.pathString])
82+
let process = TSCBasic.Process(arguments: ["unzip", "-t", path.pathString])
8383
#endif
8484
guard let registrationKey = self.cancellator.register(process) else {
8585
throw StringError("cancellation")

Sources/Basics/Cancellator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class Cancellator: Cancellable {
5151
}
5252

5353
public func register(_ process: TSCBasic.Process) -> RegistrationKey? {
54-
self.register(name: "\(process.arguments.joined(separator: " "))", handler: process.terminate)
54+
self.register(name: "\(process.arguments.joined(separator: " "))", handler: process.terminate)
5555
}
5656

5757
#if !os(iOS) && !os(watchOS) && !os(tvOS)

Sources/Build/BuildOperation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
461461
if !self.disableSandboxForPluginCommands {
462462
commandLine = Sandbox.apply(command: commandLine, strictness: .writableTemporaryDirectory, writableDirectories: [pluginResult.pluginOutputDirectory])
463463
}
464-
let processResult = try Process.popen(arguments: commandLine, environment: command.configuration.environment)
464+
let processResult = try TSCBasic.Process.popen(arguments: commandLine, environment: command.configuration.environment)
465465
let output = try processResult.utf8Output() + processResult.utf8stderrOutput()
466466
if processResult.exitStatus != .terminated(code: 0) {
467467
throw StringError("failed: \(command)\n\n\(output)")

Sources/Build/SPMSwiftDriverExecutor.swift

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,78 +16,78 @@ import Foundation
1616
@_implementationOnly import SwiftDriver
1717

1818
final class SPMSwiftDriverExecutor: DriverExecutor {
19-
20-
private enum Error: Swift.Error, CustomStringConvertible {
21-
case inPlaceExecutionUnsupported
22-
23-
var description: String {
24-
switch self {
25-
case .inPlaceExecutionUnsupported:
26-
return "the integrated Swift driver does not support in-place execution"
27-
}
19+
20+
private enum Error: Swift.Error, CustomStringConvertible {
21+
case inPlaceExecutionUnsupported
22+
23+
var description: String {
24+
switch self {
25+
case .inPlaceExecutionUnsupported:
26+
return "the integrated Swift driver does not support in-place execution"
27+
}
28+
}
2829
}
29-
}
30-
31-
let resolver: ArgsResolver
32-
let fileSystem: FileSystem
33-
let env: EnvironmentVariables
34-
35-
init(resolver: ArgsResolver,
36-
fileSystem: FileSystem,
37-
env: EnvironmentVariables) {
38-
self.resolver = resolver
39-
self.fileSystem = fileSystem
40-
self.env = env
41-
}
42-
43-
func execute(job: Job,
44-
forceResponseFiles: Bool,
45-
recordedInputModificationDates: [TypedVirtualPath : Date]) throws -> ProcessResult {
46-
let arguments: [String] = try resolver.resolveArgumentList(for: job,
47-
forceResponseFiles: forceResponseFiles)
48-
49-
try job.verifyInputsNotModified(since: recordedInputModificationDates,
50-
fileSystem: fileSystem)
51-
52-
if job.requiresInPlaceExecution {
53-
throw Error.inPlaceExecutionUnsupported
30+
31+
let resolver: ArgsResolver
32+
let fileSystem: FileSystem
33+
let env: EnvironmentVariables
34+
35+
init(resolver: ArgsResolver,
36+
fileSystem: FileSystem,
37+
env: EnvironmentVariables) {
38+
self.resolver = resolver
39+
self.fileSystem = fileSystem
40+
self.env = env
5441
}
55-
56-
var childEnv = env
57-
childEnv.merge(job.extraEnvironment, uniquingKeysWith: { (_, new) in new })
58-
59-
let process = try Process.launchProcess(arguments: arguments, env: childEnv)
60-
return try process.waitUntilExit()
61-
}
62-
63-
func execute(workload: DriverExecutorWorkload,
64-
delegate: JobExecutionDelegate,
65-
numParallelJobs: Int, forceResponseFiles: Bool,
66-
recordedInputModificationDates: [TypedVirtualPath : Date]) throws {
67-
throw InternalError("Multi-job build plans should be lifted into the SPM build graph.")
68-
}
69-
70-
func checkNonZeroExit(args: String..., environment: [String : String]) throws -> String {
71-
return try Process.checkNonZeroExit(arguments: args, environment: environment)
72-
}
73-
74-
func description(of job: Job, forceResponseFiles: Bool) throws -> String {
75-
// FIXME: This is duplicated from SwiftDriver, maybe it shouldn't be a protocol requirement.
76-
let (args, usedResponseFile) = try resolver.resolveArgumentList(for: job,
77-
forceResponseFiles: forceResponseFiles)
78-
var result = args.joined(separator: " ")
79-
80-
if usedResponseFile {
81-
// Print the response file arguments as a comment.
82-
result += " # \(job.commandLine.joinedUnresolvedArguments)"
42+
43+
func execute(job: Job,
44+
forceResponseFiles: Bool,
45+
recordedInputModificationDates: [TypedVirtualPath : Date]) throws -> ProcessResult {
46+
let arguments: [String] = try resolver.resolveArgumentList(for: job,
47+
forceResponseFiles: forceResponseFiles)
48+
49+
try job.verifyInputsNotModified(since: recordedInputModificationDates,
50+
fileSystem: fileSystem)
51+
52+
if job.requiresInPlaceExecution {
53+
throw Error.inPlaceExecutionUnsupported
54+
}
55+
56+
var childEnv = env
57+
childEnv.merge(job.extraEnvironment, uniquingKeysWith: { (_, new) in new })
58+
59+
let process = try Process.launchProcess(arguments: arguments, env: childEnv)
60+
return try process.waitUntilExit()
8361
}
84-
85-
if !job.extraEnvironment.isEmpty {
86-
result += " #"
87-
for (envVar, val) in job.extraEnvironment {
88-
result += " \(envVar)=\(val)"
89-
}
62+
63+
func execute(workload: DriverExecutorWorkload,
64+
delegate: JobExecutionDelegate,
65+
numParallelJobs: Int, forceResponseFiles: Bool,
66+
recordedInputModificationDates: [TypedVirtualPath : Date]) throws {
67+
throw InternalError("Multi-job build plans should be lifted into the SPM build graph.")
68+
}
69+
70+
func checkNonZeroExit(args: String..., environment: [String : String]) throws -> String {
71+
return try TSCBasic.Process.checkNonZeroExit(arguments: args, environment: environment)
72+
}
73+
74+
func description(of job: Job, forceResponseFiles: Bool) throws -> String {
75+
// FIXME: This is duplicated from SwiftDriver, maybe it shouldn't be a protocol requirement.
76+
let (args, usedResponseFile) = try resolver.resolveArgumentList(for: job,
77+
forceResponseFiles: forceResponseFiles)
78+
var result = args.joined(separator: " ")
79+
80+
if usedResponseFile {
81+
// Print the response file arguments as a comment.
82+
result += " # \(job.commandLine.joinedUnresolvedArguments)"
83+
}
84+
85+
if !job.extraEnvironment.isEmpty {
86+
result += " #"
87+
for (envVar, val) in job.extraEnvironment {
88+
result += " \(envVar)=\(val)"
89+
}
90+
}
91+
return result
9092
}
91-
return result
92-
}
9393
}

Sources/Commands/APIDigester.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public struct SwiftAPIDigester {
234234

235235
private func runTool(_ args: [String]) throws {
236236
let arguments = [tool.pathString] + args
237-
let process = Process(
237+
let process = TSCBasic.Process(
238238
arguments: arguments,
239239
outputRedirection: .collect
240240
)

Sources/Commands/SwiftBuildTool.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ public struct SwiftBuildTool: SwiftCommand {
124124

125125
private func checkClangVersion(observabilityScope: ObservabilityScope) {
126126
// We only care about this on Ubuntu 14.04
127-
guard let uname = try? Process.checkNonZeroExit(args: "lsb_release", "-r").spm_chomp(),
127+
guard let uname = try? TSCBasic.Process.checkNonZeroExit(args: "lsb_release", "-r").spm_chomp(),
128128
uname.hasSuffix("14.04"),
129-
let clangVersionOutput = try? Process.checkNonZeroExit(args: "clang", "--version").spm_chomp(),
129+
let clangVersionOutput = try? TSCBasic.Process.checkNonZeroExit(args: "clang", "--version").spm_chomp(),
130130
let clang = getClangVersion(versionOutput: clangVersionOutput) else {
131131
return
132132
}

Sources/Commands/SwiftPackageTool.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ extension SwiftPackageTool {
331331
let args = [swiftFormat.pathString] + formatOptions + [packagePath.pathString] + paths
332332
print("Running:", args.map{ $0.spm_shellEscaped() }.joined(separator: " "))
333333

334-
let result = try Process.popen(arguments: args)
334+
let result = try TSCBasic.Process.popen(arguments: args)
335335
let output = try (result.utf8Output() + result.utf8stderrOutput())
336336

337337
if result.exitStatus != .terminated(code: 0) {
@@ -1358,7 +1358,7 @@ final class PluginDelegate: PluginInvocationDelegate {
13581358
llvmProfCommand.append(filePath.pathString)
13591359
}
13601360
llvmProfCommand += ["-o", mergedCovFile.pathString]
1361-
try Process.checkNonZeroExit(arguments: llvmProfCommand)
1361+
try TSCBasic.Process.checkNonZeroExit(arguments: llvmProfCommand)
13621362

13631363
// Use `llvm-cov` to export the merged `.profdata` file contents in JSON form.
13641364
var llvmCovCommand = [try toolchain.getLLVMCov().pathString]
@@ -1368,7 +1368,7 @@ final class PluginDelegate: PluginInvocationDelegate {
13681368
llvmCovCommand.append(product.binaryPath.pathString)
13691369
}
13701370
// We get the output on stdout, and have to write it to a JSON ourselves.
1371-
let jsonOutput = try Process.checkNonZeroExit(arguments: llvmCovCommand)
1371+
let jsonOutput = try TSCBasic.Process.checkNonZeroExit(arguments: llvmCovCommand)
13721372
let jsonCovFile = buildParameters.codeCovDataFile.parentDirectory.appending(component: buildParameters.codeCovDataFile.basenameWithoutExt + ".json")
13731373
try swiftTool.fileSystem.writeFileContents(jsonCovFile, string: jsonOutput)
13741374

Sources/Commands/SwiftTestTool.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ public struct SwiftTestTool: SwiftCommand {
436436
}
437437
args += ["-o", buildParameters.codeCovDataFile.pathString]
438438

439-
try Process.checkNonZeroExit(arguments: args)
439+
try TSCBasic.Process.checkNonZeroExit(arguments: args)
440440
}
441441

442442
private func codeCovAsJSONPath(buildParameters: BuildParameters, packageName: String) -> AbsolutePath {
@@ -454,7 +454,7 @@ public struct SwiftTestTool: SwiftCommand {
454454
"-instr-profile=\(buildParameters.codeCovDataFile)",
455455
testBinary.pathString
456456
]
457-
let result = try Process.popen(arguments: args)
457+
let result = try TSCBasic.Process.popen(arguments: args)
458458

459459
if result.exitStatus != .terminated(code: 0) {
460460
let output = try result.utf8Output() + result.utf8stderrOutput()
@@ -621,7 +621,7 @@ final class TestRunner {
621621
stdout: outputHandler,
622622
stderr: outputHandler
623623
)
624-
let process = Process(arguments: try args(forTestAt: path), environment: self.testEnv, outputRedirection: outputRedirection)
624+
let process = TSCBasic.Process(arguments: try args(forTestAt: path), environment: self.testEnv, outputRedirection: outputRedirection)
625625
guard let terminationKey = self.cancellator.register(process) else {
626626
return false // terminating
627627
}

Sources/Commands/SymbolGraphExtract.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public struct SymbolGraphExtract {
4545
public func extractSymbolGraph(
4646
target: ResolvedTarget,
4747
buildPlan: BuildPlan,
48-
outputRedirection: Process.OutputRedirection = .none,
48+
outputRedirection: TSCBasic.Process.OutputRedirection = .none,
4949
outputDirectory: AbsolutePath,
5050
verboseOutput: Bool
5151
) throws {
@@ -80,7 +80,7 @@ public struct SymbolGraphExtract {
8080
commandLine += ["-output-dir", outputDirectory.pathString]
8181

8282
// Run the extraction.
83-
let process = Process(
83+
let process = TSCBasic.Process(
8484
arguments: commandLine,
8585
outputRedirection: outputRedirection
8686
)

Sources/Commands/TestingSupport.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ enum TestingSupport {
8888
env.appendPath("DYLD_FRAMEWORK_PATH", value: sdkPlatformFrameworksPath.fwk.pathString)
8989
env.appendPath("DYLD_LIBRARY_PATH", value: sdkPlatformFrameworksPath.lib.pathString)
9090
}
91-
try Process.checkNonZeroExit(arguments: args, environment: env)
91+
try TSCBasic.Process.checkNonZeroExit(arguments: args, environment: env)
9292
// Read the temporary file's content.
9393
return try swiftTool.fileSystem.readFileContents(tempFile.path)
9494
}

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
588588
cmd += ["-o", compiledManifestFile.pathString]
589589

590590
// Compile the manifest.
591-
Process.popen(arguments: cmd, environment: self.toolchain.swiftCompilerEnvironment, queue: callbackQueue) { result in
591+
TSCBasic.Process.popen(arguments: cmd, environment: self.toolchain.swiftCompilerEnvironment, queue: callbackQueue) { result in
592592
dispatchPrecondition(condition: .onQueue(callbackQueue))
593593

594594
var cleanupIfError = DelayableAction(target: tmpDir, action: cleanupTmpDir)
@@ -648,7 +648,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
648648
#endif
649649

650650
let cleanupAfterRunning = cleanupIfError.delay()
651-
Process.popen(arguments: cmd, environment: environment, queue: callbackQueue) { result in
651+
TSCBasic.Process.popen(arguments: cmd, environment: environment, queue: callbackQueue) { result in
652652
dispatchPrecondition(condition: .onQueue(callbackQueue))
653653

654654
defer { cleanupAfterRunning.perform() }
@@ -697,7 +697,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
697697
var sdkRootPath: AbsolutePath? = nil
698698
// Find SDKROOT on macOS using xcrun.
699699
#if os(macOS)
700-
let foundPath = try? Process.checkNonZeroExit(
700+
let foundPath = try? TSCBasic.Process.checkNonZeroExit(
701701
args: "/usr/bin/xcrun", "--sdk", "macosx", "--show-sdk-path")
702702
guard let sdkRoot = foundPath?.spm_chomp(), !sdkRoot.isEmpty else {
703703
return nil

Sources/PackageLoading/PkgConfig.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ internal struct PCFileFinder {
392392
private init(pkgConfigPath: String) {
393393
if PCFileFinder.pkgConfigPaths == nil {
394394
do {
395-
let searchPaths = try Process.checkNonZeroExit(args:
395+
let searchPaths = try TSCBasic.Process.checkNonZeroExit(args:
396396
pkgConfigPath, "--variable", "pc_path", "pkg-config"
397397
).spm_chomp()
398398

Sources/PackageLoading/Target+PkgConfig.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ extension SystemPackageProviderDescription {
174174
// to the latest version. Instead use the version as symlinked
175175
// in /usr/local/opt/(NAME)/lib/pkgconfig.
176176
struct Static {
177-
static let value = { try? Process.checkNonZeroExit(args: "brew", "--prefix").spm_chomp() }()
177+
static let value = { try? TSCBasic.Process.checkNonZeroExit(args: "brew", "--prefix").spm_chomp() }()
178178
}
179179
if let value = Static.value {
180180
brewPrefix = value

Sources/PackageModel/Destination.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public struct Destination: Encodable, Equatable {
124124
sdkPath = value
125125
} else {
126126
// No value in env, so search for it.
127-
let sdkPathStr = try Process.checkNonZeroExit(
127+
let sdkPathStr = try TSCBasic.Process.checkNonZeroExit(
128128
arguments: ["/usr/bin/xcrun", "--sdk", "macosx", "--show-sdk-path"], environment: environment).spm_chomp()
129129
guard !sdkPathStr.isEmpty else {
130130
throw DestinationError.invalidInstallation("default SDK not found")
@@ -177,7 +177,7 @@ public struct Destination: Encodable, Equatable {
177177
if let path = _sdkPlatformFrameworkPath {
178178
return path
179179
}
180-
let platformPath = try? Process.checkNonZeroExit(
180+
let platformPath = try? TSCBasic.Process.checkNonZeroExit(
181181
arguments: ["/usr/bin/xcrun", "--sdk", "macosx", "--show-sdk-platform-path"],
182182
environment: environment).spm_chomp()
183183

Sources/PackageModel/UserToolchain.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public final class UserToolchain: Toolchain {
9898
private static func findTool(_ name: String, envSearchPaths: [AbsolutePath], useXcrun: Bool) throws -> AbsolutePath {
9999
if useXcrun {
100100
#if os(macOS)
101-
let foundPath = try Process.checkNonZeroExit(arguments: ["/usr/bin/xcrun", "--find", name]).spm_chomp()
101+
let foundPath = try TSCBasic.Process.checkNonZeroExit(arguments: ["/usr/bin/xcrun", "--find", name]).spm_chomp()
102102
return try AbsolutePath(validating: foundPath)
103103
#endif
104104
}
@@ -477,7 +477,7 @@ public final class UserToolchain: Toolchain {
477477
if triple.isDarwin() {
478478
// XCTest is optional on macOS, for example when Xcode is not installed
479479
let xctestFindArgs = ["/usr/bin/xcrun", "--sdk", "macosx", "--find", "xctest"]
480-
if let path = try? Process.checkNonZeroExit(arguments: xctestFindArgs, environment: environment).spm_chomp() {
480+
if let path = try? TSCBasic.Process.checkNonZeroExit(arguments: xctestFindArgs, environment: environment).spm_chomp() {
481481
return try AbsolutePath(validating: path)
482482
}
483483
} else if triple.isWindows() {

Sources/SourceControl/GitRepository.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ private struct GitShellHelper {
3131
/// Private function to invoke the Git tool with its default environment and given set of arguments. The specified
3232
/// failure message is used only in case of error. This function waits for the invocation to finish and returns the
3333
/// output as a string.
34-
func run(_ args: [String], environment: EnvironmentVariables = Git.environment, outputRedirection: Process.OutputRedirection = .collect) throws -> String {
35-
let process = Process(arguments: [Git.tool] + args, environment: environment, outputRedirection: outputRedirection)
34+
func run(_ args: [String], environment: EnvironmentVariables = Git.environment, outputRedirection: TSCBasic.Process.OutputRedirection = .collect) throws -> String {
35+
let process = TSCBasic.Process(arguments: [Git.tool] + args, environment: environment, outputRedirection: outputRedirection)
3636
let result: ProcessResult
3737
do {
3838
guard let terminationKey = self.cancellator.register(process) else {

0 commit comments

Comments
 (0)