-
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if we should do anything special here... since we're talking about edge cases anyway, consider one where a static server that is hosting Then, let's say Wasm is under If you use relative paths, then source would be encoded as TL;DR - let's just do the simple thing and use relative paths unconditionally, which would happen to also cover edge cases more correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would break the current
Is that ok? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (if that's not ok, what would the proper output there be, do you think?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, interesting. Where is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's added in the test, using the Maybe we can remove that option? If you and @yurydelendik agree that should be fine as I don't see other users in the codebase. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yurydelendik Doesn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
To do it after the fact of creating a wasm binary. ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, but now that both compilers support native remapping, it seems that we can just skip it here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @RReverser , you are right, I had that mixed up! Should be correct now - use the prefixes if provided, otherwise use a proper relative path. |
||
# 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.