Skip to content

Commit 04f9f28

Browse files
authored
Merge pull request #1457 from apple/113984264
Prebuilt-module-generation: support a mode that aggregates broken interfaces as a JSON output for easy comparision
2 parents 86b57cc + a566d02 commit 04f9f28

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift

+41-2
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,45 @@ func printJobInfo(_ job: Job, _ start: Bool, _ verbose: Bool) {
141141
}
142142
}
143143

144+
class JSONOutputDelegate: Encodable {
145+
enum SDKFailureKind: String, Encodable {
146+
case BrokenTextualInterface
147+
}
148+
struct SDKFailure: Encodable {
149+
let inputPath: String
150+
let kind: SDKFailureKind
151+
}
152+
var allFailures = [SDKFailure]()
153+
func jobFinished(_ job: Job, _ result: ProcessResult) {
154+
switch result.exitStatus {
155+
case .terminated(code: let code):
156+
if code == 0 {
157+
break
158+
} else {
159+
allFailures.append(SDKFailure(inputPath: getLastInputPath(job).pathString,
160+
kind: .BrokenTextualInterface))
161+
}
162+
default:
163+
break
164+
}
165+
}
166+
}
167+
144168
fileprivate class ModuleCompileDelegate: JobExecutionDelegate {
145169
var failingModules = Set<String>()
146170
var commandMap: [Int: String] = [:]
147171
let diagnosticsEngine: DiagnosticsEngine
148172
let verbose: Bool
149173
var failingCriticalOutputs: Set<VirtualPath>
150174
let logPath: AbsolutePath?
151-
public init(_ jobs: [Job], _ diagnosticsEngine: DiagnosticsEngine, _ verbose: Bool, _ logPath: AbsolutePath?) {
175+
let jsonDelegate: JSONOutputDelegate
176+
init(_ jobs: [Job], _ diagnosticsEngine: DiagnosticsEngine, _ verbose: Bool,
177+
_ logPath: AbsolutePath?, _ jsonDelegate: JSONOutputDelegate) {
152178
self.diagnosticsEngine = diagnosticsEngine
153179
self.verbose = verbose
154180
self.failingCriticalOutputs = Set<VirtualPath>(jobs.compactMap(ModuleCompileDelegate.getCriticalOutput))
155181
self.logPath = logPath
182+
self.jsonDelegate = jsonDelegate
156183
}
157184

158185
/// Dangling jobs are macabi-only modules. We should run those jobs if foundation
@@ -175,6 +202,7 @@ fileprivate class ModuleCompileDelegate: JobExecutionDelegate {
175202
}
176203

177204
public func jobFinished(job: Job, result: ProcessResult, pid: Int) {
205+
self.jsonDelegate.jobFinished(job, result)
178206
switch result.exitStatus {
179207
case .terminated(code: let code):
180208
if code == 0 {
@@ -249,6 +277,7 @@ fileprivate class ABICheckingDelegate: JobExecutionDelegate {
249277

250278
public class PrebuiltModuleGenerationDelegate: JobExecutionDelegate {
251279

280+
fileprivate let jsonDelegate: JSONOutputDelegate
252281
fileprivate let compileDelegate: ModuleCompileDelegate
253282
fileprivate let abiCheckDelegate: ABICheckingDelegate
254283

@@ -264,7 +293,10 @@ public class PrebuiltModuleGenerationDelegate: JobExecutionDelegate {
264293

265294
public init(_ jobs: [Job], _ diagnosticsEngine: DiagnosticsEngine,
266295
_ verbose: Bool, _ logPath: AbsolutePath?) {
267-
self.compileDelegate = ModuleCompileDelegate(jobs.filter(ModuleCompileDelegate.canHandle), diagnosticsEngine, verbose, logPath)
296+
self.jsonDelegate = JSONOutputDelegate()
297+
self.compileDelegate = ModuleCompileDelegate(jobs.filter(ModuleCompileDelegate.canHandle),
298+
diagnosticsEngine, verbose, logPath,
299+
self.jsonDelegate)
268300
self.abiCheckDelegate = ABICheckingDelegate(verbose, logPath)
269301
}
270302

@@ -285,6 +317,13 @@ public class PrebuiltModuleGenerationDelegate: JobExecutionDelegate {
285317
public var hasCriticalFailure: Bool {
286318
return compileDelegate.hasCriticalFailure
287319
}
320+
public func emitJsonOutput(to path: AbsolutePath) throws {
321+
let data = try JSONEncoder().encode(self.jsonDelegate)
322+
if let json = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers),
323+
let jsonData = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) {
324+
try localFileSystem.writeFileContents(path, bytes: ByteString(jsonData))
325+
}
326+
}
288327
}
289328

290329
public struct PrebuiltModuleInput {

Sources/swift-build-sdk-interfaces/main.swift

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ do {
7777
exit(1)
7878
}
7979
let logDir = try getArgumentAsPath("-log-path")
80+
let jsonPath = try getArgumentAsPath("-json-path")
8081
let collector = SDKPrebuiltModuleInputsCollector(sdkPath, diagnosticsEngine)
8182
var outputDir = try VirtualPath(path: rawOutputDir).absolutePath!
8283
// if the given output dir ends with 'prebuilt-modules', we should
@@ -174,6 +175,11 @@ do {
174175
exit(0)
175176
}
176177
let delegate = PrebuiltModuleGenerationDelegate(jobs, diagnosticsEngine, verbose, logDir)
178+
defer {
179+
if let jsonPath = jsonPath {
180+
try! delegate.emitJsonOutput(to: jsonPath)
181+
}
182+
}
177183
do {
178184
try executor.execute(workload: DriverExecutorWorkload.init(jobs, nil, continueBuildingAfterErrors: true),
179185
delegate: delegate, numParallelJobs: 128)

0 commit comments

Comments
 (0)