@@ -588,9 +588,32 @@ 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
- const InputFile &PrimaryInput ,
616
+ ArrayRef< InputFile> PrimaryInputs ,
594
617
ArrayRef<const char *> Args) {
595
618
// Command line and arguments
596
619
std::string Executable = Invocation.getFrontendOptions ().MainExecutablePath ;
@@ -604,24 +627,25 @@ constructDetailedTaskDescription(const CompilerInvocation &Invocation,
604
627
CommandLine += std::string (" " ) + A;
605
628
}
606
629
607
- // Primary Input only
608
- Inputs.push_back (CommandInput (PrimaryInput.getFileName ()));
630
+ // Primary Inputs
631
+ for (const auto &input : PrimaryInputs) {
632
+ Inputs.push_back (CommandInput (input.getFileName ()));
633
+ }
609
634
610
- // Output for this Primary
611
- auto OutputFile = PrimaryInput. outputFilename ();
612
- Outputs. push_back ( OutputPair ( file_types::lookupTypeForExtension (
613
- llvm::sys::path::extension ( OutputFile)),
614
- OutputFile));
635
+ for ( const auto &input : PrimaryInputs) {
636
+ // Main outputs
637
+ auto OutputFile = input. outputFilename ();
638
+ if (! OutputFile. empty ())
639
+ Outputs. push_back ( OutputPair ( computeFileTypeForPath (OutputFile), OutputFile));
615
640
616
- // Supplementary outputs
617
- const auto &primarySpecificFiles = PrimaryInput.getPrimarySpecificPaths ();
618
- const auto &supplementaryOutputPaths =
619
- primarySpecificFiles.SupplementaryOutputs ;
620
- supplementaryOutputPaths.forEachSetOutput ([&](const std::string &output) {
621
- Outputs.push_back (OutputPair (
622
- file_types::lookupTypeForExtension (llvm::sys::path::extension (output)),
623
- output));
624
- });
641
+ // Supplementary outputs
642
+ const auto &primarySpecificFiles = input.getPrimarySpecificPaths ();
643
+ const auto &supplementaryOutputPaths =
644
+ primarySpecificFiles.SupplementaryOutputs ;
645
+ supplementaryOutputPaths.forEachSetOutput ([&](const std::string &output) {
646
+ Outputs.push_back (OutputPair (computeFileTypeForPath (output), output));
647
+ });
648
+ }
625
649
return DetailedTaskDescription{Executable, Arguments, CommandLine, Inputs,
626
650
Outputs};
627
651
}
@@ -2125,15 +2149,26 @@ int swift::performFrontend(ArrayRef<const char *> Args,
2125
2149
// making sure it cannot collide with a real PID (always positive). Non-batch
2126
2150
// compilation gets a real OS PID.
2127
2151
int64_t Pid = IO.hasUniquePrimaryInput () ? OSPid : QUASI_PID_START;
2128
- IO.forEachPrimaryInputWithIndex ([&](const InputFile &Input,
2129
- unsigned idx) -> bool {
2130
- emitBeganMessage (
2131
- llvm::errs (),
2132
- mapFrontendInvocationToAction (Invocation),
2133
- constructDetailedTaskDescription (Invocation, Input, Args), Pid - idx,
2134
- ProcInfo);
2135
- return false ;
2136
- });
2152
+
2153
+ if (IO.hasPrimaryInputs ()) {
2154
+ IO.forEachPrimaryInputWithIndex ([&](const InputFile &Input,
2155
+ unsigned idx) -> bool {
2156
+ ArrayRef<InputFile> Inputs (Input);
2157
+ emitBeganMessage (llvm::errs (),
2158
+ mapFrontendInvocationToAction (Invocation),
2159
+ constructDetailedTaskDescription (Invocation,
2160
+ Inputs,
2161
+ Args), Pid - idx,
2162
+ ProcInfo);
2163
+ return false ;
2164
+ });
2165
+ } else {
2166
+ // If no primary inputs are present, we are in WMO.
2167
+ emitBeganMessage (llvm::errs (),
2168
+ mapFrontendInvocationToAction (Invocation),
2169
+ constructDetailedTaskDescription (Invocation, IO.getAllInputs (), Args),
2170
+ OSPid, ProcInfo);
2171
+ }
2137
2172
}
2138
2173
2139
2174
int ReturnValue = 0 ;
@@ -2164,23 +2199,41 @@ int swift::performFrontend(ArrayRef<const char *> Args,
2164
2199
// making sure it cannot collide with a real PID (always positive). Non-batch
2165
2200
// compilation gets a real OS PID.
2166
2201
int64_t Pid = IO.hasUniquePrimaryInput () ? OSPid : QUASI_PID_START;
2167
- IO.forEachPrimaryInputWithIndex ([&](const InputFile &Input,
2168
- unsigned idx) -> bool {
2169
- assert (FileSpecificDiagnostics.count (Input.getFileName ()) != 0 &&
2170
- " Expected diagnostic collection for input." );
2171
2202
2172
- // Join all diagnostics produced for this file into a single output.
2173
- auto PrimaryDiags = FileSpecificDiagnostics.lookup (Input.getFileName ());
2203
+ if (IO.hasPrimaryInputs ()) {
2204
+ IO.forEachPrimaryInputWithIndex ([&](const InputFile &Input,
2205
+ unsigned idx) -> bool {
2206
+ assert (FileSpecificDiagnostics.count (Input.getFileName ()) != 0 &&
2207
+ " Expected diagnostic collection for input." );
2208
+
2209
+ // Join all diagnostics produced for this file into a single output.
2210
+ auto PrimaryDiags = FileSpecificDiagnostics.lookup (Input.getFileName ());
2211
+ const char *const Delim = " " ;
2212
+ std::ostringstream JoinedDiags;
2213
+ std::copy (PrimaryDiags.begin (), PrimaryDiags.end (),
2214
+ std::ostream_iterator<std::string>(JoinedDiags, Delim));
2215
+
2216
+ emitFinishedMessage (llvm::errs (),
2217
+ mapFrontendInvocationToAction (Invocation),
2218
+ JoinedDiags.str (), r, Pid - idx, ProcInfo);
2219
+ return false ;
2220
+ });
2221
+ } else {
2222
+ // If no primary inputs are present, we are in WMO.
2223
+ std::vector<std::string> AllDiagnostics;
2224
+ for (const auto &FileDiagnostics : FileSpecificDiagnostics) {
2225
+ AllDiagnostics.insert (AllDiagnostics.end (),
2226
+ FileDiagnostics.getValue ().begin (),
2227
+ FileDiagnostics.getValue ().end ());
2228
+ }
2174
2229
const char *const Delim = " " ;
2175
2230
std::ostringstream JoinedDiags;
2176
- std::copy (PrimaryDiags .begin (), PrimaryDiags .end (),
2231
+ std::copy (AllDiagnostics .begin (), AllDiagnostics .end (),
2177
2232
std::ostream_iterator<std::string>(JoinedDiags, Delim));
2178
-
2179
2233
emitFinishedMessage (llvm::errs (),
2180
2234
mapFrontendInvocationToAction (Invocation),
2181
- JoinedDiags.str (), r, Pid - idx, ProcInfo);
2182
- return false ;
2183
- });
2235
+ JoinedDiags.str (), r, OSPid, ProcInfo);
2236
+ }
2184
2237
}
2185
2238
2186
2239
return r;
0 commit comments