@@ -485,7 +485,9 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
485
485
let traceData = try parseTraceData ( Data ( fileSystem. read ( traceFilePath) ) ) {
486
486
487
487
switch traceData {
488
- case let . V1( traceDataV1) :
488
+ case . empty:
489
+ payload = . clangDependencies( imports: [ ] , includes: [ ] )
490
+ case let . v1( traceDataV1) :
489
491
// mapping each header path to the set of locations that include it
490
492
var allFiles = [ Path : Set < SWBUtil . Diagnostic . Location > ] ( ) ;
491
493
@@ -500,7 +502,7 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
500
502
let includes = allFiles. map { file, locations in DependencyValidationInfo . Include ( path: file, includeLocations: Array ( locations) ) }
501
503
payload = . clangDependencies( imports: [ ] , includes: includes)
502
504
}
503
- case let . V2 ( traceDataV2) :
505
+ case let . v2 ( traceDataV2) :
504
506
var allIncludes = [ Path : Set < SWBUtil . Diagnostic . Location > ] ( ) ;
505
507
var allImports = [ String : Set < SWBUtil . Diagnostic . Location > ] ( ) ;
506
508
@@ -617,16 +619,21 @@ public final class ClangNonModularCompileTaskAction: TaskAction {
617
619
}
618
620
619
621
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
+
620
627
let jsonObject = try PropertyList . fromJSONData ( data)
621
628
if let version = jsonObject. dictValue ? [ " version " ] ? . stringValue {
622
629
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) )
624
631
}
625
632
return nil
626
633
} else {
627
634
// The initial unversioned format (v1) of the trace file generated from clang
628
635
// 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) )
630
637
}
631
638
}
632
639
@@ -675,6 +682,7 @@ fileprivate enum TraceData: Decodable {
675
682
let dependencies : [ TraceDataObjectV2 ]
676
683
}
677
684
678
- case V1( TraceFileV1 )
679
- case V2( TraceFileV2 )
685
+ case empty
686
+ case v1( TraceFileV1 )
687
+ case v2( TraceFileV2 )
680
688
}
0 commit comments