@@ -590,7 +590,7 @@ mapFrontendInvocationToAction(const CompilerInvocation &Invocation) {
590
590
591
591
static DetailedTaskDescription
592
592
constructDetailedTaskDescription (const CompilerInvocation &Invocation,
593
- const InputFile &PrimaryInput ,
593
+ ArrayRef< InputFile> PrimaryInputs ,
594
594
ArrayRef<const char *> Args) {
595
595
// Command line and arguments
596
596
std::string Executable = Invocation.getFrontendOptions ().MainExecutablePath ;
@@ -604,24 +604,30 @@ constructDetailedTaskDescription(const CompilerInvocation &Invocation,
604
604
CommandLine += std::string (" " ) + A;
605
605
}
606
606
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
+ }
609
611
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
+ }
615
620
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
+ }
625
631
return DetailedTaskDescription{Executable, Arguments, CommandLine, Inputs,
626
632
Outputs};
627
633
}
@@ -2125,15 +2131,26 @@ int swift::performFrontend(ArrayRef<const char *> Args,
2125
2131
// making sure it cannot collide with a real PID (always positive). Non-batch
2126
2132
// compilation gets a real OS PID.
2127
2133
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
+ }
2137
2154
}
2138
2155
2139
2156
int ReturnValue = 0 ;
@@ -2164,23 +2181,41 @@ int swift::performFrontend(ArrayRef<const char *> Args,
2164
2181
// making sure it cannot collide with a real PID (always positive). Non-batch
2165
2182
// compilation gets a real OS PID.
2166
2183
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
2184
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
+ }
2174
2211
const char *const Delim = " " ;
2175
2212
std::ostringstream JoinedDiags;
2176
- std::copy (PrimaryDiags .begin (), PrimaryDiags .end (),
2213
+ std::copy (AllDiagnostics .begin (), AllDiagnostics .end (),
2177
2214
std::ostream_iterator<std::string>(JoinedDiags, Delim));
2178
-
2179
2215
emitFinishedMessage (llvm::errs (),
2180
2216
mapFrontendInvocationToAction (Invocation),
2181
- JoinedDiags.str (), r, Pid - idx, ProcInfo);
2182
- return false ;
2183
- });
2217
+ JoinedDiags.str (), r, OSPid, ProcInfo);
2218
+ }
2184
2219
}
2185
2220
2186
2221
return r;
0 commit comments