Skip to content

Commit 6b6685c

Browse files
committed
Dependencies: Handle empty dependency trace file in parsing
1 parent 3b99c6f commit 6b6685c

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Sources/SWBTaskExecution/TaskActions/ClangCompileTaskAction.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
485485
let traceData = try parseTraceData(Data(fileSystem.read(traceFilePath))) {
486486

487487
switch traceData {
488-
case let .V1(traceDataV1):
488+
case .empty:
489+
payload = .clangDependencies(imports: [], includes: [])
490+
case let .v1(traceDataV1):
489491
// mapping each header path to the set of locations that include it
490492
var allFiles = [Path: Set<SWBUtil.Diagnostic.Location>]();
491493

@@ -500,7 +502,7 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
500502
let includes = allFiles.map { file, locations in DependencyValidationInfo.Include(path: file, includeLocations: Array(locations)) }
501503
payload = .clangDependencies(imports: [], includes: includes)
502504
}
503-
case let .V2(traceDataV2):
505+
case let .v2(traceDataV2):
504506
var allIncludes = [Path: Set<SWBUtil.Diagnostic.Location>]();
505507
var allImports = [String: Set<SWBUtil.Diagnostic.Location>]();
506508

@@ -617,16 +619,21 @@ public final class ClangNonModularCompileTaskAction: TaskAction {
617619
}
618620

619621
fileprivate func parseTraceData(_ data: Data) throws -> TraceData? {
622+
// clang will emit an empty file instead of an empty array when there's nothing to trace
623+
if data.isEmpty {
624+
return .empty
625+
}
626+
620627
let jsonObject = try PropertyList.fromJSONData(data)
621628
if let version = jsonObject.dictValue?["version"]?.stringValue {
622629
if version == "2.0.0" {
623-
return .V2(try JSONDecoder().decode(TraceData.TraceFileV2.self, from: data))
630+
return .v2(try JSONDecoder().decode(TraceData.TraceFileV2.self, from: data))
624631
}
625632
return nil
626633
} else {
627634
// The initial unversioned format (v1) of the trace file generated from clang
628635
// is a JSON array so deserializing it as a dictionary will fail.
629-
return .V1(try JSONDecoder().decode(TraceData.TraceFileV1.self, from: data))
636+
return .v1(try JSONDecoder().decode(TraceData.TraceFileV1.self, from: data))
630637
}
631638
}
632639

@@ -675,6 +682,7 @@ fileprivate enum TraceData: Decodable {
675682
let dependencies: [TraceDataObjectV2]
676683
}
677684

678-
case V1(TraceFileV1)
679-
case V2(TraceFileV2)
685+
case empty
686+
case v1(TraceFileV1)
687+
case v2(TraceFileV2)
680688
}

0 commit comments

Comments
 (0)