[llvm] 8245f26 - [dsymutil] Remove empty reproducer directory on exit

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 5 11:05:36 PDT 2023


Author: Keith Smiley
Date: 2023-04-05T11:05:16-07:00
New Revision: 8245f2665240f7961ae39bc606d7b6a4b0d62c4d

URL: https://github.com/llvm/llvm-project/commit/8245f2665240f7961ae39bc606d7b6a4b0d62c4d
DIFF: https://github.com/llvm/llvm-project/commit/8245f2665240f7961ae39bc606d7b6a4b0d62c4d.diff

LOG: [dsymutil] Remove empty reproducer directory on exit

In the case the reproducer isn't generated, we don't want to leave
around an empty temporary directory.

Fixes https://github.com/llvm/llvm-project/issues/61920

Differential Revision: https://reviews.llvm.org/D147498

Added: 
    

Modified: 
    llvm/test/tools/dsymutil/X86/reproducer.test
    llvm/tools/dsymutil/Reproducer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/dsymutil/X86/reproducer.test b/llvm/test/tools/dsymutil/X86/reproducer.test
index a09d059c22caa..7e65d4ee2d77b 100644
--- a/llvm/test/tools/dsymutil/X86/reproducer.test
+++ b/llvm/test/tools/dsymutil/X86/reproducer.test
@@ -4,7 +4,7 @@
 
 # Recreate the folder structure in a temp directory we can remove later.
 RUN: rm -rf %t
-RUN: mkdir -p %t/Inputs
+RUN: mkdir -p %t/Inputs %t/tempdir
 RUN: cp %p/../Inputs/basic.macho.x86_64 %t/Inputs
 RUN: cp %p/../Inputs/basic1.macho.x86_64.o %t/Inputs
 RUN: cp %p/../Inputs/basic2.macho.x86_64.o %t/Inputs
@@ -16,6 +16,10 @@ RUN: dsymutil -f -o - -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 | llvm-d
 # Make sure we don't crash with an empty TMPDIR.
 RUN: env TMPDIR="" dsymutil -o -f -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 2>&1
 
+# Make sure we don't leave around a temporary directory.
+RUN: env TMPDIR="%t/tempdir" dsymutil -o - -f %t/Inputs/basic.macho.x86_64
+RUN: not ls %t/tempdir/dsymutil-*
+
 # Create a reproducer.
 RUN: env DSYMUTIL_REPRODUCER_PATH=%t.repro dsymutil -gen-reproducer -f -o %t.generate -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 2>&1 | FileCheck %s --check-prefixes=REPRODUCER
 RUN: llvm-dwarfdump -a %t.generate | FileCheck %s

diff  --git a/llvm/tools/dsymutil/Reproducer.cpp b/llvm/tools/dsymutil/Reproducer.cpp
index dda5557b2dec9..2522e2c091791 100644
--- a/llvm/tools/dsymutil/Reproducer.cpp
+++ b/llvm/tools/dsymutil/Reproducer.cpp
@@ -40,6 +40,8 @@ ReproducerGenerate::ReproducerGenerate(std::error_code &EC, int Argc,
 ReproducerGenerate::~ReproducerGenerate() {
   if (GenerateOnExit && !Generated)
     generate();
+  else if (!Generated && !Root.empty())
+    sys::fs::remove_directories(Root, /* IgnoreErrors */ true);
 }
 
 void ReproducerGenerate::generate() {


        


More information about the llvm-commits mailing list