Skip to content

PrebuiltModuleGen: run dangling jobs only when Foundation is built successfully for macabi #601

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
Apr 14, 2021
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
20 changes: 15 additions & 5 deletions Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
import TSCBasic
import SwiftOptions

func isIosMac(_ path: TypedVirtualPath) -> Bool {
// Infer macabi interfaces by the file name.
// FIXME: more robust way to do this.
return path.file.basenameWithoutExt.contains("macabi")
}

public class PrebuitModuleGenerationDelegate: JobExecutionDelegate {
var failingModules = Set<String>()
var succeededJobs: [Job] = []
var commandMap: [Int: String] = [:]
let diagnosticsEngine: DiagnosticsEngine
let verbose: Bool
Expand All @@ -22,6 +29,13 @@ public class PrebuitModuleGenerationDelegate: JobExecutionDelegate {
self.verbose = verbose
}

/// Dangling jobs are macabi-only modules. We should run those jobs if foundation
/// is built successfully for macabi.
public var shouldRunDanglingJobs: Bool {
return succeededJobs.contains { job in
return isIosMac(job.outputs[0]) && job.moduleName == "Foundation"
}
}
func printJobInfo(_ job: Job, _ start: Bool) {
guard verbose else {
return
Expand Down Expand Up @@ -54,6 +68,7 @@ public class PrebuitModuleGenerationDelegate: JobExecutionDelegate {
case .terminated(code: let code):
if code == 0 {
printJobInfo(job, false)
succeededJobs.append(job)
} else {
failingModules.insert(job.moduleName)
let result: String = try! result.utf8stderrOutput()
Expand Down Expand Up @@ -224,11 +239,6 @@ extension Driver {
_ inputPath: PrebuiltModuleInput, _ outputPath: PrebuiltModuleOutput,
_ dependencies: [TypedVirtualPath]) throws -> Job {
assert(inputPath.path.file.basenameWithoutExt == outputPath.path.file.basenameWithoutExt)
func isIosMac(_ path: TypedVirtualPath) -> Bool {
// Infer macabi interfaces by the file name.
// FIXME: more robust way to do this.
return path.file.basenameWithoutExt.contains("macabi")
}
var commandLine: [Job.ArgTemplate] = []
commandLine.appendFlag(.compileModuleFromInterface)
commandLine.appendFlag(.sdk)
Expand Down
4 changes: 3 additions & 1 deletion Sources/swift-build-sdk-interfaces/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ do {
}
}
do {
try executor.execute(workload: DriverExecutorWorkload.init(danglingJobs, nil, continueBuildingAfterErrors: true), delegate: delegate, numParallelJobs: 128)
if !danglingJobs.isEmpty && delegate.shouldRunDanglingJobs {
try executor.execute(workload: DriverExecutorWorkload.init(danglingJobs, nil, continueBuildingAfterErrors: true), delegate: delegate, numParallelJobs: 128)
}
} catch {
// Failing of dangling jobs don't fail the process.
exit(0)
Expand Down