2020#include " swift/Frontend/CompileJobCacheKey.h"
2121#include " swift/Frontend/CompileJobCacheResult.h"
2222#include " swift/Frontend/FrontendOptions.h"
23+ #include " swift/Frontend/MakeStyleDependencies.h"
2324#include " swift/Option/Options.h"
2425#include " clang/CAS/CASOptions.h"
2526#include " clang/CAS/IncludeTree.h"
@@ -135,19 +136,21 @@ lookupCacheKey(ObjectStore &CAS, ActionCache &Cache, ObjectRef CacheKey) {
135136
136137bool replayCachedCompilerOutputs (
137138 ObjectStore &CAS, ActionCache &Cache, ObjectRef BaseKey,
138- DiagnosticEngine &Diag, const FrontendInputsAndOutputs &InputsAndOutputs ,
139+ DiagnosticEngine &Diag, const FrontendOptions &Opts ,
139140 CachingDiagnosticsProcessor &CDP, bool CacheRemarks, bool UseCASBackend) {
140141 bool CanReplayAllOutput = true ;
141142 struct OutputEntry {
142143 std::string Path;
143144 CASID Key;
145+ file_types::ID Kind;
146+ const InputFile &Input;
144147 ObjectProxy Proxy;
145148 };
146149 SmallVector<OutputEntry> OutputProxies;
147150 std::optional<OutputEntry> DiagnosticsOutput;
148- std::string ObjFile;
149151
150- auto replayOutputsForInputFile = [&](const std::string &InputPath,
152+ auto replayOutputsForInputFile = [&](const InputFile &Input,
153+ const std::string &InputPath,
151154 unsigned InputIndex,
152155 const DenseMap<file_types::ID,
153156 std::string> &Outputs) {
@@ -190,15 +193,13 @@ bool replayCachedCompilerOutputs(
190193 if (!Proxy)
191194 return Proxy.takeError ();
192195
193- if (Kind == file_types::ID::TY_Object && UseCASBackend)
194- ObjFile = OutputPath->second ;
195-
196196 if (Kind == file_types::ID::TY_CachedDiagnostics) {
197197 assert (!DiagnosticsOutput && " more than 1 diagnotics found" );
198- DiagnosticsOutput = OutputEntry{OutputPath->second , OutID, *Proxy};
198+ DiagnosticsOutput.emplace (
199+ OutputEntry{OutputPath->second , OutID, Kind, Input, *Proxy});
199200 } else
200201 OutputProxies.emplace_back (
201- OutputEntry{OutputPath->second , OutID, *Proxy});
202+ OutputEntry{OutputPath->second , OutID, Kind, Input, *Proxy});
202203 return Error::success ();
203204 })) {
204205 Diag.diagnose (SourceLoc (), diag::error_cas, toString (std::move (Err)));
@@ -211,7 +212,7 @@ bool replayCachedCompilerOutputs(
211212 auto InputPath = Input.getFileName ();
212213 DenseMap<file_types::ID, std::string> Outputs;
213214 if (!Input.outputFilename ().empty ())
214- Outputs.try_emplace (InputsAndOutputs.getPrincipalOutputType (),
215+ Outputs.try_emplace (Opts. InputsAndOutputs .getPrincipalOutputType (),
215216 Input.outputFilename ());
216217
217218 Input.getPrimarySpecificPaths ()
@@ -233,15 +234,15 @@ bool replayCachedCompilerOutputs(
233234 Outputs.try_emplace (file_types::ID::TY_CachedDiagnostics,
234235 " <cached-diagnostics>" );
235236
236- return replayOutputsForInputFile (InputPath, InputIndex, Outputs);
237+ return replayOutputsForInputFile (Input, InputPath, InputIndex, Outputs);
237238 };
238239
239- auto AllInputs = InputsAndOutputs.getAllInputs ();
240+ auto AllInputs = Opts. InputsAndOutputs .getAllInputs ();
240241 // If there are primary inputs, look up only the primary input files.
241242 // Otherwise, prepare to do cache lookup for all inputs.
242243 for (unsigned Index = 0 ; Index < AllInputs.size (); ++Index) {
243244 const auto &Input = AllInputs[Index];
244- if (InputsAndOutputs.hasPrimaryInputs () && !Input.isPrimary ())
245+ if (Opts. InputsAndOutputs .hasPrimaryInputs () && !Input.isPrimary ())
245246 continue ;
246247
247248 replayOutputFromInput (Input, Index);
@@ -255,8 +256,9 @@ bool replayCachedCompilerOutputs(
255256 // diagnostics from first file.
256257 if (!DiagnosticsOutput)
257258 replayOutputsForInputFile (
259+ Opts.InputsAndOutputs .getFirstOutputProducingInput (),
258260 " <cached-diagnostics>" ,
259- InputsAndOutputs.getIndexOfFirstOutputProducingInput (),
261+ Opts. InputsAndOutputs .getIndexOfFirstOutputProducingInput (),
260262 {{file_types::ID::TY_CachedDiagnostics, " <cached-diagnostics>" }});
261263
262264 // Check again to make sure diagnostics is fetched successfully.
@@ -287,10 +289,16 @@ bool replayCachedCompilerOutputs(
287289 continue ;
288290 }
289291
290- if (UseCASBackend && Output.Path == ObjFile ) {
292+ if (UseCASBackend && Output.Kind == file_types::ID::TY_Object ) {
291293 auto Schema = std::make_unique<llvm::mccasformats::v1::MCSchema>(CAS);
292- if (auto E = Schema->serializeObjectFile (Output.Proxy , *File))
294+ if (auto E = Schema->serializeObjectFile (Output.Proxy , *File)) {
293295 Diag.diagnose (SourceLoc (), diag::error_mccas, toString (std::move (E)));
296+ return false ;
297+ }
298+ } else if (Output.Kind == file_types::ID::TY_Dependencies) {
299+ if (emitMakeDependenciesFromSerializedBuffer (
300+ Output.Proxy .getData (), *File, Opts, Output.Input , Diag))
301+ return false ;
294302 } else
295303 *File << Output.Proxy .getData ();
296304
0 commit comments