38
38
39
39
40
40
import emscripten
41
- from tools import shared , system_libs
41
+ from tools import shared , system_libs , utils
42
42
from tools import colored_logger , diagnostics , building
43
43
from tools .shared import unsuffixed , unsuffixed_basename , WINDOWS , safe_copy
44
44
from tools .shared import run_process , read_and_preprocess , exit_with_error , DEBUG
@@ -240,7 +240,7 @@ def __init__(self):
240
240
self .embed_files = []
241
241
self .exclude_files = []
242
242
self .ignore_dynamic_linking = False
243
- self .shell_path = shared .path_from_root ('src' , ' shell.html' )
243
+ self .shell_path = utils .path_from_root ('src/ shell.html' )
244
244
self .source_map_base = ''
245
245
self .emrun = False
246
246
self .cpu_profiler = False
@@ -979,7 +979,7 @@ def run(args):
979
979
# site/build/text/docs/tools_reference/emcc.txt
980
980
# This then needs to be copied to its final home in docs/emcc.txt from where
981
981
# we read it here. We have CI rules that ensure its always up-to-date.
982
- with open (shared .path_from_root ('docs' , ' emcc.txt' ), 'r' ) as f :
982
+ with open (utils .path_from_root ('docs/ emcc.txt' ), 'r' ) as f :
983
983
print (f .read ())
984
984
985
985
print ('''
@@ -1023,7 +1023,7 @@ def run(args):
1023
1023
args = [x for x in args if x != '--cflags' ]
1024
1024
with misc_temp_files .get_file (suffix = '.o' ) as temp_target :
1025
1025
input_file = 'hello_world.c'
1026
- cmd = [shared .PYTHON , sys .argv [0 ], shared .path_from_root ('tests' , input_file ), '-v' , '-c' , '-o' , temp_target ] + args
1026
+ cmd = [shared .PYTHON , sys .argv [0 ], utils .path_from_root ('tests' , input_file ), '-v' , '-c' , '-o' , temp_target ] + args
1027
1027
proc = run_process (cmd , stderr = PIPE , check = False )
1028
1028
if proc .returncode != 0 :
1029
1029
print (proc .stderr )
@@ -1367,19 +1367,19 @@ def phase_linker_setup(options, state, newargs, settings_map):
1367
1367
add_link_flag (state , sys .maxsize , f )
1368
1368
1369
1369
if options .emrun :
1370
- options .pre_js += read_file (shared .path_from_root ('src' , ' emrun_prejs.js' )) + '\n '
1371
- options .post_js += read_file (shared .path_from_root ('src' , ' emrun_postjs.js' )) + '\n '
1370
+ options .pre_js += read_file (utils .path_from_root ('src/ emrun_prejs.js' )) + '\n '
1371
+ options .post_js += read_file (utils .path_from_root ('src/ emrun_postjs.js' )) + '\n '
1372
1372
# emrun mode waits on program exit
1373
1373
settings .EXIT_RUNTIME = 1
1374
1374
1375
1375
if options .cpu_profiler :
1376
- options .post_js += read_file (shared .path_from_root ('src' , ' cpuprofiler.js' )) + '\n '
1376
+ options .post_js += read_file (utils .path_from_root ('src/ cpuprofiler.js' )) + '\n '
1377
1377
1378
1378
if options .memory_profiler :
1379
1379
settings .MEMORYPROFILER = 1
1380
1380
1381
1381
if options .thread_profiler :
1382
- options .post_js += read_file (shared .path_from_root ('src' , ' threadprofiler.js' )) + '\n '
1382
+ options .post_js += read_file (utils .path_from_root ('src/ threadprofiler.js' )) + '\n '
1383
1383
1384
1384
if options .memory_init_file is None :
1385
1385
options .memory_init_file = settings .OPT_LEVEL >= 2
@@ -2030,8 +2030,8 @@ def check_memory_setting(setting):
2030
2030
2031
2031
if settings .MINIMAL_RUNTIME :
2032
2032
# Minimal runtime uses a different default shell file
2033
- if options .shell_path == shared .path_from_root ('src' , ' shell.html' ):
2034
- options .shell_path = shared .path_from_root ('src' , ' shell_minimal_runtime.html' )
2033
+ if options .shell_path == utils .path_from_root ('src/ shell.html' ):
2034
+ options .shell_path = utils .path_from_root ('src/ shell_minimal_runtime.html' )
2035
2035
2036
2036
if settings .EXIT_RUNTIME :
2037
2037
settings .DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['proc_exit' ]
@@ -2045,7 +2045,7 @@ def check_memory_setting(setting):
2045
2045
2046
2046
if settings .MODULARIZE and not (settings .EXPORT_ES6 and not settings .SINGLE_FILE ) and \
2047
2047
settings .EXPORT_NAME == 'Module' and options .oformat == OFormat .HTML and \
2048
- (options .shell_path == shared .path_from_root ('src' , ' shell.html' ) or options .shell_path == shared .path_from_root ('src' , ' shell_minimal.html' )):
2048
+ (options .shell_path == utils .path_from_root ('src/ shell.html' ) or options .shell_path == utils .path_from_root ('src/ shell_minimal.html' )):
2049
2049
exit_with_error (f'Due to collision in variable name "Module", the shell file "{ options .shell_path } " is not compatible with build options "-s MODULARIZE=1 -s EXPORT_NAME=Module". Either provide your own shell file, change the name of the export to something else to avoid the name collision. (see https://github.com/emscripten-core/emscripten/issues/7950 for details)' )
2050
2050
2051
2051
if settings .STANDALONE_WASM :
@@ -2638,7 +2638,7 @@ def phase_final_emitting(options, state, target, wasm_target, memfile):
2638
2638
target_dir = os .path .dirname (os .path .abspath (target ))
2639
2639
worker_output = os .path .join (target_dir , settings .PTHREAD_WORKER_FILE )
2640
2640
with open (worker_output , 'w' ) as f :
2641
- f .write (shared .read_and_preprocess (shared .path_from_root ('src' , ' worker.js' ), expand_macros = True ))
2641
+ f .write (shared .read_and_preprocess (utils .path_from_root ('src/ worker.js' ), expand_macros = True ))
2642
2642
2643
2643
# Minify the worker.js file in optimized builds
2644
2644
if (settings .OPT_LEVEL >= 1 or settings .SHRINK_LEVEL >= 1 ) and not settings .DEBUG_LEVEL :
@@ -2659,7 +2659,7 @@ def phase_final_emitting(options, state, target, wasm_target, memfile):
2659
2659
# Process .js runtime file. Note that we need to handle the license text
2660
2660
# here, so that it will not confuse the hacky script.
2661
2661
shared .JS .handle_license (final_js )
2662
- shared .run_process ([shared .PYTHON , shared .path_from_root ('tools' , ' hacky_postprocess_around_closure_limitations.py' ), final_js ])
2662
+ shared .run_process ([shared .PYTHON , utils .path_from_root ('tools/ hacky_postprocess_around_closure_limitations.py' ), final_js ])
2663
2663
2664
2664
# Unmangle previously mangled `import.meta` references in both main code and libraries.
2665
2665
# See also: `preprocess` in parseTools.js.
@@ -2717,13 +2717,13 @@ def version_string():
2717
2717
# if the emscripten folder is not a git repo, don't run git show - that can
2718
2718
# look up and find the revision in a parent directory that is a git repo
2719
2719
revision_suffix = ''
2720
- if os .path .exists (shared .path_from_root ('.git' )):
2720
+ if os .path .exists (utils .path_from_root ('.git' )):
2721
2721
git_rev = run_process (
2722
2722
['git' , 'rev-parse' , 'HEAD' ],
2723
- stdout = PIPE , stderr = PIPE , cwd = shared .path_from_root ()).stdout .strip ()
2723
+ stdout = PIPE , stderr = PIPE , cwd = utils .path_from_root ()).stdout .strip ()
2724
2724
revision_suffix = '-git (%s)' % git_rev
2725
- elif os .path .exists (shared .path_from_root ('emscripten-revision.txt' )):
2726
- with open (shared .path_from_root ('emscripten-revision.txt' )) as f :
2725
+ elif os .path .exists (utils .path_from_root ('emscripten-revision.txt' )):
2726
+ with open (utils .path_from_root ('emscripten-revision.txt' )) as f :
2727
2727
git_rev = f .read ().strip ()
2728
2728
revision_suffix = ' (%s)' % git_rev
2729
2729
return f'emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) { shared .EMSCRIPTEN_VERSION } { revision_suffix } '
@@ -3163,7 +3163,7 @@ def phase_binaryen(target, options, wasm_target):
3163
3163
building .asyncify_lazy_load_code (wasm_target , debug = intermediate_debug_info )
3164
3164
3165
3165
def preprocess_wasm2js_script ():
3166
- return read_and_preprocess (shared .path_from_root ('src' , ' wasm2js.js' ), expand_macros = True )
3166
+ return read_and_preprocess (utils .path_from_root ('src/ wasm2js.js' ), expand_macros = True )
3167
3167
3168
3168
def run_closure_compiler ():
3169
3169
global final_js
@@ -3441,7 +3441,7 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam
3441
3441
# when script.inline isn't empty, add required helper functions such as tryParseAsDataURI
3442
3442
if script .inline :
3443
3443
for filename in ('arrayUtils.js' , 'base64Utils.js' , 'URIUtils.js' ):
3444
- content = read_and_preprocess (shared .path_from_root ('src' , filename ))
3444
+ content = read_and_preprocess (utils .path_from_root ('src' , filename ))
3445
3445
script .inline = content + script .inline
3446
3446
3447
3447
script .inline = 'var ASSERTIONS = %s;\n %s' % (settings .ASSERTIONS , script .inline )
@@ -3516,7 +3516,7 @@ def generate_html(target, options, js_target, target_basename,
3516
3516
3517
3517
if settings .EXPORT_NAME != 'Module' and \
3518
3518
not settings .MINIMAL_RUNTIME and \
3519
- options .shell_path == shared .path_from_root ('src' , ' shell.html' ):
3519
+ options .shell_path == utils .path_from_root ('src/ shell.html' ):
3520
3520
# the minimal runtime shell HTML is designed to support changing the export
3521
3521
# name, but the normal one does not support that currently
3522
3522
exit_with_error ('Customizing EXPORT_NAME requires that the HTML be customized to use that name (see https://github.com/emscripten-core/emscripten/issues/10086)' )
@@ -3547,9 +3547,9 @@ def generate_worker_js(target, js_target, target_basename):
3547
3547
3548
3548
3549
3549
def worker_js_script (proxy_worker_filename ):
3550
- web_gl_client_src = read_file (shared .path_from_root ('src' , ' webGLClient.js' ))
3551
- idb_store_src = read_file (shared .path_from_root ('src' , ' IDBStore.js' ))
3552
- proxy_client_src = read_file (shared .path_from_root ('src' , ' proxyClient.js' ))
3550
+ web_gl_client_src = read_file (utils .path_from_root ('src/ webGLClient.js' ))
3551
+ idb_store_src = read_file (utils .path_from_root ('src/ IDBStore.js' ))
3552
+ proxy_client_src = read_file (utils .path_from_root ('src/ proxyClient.js' ))
3553
3553
proxy_client_src = do_replace (proxy_client_src , '{{{ filename }}}' , proxy_worker_filename )
3554
3554
proxy_client_src = do_replace (proxy_client_src , '{{{ IDBStore.js }}}' , idb_store_src )
3555
3555
return web_gl_client_src + '\n ' + proxy_client_src
@@ -3662,7 +3662,7 @@ def replacement(self):
3662
3662
3663
3663
def is_valid_abspath (options , path_name ):
3664
3664
# Any path that is underneath the emscripten repository root must be ok.
3665
- if shared .path_from_root ().replace ('\\ ' , '/' ) in path_name .replace ('\\ ' , '/' ):
3665
+ if utils .path_from_root ().replace ('\\ ' , '/' ) in path_name .replace ('\\ ' , '/' ):
3666
3666
return True
3667
3667
3668
3668
def in_directory (root , child ):
0 commit comments