@@ -1115,10 +1115,10 @@ def check(input_file):
11151115 os .environ ['EMCC_WASM_BACKEND_BINARYEN' ] = '1'
11161116
11171117 if shared .Settings .BINARYEN :
1118- # set file locations, so that JS glue can find what it needs
1119- shared .Settings .WASM_TEXT_FILE = shared .JS . get_subresource_location ( wasm_text_target )
1120- shared .Settings .WASM_BINARY_FILE = shared .JS . get_subresource_location ( wasm_binary_target )
1121- shared .Settings .ASMJS_CODE_FILE = shared .JS . get_subresource_location ( asm_target )
1118+ # placeholder strings for JS glue, to be replaced with subresource locations in do_binaryen
1119+ shared .Settings .WASM_TEXT_FILE = shared .FilenameReplacementStrings . WASM_TEXT_FILE
1120+ shared .Settings .WASM_BINARY_FILE = shared .FilenameReplacementStrings . WASM_BINARY_FILE
1121+ shared .Settings .ASMJS_CODE_FILE = shared .FilenameReplacementStrings . ASMJS_CODE_FILE
11221122
11231123 shared .Settings .ASM_JS = 2 # when targeting wasm, we use a wasm Memory, but that is not compatible with asm.js opts
11241124 shared .Settings .GLOBAL_BASE = 1024 # leave some room for mapping global vars
@@ -2313,6 +2313,23 @@ def do_binaryen(final, target, asm_target, options, memfile, wasm_binary_target,
23132313 passes .append ('minifyWhitespace' )
23142314 final = shared .Building .js_optimizer_no_asmjs (final , passes )
23152315 if DEBUG : save_intermediate ('postclean' , 'js' )
2316+ # replace placeholder strings with correct subresource locations
2317+ f = open (final , 'r' )
2318+ js = f .read ()
2319+ f .close ()
2320+ f = open (final , 'w' )
2321+ for tup in [
2322+ (wasm_text_target , shared .FilenameReplacementStrings .WASM_TEXT_FILE ),
2323+ (wasm_binary_target , shared .FilenameReplacementStrings .WASM_BINARY_FILE ),
2324+ (asm_target , shared .FilenameReplacementStrings .ASMJS_CODE_FILE )
2325+ ]:
2326+ if not os .path .isfile (tup [0 ]):
2327+ continue
2328+ js = js .replace (tup [1 ], shared .JS .get_subresource_location (tup [0 ]))
2329+ if shared .Settings .SINGLE_FILE :
2330+ os .remove (tup [0 ])
2331+ f .write (js )
2332+ f .close ()
23162333 return final
23172334
23182335
0 commit comments