Skip to content

Commit 756a6ff

Browse files
committed
Extract everything depending on LLBuild into a SwiftDriverExecution library
- Moved llbuild.Swift and the SwiftDriverExecutor into the new library - Avoid reexporting llbuildSwift through the new library - Update SPM and CMake builds
1 parent 9081a08 commit 756a6ff

19 files changed

+439
-371
lines changed

Package.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,25 @@ let package = Package(
2727
.library(
2828
name: "SwiftOptions",
2929
targets: ["SwiftOptions"]),
30+
.library(
31+
name: "SwiftDriverExecution",
32+
targets: ["SwiftDriverExecution"]),
3033
],
3134
targets: [
3235
/// The driver library.
3336
.target(
3437
name: "SwiftDriver",
3538
dependencies: ["SwiftOptions", "SwiftToolsSupport-auto", "Yams"]),
39+
40+
/// The execution library.
41+
.target(
42+
name: "SwiftDriverExecution",
43+
dependencies: ["SwiftDriver", "SwiftToolsSupport-auto"]),
44+
45+
/// Driver tests.
3646
.testTarget(
3747
name: "SwiftDriverTests",
38-
dependencies: ["SwiftDriver", "swift-driver"]),
48+
dependencies: ["SwiftDriver", "SwiftDriverExecution", "swift-driver"]),
3949

4050
/// The options library.
4151
.target(
@@ -48,7 +58,7 @@ let package = Package(
4858
/// The primary driver executable.
4959
.target(
5060
name: "swift-driver",
51-
dependencies: ["SwiftDriver"]),
61+
dependencies: ["SwiftDriverExecution", "SwiftDriver"]),
5262

5363
/// The help executable.
5464
.target(
@@ -75,7 +85,7 @@ if ProcessInfo.processInfo.environment["SWIFT_DRIVER_LLBUILD_FWK"] == nil {
7585
.package(path: "../llbuild"),
7686
]
7787
}
78-
package.targets.first(where: { $0.name == "SwiftDriver" })!.dependencies += ["llbuildSwift"]
88+
package.targets.first(where: { $0.name == "SwiftDriverExecution" })!.dependencies += ["llbuildSwift"]
7989
}
8090

8191
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {

Sources/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88

99
add_subdirectory(SwiftOptions)
1010
add_subdirectory(SwiftDriver)
11+
add_subdirectory(SwiftDriverExecution)
1112
add_subdirectory(swift-driver)
1213
add_subdirectory(swift-help)

Sources/SwiftDriver/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ add_library(SwiftDriver
2424
Driver/ToolExecutionDelegate.swift
2525

2626
Execution/ArgsResolver.swift
27-
Execution/MultiJobExecutor.swift
2827
Execution/DriverExecutor.swift
2928
Execution/ParsableOutput.swift
3029
Execution/ProcessProtocol.swift
31-
Execution/llbuild.swift
3230

3331
"Incremental Compilation/IncrementalCompilationState.swift"
3432
"Incremental Compilation/InputIInfoMap.swift"
@@ -84,8 +82,7 @@ add_library(SwiftDriver
8482
target_link_libraries(SwiftDriver PUBLIC
8583
TSCBasic
8684
TSCUtility
87-
SwiftOptions
88-
llbuildSwift)
85+
SwiftOptions)
8986
target_link_libraries(SwiftDriver PRIVATE
9087
CYaml
9188
Yams)

Sources/SwiftDriver/Driver/OutputFileMap.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import TSCBasic
1313
import Foundation
1414

15-
public typealias FileSystem = TSCBasic.FileSystem
16-
1715
/// Mapping of input file paths to specific output files.
1816
public struct OutputFileMap: Hashable, Codable {
1917
static let singleInputKey = VirtualPath.relative(RelativePath(""))

Sources/SwiftDriver/Execution/DriverExecutor.swift

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -84,87 +84,3 @@ public protocol JobExecutionDelegate {
8484
/// Called when a job finished.
8585
func jobFinished(job: Job, result: ProcessResult, pid: Int)
8686
}
87-
88-
public final class SwiftDriverExecutor: DriverExecutor {
89-
let diagnosticsEngine: DiagnosticsEngine
90-
let processSet: ProcessSet
91-
let fileSystem: FileSystem
92-
public let resolver: ArgsResolver
93-
let env: [String: String]
94-
95-
public init(diagnosticsEngine: DiagnosticsEngine,
96-
processSet: ProcessSet,
97-
fileSystem: FileSystem,
98-
env: [String: String]) throws {
99-
self.diagnosticsEngine = diagnosticsEngine
100-
self.processSet = processSet
101-
self.fileSystem = fileSystem
102-
self.env = env
103-
self.resolver = try ArgsResolver(fileSystem: fileSystem)
104-
}
105-
106-
public func execute(job: Job,
107-
forceResponseFiles: Bool = false,
108-
recordedInputModificationDates: [TypedVirtualPath: Date] = [:]) throws -> ProcessResult {
109-
let arguments: [String] = try resolver.resolveArgumentList(for: job,
110-
forceResponseFiles: forceResponseFiles)
111-
112-
try job.verifyInputsNotModified(since: recordedInputModificationDates,
113-
fileSystem: fileSystem)
114-
115-
if job.requiresInPlaceExecution {
116-
for (envVar, value) in job.extraEnvironment {
117-
try ProcessEnv.setVar(envVar, value: value)
118-
}
119-
120-
try exec(path: arguments[0], args: arguments)
121-
fatalError("unreachable, exec always throws on failure")
122-
} else {
123-
var childEnv = env
124-
childEnv.merge(job.extraEnvironment, uniquingKeysWith: { (_, new) in new })
125-
126-
let process = try Process.launchProcess(arguments: arguments, env: childEnv)
127-
return try process.waitUntilExit()
128-
}
129-
}
130-
131-
public func execute(jobs: [Job],
132-
delegate: JobExecutionDelegate,
133-
numParallelJobs: Int = 1,
134-
forceResponseFiles: Bool = false,
135-
recordedInputModificationDates: [TypedVirtualPath: Date] = [:]
136-
) throws {
137-
let llbuildExecutor = MultiJobExecutor(jobs: jobs,
138-
resolver: resolver,
139-
executorDelegate: delegate,
140-
diagnosticsEngine: diagnosticsEngine,
141-
numParallelJobs: numParallelJobs,
142-
processSet: processSet,
143-
forceResponseFiles: forceResponseFiles,
144-
recordedInputModificationDates: recordedInputModificationDates)
145-
try llbuildExecutor.execute(env: env, fileSystem: fileSystem)
146-
}
147-
148-
@discardableResult
149-
public func checkNonZeroExit(args: String..., environment: [String: String] = ProcessEnv.vars) throws -> String {
150-
return try Process.checkNonZeroExit(arguments: args, environment: environment)
151-
}
152-
153-
public func description(of job: Job, forceResponseFiles: Bool) throws -> String {
154-
let (args, usedResponseFile) = try resolver.resolveArgumentList(for: job, forceResponseFiles: forceResponseFiles)
155-
var result = args.joined(separator: " ")
156-
157-
if usedResponseFile {
158-
// Print the response file arguments as a comment.
159-
result += " # \(job.commandLine.joinedArguments)"
160-
}
161-
162-
if !job.extraEnvironment.isEmpty {
163-
result += " #"
164-
for (envVar, val) in job.extraEnvironment {
165-
result += " \(envVar)=\(val)"
166-
}
167-
}
168-
return result
169-
}
170-
}

0 commit comments

Comments
 (0)