Skip to content

Commit b31cadf

Browse files
committed
[Explicit Modules] Provide an API for querying whether a job is a main module job.
This will be useful for SwiftPM (and other build systems) to distinguish intermediate dependency artifacts versus the main module build, in order to correctly pass in cross-target dependencies.
1 parent cad0d23 commit b31cadf

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,13 @@ extension Driver {
344344
}
345345
try handler.resolveMainModuleDependencies(inputs: &inputs, commandLine: &commandLine)
346346
}
347+
348+
/// In Explicit Module Build mode, distinguish between main module jobs and intermediate dependency build jobs,
349+
/// such as Swift modules built from .swiftmodule files and Clang PCMs.
350+
public func isExplicitMainModuleJob(job: Job) -> Bool {
351+
guard let handler = explicitModuleBuildHandler else {
352+
fatalError("No handler in Explicit Module Build mode.")
353+
}
354+
return job.moduleName == handler.dependencyGraph.mainModuleName
355+
}
347356
}

Sources/SwiftDriver/Jobs/Job.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public struct Job: Codable, Equatable, Hashable {
4343
case path(VirtualPath)
4444
}
4545

46-
/// The SWift module this job involves.
46+
/// The Swift module this job involves.
4747
public var moduleName: String
4848

4949
/// The tool to invoke.

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
129129
XCTAssertEqual(modulePrebuildJobs.count, 4)
130130
for job in modulePrebuildJobs {
131131
XCTAssertEqual(job.outputs.count, 1)
132+
XCTAssertFalse(driver.isExplicitMainModuleJob(job: job))
132133
switch (job.outputs[0].file) {
133134

134135
case .relative(try pcmArgsEncodedRelativeModulePath(for: "SwiftShims", with: pcmArgs)):
@@ -221,6 +222,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
221222
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("SwiftShims"),
222223
moduleDependencyGraph: dependencyGraph)
223224
case .temporary(RelativePath("main.o")):
225+
XCTAssertTrue(driver.isExplicitMainModuleJob(job: job))
224226
guard case .swift(let mainModuleSwiftDetails) = dependencyGraph.mainModule.details else {
225227
XCTFail("Main module does not have Swift details field")
226228
return
@@ -230,6 +232,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
230232
moduleInfo: dependencyGraph.mainModule,
231233
moduleDependencyGraph: dependencyGraph)
232234
case .relative(RelativePath("main")):
235+
XCTAssertTrue(driver.isExplicitMainModuleJob(job: job))
233236
XCTAssertEqual(job.kind, .link)
234237
default:
235238
XCTFail("Unexpected module dependency build job output: \(job.outputs[0].file)")

0 commit comments

Comments
 (0)