Skip to content

Commit

Permalink
[libc++] Run tests in a directory related to %t instead of /tmp
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
ldionne committed Apr 7, 2020
1 parent ff30d01 commit 3fefda6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions libcxx/utils/libcxx/test/config.py
Expand Up @@ -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),
Expand Down
18 changes: 10 additions & 8 deletions libcxx/utils/run.py
Expand Up @@ -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())
Expand All @@ -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())

0 comments on commit 3fefda6

Please sign in to comment.