-
Notifications
You must be signed in to change notification settings - Fork 3.4k
MODULARIZE / scriptDirectory improvements #6914
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a7f53ff
support new Module() in MODULARIZE mode, including saving the scriptD…
kripken 3bd194b
refactor emcc.py code, do not add _scriptDir when MODULARIZE_INSTANCE
kripken df3bbd2
wip [ci skip]
kripken c7f87e8
fix
kripken 228ff02
fix comment
kripken 364f9cf
avoid mixing function X() with var X
kripken 06eff64
fix
kripken 92a5dbb
feedback
kripken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3950,46 +3950,49 @@ def test_browser_run_from_different_directory(self): | |
src = open('test.html').read() | ||
# Make sure JS is loaded from subdirectory | ||
open('test-subdir.html', 'w').write(src.replace('test.js', 'subdir/test.js')) | ||
|
||
self.run_browser('test-subdir.html', None, '/report_result?0') | ||
|
||
# Similar to `test_browser_run_from_different_directory`, but asynchronous because of `-s MODULARIZE=1` | ||
def test_browser_run_from_different_directory_async(self): | ||
src = open(path_from_root('tests', 'browser_test_hello_world.c')).read() | ||
open('test.c', 'w').write(self.with_report_result(src)) | ||
# compile the code with the modularize feature and the preload-file option enabled | ||
Popen([PYTHON, EMCC, 'test.c', '-o', 'test.js', '-s', 'MODULARIZE=1', '-O3']).communicate() | ||
if not os.path.exists('subdir'): | ||
os.mkdir('subdir') | ||
shutil.move('test.js', os.path.join('subdir', 'test.js')) | ||
shutil.move('test.wasm', os.path.join('subdir', 'test.wasm')) | ||
# Make sure JS is loaded from subdirectory | ||
open('test-subdir.html', 'w').write(''' | ||
<script src="subdir/test.js"></script> | ||
<script> | ||
Module(); | ||
</script> | ||
''') | ||
|
||
self.run_browser('test-subdir.html', None, '/report_result?0') | ||
for instance in (0, 1): | ||
print(instance) | ||
# compile the code with the modularize feature and the preload-file option enabled | ||
Popen([PYTHON, EMCC, 'test.c', '-o', 'test.js', '-s', 'MODULARIZE=1', '-O3', '-s', 'MODULARIZE_INSTANCE=%d' % instance]).communicate() | ||
if not os.path.exists('subdir'): | ||
os.mkdir('subdir') | ||
shutil.move('test.js', os.path.join('subdir', 'test.js')) | ||
shutil.move('test.wasm', os.path.join('subdir', 'test.wasm')) | ||
if instance: | ||
creations = [''] | ||
else: | ||
creations = [ | ||
'Module();', | ||
'new Module();' # not documented as working, but we support it | ||
] | ||
for creation in creations: | ||
print(creation) | ||
# Make sure JS is loaded from subdirectory | ||
open('test-subdir.html', 'w').write(''' | ||
<script src="subdir/test.js"></script> | ||
<script> | ||
%s | ||
</script> | ||
''' % creation) | ||
self.run_browser('test-subdir.html', None, '/report_result?0') | ||
|
||
# Similar to `test_browser_run_from_different_directory`, but | ||
# also also we eval the initial code, so currentScript is not present. That prevents us | ||
# from finding the file in a subdir, but here we at least check we do not regress compared to the | ||
# normal case of finding in the current dir. | ||
# In addition, check for new Module(), which overrides the bind() and replaces the object | ||
# which saved the _scriptDir. Again, we can't get the script dir that way, but at least we | ||
# should not regress compared to the normal case. | ||
def test_browser_modularize_no_current_script(self): | ||
src = open(path_from_root('tests', 'browser_test_hello_world.c')).read() | ||
open('test.c', 'w').write(self.with_report_result(src)) | ||
# compile the code with the modularize feature and the preload-file option enabled | ||
Popen([PYTHON, EMCC, 'test.c', '-o', 'test.js', '-s', 'MODULARIZE=1']).communicate() | ||
for creation in ( | ||
'Module();', | ||
'new Module();' | ||
): | ||
print(creation) | ||
for instance in (0, 1): | ||
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. And the same idea here as above. |
||
print(instance) | ||
# compile the code with the modularize feature and the preload-file option enabled | ||
Popen([PYTHON, EMCC, 'test.c', '-o', 'test.js', '-s', 'MODULARIZE=1', '-s', 'MODULARIZE_INSTANCE=%d' % instance]).communicate() | ||
open('test.html', 'w').write(''' | ||
<script> | ||
setTimeout(function() { | ||
|
@@ -4000,6 +4003,6 @@ def test_browser_modularize_no_current_script(self): | |
%s | ||
}, 1); | ||
</script> | ||
''' % creation) | ||
''' % ('Module();' if not instance else '')) | ||
self.run_browser('test.html', None, '/report_result?0') | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'd rather make a list of tuples or something like that here. Looks hacky and takes more brain cycles to comprehend than necessary.
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.
Makes sense. I rewrote them that way, let me know what you think.