[dsymutil] Compute the output location once per input file (NFC)

Compute the location of the output file just once outside the loop over
the different architectures.
This commit is contained in:
Jonas Devlieghere 2021-05-24 14:49:14 -07:00
parent de6164ec4d
commit aab488ac2a
1 changed files with 14 additions and 14 deletions

View File

@ -436,6 +436,11 @@ getOutputFileName(StringRef InputFile, const DsymutilOptions &Options) {
(Options.LinkOpts.Update || !Options.SymbolMap.empty()))
return OutputLocation(std::string(InputFile));
// When dumping the debug map, just return an empty output location. This
// allows us to compute the output location once.
if (Options.DumpDebugMap)
return OutputLocation("");
// If a flat dSYM has been requested, things are pretty simple.
if (Options.Flat) {
if (Options.OutputFile.empty()) {
@ -580,6 +585,15 @@ int main(int argc, char **argv) {
// Shared a single binary holder for all the link steps.
BinaryHolder BinHolder(Options.LinkOpts.VFS);
// Compute the output location and update the resource directory.
Expected<OutputLocation> OutputLocationOrErr =
getOutputFileName(InputFile, Options);
if (!OutputLocationOrErr) {
WithColor::error() << toString(OutputLocationOrErr.takeError());
return 1;
}
Options.LinkOpts.ResourceDir = OutputLocationOrErr->getResourceDir();
// Statistics only require different architectures to be processed
// sequentially, the link itself can still happen in parallel. Change the
// thread pool strategy here instead of modifying LinkOpts.Threads.
@ -621,14 +635,6 @@ int main(int argc, char **argv) {
// types don't work with std::bind in the ThreadPool implementation.
std::shared_ptr<raw_fd_ostream> OS;
Expected<OutputLocation> OutputLocationOrErr =
getOutputFileName(InputFile, Options);
if (!OutputLocationOrErr) {
WithColor::error() << toString(OutputLocationOrErr.takeError());
return 1;
}
Options.LinkOpts.ResourceDir = OutputLocationOrErr->getResourceDir();
std::string OutputFile = OutputLocationOrErr->DWARFFile;
if (NeedsTempFiles) {
TempFiles.emplace_back(Map->getTriple().getArchName().str());
@ -678,12 +684,6 @@ int main(int argc, char **argv) {
return 1;
if (NeedsTempFiles) {
Expected<OutputLocation> OutputLocationOrErr =
getOutputFileName(InputFile, Options);
if (!OutputLocationOrErr) {
WithColor::error() << toString(OutputLocationOrErr.takeError());
return 1;
}
if (!MachOUtils::generateUniversalBinary(TempFiles,
OutputLocationOrErr->DWARFFile,
Options.LinkOpts, SDKPath))