Skip to content

Commit c5f62f1

Browse files
sina-mahdavibob-wilson
authored andcommitted
Dependencies: Handle empty dependency trace file in parsing
1 parent a43af46 commit c5f62f1

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
@@ -492,7 +492,9 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
492492
}
493493

494494
switch traceData {
495-
case let .V1(traceDataV1):
495+
case .empty:
496+
payload = .clangDependencies(imports: [], includes: [])
497+
case let .v1(traceDataV1):
496498
// mapping each header path to the set of locations that include it
497499
var allFiles = [Path: Set<SWBUtil.Diagnostic.Location>]();
498500

@@ -510,7 +512,7 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
510512
outputDelegate.incrementTaskCounter(.headerDependenciesScanned, by: includes.count)
511513
payload = .clangDependencies(imports: [], includes: includes)
512514
}
513-
case let .V2(traceDataV2):
515+
case let .v2(traceDataV2):
514516
var allIncludes = [Path: Set<SWBUtil.Diagnostic.Location>]();
515517
var allImports = [String: Set<SWBUtil.Diagnostic.Location>]();
516518

@@ -634,16 +636,21 @@ public final class ClangNonModularCompileTaskAction: TaskAction {
634636
}
635637

636638
fileprivate func parseTraceData(_ data: Data) throws -> TraceData? {
639+
// clang will emit an empty file instead of an empty array when there's nothing to trace
640+
if data.isEmpty {
641+
return .empty
642+
}
643+
637644
let jsonObject = try PropertyList.fromJSONData(data)
638645
if let version = jsonObject.dictValue?["version"]?.stringValue {
639646
if version == "2.0.0" {
640-
return .V2(try JSONDecoder().decode(TraceData.TraceFileV2.self, from: data))
647+
return .v2(try JSONDecoder().decode(TraceData.TraceFileV2.self, from: data))
641648
}
642649
return nil
643650
} else {
644651
// The initial unversioned format (v1) of the trace file generated from clang
645652
// is a JSON array so deserializing it as a dictionary will fail.
646-
return .V1(try JSONDecoder().decode(TraceData.TraceFileV1.self, from: data))
653+
return .v1(try JSONDecoder().decode(TraceData.TraceFileV1.self, from: data))
647654
}
648655
}
649656

@@ -692,6 +699,7 @@ fileprivate enum TraceData: Decodable {
692699
let dependencies: [TraceDataObjectV2]
693700
}
694701

695-
case V1(TraceFileV1)
696-
case V2(TraceFileV2)
702+
case empty
703+
case v1(TraceFileV1)
704+
case v2(TraceFileV2)
697705
}

0 commit comments

Comments
 (0)