Skip to content

Commit

Permalink
file_packager: Fix regression in --separate-metadata output (#22802)
Browse files Browse the repository at this point in the history
This reverts commit 483cdcd.

This also adds some testing of the `--separate-metadata` file_packager
options where we actually run the generated code. As part of adding this
test I also made the code work under node.

Fixes: #22790
  • Loading branch information
sbc100 authored Oct 30, 2024
1 parent 48d9bc0 commit c0575ef
Show file tree
Hide file tree
Showing 82 changed files with 154 additions and 118 deletions.
6 changes: 4 additions & 2 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -1946,8 +1946,10 @@ addToLibrary({
$callRuntimeCallbacks__internal: true,
$callRuntimeCallbacks: (callbacks) => {
// Pass the module as the first argument.
callbacks.forEach((f) => f(Module));
while (callbacks.length > 0) {
// Pass the module as the first argument.
callbacks.shift()(Module);
}
},
#if SHRINK_LEVEL == 0 || ASYNCIFY == 2
Expand Down
20 changes: 8 additions & 12 deletions src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ if (ENVIRONMENT_IS_WORKER) {
{{{ exportRuntime() }}}
var calledRun;
var calledPrerun;
#if STANDALONE_WASM && MAIN_READS_PARAMS
var mainArgs = undefined;
Expand All @@ -47,7 +46,7 @@ function callMain() {
#endif
#if ASSERTIONS
assert(runDependencies == 0, 'cannot call main when async dependencies remain! (listen on Module["onRuntimeInitialized"])');
assert(calledPrerun, 'cannot call main without calling preRun first');
assert(__ATPRERUN__.length == 0, 'cannot call main when preRun functions remain to be called');
#endif
var entryFunction = {{{ getEntryFunction() }}};
Expand Down Expand Up @@ -189,25 +188,22 @@ function run() {
stackCheckInit();
#endif
if (!calledPrerun) {
calledPrerun = 1;
preRun();
preRun();
// a preRun added a dependency, run will be called later
if (runDependencies > 0) {
// a preRun added a dependency, run will be called later
if (runDependencies > 0) {
#if RUNTIME_DEBUG
dbg('run() called, but dependencies remain, so not running');
dbg('run() called, but dependencies remain, so not running');
#endif
return;
}
return;
}
function doRun() {
// run may have just been called through dependencies being fulfilled just in this very frame,
// or while the async setStatus time below was happening
if (calledRun) return;
calledRun = 1;
Module['calledRun'] = 1;
calledRun = true;
Module['calledRun'] = true;
if (ABORT) return;
Expand Down
18 changes: 10 additions & 8 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ function preRun() {
assert(!ENVIRONMENT_IS_PTHREAD); // PThreads reuse the runtime from the main thread.
#endif
#if expectToReceiveOnModule('preRun')
var preRuns = Module['preRun'];
if (preRuns) {
if (typeof preRuns == 'function') preRuns = [preRuns];
preRuns.forEach(addOnPreRun);
if (Module['preRun']) {
if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
while (Module['preRun'].length) {
addOnPreRun(Module['preRun'].shift());
}
}
#endif
callRuntimeCallbacks(__ATPRERUN__);
Expand Down Expand Up @@ -288,10 +289,11 @@ function postRun() {
#endif
#if expectToReceiveOnModule('postRun')
var postRuns = Module['postRun'];
if (postRuns) {
if (typeof postRuns == 'function') postRuns = [postRuns];
postRuns.forEach(addOnPostRun);
if (Module['postRun']) {
if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
while (Module['postRun'].length) {
addOnPostRun(Module['postRun'].shift());
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors1.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8472
8465
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20767
20821
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors2.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8453
8449
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20735
20789
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9499
9487
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24611
24665
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except_wasm.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8431
8427
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except_wasm.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20660
20715
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8431
8427
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20660
20715
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_lto.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8365
8359
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_lto.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20346
20399
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_mangle.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9502
9490
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_mangle.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24612
24665
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_noexcept.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8472
8465
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_noexcept.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20767
20821
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_wasmfs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3903
3899
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_wasmfs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8638
8693
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_js_fs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7601
7603
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_js_fs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18662
18716
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_wasmfs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2993
2987
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_wasmfs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6275
6329
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O0.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8032
8052
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O0.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21321
21435
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O1.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2816
2818
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6932
7025
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O2.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2503
2499
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4982
5036
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O3.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4828
4882
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_Os.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4828
4882
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_Oz.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2400
2398
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_Oz.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4794
4849
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_dylink.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6340
6339
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_dylink.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13882
13936
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3672
3733
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_wasmfs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4828
4882
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1974
1971
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4049
4110
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2010
2007
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4098
4157
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_mem_O3.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2431
2434
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_mem_O3.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4971
5024
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_mem_O3_grow.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2577
2579
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_mem_O3_grow.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5253
5306
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2274
2277
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4659
4713
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_mem_O3_standalone.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2233
2243
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_mem_O3_standalone.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4589
4643
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1996
1991
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4100
4161
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2010
2007
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4098
4157
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2010
2007
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4098
4157
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_64.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1587
1589
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_64.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3276
3311
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_O0.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6559
6576
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_O0.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17442
17571
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_O1.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1590
1595
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_O1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3641
3726
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_O2.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1450
1451
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_O2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2849
2884
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_O3.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1414
1416
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_O3.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2799
2834
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_Os.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1414
1416
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_Os.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2799
2834
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_Oz-ctors.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1404
1407
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_Oz-ctors.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2784
2819
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_Oz.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1414
1416
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_Oz.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2799
2834
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_pthreads.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4735
4711
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_pthreads.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9954
9984
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_wasmfs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1414
1416
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_wasmfs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2799
2834
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54876
54982
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_no_asserts.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
30529
30610
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_strict.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
53785
53778
15 changes: 15 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -3620,6 +3620,21 @@ def test_file_packager_separate_metadata(self):

self.assertEqual(metadata['package_uuid'], 'sha256-53ddc03623f867c7d4a631ded19c2613f2cb61d47b6aa214f47ff3cc15445bcd')

create_file('src.c', r'''
#include <assert.h>
#include <sys/stat.h>
#include <stdio.h>

int main() {
struct stat buf;
assert(stat("data1.txt", &buf) == 0);
assert(stat("subdir/data2.txt", &buf) == 0);
printf("done\n");
return 0;
}
''')
self.do_runf('src.c', emcc_args=['--pre-js=immutable.js', '-sFORCE_FILESYSTEM'])

def test_file_packager_unicode(self):
unicode_name = 'unicode…☃'
try:
Expand Down
Loading

0 comments on commit c0575ef

Please sign in to comment.