@@ -588,6 +588,29 @@ mapFrontendInvocationToAction(const CompilerInvocation &Invocation) {
588
588
// StaticLinkJob, DynamicLinkJob
589
589
}
590
590
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
+
591
614
static DetailedTaskDescription
592
615
constructDetailedTaskDescription (const CompilerInvocation &Invocation,
593
616
ArrayRef<InputFile> PrimaryInputs,
@@ -612,20 +635,15 @@ constructDetailedTaskDescription(const CompilerInvocation &Invocation,
612
635
for (const auto &input : PrimaryInputs) {
613
636
// Main outputs
614
637
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));
620
640
621
641
// Supplementary outputs
622
642
const auto &primarySpecificFiles = input.getPrimarySpecificPaths ();
623
643
const auto &supplementaryOutputPaths =
624
644
primarySpecificFiles.SupplementaryOutputs ;
625
645
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));
629
647
});
630
648
}
631
649
return DetailedTaskDescription{Executable, Arguments, CommandLine, Inputs,
0 commit comments