[libcxx-commits] [libcxx] 3fefda6 - [libc++] Run tests in a directory related to %t instead of /tmp

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 7 13:10:10 PDT 2020


Author: Louis Dionne
Date: 2020-04-07T16:09:52-04:00
New Revision: 3fefda6e578b431875405791bc7216595d767fbf

URL: https://github.com/llvm/llvm-project/commit/3fefda6e578b431875405791bc7216595d767fbf
DIFF: https://github.com/llvm/llvm-project/commit/3fefda6e578b431875405791bc7216595d767fbf.diff

LOG: [libc++] Run tests in a directory related to %t instead of /tmp

Instead of creating a temporary directory inside /tmp and running the
tests there, use a directory name based on LIT's %t substitution. This
has the benefit of not hitting /tmp so much (which is slow on some
filesystems). It also has the benefit that `ninja -C build clean` will
automatically remove the artifacts even if a test somehow failed to
remove its temporary directory (I've seen this happen when CTRL-C is
received).

Added: 
    

Modified: 
    libcxx/utils/libcxx/test/config.py
    libcxx/utils/run.py

Removed: 
    


################################################################################
diff  --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py
index e3a48206d2eb..f86a796b9300 100644
--- a/libcxx/utils/libcxx/test/config.py
+++ b/libcxx/utils/libcxx/test/config.py
@@ -1064,6 +1064,7 @@ def configure_substitutions(self):
             exec_args.append('--host {}'.format(self.executor.user_prefix + self.executor.host))
             executor = os.path.join(self.libcxx_src_root, 'utils', 'ssh.py')
         else:
+            exec_args.append('--execdir %t.execdir')
             executor = os.path.join(self.libcxx_src_root, 'utils', 'run.py')
         sub.append(('%{exec}', '{} {} {} -- '.format(pipes.quote(sys.executable),
                                                      pipes.quote(executor),

diff  --git a/libcxx/utils/run.py b/libcxx/utils/run.py
index 3290416c469a..8c3eaeb227ce 100644
--- a/libcxx/utils/run.py
+++ b/libcxx/utils/run.py
@@ -17,11 +17,11 @@
 import shutil
 import subprocess
 import sys
-import tempfile
 
 
 def main():
     parser = argparse.ArgumentParser()
+    parser.add_argument('--execdir', type=str, required=True)
     parser.add_argument('--codesign_identity', type=str, required=False, default=None)
     parser.add_argument('--dependencies', type=str, nargs='*', required=False, default=[])
     parser.add_argument('--env', type=str, nargs='*', required=False, default=dict())
@@ -43,23 +43,25 @@ def main():
     # Extract environment variables into a dictionary
     env = {k : v  for (k, v) in map(lambda s: s.split('=', 1), args.env)}
 
+    # Create the execution directory, and make sure we remove it at the end.
     try:
-        tmpDir = tempfile.mkdtemp()
+        os.mkdir(args.execdir)
 
-        # Ensure the file dependencies exist and copy them to a temporary directory.
+        # Ensure the file dependencies exist and copy them to the execution directory.
         for dep in args.dependencies:
             if not os.path.exists(dep):
                 sys.stderr.write('Missing file or directory "{}" marked as a dependency of a test'.format(dep))
                 exit(1)
             if os.path.isdir(dep):
-                shutil.copytree(dep, os.path.join(tmpDir, os.path.basename(dep)), symlinks=True)
+                shutil.copytree(dep, os.path.join(args.execdir, os.path.basename(dep)), symlinks=True)
             else:
-                shutil.copy2(dep, tmpDir)
+                shutil.copy2(dep, args.execdir)
 
-        # Run the executable with the given environment in the temporary directory.
-        return subprocess.call(' '.join(remaining), cwd=tmpDir, env=env, shell=True)
+        # Run the executable with the given environment in the execution directory.
+        return subprocess.call(' '.join(remaining), cwd=args.execdir, env=env, shell=True)
     finally:
-        shutil.rmtree(tmpDir)
+        shutil.rmtree(args.execdir)
+
 
 if __name__ == '__main__':
     exit(main())


        


More information about the libcxx-commits mailing list