Skip to content

Commit a455a08

Browse files
authored
Convert wasm-sourcemap call from subprocess to library call. NFC (#25373)
Fixes: #25323
1 parent ee2af97 commit a455a08

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

tools/building.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from .toolchain_profiler import ToolchainProfiler
77

8+
import importlib
89
import json
910
import logging
1011
import os
@@ -1145,8 +1146,11 @@ def emit_wasm_source_map(wasm_file, map_file, final_wasm):
11451146
# source file paths must be relative to the location of the map (which is
11461147
# emitted alongside the wasm)
11471148
base_path = os.path.dirname(os.path.abspath(final_wasm))
1148-
sourcemap_cmd = [sys.executable, '-E', path_from_root('tools/wasm-sourcemap.py'),
1149-
wasm_file,
1149+
1150+
# TODO(sbc): Rename wasm-sourcemap so it can be imported directly without
1151+
# importlib.
1152+
wasm_sourcemap = importlib.import_module('tools.wasm-sourcemap')
1153+
sourcemap_cmd = [wasm_file,
11501154
'--dwarfdump=' + LLVM_DWARFDUMP,
11511155
'-o', map_file,
11521156
'--basepath=' + base_path]
@@ -1157,7 +1161,10 @@ def emit_wasm_source_map(wasm_file, map_file, final_wasm):
11571161
if settings.GENERATE_SOURCE_MAP == 2:
11581162
sourcemap_cmd += ['--sources']
11591163

1160-
check_call(sourcemap_cmd)
1164+
# TODO(sbc): Convert to using library internal API instead of running `main` here
1165+
rtn = wasm_sourcemap.main(sourcemap_cmd)
1166+
if rtn != 0:
1167+
exit_with_error('wasm-sourcemap failed (%s)', sourcemap_cmd)
11611168

11621169

11631170
def get_binaryen_feature_flags():

tools/wasm-sourcemap.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
logger = logging.getLogger('wasm-sourcemap')
3434

3535

36-
def parse_args():
36+
def parse_args(args):
3737
parser = argparse.ArgumentParser(prog='wasm-sourcemap.py', description=__doc__)
3838
parser.add_argument('wasm', help='wasm file')
3939
parser.add_argument('-o', '--output', help='output source map')
@@ -46,7 +46,7 @@ def parse_args():
4646
parser.add_argument('--dwarfdump', help="path to llvm-dwarfdump executable")
4747
parser.add_argument('--dwarfdump-output', nargs='?', help=argparse.SUPPRESS)
4848
parser.add_argument('--basepath', help='base path for source files, which will be relative to this')
49-
return parser.parse_args()
49+
return parser.parse_args(args)
5050

5151

5252
class Prefixes:
@@ -361,8 +361,8 @@ def build_sourcemap(entries, code_section_offset, options):
361361
'mappings': ','.join(mappings)}
362362

363363

364-
def main():
365-
options = parse_args()
364+
def main(args):
365+
options = parse_args(args)
366366

367367
wasm_input = options.wasm
368368
with open(wasm_input, 'rb') as infile:
@@ -394,4 +394,4 @@ def main():
394394

395395
if __name__ == '__main__':
396396
logging.basicConfig(level=logging.DEBUG if os.environ.get('EMCC_DEBUG') else logging.INFO)
397-
sys.exit(main())
397+
sys.exit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)