Skip to content

Commit 1bed53c

Browse files
committed
Produce a warning when the compiler is too old
If VALIDATE_MODULE_DEPENDENCIES is enabled but the version of Clang in the toolchain does not support the necessary header tracing, then report a warning.
1 parent 42d5641 commit 1bed53c

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Sources/SWBCore/Dependencies.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,17 @@ public struct ModuleDependenciesContext: Sendable, SerializableCodable {
8080
self.init(validate: validate, moduleDependencies: settings.moduleDependencies, fixItContext: fixItContext)
8181
}
8282

83-
// For Clang imports, we do not get the import locations and do not know whether it was a public
84-
// import (which depends on whether the import is in an installed header file).
85-
public func makeDiagnostics(files: [Path]) -> [Diagnostic] {
83+
/// For Clang imports, we do not get the import locations and do not know whether it was a public
84+
/// import (which depends on whether the import is in an installed header file).
85+
/// Nil `files` means the current toolchain doesn't have the features to trace imports. This is temporarily required to support running against older toolchains.
86+
public func makeDiagnostics(files: [Path]?) -> [Diagnostic] {
8687
guard validate != .no else { return [] }
88+
guard let files else {
89+
return [Diagnostic(
90+
behavior: .warning,
91+
location: .unknown,
92+
data: DiagnosticData("The current toolchain does not support \(BuiltinMacros.VALIDATE_MODULE_DEPENDENCIES.name)"))]
93+
}
8794

8895
// The following is a provisional/incomplete mechanism for resolving a module dependency from a file path.
8996
// For now, just grab the framework name and assume there is a module with the same name.

Sources/SWBTaskExecution/TaskActions/ClangCompileTaskAction.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,20 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
322322
}
323323
}
324324

325-
if let moduleDependenciesContext, let traceFilePath, lastResult == .succeeded {
325+
if let moduleDependenciesContext, lastResult == .succeeded {
326326
// Verify the dependencies from the trace data.
327-
let fs = executionDelegate.fs
328-
let traceData = try JSONDecoder().decode(Array<TraceData>.self, from: Data(fs.read(traceFilePath)))
329-
330-
var allFiles = Set<Path>()
331-
traceData.forEach { allFiles.formUnion(Set($0.includes)) }
332-
let diagnostics = moduleDependenciesContext.makeDiagnostics(files: Array(allFiles))
327+
let files: [Path]?
328+
if let traceFilePath {
329+
let fs = executionDelegate.fs
330+
let traceData = try JSONDecoder().decode(Array<TraceData>.self, from: Data(fs.read(traceFilePath)))
331+
332+
var allFiles = Set<Path>()
333+
traceData.forEach { allFiles.formUnion(Set($0.includes)) }
334+
files = Array(allFiles)
335+
} else {
336+
files = nil
337+
}
338+
let diagnostics = moduleDependenciesContext.makeDiagnostics(files: files)
333339
for diagnostic in diagnostics {
334340
outputDelegate.emit(diagnostic)
335341
}

0 commit comments

Comments
 (0)