Skip to content

Commit a6a8b96

Browse files
authored
Refactor debug_copy (emscripten-core#9876)
This moves the emscripten.py method of that name, which makes a copy of the current file to the temp dir, for later debugging, to shared.py. It also uses it in run_binaryen_command, to make it easier to debug. It also adds an integer counter to the files, so their their order is clear.
1 parent de0c744 commit a6a8b96

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

emscripten.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import re
1919
import time
2020
import logging
21-
import shutil
2221
import pprint
2322
from collections import OrderedDict
2423

@@ -2275,21 +2274,17 @@ def remove_trailing_zeros(memfile):
22752274

22762275

22772276
def finalize_wasm(temp_files, infile, outfile, memfile, DEBUG):
2278-
def debug_copy(src, dst):
2279-
if DEBUG:
2280-
shutil.copyfile(src, os.path.join(shared.CANONICAL_TEMP_DIR, dst))
2281-
22822277
basename = shared.unsuffixed(outfile.name)
22832278
wasm = basename + '.wasm'
22842279
base_wasm = infile
2285-
debug_copy(infile, 'base.wasm')
2280+
shared.Building.debug_copy(infile, 'base.wasm')
22862281

22872282
args = ['--detect-features']
22882283

22892284
write_source_map = shared.Settings.DEBUG_LEVEL >= 4
22902285
if write_source_map:
22912286
shared.Building.emit_wasm_source_map(base_wasm, base_wasm + '.map')
2292-
debug_copy(base_wasm + '.map', 'base_wasm.map')
2287+
shared.Building.debug_copy(base_wasm + '.map', 'base_wasm.map')
22932288
args += ['--output-source-map-url=' + shared.Settings.SOURCE_MAP_BASE + os.path.basename(shared.Settings.WASM_BINARY_FILE) + '.map']
22942289

22952290
# tell binaryen to look at the features section, and if there isn't one, to use MVP
@@ -2329,8 +2324,8 @@ def debug_copy(src, dst):
23292324
args=args,
23302325
stdout=subprocess.PIPE)
23312326
if write_source_map:
2332-
debug_copy(wasm + '.map', 'post_finalize.map')
2333-
debug_copy(wasm, 'post_finalize.wasm')
2327+
shared.Building.debug_copy(wasm + '.map', 'post_finalize.map')
2328+
shared.Building.debug_copy(wasm, 'post_finalize.wasm')
23342329

23352330
if not shared.Settings.MEM_INIT_IN_WASM:
23362331
# we have a separate .mem file. binaryen did not strip any trailing zeros,

tools/shared.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,12 +2913,23 @@ def run_binaryen_command(tool, infile, outfile=None, args=[], debug=False, stdou
29132913
# that info in the map anyhow
29142914
cmd += ['--strip-dwarf']
29152915

2916-
return run_process(cmd, stdout=stdout).stdout
2916+
ret = run_process(cmd, stdout=stdout).stdout
2917+
if outfile:
2918+
Building.debug_copy(outfile, '%s.wasm' % tool)
2919+
return ret
29172920

29182921
@staticmethod
29192922
def run_wasm_opt(*args, **kwargs):
29202923
return Building.run_binaryen_command('wasm-opt', *args, **kwargs)
29212924

2925+
debug_copy_counter = 0
2926+
2927+
@staticmethod
2928+
def debug_copy(src, dst):
2929+
if DEBUG:
2930+
shutil.copyfile(src, os.path.join(CANONICAL_TEMP_DIR, 'emdebug-%d-%s' % (Building.debug_copy_counter, dst)))
2931+
Building.debug_copy_counter += 1
2932+
29222933

29232934
# compatibility with existing emcc, etc. scripts
29242935
Cache = cache.Cache()

0 commit comments

Comments
 (0)