1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
@_spi(SwiftPMInternal)
import Basics
import SwiftDriver
import class TSCBasic.Process
import struct TSCBasic.ProcessResult
public final class SPMSwiftDriverExecutor: DriverExecutor {
private enum Error: Swift.Error, CustomStringConvertible {
case inPlaceExecutionUnsupported
var description: String {
switch self {
case .inPlaceExecutionUnsupported:
return "the integrated Swift driver does not support in-place execution"
}
}
}
public let resolver: ArgsResolver
let fileSystem: FileSystem
let env: Environment
public init(resolver: ArgsResolver,
fileSystem: FileSystem,
env: Environment) {
self.resolver = resolver
self.fileSystem = fileSystem
self.env = env
}
public func execute(job: Job,
forceResponseFiles: Bool,
recordedInputModificationDates: [TypedVirtualPath : TimePoint]) throws -> ProcessResult {
let arguments: [String] = try resolver.resolveArgumentList(for: job,
useResponseFiles: forceResponseFiles ? .forced : .heuristic)
try job.verifyInputsNotModified(since: recordedInputModificationDates,
fileSystem: fileSystem)
if job.requiresInPlaceExecution {
throw Error.inPlaceExecutionUnsupported
}
var childEnv = [String: String](env)
childEnv.merge(job.extraEnvironment, uniquingKeysWith: { (_, new) in new })
let process = try Process.launchProcess(arguments: arguments, env: childEnv)
return try process.waitUntilExit()
}
public func execute(workload: DriverExecutorWorkload,
delegate: JobExecutionDelegate,
numParallelJobs: Int, forceResponseFiles: Bool,
recordedInputModificationDates: [TypedVirtualPath : TimePoint]) throws {
throw InternalError("Multi-job build plans should be lifted into the SPM build graph.")
}
public func checkNonZeroExit(args: String..., environment: [String : String]) throws -> String {
try AsyncProcess.checkNonZeroExit(arguments: args, environment: .init(environment))
}
public func description(of job: Job, forceResponseFiles: Bool) throws -> String {
// FIXME: This is duplicated from SwiftDriver, maybe it shouldn't be a protocol requirement.
let (args, usedResponseFile) = try resolver.resolveArgumentList(for: job,
useResponseFiles: forceResponseFiles ? .forced : .heuristic)
var result = args.joined(separator: " ")
if usedResponseFile {
// Print the response file arguments as a comment.
result += " # \(job.commandLine.joinedUnresolvedArguments)"
}
if !job.extraEnvironment.isEmpty {
result += " #"
for (envVar, val) in job.extraEnvironment {
result += " \(envVar)=\(val)"
}
}
return result
}
}
|