Skip to content

Commit 5940330

Browse files
authored
Merge pull request #263 from owenv/library-split
Extract everything depending on LLBuild into a SwiftDriverExecution library
2 parents b723267 + 07caf40 commit 5940330

18 files changed

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

0 commit comments

Comments
 (0)