@@ -50,9 +50,8 @@ enum class SwiftCacheToolAction {
5050
5151struct OutputEntry {
5252 std::string InputPath;
53- std::string OutputPath;
54- std::string OutputKind;
5553 std::string CacheKey;
54+ std::vector<std::pair<std::string, std::string>> Outputs;
5655};
5756
5857enum ID {
@@ -285,44 +284,41 @@ int SwiftCacheToolInvocation::printOutputKeys() {
285284
286285 std::vector<OutputEntry> OutputKeys;
287286 bool hasError = false ;
288- auto addOutputKey = [&](StringRef InputPath, file_types::ID OutputKind,
289- StringRef OutputPath) {
287+ auto addFromInputFile = [&](const InputFile &Input) {
288+ auto InputPath = Input. getFileName ();
290289 auto OutputKey =
291290 createCompileJobCacheKeyForOutput (CAS, *BaseKey, InputPath);
292291 if (!OutputKey) {
293- llvm::errs () << " cannot create cache key for " << OutputPath << " : "
292+ llvm::errs () << " cannot create cache key for " << InputPath << " : "
294293 << toString (OutputKey.takeError ()) << " \n " ;
295294 hasError = true ;
296295 }
297296 OutputKeys.emplace_back (
298- OutputEntry{InputPath.str (), OutputPath.str (),
299- file_types::getTypeName (OutputKind).str (),
300- CAS.getID (*OutputKey).toString ()});
301- };
302- auto addFromInputFile = [&](const InputFile &Input) {
303- auto InputPath = Input.getFileName ();
297+ OutputEntry{InputPath, CAS.getID (*OutputKey).toString (), {}});
298+ auto &Outputs = OutputKeys.back ().Outputs ;
304299 if (!Input.outputFilename ().empty ())
305- addOutputKey (InputPath,
306- Invocation.getFrontendOptions ()
307- .InputsAndOutputs .getPrincipalOutputType (),
308- Input.outputFilename ());
300+ Outputs. emplace_back ( file_types::getTypeName (
301+ Invocation.getFrontendOptions ()
302+ .InputsAndOutputs .getPrincipalOutputType () ),
303+ Input.outputFilename ());
309304 Input.getPrimarySpecificPaths ()
310305 .SupplementaryOutputs .forEachSetOutputAndType (
311306 [&](const std::string &File, file_types::ID ID) {
312307 // Dont print serialized diagnostics.
313308 if (file_types::isProducedFromDiagnostics (ID))
314309 return ;
315-
316- addOutputKey (InputPath, ID, File);
310+ Outputs.emplace_back (file_types::getTypeName (ID), File);
317311 });
318312 };
319313 llvm::for_each (
320314 Invocation.getFrontendOptions ().InputsAndOutputs .getAllInputs (),
321315 addFromInputFile);
322316
323317 // Add diagnostics file.
324- addOutputKey (" <cached-diagnostics>" , file_types::ID::TY_CachedDiagnostics,
325- " <cached-diagnostics>" );
318+ if (!OutputKeys.empty ())
319+ OutputKeys.front ().Outputs .emplace_back (
320+ file_types::getTypeName (file_types::ID::TY_CachedDiagnostics),
321+ " <cached-diagnostics>" );
326322
327323 if (hasError)
328324 return 1 ;
@@ -331,10 +327,16 @@ int SwiftCacheToolInvocation::printOutputKeys() {
331327 Out.array ([&] {
332328 for (const auto &E : OutputKeys) {
333329 Out.object ([&] {
334- Out.attribute (" OutputPath" , E.OutputPath );
335- Out.attribute (" OutputKind" , E.OutputKind );
336330 Out.attribute (" Input" , E.InputPath );
337331 Out.attribute (" CacheKey" , E.CacheKey );
332+ Out.attributeArray (" Outputs" , [&] {
333+ for (const auto &OutEntry : E.Outputs ) {
334+ Out.object ([&] {
335+ Out.attribute (" Kind" , OutEntry.first );
336+ Out.attribute (" Path" , OutEntry.second );
337+ });
338+ }
339+ });
338340 });
339341 }
340342 });
0 commit comments