Skip to content
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
31 changes: 31 additions & 0 deletions Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ fileprivate class ModuleCompileDelegate: JobExecutionDelegate {
var failingCriticalOutputs: Set<VirtualPath>
let logPath: AbsolutePath?
let jsonDelegate: JSONOutputDelegate
var compiledModules: [String: Int] = [:]
init(_ jobs: [Job], _ diagnosticsEngine: DiagnosticsEngine, _ verbose: Bool,
_ logPath: AbsolutePath?, _ jsonDelegate: JSONOutputDelegate) {
self.diagnosticsEngine = diagnosticsEngine
Expand Down Expand Up @@ -201,13 +202,40 @@ fileprivate class ModuleCompileDelegate: JobExecutionDelegate {
return !failingCriticalOutputs.isEmpty
}

public func checkCriticalModulesGenerated() -> Bool {
let sortedModules = compiledModules.sorted(by: <)
Driver.stdErrQueue.sync {
stderrStream.send("===================================================\n")
sortedModules.forEach {
stderrStream.send("\($0.key): \($0.value)\n")
}
stderrStream.send("===================================================\n")
stderrStream.flush()
}
let keyModules = ["Swift", "SwiftUI", "Foundation"]
return keyModules.allSatisfy {
if compiledModules.keys.contains($0) {
return true
}
stderrStream.send("Missing critical module: \($0)\n")
return false
}
}

public func jobFinished(job: Job, result: ProcessResult, pid: Int) {
self.jsonDelegate.jobFinished(job, result)
switch result.exitStatus {
case .terminated(code: let code):
if code == 0 {
printJobInfo(job, false, verbose)
failingCriticalOutputs.remove(job.outputs[0].file)

// Keep track of Swift modules that have been already generated.
if let seen = compiledModules[job.moduleName] {
compiledModules[job.moduleName] = seen + 1
} else {
compiledModules[job.moduleName] = 1
}
} else {
failingModules.insert(job.moduleName)
let result: String = try! result.utf8stderrOutput()
Expand Down Expand Up @@ -317,6 +345,9 @@ public class PrebuiltModuleGenerationDelegate: JobExecutionDelegate {
public var hasCriticalFailure: Bool {
return compileDelegate.hasCriticalFailure
}
public func checkCriticalModulesGenerated() -> Bool {
return compileDelegate.checkCriticalModulesGenerated()
}
public func emitJsonOutput(to path: AbsolutePath) throws {
let data = try JSONEncoder().encode(self.jsonDelegate)
if let json = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers),
Expand Down
3 changes: 3 additions & 0 deletions Sources/swift-build-sdk-interfaces/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ do {
if let jsonPath = jsonPath {
try! delegate.emitJsonOutput(to: jsonPath)
}
if !delegate.checkCriticalModulesGenerated() {
exit(1)
}
}
do {
try executor.execute(workload: DriverExecutorWorkload.init(jobs, nil, nil, continueBuildingAfterErrors: true),
Expand Down