@@ -313,13 +313,6 @@ static std::string getOutputFileName(llvm::StringRef InputFile) {
313
313
return BundleDir.str ();
314
314
}
315
315
316
- static Expected<sys::fs::TempFile> createTempFile () {
317
- llvm::SmallString<128 > TmpModel;
318
- llvm::sys::path::system_temp_directory (true , TmpModel);
319
- llvm::sys::path::append (TmpModel, " dsym.tmp%%%%%.dwarf" );
320
- return sys::fs::TempFile::create (TmpModel);
321
- }
322
-
323
316
// / Parses the command line options into the LinkOptions struct and performs
324
317
// / some sanity checking. Returns an error in case the latter fails.
325
318
static Expected<LinkOptions> getOptions () {
@@ -400,18 +393,6 @@ static Expected<std::vector<std::string>> getInputs(bool DsymAsInput) {
400
393
return Inputs;
401
394
}
402
395
403
- namespace {
404
- struct TempFileVector {
405
- std::vector<sys::fs::TempFile> Files;
406
- ~TempFileVector () {
407
- for (sys::fs::TempFile &Tmp : Files) {
408
- if (Error E = Tmp.discard ())
409
- errs () << toString (std::move (E));
410
- }
411
- }
412
- };
413
- } // namespace
414
-
415
396
int main (int argc, char **argv) {
416
397
InitLLVM X (argc, argv);
417
398
@@ -523,8 +504,7 @@ int main(int argc, char **argv) {
523
504
!DumpDebugMap && (OutputFileOpt != " -" ) &&
524
505
(DebugMapPtrsOrErr->size () != 1 || OptionsOrErr->Update );
525
506
526
- llvm::SmallVector<MachOUtils::ArchAndFilename, 4 > TempFiles;
527
- TempFileVector TempFileStore;
507
+ llvm::SmallVector<MachOUtils::ArchAndFile, 4 > TempFiles;
528
508
std::atomic_char AllOK (1 );
529
509
for (auto &Map : *DebugMapPtrsOrErr) {
530
510
if (Verbose || DumpDebugMap)
@@ -543,16 +523,18 @@ int main(int argc, char **argv) {
543
523
std::shared_ptr<raw_fd_ostream> OS;
544
524
std::string OutputFile = getOutputFileName (InputFile);
545
525
if (NeedsTempFiles) {
546
- Expected<sys::fs::TempFile> T = createTempFile ();
547
- if (!T) {
548
- errs () << toString (T.takeError ());
526
+ TempFiles.emplace_back (Map->getTriple ().getArchName ().str ());
527
+
528
+ auto E = TempFiles.back ().createTempFile ();
529
+ if (E) {
530
+ errs () << toString (std::move (E));
549
531
return 1 ;
550
532
}
551
- OS = std::make_shared<raw_fd_ostream>(T-> FD , /* shouldClose */ false );
552
- OutputFile = T-> TmpName ;
553
- TempFileStore. Files . push_back ( std::move (*T));
554
- TempFiles. emplace_back (Map-> getTriple (). getArchName (). str (),
555
- OutputFile) ;
533
+
534
+ auto &TempFile = *(TempFiles. back (). File ) ;
535
+ OS = std::make_shared<raw_fd_ostream>(TempFile. FD ,
536
+ /* shouldClose */ false );
537
+ OutputFile = TempFile. TmpName ;
556
538
} else {
557
539
std::error_code EC;
558
540
OS = std::make_shared<raw_fd_ostream>(NoOutput ? " -" : OutputFile, EC,
0 commit comments