Skip to content

[Explicit Modules] Provide an API for querying whether a job is a main module job. #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,13 @@ extension Driver {
}
try handler.resolveMainModuleDependencies(inputs: &inputs, commandLine: &commandLine)
}

/// In Explicit Module Build mode, distinguish between main module jobs and intermediate dependency build jobs,
/// such as Swift modules built from .swiftmodule files and Clang PCMs.
public func isExplicitMainModuleJob(job: Job) -> Bool {
guard let handler = explicitModuleBuildHandler else {
fatalError("No handler in Explicit Module Build mode.")
}
return job.moduleName == handler.dependencyGraph.mainModuleName
}
}
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Jobs/Job.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct Job: Codable, Equatable, Hashable {
case path(VirtualPath)
}

/// The SWift module this job involves.
/// The Swift module this job involves.
public var moduleName: String

/// The tool to invoke.
Expand Down
3 changes: 3 additions & 0 deletions Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
XCTAssertEqual(modulePrebuildJobs.count, 4)
for job in modulePrebuildJobs {
XCTAssertEqual(job.outputs.count, 1)
XCTAssertFalse(driver.isExplicitMainModuleJob(job: job))
switch (job.outputs[0].file) {

case .relative(try pcmArgsEncodedRelativeModulePath(for: "SwiftShims", with: pcmArgs)):
Expand Down Expand Up @@ -221,6 +222,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
try checkExplicitModuleBuildJob(job: job, moduleId: .clang("SwiftShims"),
moduleDependencyGraph: dependencyGraph)
case .temporary(RelativePath("main.o")):
XCTAssertTrue(driver.isExplicitMainModuleJob(job: job))
guard case .swift(let mainModuleSwiftDetails) = dependencyGraph.mainModule.details else {
XCTFail("Main module does not have Swift details field")
return
Expand All @@ -230,6 +232,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
moduleInfo: dependencyGraph.mainModule,
moduleDependencyGraph: dependencyGraph)
case .relative(RelativePath("main")):
XCTAssertTrue(driver.isExplicitMainModuleJob(job: job))
XCTAssertEqual(job.kind, .link)
default:
XCTFail("Unexpected module dependency build job output: \(job.outputs[0].file)")
Expand Down