@@ -817,6 +817,18 @@ def get_file_suffix(filename):
817
817
return ''
818
818
819
819
820
+ def get_secondary_target (target , ext ):
821
+ # Depending on the output format emscripten creates zero or more secondary
822
+ # output files (e.g. the .wasm file when creating JS output, or the
823
+ # .js and the .wasm file when creating html output.
824
+ # Thus function names the secondary output files, while ensuring they
825
+ # never collide with the primary one.
826
+ base = unsuffixed (target )
827
+ if get_file_suffix (target ) == ext :
828
+ base += '_'
829
+ return base + ext
830
+
831
+
820
832
def in_temp (name ):
821
833
temp_dir = shared .get_emscripten_temp_dir ()
822
834
return os .path .join (temp_dir , os .path .basename (name ))
@@ -829,8 +841,6 @@ def in_temp(name):
829
841
# Main run() function
830
842
#
831
843
def run (args ):
832
- target = None
833
-
834
844
# Additional compiler flags that we treat as if they were passed to us on the
835
845
# commandline
836
846
EMCC_CFLAGS = os .environ .get ('EMCC_CFLAGS' )
@@ -1227,7 +1237,7 @@ def add_link_flag(i, f):
1227
1237
wasm_target = target
1228
1238
else :
1229
1239
# Otherwise the wasm file is produced alongside the final target.
1230
- wasm_target = unsuffixed (target ) + '.wasm'
1240
+ wasm_target = get_secondary_target (target , '.wasm' )
1231
1241
1232
1242
# Apply user -jsD settings
1233
1243
for s in user_js_defines :
@@ -2438,7 +2448,7 @@ def post_link(options, in_wasm, wasm_target, target):
2438
2448
if options .oformat in (OFormat .JS , OFormat .MJS ):
2439
2449
js_target = target
2440
2450
else :
2441
- js_target = unsuffixed (target ) + '.js'
2451
+ js_target = get_secondary_target (target , '.js' )
2442
2452
2443
2453
# The JS is now final. Move it to its final location
2444
2454
move_file (final_js , js_target )
0 commit comments