diff --git a/emar.py b/emar.py index 23147feb1f2dd..2153890308a17 100755 --- a/emar.py +++ b/emar.py @@ -10,5 +10,4 @@ import sys from tools import shared -cmd = [shared.LLVM_AR] + sys.argv[1:] -sys.exit(shared.run_process(cmd, stdin=sys.stdin, check=False).returncode) +shared.exec_process([shared.LLVM_AR] + sys.argv[1:]) diff --git a/emcc.py b/emcc.py index de1f32446e754..a748b2652d088 100644 --- a/emcc.py +++ b/emcc.py @@ -934,17 +934,6 @@ def get_clang_output_extension(state): return '.o' -def exec_subprocess_and_exit(cmd): - if utils.WINDOWS: - shared.check_call(cmd) - sys.exit(0) - else: - shared.print_compiler_stage(cmd) - sys.stdout.flush() - sys.stderr.flush() - os.execv(cmd[0], cmd) - - @ToolchainProfiler.profile_block('compile inputs') def phase_compile_inputs(options, state, newargs, input_files): if shared.run_via_emxx: @@ -993,7 +982,7 @@ def get_clang_command_asm(): # output the dependency rule. Warning: clang and gcc behave differently # with -MF! (clang seems to not recognize it) logger.debug(('just preprocessor ' if state.has_dash_E else 'just dependencies: ') + ' '.join(cmd)) - exec_subprocess_and_exit(cmd) + shared.exec_process(cmd) # Precompiled headers support if state.mode == Mode.PCH: @@ -1005,7 +994,7 @@ def get_clang_command_asm(): if options.output_file: cmd += ['-o', options.output_file] logger.debug(f"running (for precompiled headers): {cmd[0]} {' '.join(cmd[1:])}") - exec_subprocess_and_exit(cmd) + shared.exec_process(cmd) if state.mode == Mode.COMPILE_ONLY: inputs = [i[1] for i in input_files] @@ -1020,7 +1009,7 @@ def get_clang_command_asm(): ext = get_clang_output_extension(state) if not options.output_file and options.default_object_extension != ext: # If we are using a non-standard output file extention we cannot use - # exec_subprocess_and_exit here since we need to rename the files + # exec_process here since we need to rename the files # after clang runs (since clang does not support --default-obj-ext) # TODO: Remove '--default-obj-ext' to reduce this complexity shared.check_call(cmd) @@ -1030,7 +1019,7 @@ def get_clang_command_asm(): shutil.move(output, new_output) sys.exit(0) else: - exec_subprocess_and_exit(cmd) + shared.exec_process(cmd) # In COMPILE_AND_LINK we need to compile source files too, but we also need to # filter out the link flags diff --git a/emranlib.py b/emranlib.py index 813ca45ffc742..811ef061cb6dc 100755 --- a/emranlib.py +++ b/emranlib.py @@ -13,11 +13,4 @@ import sys from tools import shared - -def run(): - newargs = [shared.LLVM_RANLIB] + sys.argv[1:] - return shared.run_process(newargs, stdin=sys.stdin, check=False).returncode - - -if __name__ == '__main__': - sys.exit(run()) +shared.exec_process([shared.LLVM_RANLIB] + sys.argv[1:]) diff --git a/emstrip.py b/emstrip.py index 01c1d1b00b439..f054fe7e9f1df 100755 --- a/emstrip.py +++ b/emstrip.py @@ -10,5 +10,4 @@ import sys from tools import shared -cmd = [shared.LLVM_STRIP] + sys.argv[1:] -sys.exit(shared.run_process(cmd, stdin=sys.stdin, check=False).returncode) +shared.exec_process([shared.LLVM_STRIP] + sys.argv[1:]) diff --git a/tools/emdwp.py b/tools/emdwp.py index cf587b3c5ad0f..52f52edd96ae2 100755 --- a/tools/emdwp.py +++ b/tools/emdwp.py @@ -16,5 +16,4 @@ from tools import shared -cmd = [shared.LLVM_DWP] + sys.argv[1:] -sys.exit(shared.run_process(cmd, stdin=sys.stdin, check=False).returncode) +shared.exec_process([shared.LLVM_DWP] + sys.argv[1:]) diff --git a/tools/emnm.py b/tools/emnm.py index 37ea903396670..09de95b900466 100755 --- a/tools/emnm.py +++ b/tools/emnm.py @@ -16,5 +16,4 @@ from tools import shared -cmd = [shared.LLVM_NM] + sys.argv[1:] -sys.exit(shared.run_process(cmd, stdin=sys.stdin, check=False).returncode) +shared.exec_process([shared.LLVM_NM] + sys.argv[1:]) diff --git a/tools/shared.py b/tools/shared.py index 4880cba538591..7fe86e8f002e5 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -240,6 +240,17 @@ def check_call(cmd, *args, **kw): exit_with_error("'%s' failed: %s", shlex_join(cmd), str(e)) +def exec_process(cmd): + if utils.WINDOWS: + rtn = run_process(cmd, stdin=sys.stdin, check=False).returncode + sys.exit(rtn) + else: + print_compiler_stage(cmd) + sys.stdout.flush() + sys.stderr.flush() + os.execv(cmd[0], cmd) + + def run_js_tool(filename, jsargs=[], node_args=[], **kw): # noqa: mutable default args """Execute a javascript tool.