def write_chunk(chunk, i): temp_file = temp_files.get('.jsfunc_%d.js' % i).name with open(temp_file, 'w') as f: f.write(chunk) if not gen_hash_info: f.write('\n') f.write(equivalentfn_hash_info) return temp_file
def write_chunk(chunk, i): temp_file = temp_files.get('.jsfunc_%d.js' % i).name f = open(temp_file, 'w') f.write(chunk) if not gen_hash_info: f.write('\n') f.write(equivalentfn_hash_info) f.close() return temp_file
def run_on_chunk(command): try: file_suffix = '.js' index = command.index(DUPLICATE_FUNCTION_ELIMINATOR) filename = command[index + 1] if '--gen-hash-info' in command: file_suffix = '.json' if os.environ.get('EMCC_SAVE_OPT_TEMP' ) and os.environ.get('EMCC_SAVE_OPT_TEMP') != '0': saved = 'save_' + os.path.basename(filename) while os.path.exists(saved): saved = 'input' + str( int(saved.replace('input', '').replace('.txt', '')) + 1) + '.txt' print('running DFE command', ' '.join([c if c != filename else saved for c in command]), file=sys.stderr) shutil.copyfile( filename, os.path.join(shared.get_emscripten_temp_dir(), saved)) if shared.EM_BUILD_VERBOSE >= 3: print('run_on_chunk: ' + str(command), file=sys.stderr) proc = shared.run_process(command, stdout=subprocess.PIPE) output = proc.stdout assert proc.returncode == 0, 'Error in optimizer (return code ' + str( proc.returncode) + '): ' + output assert len(output) and not output.startswith( 'Assertion failed'), 'Error in optimizer: ' + output filename = temp_files.get( os.path.basename(filename) + '.dfjo' + file_suffix).name with open(filename, 'w') as f: f.write(output) if DEBUG and not shared.WINDOWS: print( '.', file=sys.stderr ) # Skip debug progress indicator on Windows, since it doesn't buffer well with multiple threads printing to console. return filename except KeyboardInterrupt: # avoid throwing keyboard interrupts from a child process raise Exception() except (TypeError, ValueError): formatted_lines = traceback.format_exc().splitlines() print(">>>>>>>>>>>>>>>>>", file=sys.stderr) for formatted_line in formatted_lines: print(formatted_line, file=sys.stderr) print("<<<<<<<<<<<<<<<<<", file=sys.stderr) raise
def run_on_chunk(command): try: file_suffix = '.js' index = command.index(DUPLICATE_FUNCTION_ELIMINATOR) filename = command[index + 1] if '--gen-hash-info' in command: file_suffix = '.json' if os.environ.get('EMCC_SAVE_OPT_TEMP') and os.environ.get('EMCC_SAVE_OPT_TEMP') != '0': saved = 'save_' + os.path.basename(filename) while os.path.exists(saved): saved = 'input' + str(int(saved.replace('input', '').replace('.txt', '')) + 1) + '.txt' print('running DFE command', ' '.join([c if c != filename else saved for c in command]), file=sys.stderr) shutil.copyfile(filename, os.path.join(shared.get_emscripten_temp_dir(), saved)) if shared.EM_BUILD_VERBOSE >= 3: print('run_on_chunk: ' + str(command), file=sys.stderr) proc = shared.run_process(command, stdout=subprocess.PIPE) output = proc.stdout assert proc.returncode == 0, 'Error in optimizer (return code ' + str(proc.returncode) + '): ' + output assert len(output) and not output.startswith('Assertion failed'), 'Error in optimizer: ' + output filename = temp_files.get(os.path.basename(filename) + '.dfjo' + file_suffix).name f = open(filename, 'w') f.write(output) f.close() if DEBUG and not shared.WINDOWS: print('.', file=sys.stderr) # Skip debug progress indicator on Windows, since it doesn't buffer well with multiple threads printing to console. return filename except KeyboardInterrupt: # avoid throwing keyboard interrupts from a child process raise Exception() except (TypeError, ValueError): formatted_lines = traceback.format_exc().splitlines() print(">>>>>>>>>>>>>>>>>", file=sys.stderr) for formatted_line in formatted_lines: print(formatted_line, file=sys.stderr) print("<<<<<<<<<<<<<<<<<", file=sys.stderr) raise