Skip to content

Prebuilt-module-generation: support a mode that aggregates broken interfaces as a JSON output for easy comparision #1457

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
Oct 6, 2023
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
43 changes: 41 additions & 2 deletions Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,45 @@ func printJobInfo(_ job: Job, _ start: Bool, _ verbose: Bool) {
}
}

class JSONOutputDelegate: Encodable {
enum SDKFailureKind: String, Encodable {
case BrokenTextualInterface
}
struct SDKFailure: Encodable {
let inputPath: String
let kind: SDKFailureKind
}
var allFailures = [SDKFailure]()
func jobFinished(_ job: Job, _ result: ProcessResult) {
switch result.exitStatus {
case .terminated(code: let code):
if code == 0 {
break
} else {
allFailures.append(SDKFailure(inputPath: getLastInputPath(job).pathString,
kind: .BrokenTextualInterface))
}
default:
break
}
}
}

fileprivate class ModuleCompileDelegate: JobExecutionDelegate {
var failingModules = Set<String>()
var commandMap: [Int: String] = [:]
let diagnosticsEngine: DiagnosticsEngine
let verbose: Bool
var failingCriticalOutputs: Set<VirtualPath>
let logPath: AbsolutePath?
public init(_ jobs: [Job], _ diagnosticsEngine: DiagnosticsEngine, _ verbose: Bool, _ logPath: AbsolutePath?) {
let jsonDelegate: JSONOutputDelegate
init(_ jobs: [Job], _ diagnosticsEngine: DiagnosticsEngine, _ verbose: Bool,
_ logPath: AbsolutePath?, _ jsonDelegate: JSONOutputDelegate) {
self.diagnosticsEngine = diagnosticsEngine
self.verbose = verbose
self.failingCriticalOutputs = Set<VirtualPath>(jobs.compactMap(ModuleCompileDelegate.getCriticalOutput))
self.logPath = logPath
self.jsonDelegate = jsonDelegate
}

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

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 {
Expand Down Expand Up @@ -249,6 +277,7 @@ fileprivate class ABICheckingDelegate: JobExecutionDelegate {

public class PrebuiltModuleGenerationDelegate: JobExecutionDelegate {

fileprivate let jsonDelegate: JSONOutputDelegate
fileprivate let compileDelegate: ModuleCompileDelegate
fileprivate let abiCheckDelegate: ABICheckingDelegate

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

public init(_ jobs: [Job], _ diagnosticsEngine: DiagnosticsEngine,
_ verbose: Bool, _ logPath: AbsolutePath?) {
self.compileDelegate = ModuleCompileDelegate(jobs.filter(ModuleCompileDelegate.canHandle), diagnosticsEngine, verbose, logPath)
self.jsonDelegate = JSONOutputDelegate()
self.compileDelegate = ModuleCompileDelegate(jobs.filter(ModuleCompileDelegate.canHandle),
diagnosticsEngine, verbose, logPath,
self.jsonDelegate)
self.abiCheckDelegate = ABICheckingDelegate(verbose, logPath)
}

Expand All @@ -285,6 +317,13 @@ public class PrebuiltModuleGenerationDelegate: JobExecutionDelegate {
public var hasCriticalFailure: Bool {
return compileDelegate.hasCriticalFailure
}
public func emitJsonOutput(to path: AbsolutePath) throws {
let data = try JSONEncoder().encode(self.jsonDelegate)
if let json = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers),
let jsonData = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) {
try localFileSystem.writeFileContents(path, bytes: ByteString(jsonData))
}
}
}

public struct PrebuiltModuleInput {
Expand Down
6 changes: 6 additions & 0 deletions Sources/swift-build-sdk-interfaces/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ do {
exit(1)
}
let logDir = try getArgumentAsPath("-log-path")
let jsonPath = try getArgumentAsPath("-json-path")
let collector = SDKPrebuiltModuleInputsCollector(sdkPath, diagnosticsEngine)
var outputDir = try VirtualPath(path: rawOutputDir).absolutePath!
// if the given output dir ends with 'prebuilt-modules', we should
Expand Down Expand Up @@ -174,6 +175,11 @@ do {
exit(0)
}
let delegate = PrebuiltModuleGenerationDelegate(jobs, diagnosticsEngine, verbose, logDir)
defer {
if let jsonPath = jsonPath {
try! delegate.emitJsonOutput(to: jsonPath)
}
}
do {
try executor.execute(workload: DriverExecutorWorkload.init(jobs, nil, continueBuildingAfterErrors: true),
delegate: delegate, numParallelJobs: 128)
Expand Down