Skip to content

Commit 6c082e6

Browse files
authored
Revert "Fix relative paths in wasm backend source maps. Fixes #9837 (#9882)"
This reverts commit 5486c4a.
1 parent d016245 commit 6c082e6

File tree

4 files changed

+20
-66
lines changed

4 files changed

+20
-66
lines changed

tests/test_core.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7196,12 +7196,6 @@ def encode_utf8(data):
71967196
else:
71977197
return data
71987198

7199-
def source_map_file_loc(name):
7200-
if shared.Settings.WASM_BACKEND:
7201-
return name
7202-
# in fastcomp, we have the absolute path, which is not good
7203-
return os.path.abspath(name)
7204-
72057199
data = json.load(open(map_filename))
72067200
if str is bytes:
72077201
# Python 2 compatibility
@@ -7211,7 +7205,7 @@ def source_map_file_loc(name):
72117205
# the output file.
72127206
self.assertPathsIdentical(map_referent, data['file'])
72137207
assert len(data['sources']) == 1, data['sources']
7214-
self.assertPathsIdentical(source_map_file_loc('src.cpp'), data['sources'][0])
7208+
self.assertPathsIdentical(os.path.abspath('src.cpp'), data['sources'][0])
72157209
if hasattr(data, 'sourcesContent'):
72167210
# the sourcesContent attribute is optional, but if it is present it
72177211
# needs to containt valid source text.
@@ -7224,7 +7218,7 @@ def source_map_file_loc(name):
72247218
mappings = encode_utf8(mappings)
72257219
seen_lines = set()
72267220
for m in mappings:
7227-
self.assertPathsIdentical(source_map_file_loc('src.cpp'), m['source'])
7221+
self.assertPathsIdentical(os.path.abspath('src.cpp'), m['source'])
72287222
seen_lines.add(m['originalLine'])
72297223
# ensure that all the 'meaningful' lines in the original code get mapped
72307224
# when optimizing, the binaryen optimizer may remove some of them (by inlining, etc.)
@@ -8264,7 +8258,7 @@ def test_ubsan_full_static_cast(self, args):
82648258
'g4': ('-g4', [
82658259
"src.cpp:3:12: runtime error: reference binding to null pointer of type 'int'",
82668260
'in main ',
8267-
'src.cpp:3:8'
8261+
'/src.cpp:3:8'
82688262
]),
82698263
})
82708264
@no_fastcomp('ubsan not supported on fastcomp')

tests/test_other.py

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8902,8 +8902,7 @@ def test_wasm_sourcemap(self):
89028902
'--dwarfdump-output',
89038903
path_from_root('tests', 'other', 'wasm_sourcemap', 'foo.wasm.dump'),
89048904
'-o', 'a.out.wasm.map',
8905-
path_from_root('tests', 'other', 'wasm_sourcemap', 'foo.wasm'),
8906-
'--basepath=' + os.getcwd()]
8905+
path_from_root('tests', 'other', 'wasm_sourcemap', 'foo.wasm')]
89078906
run_process(wasm_map_cmd)
89088907
output = open('a.out.wasm.map').read()
89098908
# has "sources" entry with file (includes also `--prefix =wasm-src:///` replacement)
@@ -8918,35 +8917,12 @@ def test_wasm_sourcemap_dead(self):
89188917
'--dwarfdump-output',
89198918
path_from_root('tests', 'other', 'wasm_sourcemap_dead', 't.wasm.dump'),
89208919
'-o', 'a.out.wasm.map',
8921-
path_from_root('tests', 'other', 'wasm_sourcemap_dead', 't.wasm'),
8922-
'--basepath=' + os.getcwd()]
8920+
path_from_root('tests', 'other', 'wasm_sourcemap_dead', 't.wasm')]
89238921
run_process(wasm_map_cmd, stdout=PIPE, stderr=PIPE)
89248922
output = open('a.out.wasm.map').read()
89258923
# has only two entries
89268924
self.assertRegexpMatches(output, r'"mappings":\s*"[A-Za-z0-9+/]+,[A-Za-z0-9+/]+"')
89278925

8928-
@no_fastcomp()
8929-
def test_wasm_sourcemap_relative_paths(self):
8930-
def test(infile, source_map_added_dir=''):
8931-
expected_source_map_path = os.path.join(source_map_added_dir, 'a.cpp')
8932-
print(infile, expected_source_map_path)
8933-
shutil.copyfile(path_from_root('tests', 'hello_123.c'), infile)
8934-
infiles = [
8935-
infile,
8936-
os.path.abspath(infile),
8937-
'./' + infile
8938-
]
8939-
for curr in infiles:
8940-
print(' ', curr)
8941-
run_process([PYTHON, EMCC, curr, '-g4'])
8942-
with open('a.out.wasm.map', 'r') as f:
8943-
self.assertIn('"%s"' % expected_source_map_path, str(f.read()))
8944-
8945-
test('a.cpp')
8946-
8947-
os.mkdir('inner')
8948-
test(os.path.join('inner', 'a.cpp'), 'inner')
8949-
89508926
def test_wasm_producers_section(self):
89518927
# no producers section by default
89528928
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_world.c')])
@@ -9723,17 +9699,17 @@ def test_lsan_leaks(self, ext):
97239699
@parameterized({
97249700
'c': ['c', [
97259701
r'in malloc.*a\.out\.wasm\+0x',
9726-
r'(?im)in f (|[/a-z\.]:).*/test_lsan_leaks\.c:6:21$',
9727-
r'(?im)in main (|[/a-z\.]:).*/test_lsan_leaks\.c:10:16$',
9728-
r'(?im)in main (|[/a-z\.]:).*/test_lsan_leaks\.c:12:3$',
9729-
r'(?im)in main (|[/a-z\.]:).*/test_lsan_leaks\.c:13:3$',
9702+
r'(?im)in f (/|[a-z]:).*/test_lsan_leaks\.c:6:21$',
9703+
r'(?im)in main (/|[a-z]:).*/test_lsan_leaks\.c:10:16$',
9704+
r'(?im)in main (/|[a-z]:).*/test_lsan_leaks\.c:12:3$',
9705+
r'(?im)in main (/|[a-z]:).*/test_lsan_leaks\.c:13:3$',
97309706
]],
97319707
'cpp': ['cpp', [
97329708
r'in operator new\[\]\(unsigned long\).*a\.out\.wasm\+0x',
9733-
r'(?im)in f\(\) (|[/a-z\.]:).*/test_lsan_leaks\.cpp:4:21$',
9734-
r'(?im)in main (|[/a-z\.]:).*/test_lsan_leaks\.cpp:8:16$',
9735-
r'(?im)in main (|[/a-z\.]:).*/test_lsan_leaks\.cpp:10:3$',
9736-
r'(?im)in main (|[/a-z\.]:).*/test_lsan_leaks\.cpp:11:3$',
9709+
r'(?im)in f\(\) (/|[a-z]:).*/test_lsan_leaks\.cpp:4:21$',
9710+
r'(?im)in main (/|[a-z]:).*/test_lsan_leaks\.cpp:8:16$',
9711+
r'(?im)in main (/|[a-z]:).*/test_lsan_leaks\.cpp:10:3$',
9712+
r'(?im)in main (/|[a-z]:).*/test_lsan_leaks\.cpp:11:3$',
97379713
]],
97389714
})
97399715
@no_fastcomp('lsan not supported on fastcomp')

tools/shared.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,14 +2871,10 @@ def path_to_system_js_libraries(library_name):
28712871

28722872
@staticmethod
28732873
def emit_wasm_source_map(wasm_file, map_file):
2874-
# source file paths must be relative to the location of the map (which is
2875-
# emitted alongside the wasm)
2876-
base_path = os.path.dirname(os.path.abspath(Settings.WASM_BINARY_FILE))
28772874
sourcemap_cmd = [PYTHON, path_from_root('tools', 'wasm-sourcemap.py'),
28782875
wasm_file,
28792876
'--dwarfdump=' + LLVM_DWARFDUMP,
2880-
'-o', map_file,
2881-
'--basepath=' + base_path]
2877+
'-o', map_file]
28822878
check_call(sourcemap_cmd)
28832879

28842880
@staticmethod

tools/wasm-sourcemap.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
import argparse
14-
from collections import OrderedDict
14+
from collections import OrderedDict, namedtuple
1515
import json
1616
import logging
1717
from math import floor, log
@@ -39,7 +39,6 @@ def parse_args():
3939
parser.add_argument('-u', '--source-map-url', nargs='?', help='specifies sourceMappingURL section contest')
4040
parser.add_argument('--dwarfdump', help="path to llvm-dwarfdump executable")
4141
parser.add_argument('--dwarfdump-output', nargs='?', help=argparse.SUPPRESS)
42-
parser.add_argument('--basepath', help='base path for source files, which will be relative to this')
4342
return parser.parse_args()
4443

4544

@@ -74,13 +73,7 @@ def resolve(self, name):
7473
# SourceMapPrefixes contains resolver for file names that are:
7574
# - "sources" is for names that output to source maps JSON
7675
# - "load" is for paths that used to load source text
77-
class SourceMapPrefixes:
78-
def __init__(self, sources, load):
79-
self.sources = sources
80-
self.load = load
81-
82-
def provided(self):
83-
return bool(self.sources.prefixes or self.load.prefixes)
76+
SourceMapPrefixes = namedtuple('SourceMapPrefixes', 'sources, load')
8477

8578

8679
def encode_vlq(n):
@@ -250,10 +243,11 @@ def read_dwarf_entries(wasm, options):
250243
return sorted(entries, key=lambda entry: entry['address'])
251244

252245

253-
def build_sourcemap(entries, code_section_offset, prefixes, collect_sources, base_path):
246+
def build_sourcemap(entries, code_section_offset, prefixes, collect_sources):
254247
sources = []
255248
sources_content = [] if collect_sources else None
256249
mappings = []
250+
257251
sources_map = {}
258252
last_address = 0
259253
last_source_id = 0
@@ -270,13 +264,7 @@ def build_sourcemap(entries, code_section_offset, prefixes, collect_sources, bas
270264
column = 1
271265
address = entry['address'] + code_section_offset
272266
file_name = entry['file']
273-
# if prefixes were provided, we use that; otherwise, we emit a relative
274-
# path
275-
if prefixes.provided():
276-
source_name = prefixes.sources.resolve(file_name)
277-
else:
278-
file_name = os.path.relpath(os.path.abspath(file_name), base_path)
279-
source_name = file_name
267+
source_name = prefixes.sources.resolve(file_name)
280268
if source_name not in sources_map:
281269
source_id = len(sources)
282270
sources_map[source_name] = source_id
@@ -323,7 +311,7 @@ def main():
323311
prefixes = SourceMapPrefixes(sources=Prefixes(options.prefix), load=Prefixes(options.load_prefix))
324312

325313
logger.debug('Saving to %s' % options.output)
326-
map = build_sourcemap(entries, code_section_offset, prefixes, options.sources, options.basepath)
314+
map = build_sourcemap(entries, code_section_offset, prefixes, options.sources)
327315
with open(options.output, 'w') as outfile:
328316
json.dump(map, outfile, separators=(',', ':'))
329317

0 commit comments

Comments
 (0)