@@ -590,7 +590,7 @@ mapFrontendInvocationToAction(const CompilerInvocation &Invocation) {
590590
591591static DetailedTaskDescription
592592constructDetailedTaskDescription (const CompilerInvocation &Invocation,
593- const InputFile &PrimaryInput ,
593+ ArrayRef< InputFile> PrimaryInputs ,
594594 ArrayRef<const char *> Args) {
595595 // Command line and arguments
596596 std::string Executable = Invocation.getFrontendOptions ().MainExecutablePath ;
@@ -604,24 +604,30 @@ constructDetailedTaskDescription(const CompilerInvocation &Invocation,
604604 CommandLine += std::string (" " ) + A;
605605 }
606606
607- // Primary Input only
608- Inputs.push_back (CommandInput (PrimaryInput.getFileName ()));
607+ // Primary Inputs
608+ for (const auto &input : PrimaryInputs) {
609+ Inputs.push_back (CommandInput (input.getFileName ()));
610+ }
609611
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));
612+ for (const auto &input : PrimaryInputs) {
613+ // Main outputs
614+ 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+ }
615620
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- });
621+ // Supplementary outputs
622+ const auto &primarySpecificFiles = input.getPrimarySpecificPaths ();
623+ const auto &supplementaryOutputPaths =
624+ primarySpecificFiles.SupplementaryOutputs ;
625+ supplementaryOutputPaths.forEachSetOutput ([&](const std::string &output) {
626+ Outputs.push_back (OutputPair (file_types::lookupTypeForExtension (
627+ llvm::sys::path::extension (output)),
628+ output));
629+ });
630+ }
625631 return DetailedTaskDescription{Executable, Arguments, CommandLine, Inputs,
626632 Outputs};
627633}
@@ -2125,15 +2131,26 @@ int swift::performFrontend(ArrayRef<const char *> Args,
21252131 // making sure it cannot collide with a real PID (always positive). Non-batch
21262132 // compilation gets a real OS PID.
21272133 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- });
2134+
2135+ if (IO.hasPrimaryInputs ()) {
2136+ IO.forEachPrimaryInputWithIndex ([&](const InputFile &Input,
2137+ unsigned idx) -> bool {
2138+ ArrayRef<InputFile> Inputs (Input);
2139+ emitBeganMessage (llvm::errs (),
2140+ mapFrontendInvocationToAction (Invocation),
2141+ constructDetailedTaskDescription (Invocation,
2142+ Inputs,
2143+ Args), Pid - idx,
2144+ ProcInfo);
2145+ return false ;
2146+ });
2147+ } else {
2148+ // If no primary inputs are present, we are in WMO.
2149+ emitBeganMessage (llvm::errs (),
2150+ mapFrontendInvocationToAction (Invocation),
2151+ constructDetailedTaskDescription (Invocation, IO.getAllInputs (), Args),
2152+ OSPid, ProcInfo);
2153+ }
21372154 }
21382155
21392156 int ReturnValue = 0 ;
@@ -2164,23 +2181,41 @@ int swift::performFrontend(ArrayRef<const char *> Args,
21642181 // making sure it cannot collide with a real PID (always positive). Non-batch
21652182 // compilation gets a real OS PID.
21662183 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." );
21712184
2172- // Join all diagnostics produced for this file into a single output.
2173- auto PrimaryDiags = FileSpecificDiagnostics.lookup (Input.getFileName ());
2185+ if (IO.hasPrimaryInputs ()) {
2186+ IO.forEachPrimaryInputWithIndex ([&](const InputFile &Input,
2187+ unsigned idx) -> bool {
2188+ assert (FileSpecificDiagnostics.count (Input.getFileName ()) != 0 &&
2189+ " Expected diagnostic collection for input." );
2190+
2191+ // Join all diagnostics produced for this file into a single output.
2192+ auto PrimaryDiags = FileSpecificDiagnostics.lookup (Input.getFileName ());
2193+ const char *const Delim = " " ;
2194+ std::ostringstream JoinedDiags;
2195+ std::copy (PrimaryDiags.begin (), PrimaryDiags.end (),
2196+ std::ostream_iterator<std::string>(JoinedDiags, Delim));
2197+
2198+ emitFinishedMessage (llvm::errs (),
2199+ mapFrontendInvocationToAction (Invocation),
2200+ JoinedDiags.str (), r, Pid - idx, ProcInfo);
2201+ return false ;
2202+ });
2203+ } else {
2204+ // If no primary inputs are present, we are in WMO.
2205+ std::vector<std::string> AllDiagnostics;
2206+ for (const auto &FileDiagnostics : FileSpecificDiagnostics) {
2207+ AllDiagnostics.insert (AllDiagnostics.end (),
2208+ FileDiagnostics.getValue ().begin (),
2209+ FileDiagnostics.getValue ().end ());
2210+ }
21742211 const char *const Delim = " " ;
21752212 std::ostringstream JoinedDiags;
2176- std::copy (PrimaryDiags .begin (), PrimaryDiags .end (),
2213+ std::copy (AllDiagnostics .begin (), AllDiagnostics .end (),
21772214 std::ostream_iterator<std::string>(JoinedDiags, Delim));
2178-
21792215 emitFinishedMessage (llvm::errs (),
21802216 mapFrontendInvocationToAction (Invocation),
2181- JoinedDiags.str (), r, Pid - idx, ProcInfo);
2182- return false ;
2183- });
2217+ JoinedDiags.str (), r, OSPid, ProcInfo);
2218+ }
21842219 }
21852220
21862221 return r;
0 commit comments