3838
3939
4040import emscripten
41- from tools import shared , system_libs
41+ from tools import shared , system_libs , utils
4242from tools import colored_logger , diagnostics , building
4343from tools .shared import unsuffixed , unsuffixed_basename , WINDOWS , safe_copy
4444from tools .shared import run_process , read_and_preprocess , exit_with_error , DEBUG
@@ -240,7 +240,7 @@ def __init__(self):
240240 self .embed_files = []
241241 self .exclude_files = []
242242 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' )
244244 self .source_map_base = ''
245245 self .emrun = False
246246 self .cpu_profiler = False
@@ -979,7 +979,7 @@ def run(args):
979979 # site/build/text/docs/tools_reference/emcc.txt
980980 # This then needs to be copied to its final home in docs/emcc.txt from where
981981 # 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 :
983983 print (f .read ())
984984
985985 print ('''
@@ -1023,7 +1023,7 @@ def run(args):
10231023 args = [x for x in args if x != '--cflags' ]
10241024 with misc_temp_files .get_file (suffix = '.o' ) as temp_target :
10251025 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
10271027 proc = run_process (cmd , stderr = PIPE , check = False )
10281028 if proc .returncode != 0 :
10291029 print (proc .stderr )
@@ -1367,19 +1367,19 @@ def phase_linker_setup(options, state, newargs, settings_map):
13671367 add_link_flag (state , sys .maxsize , f )
13681368
13691369 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 '
13721372 # emrun mode waits on program exit
13731373 settings .EXIT_RUNTIME = 1
13741374
13751375 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 '
13771377
13781378 if options .memory_profiler :
13791379 settings .MEMORYPROFILER = 1
13801380
13811381 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 '
13831383
13841384 if options .memory_init_file is None :
13851385 options .memory_init_file = settings .OPT_LEVEL >= 2
@@ -2030,8 +2030,8 @@ def check_memory_setting(setting):
20302030
20312031 if settings .MINIMAL_RUNTIME :
20322032 # 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' )
20352035
20362036 if settings .EXIT_RUNTIME :
20372037 settings .DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['proc_exit' ]
@@ -2045,7 +2045,7 @@ def check_memory_setting(setting):
20452045
20462046 if settings .MODULARIZE and not (settings .EXPORT_ES6 and not settings .SINGLE_FILE ) and \
20472047 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' )):
20492049 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)' )
20502050
20512051 if settings .STANDALONE_WASM :
@@ -2638,7 +2638,7 @@ def phase_final_emitting(options, state, target, wasm_target, memfile):
26382638 target_dir = os .path .dirname (os .path .abspath (target ))
26392639 worker_output = os .path .join (target_dir , settings .PTHREAD_WORKER_FILE )
26402640 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 ))
26422642
26432643 # Minify the worker.js file in optimized builds
26442644 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):
26592659 # Process .js runtime file. Note that we need to handle the license text
26602660 # here, so that it will not confuse the hacky script.
26612661 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 ])
26632663
26642664 # Unmangle previously mangled `import.meta` references in both main code and libraries.
26652665 # See also: `preprocess` in parseTools.js.
@@ -2717,13 +2717,13 @@ def version_string():
27172717 # if the emscripten folder is not a git repo, don't run git show - that can
27182718 # look up and find the revision in a parent directory that is a git repo
27192719 revision_suffix = ''
2720- if os .path .exists (shared .path_from_root ('.git' )):
2720+ if os .path .exists (utils .path_from_root ('.git' )):
27212721 git_rev = run_process (
27222722 ['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 ()
27242724 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 :
27272727 git_rev = f .read ().strip ()
27282728 revision_suffix = ' (%s)' % git_rev
27292729 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):
31633163 building .asyncify_lazy_load_code (wasm_target , debug = intermediate_debug_info )
31643164
31653165 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 )
31673167
31683168 def run_closure_compiler ():
31693169 global final_js
@@ -3441,7 +3441,7 @@ def generate_traditional_runtime_html(target, options, js_target, target_basenam
34413441 # when script.inline isn't empty, add required helper functions such as tryParseAsDataURI
34423442 if script .inline :
34433443 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 ))
34453445 script .inline = content + script .inline
34463446
34473447 script .inline = 'var ASSERTIONS = %s;\n %s' % (settings .ASSERTIONS , script .inline )
@@ -3516,7 +3516,7 @@ def generate_html(target, options, js_target, target_basename,
35163516
35173517 if settings .EXPORT_NAME != 'Module' and \
35183518 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' ):
35203520 # the minimal runtime shell HTML is designed to support changing the export
35213521 # name, but the normal one does not support that currently
35223522 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):
35473547
35483548
35493549def 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' ))
35533553 proxy_client_src = do_replace (proxy_client_src , '{{{ filename }}}' , proxy_worker_filename )
35543554 proxy_client_src = do_replace (proxy_client_src , '{{{ IDBStore.js }}}' , idb_store_src )
35553555 return web_gl_client_src + '\n ' + proxy_client_src
@@ -3662,7 +3662,7 @@ def replacement(self):
36623662
36633663def is_valid_abspath (options , path_name ):
36643664 # 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 ('\\ ' , '/' ):
36663666 return True
36673667
36683668 def in_directory (root , child ):
0 commit comments