-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
fix_relative_file_loads_node_js #5484
Conversation
emcc.py
Outdated
@@ -2410,6 +2410,7 @@ def generate_html(target, options, js_target, target_basename, | |||
} else if (Module['memoryInitializerPrefixURL']) { | |||
memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer; | |||
} | |||
if (Module['scriptDirectory'] && !/^(?:[a-z]+:)?\/\//i.test(memoryInitializer)) memoryInitializer = Module['scriptDirectory'] + memoryInitializer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a comment explaining this would be good i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check
src/preamble.js
Outdated
} | ||
|
||
function joinUrl(a, b) { | ||
return a && !isAbsoluteUrl(b) ? a + b : b; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to assume that a ends with /
, perhaps in ASSERTIONS we should check that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, added.
src/preamble.js
Outdated
@@ -2114,6 +2121,9 @@ function integrateWasmJS(Module) { | |||
wasmBinaryFile = Module['locateFile'](wasmBinaryFile); | |||
asmjsCodeFile = Module['locateFile'](asmjsCodeFile); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the goal is to support both locateFile and scriptDirectory at the same time (otherwise an else here could make sense)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the idea. The existing ways to form a URL to load will all be treated with respect to scriptDirectory
if the specified URLs are relative.
|
815d995
to
fd5a831
Compare
What is the problem that exists in browsers? I don't think that has been mentioned anywhere before? Is there an STR or a test case to illustrate this problem?
Agree that in an ideal world, we would probably have only one option, but we cannot just tear down the existing methods, since that will break anyone who is using them, and those people will then in turn complain. Once we get better mechanism for preprocessing (PR #5494), we can add optional mechanisms to disable the old ones, and eventually remove the old ones, if the added size consideration is an issue. |
Exactly the same problem as in Node. When you do XHR request, relative path will depend on the environment as I've described in my take on this issue: #5368 (comment).
Works for me, thanks! |
Thanks, I see. In that scenario the download will be done relative to the If we do choose to explicitly change the semantic of loading with respect to html, then we will need to account for the case of having loaded the . |
The same exact ways can be used for Node.js too :) The point I've pursued in my PR was to make it just work out of the box for most people, regardless of the environment, regardless of the JavaScript file location. Unless you move some of generated files to CDN (but not all of them) or do something exotic like that, in which case there are necessary options available already. |
fd5a831
to
3c88610
Compare
src/preamble.js
Outdated
return /^(?:[a-z]+:)?\/\//i.test(url); | ||
} | ||
|
||
function joinUrl(a, b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a comment that this both joins as the name suggests, but also allows a
to be undefined, in which case it is ignored.
src/preamble.js
Outdated
|
||
function joinUrl(a, b) { | ||
#if ASSERTIONS | ||
if (a && !a.endsWith('/')) throw 'First parameter to joinUrl() should end in /'!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the string is not terminated at the end of the line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check
4965b25
to
6afe133
Compare
Ok, here is what we are going to do:
|
src/preamble.js
Outdated
@@ -932,6 +932,18 @@ function stackTrace() { | |||
} | |||
{{{ maybeExport('stackTrace') }}} | |||
|
|||
function isAbsoluteUrl(url) { | |||
return /^(?:[a-z]+:)?\/\//i.test(url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute paths in Node.js don't start with //
, so this will always return false
:
>> /^(?:[a-z]+:)?\/\//i.test('/absolute/path/on/server.js')
false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Added a test for this scenario as well and fixed the regex.
With all respect I still strongly believe that #5368 is a superior alternative. |
This supersedes #4942 too, correct? Just checking, because I couldn't see that explicitly mentioned here. |
@curiousdannii, yes |
Technically it has the potential of being simpler, but sometimes the constraints are non-technical, we do not want to do semantics changing modifications on this.
Unity content for example uses the prefix paths, and emunittest overrides those with Module.locateFile. This is something we are strict about not changing. Let's follow up on the remaining limitations one issue at a time, with tests as proofs of problems, and fixes associated with them. |
Do you have a link to this? UPD: I think there is yet another approach to this that will both keep existing semantics and will achieve the same goal as #5368, will start working on it right now |
Sorry, nothing else than downloading Unity and checking their build output. |
I think we can both agree on this: https://github.com/kripken/emscripten/pull/5368/files?diff=split&w=1 |
This is what made me change my mind - I didn't realize people do use these things in combination. And there are probably more people we don't know about. I agree a nicer overall solution is possible, but I agree with @juj that we should not change the behavior here. I also agree with @nazar-pc on the link from the last comment - adding scriptDirectory that way seems safe, and a good solution, and maybe a little simpler than this PR. But maybe I'm missing something that this PR does that that doesn't? |
@juj, did we come to an agreement here? |
da6cf19
to
a2a8329
Compare
Sorry, I still think we should not change the way the existing variables work, and not hoist the old style *prefixURL variables to required-to-always-exist status in |
febc020
to
8a48d0a
Compare
fd5a137
to
a3c1d77
Compare
…ative to main .js file on Node.js.
a3c1d77
to
9f3441b
Compare
#5368 was landed, so this should be closed as it's no longer mergeable. Doesn't mean the current implementation is perfect though! |
Agree, thanks @curiousdannii |
Add Module['scriptDirectory'] to fix loading files that should be relative to main .js file on Node.js.
Intended to replace #5368 to fix #4542.