Skip to content
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

Invalid URLs (absolute paths) in source maps in some cases #9837

Closed
RReverser opened this issue Nov 14, 2019 · 5 comments
Closed

Invalid URLs (absolute paths) in source maps in some cases #9837

RReverser opened this issue Nov 14, 2019 · 5 comments

Comments

@RReverser
Copy link
Collaborator

RReverser commented Nov 14, 2019

Summary

Source maps are supposed to contain only valid URLs in the sources array (either relative, or absolute with scheme). Emscripten sometimes emits absolute paths into that array instead, making them impossible to load by a browser.

Examples

For a file C:\Users\rreverser\Projects\temp-wasm\temp.c with arbitary content in a folder temp-wasm, I'm trying different formats for the filename.

Note that this is not a Windows-specific issue, and you'll get same results with Unix filepaths.

  1. Running emcc ./temp.c -g4 -o temp.wasm (relative filename in the same folder):
{"version":3,"sources":["./temp.c"],"names":[],...
  1. Running emcc temp.c -g4 -o temp.wasm (same relative filename, but without explicit ./):
{"version":3,"sources":["C:/Users/rreverser/Projects/temp-wasm/temp.c"],"names":[],...
  1. Running emcc ../temp-wasm/temp.c (relative filename with a folder):
{"version":3,"sources":["../temp-wasm/temp.c"],"names":[],
  1. Running emcc C:\Users\rreverser\Projects\temp-wasm\temp.c -g4 -o temp.wasm (absolute filename):
{"version":3,"sources":["C:/Users/rreverser/Projects/temp-wasm/temp.c"],"names":[],...

Results

When a filename is relative but without a leading ./ or is specified as absolute, Emscripten outputs an absolute filename in sources, which is not a valid URL and can't be handled by DevTools. It could be valid if prefixed with file:/// specifier, but that's not an ideal solution.

The only case where Emscripten sources ends up being valid URL is when a filename is specified as explicitly relative (cases 1 and 3).

Then, Emscripten outputs a relative URL as well, which can be handled well by DevTools both in case of loading from filesystem as well as a static HTTP server.

More so, even though case 3 outputs a relative filename, it's not ideal.

Suggested solution

Emscripten should always compute relative URL out of the source map filename and the actual sources, and emit that in sources array.

@kripken
Copy link
Member

kripken commented Nov 15, 2019

Sorry, I may be missing something here, the output in cases 1, 2, and 4 look identical? They are all

{"version":3,"sources":["C:/Users/rreverser/Projects/temp-wasm/temp.c"],"names":[],...

All those are absolute paths, I think? That seems to conflict with

The only case where Emscripten sources ends up being valid URL is when a filename is specified as explicitly relative (cases 1 and 3).

@kripken
Copy link
Member

kripken commented Nov 16, 2019

@RReverser
Copy link
Collaborator Author

Sorry, I may be missing something here, the output in cases 1, 2, and 4 look identical?

Oops, sorry - copy-paste mistake. Fixed output of the case 1.

@RReverser
Copy link
Collaborator Author

Maybe related to /pull/7481/files ?

Maybe it was revealed by it, but definitely not the original cause as the change in PR seems correct.

@kripken
Copy link
Member

kripken commented Nov 21, 2019

Got it, thanks @RReverser! Fix in #9882, PTAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants