2 # Copyright (c) 2014 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 # IMPORTANT NOTE: If you make local mods to this file, you must run:
7 # % pnacl/build.sh driver
8 # in order for them to take effect in the scons build. This command
9 # updates the copy in the toolchain/ tree.
12 """Manages files that'll get deleted when the driver exits unless SAVE_TEMPS.
19 from driver_env import env
20 from driver_log import Log, AtDriverExit
22 class TempFileHandler(object):
24 AtDriverExit(self.wipe)
28 if env.getbool('SAVE_TEMPS'):
30 path = pathtools.abspath(path)
31 self.files.append(path)
34 for path in self.files:
36 sys_path = pathtools.tosys(path)
37 # If exiting early, the file may not have been created yet.
38 if os.path.exists(sys_path):
39 if os.path.isdir(sys_path):
40 shutil.rmtree(sys_path)
43 except OSError as err:
44 Log.Fatal("TempFileHandler: Unable to wipe file %s w/ error %s",
45 pathtools.touser(path),
49 TempFiles = TempFileHandler()