Skip to content

Commit 893b32e

Browse files
authored
Use shared utils in wasm-sourcemap.py. NFC (#25875)
I suppose at some point the idea was to allow this script to be shipped and uses outside of emscripten, but I think that ship has sailed.
1 parent 3f9f71f commit 893b32e

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

tools/wasm-sourcemap.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
import re
1818
import sys
1919
from math import floor, log
20-
from pathlib import Path
21-
from subprocess import PIPE, Popen
2220

2321
__scriptdir__ = os.path.dirname(os.path.abspath(__file__))
2422
__rootdir__ = os.path.dirname(__scriptdir__)
2523
sys.path.insert(0, __rootdir__)
2624

27-
from tools import utils
25+
from tools import shared, utils
2826
from tools.system_libs import DETERMINISTIC_PREFIX
2927

3028
EMSCRIPTEN_PREFIX = utils.normalize_path(utils.path_from_root())
@@ -233,24 +231,18 @@ def extract_comp_dir_map(text):
233231

234232
def read_dwarf_entries(wasm, options):
235233
if options.dwarfdump_output:
236-
output = Path(options.dwarfdump_output).read_bytes()
234+
output = utils.read_file(options.dwarfdump_output)
237235
elif options.dwarfdump:
238236
logger.debug('Reading DWARF information from %s' % wasm)
239237
if not os.path.exists(options.dwarfdump):
240-
logger.error('llvm-dwarfdump not found: ' + options.dwarfdump)
241-
sys.exit(1)
242-
process = Popen([options.dwarfdump, '-debug-info', '-debug-line', '--recurse-depth=0', wasm], stdout=PIPE)
243-
output, err = process.communicate()
244-
exit_code = process.wait()
245-
if exit_code != 0:
246-
logger.error('Error during llvm-dwarfdump execution (%s)' % exit_code)
247-
sys.exit(1)
238+
utils.exit_with_error('llvm-dwarfdump not found: ' + options.dwarfdump)
239+
proc = shared.check_call([options.dwarfdump, '-debug-info', '-debug-line', '--recurse-depth=0', wasm], stdout=shared.PIPE)
240+
output = proc.stdout
248241
else:
249-
logger.error('Please specify either --dwarfdump or --dwarfdump-output')
250-
sys.exit(1)
242+
utils.exit_with_error('Please specify either --dwarfdump or --dwarfdump-output')
251243

252244
entries = []
253-
debug_line_chunks = re.split(r"debug_line\[(0x[0-9a-f]*)\]", output.decode('utf-8'))
245+
debug_line_chunks = re.split(r"debug_line\[(0x[0-9a-f]*)\]", output)
254246
map_stmt_list_to_comp_dir = extract_comp_dir_map(debug_line_chunks[0])
255247
for stmt_list, line_chunk in zip(debug_line_chunks[1::2], debug_line_chunks[2::2]):
256248
comp_dir = map_stmt_list_to_comp_dir.get(stmt_list, '')

0 commit comments

Comments
 (0)