-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix relative paths in wasm backend source maps. Fixes #9837 #9882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
a213913
c813941
6367083
4c2cf4a
842caaf
acef71d
a9467bd
18ac680
c9a3bd0
bb04bd9
917b74c
3b15d9e
6bdc495
8412ca7
2174057
f2b9909
450097c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ def parse_args(): | |
| parser.add_argument('-u', '--source-map-url', nargs='?', help='specifies sourceMappingURL section contest') | ||
| parser.add_argument('--dwarfdump', help="path to llvm-dwarfdump executable") | ||
| parser.add_argument('--dwarfdump-output', nargs='?', help=argparse.SUPPRESS) | ||
| parser.add_argument('--basepath', help='base path for source files, which will be relative to this') | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
|
|
@@ -243,11 +244,10 @@ def read_dwarf_entries(wasm, options): | |
| return sorted(entries, key=lambda entry: entry['address']) | ||
|
|
||
|
|
||
| def build_sourcemap(entries, code_section_offset, prefixes, collect_sources): | ||
| def build_sourcemap(entries, code_section_offset, prefixes, collect_sources, base_path): | ||
| sources = [] | ||
| sources_content = [] if collect_sources else None | ||
| mappings = [] | ||
|
|
||
| sources_map = {} | ||
| last_address = 0 | ||
| last_source_id = 0 | ||
|
|
@@ -264,6 +264,14 @@ def build_sourcemap(entries, code_section_offset, prefixes, collect_sources): | |
| column = 1 | ||
| address = entry['address'] + code_section_offset | ||
| file_name = entry['file'] | ||
| # prefer to emit a relative path to the base path, which is where the | ||
|
||
| # source map file itself is, so the browser can find it. however, if they | ||
| # have no shared prefix (like one is /a/b and the other /c/d) then we | ||
| # would not end up with anything more useful (like ../../c/d), so avoid | ||
| # that (a shared prefix of size 1, like '/', is useless) | ||
| abs_file_name = os.path.abspath(file_name) | ||
| if len(os.path.commonprefix([abs_file_name, base_path])) > 1: | ||
| file_name = os.path.relpath(abs_file_name, base_path) | ||
| source_name = prefixes.sources.resolve(file_name) | ||
| if source_name not in sources_map: | ||
| source_id = len(sources) | ||
|
|
@@ -311,7 +319,7 @@ def main(): | |
| prefixes = SourceMapPrefixes(sources=Prefixes(options.prefix), load=Prefixes(options.load_prefix)) | ||
|
|
||
| logger.debug('Saving to %s' % options.output) | ||
| map = build_sourcemap(entries, code_section_offset, prefixes, options.sources) | ||
| map = build_sourcemap(entries, code_section_offset, prefixes, options.sources, options.basepath) | ||
| with open(options.output, 'w') as outfile: | ||
| json.dump(map, outfile, separators=(',', ':')) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.