@@ -232,10 +232,10 @@ def __init__(self):
232
232
self .use_closure_compiler = None
233
233
self .closure_args = []
234
234
self .js_transform = None
235
- self .pre_js = '' # before all js
236
- self .post_js = '' # after all js
237
- self .extern_pre_js = '' # before all js, external to optimized code
238
- self .extern_post_js = '' # after all js, external to optimized code
235
+ self .pre_js = [] # before all js
236
+ self .post_js = [] # after all js
237
+ self .extern_pre_js = [] # before all js, external to optimized code
238
+ self .extern_post_js = [] # after all js, external to optimized code
239
239
self .preload_files = []
240
240
self .embed_files = []
241
241
self .exclude_files = []
@@ -498,6 +498,11 @@ def fix_windows_newlines(text):
498
498
return text
499
499
500
500
501
+ def read_js_files (files ):
502
+ contents = '\n ' .join (read_file (f ) for f in files )
503
+ return fix_windows_newlines (contents )
504
+
505
+
501
506
def cxx_to_c_compiler (cxx ):
502
507
# Convert C++ compiler name into C compiler name
503
508
dirname , basename = os .path .split (cxx )
@@ -1366,19 +1371,24 @@ def phase_linker_setup(options, state, newargs, settings_map):
1366
1371
add_link_flag (state , sys .maxsize , f )
1367
1372
1368
1373
if options .emrun :
1369
- options .pre_js += read_file (utils .path_from_root ('src/emrun_prejs.js' )) + ' \n '
1370
- options .post_js += read_file (utils .path_from_root ('src/emrun_postjs.js' )) + ' \n '
1374
+ options .pre_js . append (utils .path_from_root ('src/emrun_prejs.js' ))
1375
+ options .post_js . append (utils .path_from_root ('src/emrun_postjs.js' ))
1371
1376
# emrun mode waits on program exit
1372
1377
settings .EXIT_RUNTIME = 1
1373
1378
1374
1379
if options .cpu_profiler :
1375
- options .post_js += read_file (utils .path_from_root ('src/cpuprofiler.js' )) + ' \n '
1380
+ options .post_js . append (utils .path_from_root ('src/cpuprofiler.js' ))
1376
1381
1377
1382
if options .memory_profiler :
1378
1383
settings .MEMORYPROFILER = 1
1379
1384
1380
1385
if options .thread_profiler :
1381
- options .post_js += read_file (utils .path_from_root ('src/threadprofiler.js' )) + '\n '
1386
+ options .post_js .append (utils .path_from_root ('src/threadprofiler.js' ))
1387
+
1388
+ options .pre_js = read_js_files (options .pre_js )
1389
+ options .post_js = read_js_files (options .post_js )
1390
+ options .extern_pre_js = read_js_files (options .extern_pre_js )
1391
+ options .extern_post_js = read_js_files (options .extern_post_js )
1382
1392
1383
1393
if options .memory_init_file is None :
1384
1394
options .memory_init_file = settings .OPT_LEVEL >= 2
@@ -2597,9 +2607,8 @@ def phase_source_transforms(options, target):
2597
2607
with open (final_js , 'w' ) as f :
2598
2608
# pre-js code goes right after the Module integration code (so it
2599
2609
# can use Module), we have a marker for it
2600
- f .write (do_replace (src , '// {{PRE_JSES}}' , fix_windows_newlines (options .pre_js )))
2601
- f .write (fix_windows_newlines (options .post_js ))
2602
- options .pre_js = src = options .post_js = None
2610
+ f .write (do_replace (src , '// {{PRE_JSES}}' , options .pre_js ))
2611
+ f .write (options .post_js )
2603
2612
save_intermediate ('pre-post' )
2604
2613
2605
2614
# Apply a source code transformation, if requested
@@ -2675,9 +2684,9 @@ def phase_final_emitting(options, state, target, wasm_target, memfile):
2675
2684
src = read_file (final_js )
2676
2685
final_js += '.epp.js'
2677
2686
with open (final_js , 'w' ) as f :
2678
- f .write (fix_windows_newlines ( options .extern_pre_js ) )
2687
+ f .write (options .extern_pre_js )
2679
2688
f .write (src )
2680
- f .write (fix_windows_newlines ( options .extern_post_js ) )
2689
+ f .write (options .extern_post_js )
2681
2690
save_intermediate ('extern-pre-post' )
2682
2691
2683
2692
shared .JS .handle_license (final_js )
@@ -2816,13 +2825,13 @@ def consume_arg_file():
2816
2825
elif check_arg ('--js-transform' ):
2817
2826
options .js_transform = consume_arg ()
2818
2827
elif check_arg ('--pre-js' ):
2819
- options .pre_js += read_file (consume_arg_file ()) + ' \n '
2828
+ options .pre_js . append (consume_arg_file ())
2820
2829
elif check_arg ('--post-js' ):
2821
- options .post_js += read_file (consume_arg_file ()) + ' \n '
2830
+ options .post_js . append (consume_arg_file ())
2822
2831
elif check_arg ('--extern-pre-js' ):
2823
- options .extern_pre_js += read_file (consume_arg_file ()) + ' \n '
2832
+ options .extern_pre_js . append (consume_arg_file ())
2824
2833
elif check_arg ('--extern-post-js' ):
2825
- options .extern_post_js += read_file (consume_arg_file ()) + ' \n '
2834
+ options .extern_post_js . append (consume_arg_file ())
2826
2835
elif check_arg ('--compiler-wrapper' ):
2827
2836
config .COMPILER_WRAPPER = consume_arg ()
2828
2837
elif check_flag ('--post-link' ):
0 commit comments