@@ -537,7 +537,7 @@ static bool emitReferenceDependencies(CompilerInstance &Instance,
537
537
});
538
538
}
539
539
540
- static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded (
540
+ static void emitSwiftdepsForAllPrimaryInputsIfNeeded (
541
541
CompilerInstance &Instance) {
542
542
const auto &Invocation = Instance.getInvocation ();
543
543
if (Invocation.getFrontendOptions ()
@@ -547,6 +547,22 @@ static void emitReferenceDependenciesForAllPrimaryInputsIfNeeded(
547
547
SourceLoc (), diag::emit_reference_dependencies_without_primary_file);
548
548
return ;
549
549
}
550
+
551
+ // Do not write out swiftdeps for any primaries if we've encountered an
552
+ // error. Without this, the driver will attempt to integrate swiftdeps
553
+ // from broken swift files. One way this could go wrong is if a primary that
554
+ // fails to build in an early wave has dependents in a later wave. The
555
+ // driver will not schedule those later dependents after this batch exits,
556
+ // so they will have no opportunity to bring their swiftdeps files up to
557
+ // date. With this early exit, the driver sees the same priors in the
558
+ // swiftdeps files from before errors were introduced into the batch, and
559
+ // integration therefore always hops from "known good" to "known good" states.
560
+ //
561
+ // FIXME: It seems more appropriate for the driver to notice the early-exit
562
+ // and react by always enqueuing the jobs it dropped in the other waves.
563
+ if (Instance.getDiags ().hadAnyError ())
564
+ return ;
565
+
550
566
for (auto *SF : Instance.getPrimarySourceFiles ()) {
551
567
const std::string &referenceDependenciesFilePath =
552
568
Invocation.getReferenceDependenciesFilePathForPrimary (
@@ -955,8 +971,10 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
955
971
emitIndexData (Instance);
956
972
}
957
973
958
- // Emit dependencies.
959
- emitReferenceDependenciesForAllPrimaryInputsIfNeeded (Instance);
974
+ // Emit Swiftdeps for every file in the batch.
975
+ emitSwiftdepsForAllPrimaryInputsIfNeeded (Instance);
976
+
977
+ // Emit Make-style dependencies.
960
978
emitMakeDependenciesIfNeeded (Instance.getDiags (),
961
979
Instance.getDependencyTracker (), opts);
962
980
0 commit comments