Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scripts/build_mpos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,10 @@ elif [ "$target" == "web" ]; then
# /data is recreated empty by IDBFS at boot; drop the preloaded copy so it
# does not collide with the persistent mount.
rm -rf "$staged_fs"/data
staged_bundled_data="$codebasedir"/web/.preload_bundled_data
rm -rf "$staged_bundled_data"
mkdir -p "$staged_bundled_data"
cp -a "$codebasedir"/internal_filesystem_data/. "$staged_bundled_data"/

# The browser build disables native threading (MICROPY_PY_THREAD=0), so the
# C builtin `_thread` module is absent. MicroPythonOS imports `_thread`
Expand Down Expand Up @@ -639,7 +643,7 @@ elif [ "$target" == "web" ]; then
# The bundled demo apps are packaged separately at /.bundled_apps because
# /apps is a persistent IDBFS mount (see web/shell.html); they are seeded
# into /apps on first boot.
export MPOS_WEB_LINK_FLAGS="--preload-file $staged_fs@/ --preload-file $staged_bundled_apps@/.bundled_apps --shell-file $shell_file"
export MPOS_WEB_LINK_FLAGS="--preload-file $staged_fs@/ --preload-file $staged_bundled_apps@/.bundled_apps --preload-file $staged_bundled_data@/.bundled_data --shell-file $shell_file"

pushd "$codebasedir"/lvgl_micropython/
set -x
Expand Down
33 changes: 33 additions & 0 deletions tests/web_bridge_smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,27 @@ import path from "node:path";
import puppeteer from "puppeteer";

const webDir = path.resolve(process.argv[2] || "web");
const dataDir = path.resolve("internal_filesystem_data");
const TIMEOUT_MS = 120000; // wasm boot in CI can be slow

function readDataFiles(dir, prefix = "") {
const files = new Map();
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const relativePath = path.posix.join(prefix, entry.name);
const sourcePath = path.join(dir, entry.name);
if (entry.isDirectory()) {
for (const [nestedPath, contents] of readDataFiles(sourcePath, relativePath)) {
files.set(nestedPath, contents);
}
} else if (entry.isFile()) {
files.set(relativePath, fs.readFileSync(sourcePath));
}
}
return files;
}

const expectedDataFiles = readDataFiles(dataDir);

const MIME = {
".html": "text/html",
".js": "text/javascript",
Expand Down Expand Up @@ -64,6 +83,20 @@ server.listen(0, "127.0.0.1", async () => {
);
console.log("Runtime up, __webterm.ready = true");

const bundledDataFiles = await page.evaluate((relativePaths) => {
return relativePaths.map((relativePath) => ({
relativePath,
contents: Array.from(FS.readFile("/data/" + relativePath)),
}));
}, Array.from(expectedDataFiles.keys()));
for (const file of bundledDataFiles) {
const expected = expectedDataFiles.get(file.relativePath);
if (!expected.equals(Buffer.from(file.contents))) {
fail("bundled data differs: /data/" + file.relativePath);
}
}
console.log(`Bundled data present, ${bundledDataFiles.length} files matched`);

// Install onOutput and send the raw-REPL handshake, then wait for banner.
const result = await page.evaluate(
() =>
Expand Down
14 changes: 12 additions & 2 deletions web/shell.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
// user-installed apps survive page reloads. The functions below run inside
// the Emscripten runtime once `FS` exists (preRun / onRuntimeInitialized).

function copyRecursive(src, dst) {
function copyRecursive(src, dst, onlyMissing) {
var entries = FS.readdir(src);
for (var i = 0; i < entries.length; i++) {
var name = entries[i];
Expand All @@ -233,10 +233,13 @@
}
if (FS.isDir(mode)) {
try { FS.mkdir(d); } catch (e) {}
copyRecursive(s, d);
copyRecursive(s, d, onlyMissing);
} else {
// Regular files (and any symlink resolved by readFile).
try {
if (onlyMissing) {
try { FS.stat(d); continue; } catch (e) {}
}
FS.writeFile(d, FS.readFile(s));
} catch (e) {
console.error("seed copy failed for " + s + ":", e);
Expand All @@ -257,6 +260,12 @@
flushPersist();
}

function seedBundledData() {
try { FS.stat("/.bundled_data"); } catch (e) { return; }
copyRecursive("/.bundled_data", "/data", true);
flushPersist();
}

var _persistInFlight = false;
var _persistTimer = null;
function flushPersist() {
Expand Down Expand Up @@ -475,6 +484,7 @@
// Seed bundled apps into /apps on first run (after preload + syncfs),
// then start flushing writes back to IndexedDB periodically.
try { seedBundledApps(); } catch (e) { console.error("seedBundledApps failed:", e); }
try { seedBundledData(); } catch (e) { console.error("seedBundledData failed:", e); }
startPersistFlush();
}
};
Expand Down
Loading