def read_and_delete(filename): result = '' try: result = open(filename, 'r').read() finally: try_delete(filename) return result
def erase(self): tempfiles.try_delete(self.dirname) try: open(self.dirname + '__last_clear', 'w').write('last clear: ' + time.asctime() + '\n') except Exception, e: print >> sys.stderr, 'failed to save last clear time: ', e
def collect_results(self): buffered_results = [] while len(self.processes) > 0: res = get_from_queue(self.result_queue) if res is not None: buffered_results.append(res) else: self.clear_finished_processes() for temp_dir in self.dedicated_temp_dirs: try_delete(temp_dir) return buffered_results
CONSTRUCTOR_CLOSURE_SUPPRESSIONS = '/** @suppress {undefinedVars, duplicate} @this{Object} */' class Dummy: def __init__(self, init): for k, v in init.items(): self.__dict__[k] = v def getExtendedAttribute(self, name): # noqa: U100 return None input_file = sys.argv[1] output_base = sys.argv[2] try_delete(output_base + '.cpp') try_delete(output_base + '.js') p = WebIDL.Parser() p.parse(r''' interface VoidPtr { }; ''' + open(input_file).read()) data = p.finish() interfaces = {} implements = {} enums = {} for thing in data: if isinstance(thing, WebIDL.IDLInterface):
class Cache: # If EM_EXCLUSIVE_CACHE_ACCESS is true, this process is allowed to have direct access to # the Emscripten cache without having to obtain an interprocess lock for it. Generally this # is false, and this is used in the case that Emscripten process recursively calls to itself # when building the cache, in which case the parent Emscripten process has already locked # the cache. Essentially the env. var EM_EXCLUSIVE_CACHE_ACCESS signals from parent to # child process that the child can reuse the lock that the parent already has acquired. EM_EXCLUSIVE_CACHE_ACCESS = int( os.environ.get('EM_EXCLUSIVE_CACHE_ACCESS') or 0) def __init__(self, dirname=None, debug=False, use_subdir=True): if dirname is None: dirname = os.environ.get('EM_CACHE') if not dirname: dirname = os.path.expanduser(os.path.join('~', '.emscripten_cache')) def try_remove_ending(thestring, ending): if thestring.endswith(ending): return thestring[:-len(ending)] return thestring self.filelock_name = try_remove_ending(try_remove_ending(dirname, '/'), '\\') + '.lock' self.filelock = filelock.FileLock(self.filelock_name) if use_subdir: if os.environ.get('EMCC_WASM_BACKEND' ) and os.environ.get('EMCC_WASM_BACKEND') != '0': dirname = os.path.join(dirname, 'wasm') else: dirname = os.path.join(dirname, 'asmjs') self.dirname = dirname self.debug = debug def acquire_cache_lock(self): if not self.EM_EXCLUSIVE_CACHE_ACCESS: logging.debug( 'Cache: acquiring multiprocess file lock to Emscripten cache') try: self.filelock.acquire(60) except filelock.Timeout: # The multiprocess cache locking can be disabled altogether by setting EM_EXCLUSIVE_CACHE_ACCESS=1 environment # variable before building. (in that case, use "embuilder.py build ALL" to prepopulate the cache) logging.warning( 'Accessing the Emscripten cache at "' + self.dirname + '" is taking a long time, another process should be writing to it. If there are none and you suspect this process has deadlocked, try deleting the lock file "' + self.filelock_name + '" and try again. If this occurs deterministically, consider filing a bug.' ) self.filelock.acquire() self.prev_EM_EXCLUSIVE_CACHE_ACCESS = os.environ.get( 'EM_EXCLUSIVE_CACHE_ACCESS') os.environ['EM_EXCLUSIVE_CACHE_ACCESS'] = '1' logging.debug('Cache: done') def release_cache_lock(self): if not self.EM_EXCLUSIVE_CACHE_ACCESS: if self.prev_EM_EXCLUSIVE_CACHE_ACCESS: os.environ[ 'EM_EXCLUSIVE_CACHE_ACCESS'] = self.prev_EM_EXCLUSIVE_CACHE_ACCESS else: del os.environ['EM_EXCLUSIVE_CACHE_ACCESS'] self.filelock.release() logging.debug( 'Cache: released multiprocess file lock to Emscripten cache') def ensure(self): self.acquire_cache_lock() try: shared.safe_ensure_dirs(self.dirname) finally: self.release_cache_lock() def erase(self): tempfiles.try_delete(self.dirname) try: open(self.dirname + '__last_clear', 'w').write('last clear: ' + time.asctime() + '\n') except Exception, e: print >> sys.stderr, 'failed to save last clear time: ', e self.filelock = None tempfiles.try_delete(self.filelock_name) self.filelock = filelock.FileLock(self.filelock_name)