2828import sys
2929import shutil
3030import tempfile
31- import subprocess
3231import shlex
3332import time
3433import re
3534import logging
3635from subprocess import PIPE
3736
3837from tools import shared , jsrun , system_libs , client_mods
39- from tools .shared import execute , suffix , unsuffixed , unsuffixed_basename , WINDOWS , safe_copy , safe_move , run_process , asbytes
38+ from tools .shared import suffix , unsuffixed , unsuffixed_basename , WINDOWS , safe_copy , safe_move , run_process , asbytes
4039from tools .response_file import substitute_response_files
4140import tools .line_endings
4241from tools .toolchain_profiler import ToolchainProfiler
@@ -384,7 +383,7 @@ def run():
384383 here = os .getcwd ()
385384 os .chdir (shared .path_from_root ())
386385 try :
387- revision = execute (['git' , 'show' ], stdout = PIPE , stderr = PIPE )[ 0 ] .split ('\n ' )[0 ]
386+ revision = run_process (['git' , 'show' ], stdout = PIPE , stderr = PIPE ). stdout .split ('\n ' )[0 ]
388387 except :
389388 pass
390389 finally :
@@ -399,7 +398,7 @@ def run():
399398 elif len (sys .argv ) == 2 and sys .argv [1 ] == '-v' : # -v with no inputs
400399 # autoconf likes to see 'GNU' in the output to enable shared object support
401400 print ('emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) %s' % shared .EMSCRIPTEN_VERSION )
402- code = subprocess . call ([shared .CLANG , '-v' ])
401+ code = run_process ([shared .CLANG , '-v' ], check = False ). returncode
403402 shared .check_sanity (force = True )
404403 return code
405404
@@ -418,7 +417,7 @@ def run():
418417 args = [x for x in sys .argv if x != '--cflags' ]
419418 with misc_temp_files .get_file (suffix = '.o' ) as temp_target :
420419 input_file = 'hello_world.c'
421- err = run_process ([shared .PYTHON ] + args + [shared .path_from_root ('tests' , input_file ), '-c' , '-o' , temp_target ], stderr = subprocess . PIPE , env = debug_env ).stderr
420+ err = run_process ([shared .PYTHON ] + args + [shared .path_from_root ('tests' , input_file ), '-c' , '-o' , temp_target ], stderr = PIPE , env = debug_env ).stderr
422421 lines = [x for x in err .split ('\n ' ) if shared .CLANG_CC in x and input_file in x ]
423422 line = re .search ('running: (.*)' , lines [0 ]).group (1 )
424423 parts = shlex .split (line .replace ('\\ ' , '\\ \\ ' ))
@@ -524,7 +523,7 @@ def filter_emscripten_options(argv):
524523 open (tempout , 'a' ).write ('emcc, just configuring: ' + ' ' .join (cmd ) + '\n \n ' )
525524
526525 if not use_js :
527- return subprocess . call (cmd )
526+ return run_process (cmd , check = False ). returncode
528527 else :
529528 only_object = '-c' in cmd
530529 for i in reversed (range (len (cmd ) - 1 )): # Last -o directive should take precedence, if multiple are specified
@@ -536,7 +535,7 @@ def filter_emscripten_options(argv):
536535 if not target :
537536 target = 'a.out.js'
538537 os .environ ['EMMAKEN_JUST_CONFIGURE_RECURSE' ] = '1'
539- ret = subprocess . call (cmd )
538+ ret = run_process (cmd , check = False ). returncode
540539 os .environ ['EMMAKEN_JUST_CONFIGURE_RECURSE' ] = ''
541540 if not os .path .exists (target ):
542541 # note that emcc -c will cause target to have the wrong value here;
@@ -1432,8 +1431,7 @@ def check(input_file):
14321431 args += ['-o' , specified_target ]
14331432 args = system_libs .process_args (args , shared .Settings )
14341433 logging .debug ("running (for precompiled headers): " + call + ' ' + ' ' .join (args ))
1435- execute ([call ] + args ) # let compiler frontend print directly, so colors are saved (PIPE kills that)
1436- return 0
1434+ return run_process ([call ] + args , check = False ).returncode
14371435
14381436 def get_bitcode_file (input_file ):
14391437 if final_suffix not in JS_CONTAINING_SUFFIXES :
@@ -1481,17 +1479,17 @@ def get_bitcode_args(input_files):
14811479 cmd += ['-o' , specified_target ]
14821480 # Do not compile, but just output the result from preprocessing stage or output the dependency rule. Warning: clang and gcc behave differently with -MF! (clang seems to not recognize it)
14831481 logging .debug (('just preprocessor ' if '-E' in newargs else 'just dependencies: ' ) + ' ' .join (cmd ))
1484- return subprocess . call (cmd )
1482+ return run_process (cmd , check = False ). returncode
14851483
14861484 def compile_source_file (i , input_file ):
14871485 logging .debug ('compiling source file: ' + input_file )
14881486 output_file = get_bitcode_file (input_file )
14891487 temp_files .append ((i , output_file ))
14901488 args = get_bitcode_args ([input_file ]) + ['-emit-llvm' , '-c' , '-o' , output_file ]
14911489 logging .debug ("running: " + ' ' .join (shared .Building .doublequote_spaces (args ))) # NOTE: Printing this line here in this specific format is important, it is parsed to implement the "emcc --cflags" command
1492- execute (args ) # let compiler frontend print directly, so colors are saved (PIPE kills that)
1493- if not os .path .exists (output_file ):
1490+ if run_process (args , check = False ).returncode != 0 :
14941491 exit_with_error ('compiler frontend failed to generate LLVM bitcode, halting' )
1492+ assert (os .path .exists (output_file ))
14951493
14961494 # First, generate LLVM bitcode. For each input file, we get base.o with bitcode
14971495 for i , input_file in input_files :
@@ -1707,7 +1705,7 @@ def get_final():
17071705 if AUTODEBUG :
17081706 logging .debug ('autodebug' )
17091707 next = get_final () + '.ad.ll'
1710- execute ([shared .PYTHON , shared .AUTODEBUGGER , final , next ])
1708+ run_process ([shared .PYTHON , shared .AUTODEBUGGER , final , next ])
17111709 final = next
17121710 save_intermediate ('autodebug' , 'll' )
17131711
@@ -1783,7 +1781,7 @@ def get_final():
17831781 file_args .append ('--lz4' )
17841782 if options .use_preload_plugins :
17851783 file_args .append ('--use-preload-plugins' )
1786- file_code = execute ([shared .PYTHON , shared .FILE_PACKAGER , unsuffixed (target ) + '.data' ] + file_args , stdout = PIPE )[ 0 ]
1784+ file_code = run_process ([shared .PYTHON , shared .FILE_PACKAGER , unsuffixed (target ) + '.data' ] + file_args , stdout = PIPE ). stdout
17871785 options .pre_js = file_code + options .pre_js
17881786
17891787 # Apply pre and postjs files
@@ -1811,7 +1809,7 @@ def get_final():
18111809 final += '.tr.js'
18121810 posix = not shared .WINDOWS
18131811 logging .debug ('applying transform: %s' , options .js_transform )
1814- subprocess .check_call (shared .Building .remove_quotes (shlex .split (options .js_transform , posix = posix ) + [os .path .abspath (final )]))
1812+ shared .check_call (shared .Building .remove_quotes (shlex .split (options .js_transform , posix = posix ) + [os .path .abspath (final )]))
18151813 save_intermediate ('transformed' )
18161814
18171815 js_transform_tempfiles = [final ]
@@ -1986,7 +1984,7 @@ def get_eliminate():
19861984
19871985 # Bundle symbol data in with the cyberdwarf file
19881986 if shared .Settings .CYBERDWARF :
1989- execute ([shared .PYTHON , shared .path_from_root ('tools' , 'emdebug_cd_merger.py' ), target + '.cd' , target + '.symbols' ])
1987+ run_process ([shared .PYTHON , shared .path_from_root ('tools' , 'emdebug_cd_merger.py' ), target + '.cd' , target + '.symbols' ])
19901988
19911989 if use_source_map (options ) and not shared .Settings .WASM :
19921990 emit_js_source_maps (target , optimizer .js_transform_tempfiles )
@@ -2336,7 +2334,7 @@ def emterpretify(js_target, optimizer, options):
23362334 args += ['MEMORY_SAFE=1' ]
23372335 if shared .Settings .EMTERPRETIFY_FILE :
23382336 args += ['FILE="' + shared .Settings .EMTERPRETIFY_FILE + '"' ]
2339- execute (args )
2337+ run_process (args )
23402338 final = final + '.em.js'
23412339 finally :
23422340 shared .try_delete (js_target )
@@ -2379,7 +2377,7 @@ def emit_js_source_maps(target, js_transform_tempfiles):
23792377def separate_asm_js (final , asm_target ):
23802378 """Separate out the asm.js code, if asked. Or, if necessary for another option"""
23812379 logging .debug ('separating asm' )
2382- subprocess .check_call ([shared .PYTHON , shared .path_from_root ('tools' , 'separate_asm.py' ), final , asm_target , final ])
2380+ shared .check_call ([shared .PYTHON , shared .path_from_root ('tools' , 'separate_asm.py' ), final , asm_target , final ])
23832381
23842382 # extra only-my-code logic
23852383 if shared .Settings .ONLY_MY_CODE :
@@ -2473,7 +2471,7 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
24732471 wrote_wasm_text = True
24742472 logging .debug ('asm2wasm (asm.js => WebAssembly): ' + ' ' .join (cmd ))
24752473 TimeLogger .update ()
2476- subprocess .check_call (cmd )
2474+ shared .check_call (cmd )
24772475
24782476 if not target_binary :
24792477 cmd = [os .path .join (binaryen_bin , 'wasm-as' ), wasm_text_target , '-o' , wasm_binary_target ]
@@ -2484,7 +2482,7 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
24842482 if options .source_map_base :
24852483 cmd += ['--source-map-url=' + options .source_map_base + os .path .basename (wasm_binary_target ) + '.map' ]
24862484 logging .debug ('wasm-as (text => binary): ' + ' ' .join (cmd ))
2487- subprocess .check_call (cmd )
2485+ shared .check_call (cmd )
24882486 if import_mem_init :
24892487 # remove the mem init file in later processing; it does not need to be prefetched in the html, etc.
24902488 if DEBUG :
@@ -2500,11 +2498,11 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
25002498 if debug_info :
25012499 cmd += ['-g' ] # preserve the debug info
25022500 logging .debug ('wasm-opt on BINARYEN_PASSES: ' + ' ' .join (cmd ))
2503- subprocess .check_call (cmd )
2501+ shared .check_call (cmd )
25042502 if not wrote_wasm_text and 'interpret-s-expr' in shared .Settings .BINARYEN_METHOD :
25052503 cmd = [os .path .join (binaryen_bin , 'wasm-dis' ), wasm_binary_target , '-o' , wasm_text_target ]
25062504 logging .debug ('wasm-dis (binary => text): ' + ' ' .join (cmd ))
2507- subprocess .check_call (cmd )
2505+ shared .check_call (cmd )
25082506 if shared .Settings .BINARYEN_SCRIPTS :
25092507 binaryen_scripts = os .path .join (shared .Settings .BINARYEN_ROOT , 'scripts' )
25102508 script_env = os .environ .copy ()
@@ -2515,7 +2513,7 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
25152513 script_env ['PYTHONPATH' ] = root_dir
25162514 for script in shared .Settings .BINARYEN_SCRIPTS .split (',' ):
25172515 logging .debug ('running binaryen script: ' + script )
2518- subprocess .check_call ([shared .PYTHON , os .path .join (binaryen_scripts , script ), final , wasm_text_target ], env = script_env )
2516+ shared .check_call ([shared .PYTHON , os .path .join (binaryen_scripts , script ), final , wasm_text_target ], env = script_env )
25192517 if shared .Settings .EVAL_CTORS :
25202518 if DEBUG :
25212519 save_intermediate ('pre-eval-ctors' , 'js' )
0 commit comments