Skip to content

Commit 915b1df

Browse files
authored
WasmFS: Get emscripten_run_preload_plugins working (#19634)
Add a minimal version of FS.analyzePath. Fix FS.findObject, which was not tested before. Remove a hack from FS_createPreloadedFile that prevented things from working (it canonicalized paths in a way that didn't match other expectations).
1 parent 11c4b7e commit 915b1df

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/library_browser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,8 @@ var LibraryBrowser = {
711711
FS.createPreloadedFile(
712712
PATH.dirname(_file),
713713
PATH.basename(_file),
714+
// TODO: This copy is not needed if the contents are already a Uint8Array,
715+
// which they often are (and always are in WasmFS).
714716
new Uint8Array(data.object.contents), true, true,
715717
() => {
716718
{{{ runtimeKeepalivePop() }}}

src/library_fs_shared.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,17 @@ mergeInto(LibraryManager.library, {
4242
// You can also call this with a typed array instead of a url. It will then
4343
// do preloading for the Image/Audio part, as if the typed array were the
4444
// result of an XHR that you did manually.
45-
$FS_createPreloadedFile__deps: ['$asyncLoad',
45+
$FS_createPreloadedFile__deps: [
46+
'$asyncLoad',
47+
'$PATH_FS',
4648
#if !MINIMAL_RUNTIME
4749
'$FS_handledByPreloadPlugin',
4850
#endif
4951
],
5052
$FS_createPreloadedFile: function(parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) {
51-
#if WASMFS
52-
// TODO: use WasmFS code to resolve and join the path here?
53-
var fullname = name ? parent + '/' + name : parent;
54-
#else
5553
// TODO we should allow people to just pass in a complete filename instead
5654
// of parent and name being that we just join them anyways
5755
var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
58-
#endif
5956
var dep = getUniqueRunDependency(`cp ${fullname}`); // might have several active requests for the same fullname
6057
function processData(byteArray) {
6158
function finish(byteArray) {

src/library_wasmfs.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ FS.createPreloadedFile = FS_createPreloadedFile;
129129
#if FORCE_FILESYSTEM
130130
// Full JS API support
131131

132+
analyzePath: (path) => {
133+
// TODO: Consider simplifying this API, which for now matches the JS FS.
134+
var exists = !!FS.findObject(path);
135+
return {
136+
exists: exists,
137+
object: {
138+
contents: exists ? FS.readFile(path) : null
139+
}
140+
};
141+
},
142+
143+
// libc methods
144+
132145
mkdir: (path, mode) => FS.handleError(withStackSave(() => {
133146
mode = mode !== undefined ? mode : 511 /* 0777 */;
134147
var buffer = stringToUTF8OnStack(path);
@@ -312,7 +325,7 @@ FS.createPreloadedFile = FS_createPreloadedFile;
312325
return FS.handleError(__wasmfs_ftruncate(fd, {{{ splitI64('len') }}}));
313326
},
314327
findObject: (path) => {
315-
var result = __wasmfs_identify(path);
328+
var result = withStackSave(() => __wasmfs_identify(stringToUTF8OnStack(path)));
316329
if (result == {{{ cDefs.ENOENT }}}) {
317330
return null;
318331
}

test/test_browser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ def test_sdl_image_jpeg(self):
794794
'-lSDL', '-lGL',
795795
])
796796

797+
@also_with_wasmfs
797798
def test_sdl_image_prepare(self):
798799
# load an image file, get pixel data.
799800
shutil.copyfile(test_file('screenshot.jpg'), 'screenshot.not')

0 commit comments

Comments
 (0)