mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/main' into rebranch
This commit is contained in:
@@ -2092,6 +2092,85 @@ int swift::performFrontend(ArrayRef<const char *> Args,
|
||||
PDC.setSuppressOutput(true);
|
||||
}
|
||||
|
||||
auto emitParseableBeganMessage = [&Invocation, &Args]() {
|
||||
const auto &IO = Invocation.getFrontendOptions().InputsAndOutputs;
|
||||
const auto OSPid = getpid();
|
||||
const auto ProcInfo = sys::TaskProcessInformation(OSPid);
|
||||
|
||||
// Parseable output clients may not understand the idea of a batch
|
||||
// compilation. We assign each primary in a batch job a quasi process id,
|
||||
// making sure it cannot collide with a real PID (always positive). Non-batch
|
||||
// compilation gets a real OS PID.
|
||||
int64_t Pid = IO.hasUniquePrimaryInput() ? OSPid : QUASI_PID_START;
|
||||
|
||||
if (IO.hasPrimaryInputs()) {
|
||||
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
|
||||
unsigned idx) -> bool {
|
||||
ArrayRef<InputFile> Inputs(Input);
|
||||
emitBeganMessage(llvm::errs(),
|
||||
mapFrontendInvocationToAction(Invocation),
|
||||
constructDetailedTaskDescription(Invocation,
|
||||
Inputs,
|
||||
Args), Pid - idx,
|
||||
ProcInfo);
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
// If no primary inputs are present, we are in WMO.
|
||||
emitBeganMessage(llvm::errs(),
|
||||
mapFrontendInvocationToAction(Invocation),
|
||||
constructDetailedTaskDescription(Invocation, IO.getAllInputs(), Args),
|
||||
OSPid, ProcInfo);
|
||||
}
|
||||
};
|
||||
|
||||
auto emitParseableFinishedMessage = [&Invocation, &Args, &FileSpecificDiagnostics](int ExitStatus) {
|
||||
const auto &IO = Invocation.getFrontendOptions().InputsAndOutputs;
|
||||
const auto OSPid = getpid();
|
||||
const auto ProcInfo = sys::TaskProcessInformation(OSPid);
|
||||
|
||||
// Parseable output clients may not understand the idea of a batch
|
||||
// compilation. We assign each primary in a batch job a quasi process id,
|
||||
// making sure it cannot collide with a real PID (always positive). Non-batch
|
||||
// compilation gets a real OS PID.
|
||||
int64_t Pid = IO.hasUniquePrimaryInput() ? OSPid : QUASI_PID_START;
|
||||
|
||||
if (IO.hasPrimaryInputs()) {
|
||||
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
|
||||
unsigned idx) -> bool {
|
||||
assert(FileSpecificDiagnostics.count(Input.getFileName()) != 0 &&
|
||||
"Expected diagnostic collection for input.");
|
||||
|
||||
// Join all diagnostics produced for this file into a single output.
|
||||
auto PrimaryDiags = FileSpecificDiagnostics.lookup(Input.getFileName());
|
||||
const char *const Delim = "";
|
||||
std::ostringstream JoinedDiags;
|
||||
std::copy(PrimaryDiags.begin(), PrimaryDiags.end(),
|
||||
std::ostream_iterator<std::string>(JoinedDiags, Delim));
|
||||
|
||||
emitFinishedMessage(llvm::errs(),
|
||||
mapFrontendInvocationToAction(Invocation),
|
||||
JoinedDiags.str(), ExitStatus, Pid - idx, ProcInfo);
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
// If no primary inputs are present, we are in WMO.
|
||||
std::vector<std::string> AllDiagnostics;
|
||||
for (const auto &FileDiagnostics : FileSpecificDiagnostics) {
|
||||
AllDiagnostics.insert(AllDiagnostics.end(),
|
||||
FileDiagnostics.getValue().begin(),
|
||||
FileDiagnostics.getValue().end());
|
||||
}
|
||||
const char *const Delim = "";
|
||||
std::ostringstream JoinedDiags;
|
||||
std::copy(AllDiagnostics.begin(), AllDiagnostics.end(),
|
||||
std::ostream_iterator<std::string>(JoinedDiags, Delim));
|
||||
emitFinishedMessage(llvm::errs(),
|
||||
mapFrontendInvocationToAction(Invocation),
|
||||
JoinedDiags.str(), ExitStatus, OSPid, ProcInfo);
|
||||
}
|
||||
};
|
||||
|
||||
// Because the serialized diagnostics consumer is initialized here,
|
||||
// diagnostics emitted above, within CompilerInvocation::parseArgs, are never
|
||||
// serialized. This is a non-issue because, in nearly all cases, frontend
|
||||
@@ -2122,12 +2201,20 @@ int swift::performFrontend(ArrayRef<const char *> Args,
|
||||
llvm::EnableStatistics();
|
||||
}
|
||||
|
||||
|
||||
if (Invocation.getFrontendOptions().FrontendParseableOutput)
|
||||
emitParseableBeganMessage();
|
||||
|
||||
const DiagnosticOptions &diagOpts = Invocation.getDiagnosticOptions();
|
||||
bool verifierEnabled = diagOpts.VerifyMode != DiagnosticOptions::NoVerify;
|
||||
|
||||
std::string InstanceSetupError;
|
||||
if (Instance->setup(Invocation, InstanceSetupError)) {
|
||||
return finishDiagProcessing(1, /*verifierEnabled*/ false);
|
||||
int ReturnCode = 1;
|
||||
if (Invocation.getFrontendOptions().FrontendParseableOutput)
|
||||
emitParseableFinishedMessage(ReturnCode);
|
||||
|
||||
return finishDiagProcessing(ReturnCode, /*verifierEnabled*/ false);
|
||||
}
|
||||
|
||||
// The compiler instance has been configured; notify our observer.
|
||||
@@ -2141,38 +2228,6 @@ int swift::performFrontend(ArrayRef<const char *> Args,
|
||||
PDC.setSuppressOutput(true);
|
||||
}
|
||||
|
||||
if (Invocation.getFrontendOptions().FrontendParseableOutput) {
|
||||
const auto &IO = Invocation.getFrontendOptions().InputsAndOutputs;
|
||||
const auto OSPid = getpid();
|
||||
const auto ProcInfo = sys::TaskProcessInformation(OSPid);
|
||||
|
||||
// Parseable output clients may not understand the idea of a batch
|
||||
// compilation. We assign each primary in a batch job a quasi process id,
|
||||
// making sure it cannot collide with a real PID (always positive). Non-batch
|
||||
// compilation gets a real OS PID.
|
||||
int64_t Pid = IO.hasUniquePrimaryInput() ? OSPid : QUASI_PID_START;
|
||||
|
||||
if (IO.hasPrimaryInputs()) {
|
||||
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
|
||||
unsigned idx) -> bool {
|
||||
ArrayRef<InputFile> Inputs(Input);
|
||||
emitBeganMessage(llvm::errs(),
|
||||
mapFrontendInvocationToAction(Invocation),
|
||||
constructDetailedTaskDescription(Invocation,
|
||||
Inputs,
|
||||
Args), Pid - idx,
|
||||
ProcInfo);
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
// If no primary inputs are present, we are in WMO.
|
||||
emitBeganMessage(llvm::errs(),
|
||||
mapFrontendInvocationToAction(Invocation),
|
||||
constructDetailedTaskDescription(Invocation, IO.getAllInputs(), Args),
|
||||
OSPid, ProcInfo);
|
||||
}
|
||||
}
|
||||
|
||||
int ReturnValue = 0;
|
||||
bool HadError = performCompile(*Instance, ReturnValue, observer);
|
||||
|
||||
@@ -2191,52 +2246,8 @@ int swift::performFrontend(ArrayRef<const char *> Args,
|
||||
if (auto *StatsReporter = Instance->getStatsReporter())
|
||||
StatsReporter->noteCurrentProcessExitStatus(r);
|
||||
|
||||
if (Invocation.getFrontendOptions().FrontendParseableOutput) {
|
||||
const auto &IO = Invocation.getFrontendOptions().InputsAndOutputs;
|
||||
const auto OSPid = getpid();
|
||||
const auto ProcInfo = sys::TaskProcessInformation(OSPid);
|
||||
|
||||
// Parseable output clients may not understand the idea of a batch
|
||||
// compilation. We assign each primary in a batch job a quasi process id,
|
||||
// making sure it cannot collide with a real PID (always positive). Non-batch
|
||||
// compilation gets a real OS PID.
|
||||
int64_t Pid = IO.hasUniquePrimaryInput() ? OSPid : QUASI_PID_START;
|
||||
|
||||
if (IO.hasPrimaryInputs()) {
|
||||
IO.forEachPrimaryInputWithIndex([&](const InputFile &Input,
|
||||
unsigned idx) -> bool {
|
||||
assert(FileSpecificDiagnostics.count(Input.getFileName()) != 0 &&
|
||||
"Expected diagnostic collection for input.");
|
||||
|
||||
// Join all diagnostics produced for this file into a single output.
|
||||
auto PrimaryDiags = FileSpecificDiagnostics.lookup(Input.getFileName());
|
||||
const char *const Delim = "";
|
||||
std::ostringstream JoinedDiags;
|
||||
std::copy(PrimaryDiags.begin(), PrimaryDiags.end(),
|
||||
std::ostream_iterator<std::string>(JoinedDiags, Delim));
|
||||
|
||||
emitFinishedMessage(llvm::errs(),
|
||||
mapFrontendInvocationToAction(Invocation),
|
||||
JoinedDiags.str(), r, Pid - idx, ProcInfo);
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
// If no primary inputs are present, we are in WMO.
|
||||
std::vector<std::string> AllDiagnostics;
|
||||
for (const auto &FileDiagnostics : FileSpecificDiagnostics) {
|
||||
AllDiagnostics.insert(AllDiagnostics.end(),
|
||||
FileDiagnostics.getValue().begin(),
|
||||
FileDiagnostics.getValue().end());
|
||||
}
|
||||
const char *const Delim = "";
|
||||
std::ostringstream JoinedDiags;
|
||||
std::copy(AllDiagnostics.begin(), AllDiagnostics.end(),
|
||||
std::ostream_iterator<std::string>(JoinedDiags, Delim));
|
||||
emitFinishedMessage(llvm::errs(),
|
||||
mapFrontendInvocationToAction(Invocation),
|
||||
JoinedDiags.str(), r, OSPid, ProcInfo);
|
||||
}
|
||||
}
|
||||
if (Invocation.getFrontendOptions().FrontendParseableOutput)
|
||||
emitParseableFinishedMessage(r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user