@@ -492,7 +492,9 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
492
492
}
493
493
494
494
switch traceData {
495
- case let . V1( traceDataV1) :
495
+ case . empty:
496
+ payload = . clangDependencies( imports: [ ] , includes: [ ] )
497
+ case let . v1( traceDataV1) :
496
498
// mapping each header path to the set of locations that include it
497
499
var allFiles = [ Path : Set < SWBUtil . Diagnostic . Location > ] ( ) ;
498
500
@@ -510,7 +512,7 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
510
512
outputDelegate. incrementTaskCounter ( . headerDependenciesScanned, by: includes. count)
511
513
payload = . clangDependencies( imports: [ ] , includes: includes)
512
514
}
513
- case let . V2 ( traceDataV2) :
515
+ case let . v2 ( traceDataV2) :
514
516
var allIncludes = [ Path : Set < SWBUtil . Diagnostic . Location > ] ( ) ;
515
517
var allImports = [ String : Set < SWBUtil . Diagnostic . Location > ] ( ) ;
516
518
@@ -634,16 +636,21 @@ public final class ClangNonModularCompileTaskAction: TaskAction {
634
636
}
635
637
636
638
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
+
637
644
let jsonObject = try PropertyList . fromJSONData ( data)
638
645
if let version = jsonObject. dictValue ? [ " version " ] ? . stringValue {
639
646
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) )
641
648
}
642
649
return nil
643
650
} else {
644
651
// The initial unversioned format (v1) of the trace file generated from clang
645
652
// 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) )
647
654
}
648
655
}
649
656
@@ -692,6 +699,7 @@ fileprivate enum TraceData: Decodable {
692
699
let dependencies : [ TraceDataObjectV2 ]
693
700
}
694
701
695
- case V1( TraceFileV1 )
696
- case V2( TraceFileV2 )
702
+ case empty
703
+ case v1( TraceFileV1 )
704
+ case v2( TraceFileV2 )
697
705
}
0 commit comments