From: Jim Stichnoth Date: Tue, 16 Sep 2014 17:22:26 +0000 (-0700) Subject: Subzero: Make python clean up after itself by removing its /tmp subdir. X-Git-Tag: android-x86-7.1-r1~148^2~1081 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e8b404b4525983df8b790d18afcca4cc79430133;p=android-x86%2Fexternal-swiftshader.git Subzero: Make python clean up after itself by removing its /tmp subdir. BUG= none R=jvoung@chromium.org Review URL: https://codereview.chromium.org/551723003 --- diff --git a/pydir/build-pnacl-ir.py b/pydir/build-pnacl-ir.py index 5c4c9e816..96b4741f6 100755 --- a/pydir/build-pnacl-ir.py +++ b/pydir/build-pnacl-ir.py @@ -1,7 +1,9 @@ #!/usr/bin/env python2 import argparse +import errno import os +import shutil import tempfile from utils import shellcmd from utils import FindBaseNaCl @@ -21,18 +23,25 @@ if __name__ == '__main__': nacl_root + '/toolchain/linux_x86/pnacl_newlib/bin' + os.pathsep + os.pathsep + os.environ['PATH']) - tempdir = tempfile.mkdtemp() + try: + tempdir = tempfile.mkdtemp() - for cname in args.cfile: - basename = os.path.splitext(cname)[0] - llname = os.path.join(tempdir, basename + '.ll') - pnaclname = basename + '.pnacl.ll' - pnaclname = os.path.join(args.dir, pnaclname) + for cname in args.cfile: + basename = os.path.splitext(cname)[0] + llname = os.path.join(tempdir, basename + '.ll') + pnaclname = basename + '.pnacl.ll' + pnaclname = os.path.join(args.dir, pnaclname) - shellcmd('pnacl-clang -O2 -c {0} -o {1}'.format(cname, llname)) - shellcmd('pnacl-opt ' + - '-pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt' + - ('' if args.disable_verify else - ' -verify-pnaclabi-module -verify-pnaclabi-functions') + - ' -pnaclabi-allow-debug-metadata' - ' {0} -S -o {1}'.format(llname, pnaclname)) + shellcmd('pnacl-clang -O2 -c {0} -o {1}'.format(cname, llname)) + shellcmd('pnacl-opt ' + + '-pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt' + + ('' if args.disable_verify else + ' -verify-pnaclabi-module -verify-pnaclabi-functions') + + ' -pnaclabi-allow-debug-metadata' + ' {0} -S -o {1}'.format(llname, pnaclname)) + finally: + try: + shutil.rmtree(tempdir) + except OSError as exc: + if exc.errno != errno.ENOENT: # ENOENT - no such file or directory + raise # re-raise exception