28
28
import sys
29
29
import shutil
30
30
import tempfile
31
- import subprocess
32
31
import shlex
33
32
import time
34
33
import re
35
34
import logging
36
35
from subprocess import PIPE
37
36
38
37
from 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
40
39
from tools .response_file import substitute_response_files
41
40
import tools .line_endings
42
41
from tools .toolchain_profiler import ToolchainProfiler
@@ -384,7 +383,7 @@ def run():
384
383
here = os .getcwd ()
385
384
os .chdir (shared .path_from_root ())
386
385
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 ]
388
387
except :
389
388
pass
390
389
finally :
@@ -399,7 +398,7 @@ def run():
399
398
elif len (sys .argv ) == 2 and sys .argv [1 ] == '-v' : # -v with no inputs
400
399
# autoconf likes to see 'GNU' in the output to enable shared object support
401
400
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
403
402
shared .check_sanity (force = True )
404
403
return code
405
404
@@ -418,7 +417,7 @@ def run():
418
417
args = [x for x in sys .argv if x != '--cflags' ]
419
418
with misc_temp_files .get_file (suffix = '.o' ) as temp_target :
420
419
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
422
421
lines = [x for x in err .split ('\n ' ) if shared .CLANG_CC in x and input_file in x ]
423
422
line = re .search ('running: (.*)' , lines [0 ]).group (1 )
424
423
parts = shlex .split (line .replace ('\\ ' , '\\ \\ ' ))
@@ -524,7 +523,7 @@ def filter_emscripten_options(argv):
524
523
open (tempout , 'a' ).write ('emcc, just configuring: ' + ' ' .join (cmd ) + '\n \n ' )
525
524
526
525
if not use_js :
527
- return subprocess . call (cmd )
526
+ return run_process (cmd , check = False ). returncode
528
527
else :
529
528
only_object = '-c' in cmd
530
529
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):
536
535
if not target :
537
536
target = 'a.out.js'
538
537
os .environ ['EMMAKEN_JUST_CONFIGURE_RECURSE' ] = '1'
539
- ret = subprocess . call (cmd )
538
+ ret = run_process (cmd , check = False ). returncode
540
539
os .environ ['EMMAKEN_JUST_CONFIGURE_RECURSE' ] = ''
541
540
if not os .path .exists (target ):
542
541
# note that emcc -c will cause target to have the wrong value here;
@@ -1432,8 +1431,7 @@ def check(input_file):
1432
1431
args += ['-o' , specified_target ]
1433
1432
args = system_libs .process_args (args , shared .Settings )
1434
1433
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
1437
1435
1438
1436
def get_bitcode_file (input_file ):
1439
1437
if final_suffix not in JS_CONTAINING_SUFFIXES :
@@ -1481,17 +1479,17 @@ def get_bitcode_args(input_files):
1481
1479
cmd += ['-o' , specified_target ]
1482
1480
# 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)
1483
1481
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
1485
1483
1486
1484
def compile_source_file (i , input_file ):
1487
1485
logging .debug ('compiling source file: ' + input_file )
1488
1486
output_file = get_bitcode_file (input_file )
1489
1487
temp_files .append ((i , output_file ))
1490
1488
args = get_bitcode_args ([input_file ]) + ['-emit-llvm' , '-c' , '-o' , output_file ]
1491
1489
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 :
1494
1491
exit_with_error ('compiler frontend failed to generate LLVM bitcode, halting' )
1492
+ assert (os .path .exists (output_file ))
1495
1493
1496
1494
# First, generate LLVM bitcode. For each input file, we get base.o with bitcode
1497
1495
for i , input_file in input_files :
@@ -1707,7 +1705,7 @@ def get_final():
1707
1705
if AUTODEBUG :
1708
1706
logging .debug ('autodebug' )
1709
1707
next = get_final () + '.ad.ll'
1710
- execute ([shared .PYTHON , shared .AUTODEBUGGER , final , next ])
1708
+ run_process ([shared .PYTHON , shared .AUTODEBUGGER , final , next ])
1711
1709
final = next
1712
1710
save_intermediate ('autodebug' , 'll' )
1713
1711
@@ -1783,7 +1781,7 @@ def get_final():
1783
1781
file_args .append ('--lz4' )
1784
1782
if options .use_preload_plugins :
1785
1783
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
1787
1785
options .pre_js = file_code + options .pre_js
1788
1786
1789
1787
# Apply pre and postjs files
@@ -1811,7 +1809,7 @@ def get_final():
1811
1809
final += '.tr.js'
1812
1810
posix = not shared .WINDOWS
1813
1811
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 )]))
1815
1813
save_intermediate ('transformed' )
1816
1814
1817
1815
js_transform_tempfiles = [final ]
@@ -1986,7 +1984,7 @@ def get_eliminate():
1986
1984
1987
1985
# Bundle symbol data in with the cyberdwarf file
1988
1986
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' ])
1990
1988
1991
1989
if use_source_map (options ) and not shared .Settings .WASM :
1992
1990
emit_js_source_maps (target , optimizer .js_transform_tempfiles )
@@ -2336,7 +2334,7 @@ def emterpretify(js_target, optimizer, options):
2336
2334
args += ['MEMORY_SAFE=1' ]
2337
2335
if shared .Settings .EMTERPRETIFY_FILE :
2338
2336
args += ['FILE="' + shared .Settings .EMTERPRETIFY_FILE + '"' ]
2339
- execute (args )
2337
+ run_process (args )
2340
2338
final = final + '.em.js'
2341
2339
finally :
2342
2340
shared .try_delete (js_target )
@@ -2379,7 +2377,7 @@ def emit_js_source_maps(target, js_transform_tempfiles):
2379
2377
def separate_asm_js (final , asm_target ):
2380
2378
"""Separate out the asm.js code, if asked. Or, if necessary for another option"""
2381
2379
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 ])
2383
2381
2384
2382
# extra only-my-code logic
2385
2383
if shared .Settings .ONLY_MY_CODE :
@@ -2473,7 +2471,7 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
2473
2471
wrote_wasm_text = True
2474
2472
logging .debug ('asm2wasm (asm.js => WebAssembly): ' + ' ' .join (cmd ))
2475
2473
TimeLogger .update ()
2476
- subprocess .check_call (cmd )
2474
+ shared .check_call (cmd )
2477
2475
2478
2476
if not target_binary :
2479
2477
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,
2484
2482
if options .source_map_base :
2485
2483
cmd += ['--source-map-url=' + options .source_map_base + os .path .basename (wasm_binary_target ) + '.map' ]
2486
2484
logging .debug ('wasm-as (text => binary): ' + ' ' .join (cmd ))
2487
- subprocess .check_call (cmd )
2485
+ shared .check_call (cmd )
2488
2486
if import_mem_init :
2489
2487
# remove the mem init file in later processing; it does not need to be prefetched in the html, etc.
2490
2488
if DEBUG :
@@ -2500,11 +2498,11 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
2500
2498
if debug_info :
2501
2499
cmd += ['-g' ] # preserve the debug info
2502
2500
logging .debug ('wasm-opt on BINARYEN_PASSES: ' + ' ' .join (cmd ))
2503
- subprocess .check_call (cmd )
2501
+ shared .check_call (cmd )
2504
2502
if not wrote_wasm_text and 'interpret-s-expr' in shared .Settings .BINARYEN_METHOD :
2505
2503
cmd = [os .path .join (binaryen_bin , 'wasm-dis' ), wasm_binary_target , '-o' , wasm_text_target ]
2506
2504
logging .debug ('wasm-dis (binary => text): ' + ' ' .join (cmd ))
2507
- subprocess .check_call (cmd )
2505
+ shared .check_call (cmd )
2508
2506
if shared .Settings .BINARYEN_SCRIPTS :
2509
2507
binaryen_scripts = os .path .join (shared .Settings .BINARYEN_ROOT , 'scripts' )
2510
2508
script_env = os .environ .copy ()
@@ -2515,7 +2513,7 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
2515
2513
script_env ['PYTHONPATH' ] = root_dir
2516
2514
for script in shared .Settings .BINARYEN_SCRIPTS .split (',' ):
2517
2515
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 )
2519
2517
if shared .Settings .EVAL_CTORS :
2520
2518
if DEBUG :
2521
2519
save_intermediate ('pre-eval-ctors' , 'js' )
0 commit comments