Skip to content

Commit 6eaf422

Browse files
authored
More use of os.execv. NFC (#20909)
Followup to #20884
1 parent c0c2ca1 commit 6eaf422

File tree

7 files changed

+20
-31
lines changed

7 files changed

+20
-31
lines changed

emar.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@
1010
import sys
1111
from tools import shared
1212

13-
cmd = [shared.LLVM_AR] + sys.argv[1:]
14-
sys.exit(shared.run_process(cmd, stdin=sys.stdin, check=False).returncode)
13+
shared.exec_process([shared.LLVM_AR] + sys.argv[1:])

emcc.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -934,17 +934,6 @@ def get_clang_output_extension(state):
934934
return '.o'
935935

936936

937-
def exec_subprocess_and_exit(cmd):
938-
if utils.WINDOWS:
939-
shared.check_call(cmd)
940-
sys.exit(0)
941-
else:
942-
shared.print_compiler_stage(cmd)
943-
sys.stdout.flush()
944-
sys.stderr.flush()
945-
os.execv(cmd[0], cmd)
946-
947-
948937
@ToolchainProfiler.profile_block('compile inputs')
949938
def phase_compile_inputs(options, state, newargs, input_files):
950939
if shared.run_via_emxx:
@@ -993,7 +982,7 @@ def get_clang_command_asm():
993982
# output the dependency rule. Warning: clang and gcc behave differently
994983
# with -MF! (clang seems to not recognize it)
995984
logger.debug(('just preprocessor ' if state.has_dash_E else 'just dependencies: ') + ' '.join(cmd))
996-
exec_subprocess_and_exit(cmd)
985+
shared.exec_process(cmd)
997986

998987
# Precompiled headers support
999988
if state.mode == Mode.PCH:
@@ -1005,7 +994,7 @@ def get_clang_command_asm():
1005994
if options.output_file:
1006995
cmd += ['-o', options.output_file]
1007996
logger.debug(f"running (for precompiled headers): {cmd[0]} {' '.join(cmd[1:])}")
1008-
exec_subprocess_and_exit(cmd)
997+
shared.exec_process(cmd)
1009998

1010999
if state.mode == Mode.COMPILE_ONLY:
10111000
inputs = [i[1] for i in input_files]
@@ -1020,7 +1009,7 @@ def get_clang_command_asm():
10201009
ext = get_clang_output_extension(state)
10211010
if not options.output_file and options.default_object_extension != ext:
10221011
# If we are using a non-standard output file extention we cannot use
1023-
# exec_subprocess_and_exit here since we need to rename the files
1012+
# exec_process here since we need to rename the files
10241013
# after clang runs (since clang does not support --default-obj-ext)
10251014
# TODO: Remove '--default-obj-ext' to reduce this complexity
10261015
shared.check_call(cmd)
@@ -1030,7 +1019,7 @@ def get_clang_command_asm():
10301019
shutil.move(output, new_output)
10311020
sys.exit(0)
10321021
else:
1033-
exec_subprocess_and_exit(cmd)
1022+
shared.exec_process(cmd)
10341023

10351024
# In COMPILE_AND_LINK we need to compile source files too, but we also need to
10361025
# filter out the link flags

emranlib.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,4 @@
1313
import sys
1414
from tools import shared
1515

16-
17-
def run():
18-
newargs = [shared.LLVM_RANLIB] + sys.argv[1:]
19-
return shared.run_process(newargs, stdin=sys.stdin, check=False).returncode
20-
21-
22-
if __name__ == '__main__':
23-
sys.exit(run())
16+
shared.exec_process([shared.LLVM_RANLIB] + sys.argv[1:])

emstrip.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@
1010
import sys
1111
from tools import shared
1212

13-
cmd = [shared.LLVM_STRIP] + sys.argv[1:]
14-
sys.exit(shared.run_process(cmd, stdin=sys.stdin, check=False).returncode)
13+
shared.exec_process([shared.LLVM_STRIP] + sys.argv[1:])

tools/emdwp.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616

1717
from tools import shared
1818

19-
cmd = [shared.LLVM_DWP] + sys.argv[1:]
20-
sys.exit(shared.run_process(cmd, stdin=sys.stdin, check=False).returncode)
19+
shared.exec_process([shared.LLVM_DWP] + sys.argv[1:])

tools/emnm.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616

1717
from tools import shared
1818

19-
cmd = [shared.LLVM_NM] + sys.argv[1:]
20-
sys.exit(shared.run_process(cmd, stdin=sys.stdin, check=False).returncode)
19+
shared.exec_process([shared.LLVM_NM] + sys.argv[1:])

tools/shared.py

+11
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,17 @@ def check_call(cmd, *args, **kw):
240240
exit_with_error("'%s' failed: %s", shlex_join(cmd), str(e))
241241

242242

243+
def exec_process(cmd):
244+
if utils.WINDOWS:
245+
rtn = run_process(cmd, stdin=sys.stdin, check=False).returncode
246+
sys.exit(rtn)
247+
else:
248+
print_compiler_stage(cmd)
249+
sys.stdout.flush()
250+
sys.stderr.flush()
251+
os.execv(cmd[0], cmd)
252+
253+
243254
def run_js_tool(filename, jsargs=[], node_args=[], **kw): # noqa: mutable default args
244255
"""Execute a javascript tool.
245256

0 commit comments

Comments
 (0)