@@ -588,6 +588,29 @@ mapFrontendInvocationToAction(const CompilerInvocation &Invocation) {
588588 // StaticLinkJob, DynamicLinkJob
589589}
590590
591+ // TODO: Apply elsewhere in the compiler
592+ static swift::file_types::ID computeFileTypeForPath (const StringRef Path) {
593+ if (!llvm::sys::path::has_extension (Path))
594+ return swift::file_types::ID::TY_INVALID;
595+
596+ auto Extension = llvm::sys::path::extension (Path).str ();
597+ auto FileType = file_types::lookupTypeForExtension (Extension);
598+ if (FileType == swift::file_types::ID::TY_INVALID) {
599+ auto PathStem = llvm::sys::path::stem (Path);
600+ // If this path has a multiple '.' extension (e.g. .abi.json),
601+ // then iterate over all preceeding possible extension variants.
602+ while (llvm::sys::path::has_extension (PathStem)) {
603+ auto NextExtension = llvm::sys::path::extension (PathStem);
604+ Extension = NextExtension.str () + Extension;
605+ FileType = file_types::lookupTypeForExtension (Extension);
606+ if (FileType != swift::file_types::ID::TY_INVALID)
607+ break ;
608+ }
609+ }
610+
611+ return FileType;
612+ }
613+
591614static DetailedTaskDescription
592615constructDetailedTaskDescription (const CompilerInvocation &Invocation,
593616 ArrayRef<InputFile> PrimaryInputs,
@@ -612,20 +635,15 @@ constructDetailedTaskDescription(const CompilerInvocation &Invocation,
612635 for (const auto &input : PrimaryInputs) {
613636 // Main outputs
614637 auto OutputFile = input.outputFilename ();
615- if (!OutputFile.empty ()) {
616- Outputs.push_back (OutputPair (file_types::lookupTypeForExtension (
617- llvm::sys::path::extension (OutputFile)),
618- OutputFile));
619- }
638+ if (!OutputFile.empty ())
639+ Outputs.push_back (OutputPair (computeFileTypeForPath (OutputFile), OutputFile));
620640
621641 // Supplementary outputs
622642 const auto &primarySpecificFiles = input.getPrimarySpecificPaths ();
623643 const auto &supplementaryOutputPaths =
624644 primarySpecificFiles.SupplementaryOutputs ;
625645 supplementaryOutputPaths.forEachSetOutput ([&](const std::string &output) {
626- Outputs.push_back (OutputPair (file_types::lookupTypeForExtension (
627- llvm::sys::path::extension (output)),
628- output));
646+ Outputs.push_back (OutputPair (computeFileTypeForPath (output), output));
629647 });
630648 }
631649 return DetailedTaskDescription{Executable, Arguments, CommandLine, Inputs,
0 commit comments