diff --git a/kicad b/kicad index 378b502..51743e6 160000 --- a/kicad +++ b/kicad @@ -1 +1 @@ -Subproject commit 378b502e27bb84d2135464691abbfe5dc74661e3 +Subproject commit 51743e6c7981d4349adaabc9416eb35469a8c0d6 diff --git a/web/standalone/src/wasm/boot.ts b/web/standalone/src/wasm/boot.ts index a00581d..22f7d7b 100644 --- a/web/standalone/src/wasm/boot.ts +++ b/web/standalone/src/wasm/boot.ts @@ -7,6 +7,7 @@ import { } from "./constants"; import { installSpikeLibsProvider, + PCBJAM_LIB_MOUNT, SPIKE_LIB_TABLE_ROW, } from "./libs/spike-provider"; @@ -163,6 +164,10 @@ async function doBoot(opts: BootOptions): Promise { const seedKicadConfig = () => { const FS = moduleFS(); FS.mkdirTree(KICAD_CONFIG_DIR); + // libs: the mount point that pcbjam lib URIs (/mnt/pcbjam/) live under. + // A real dir so any incidental existence check on the URI passes; the lib + // contents themselves are served virtually via window.kicadLibs. + FS.mkdirTree(PCBJAM_LIB_MOUNT); const writeIfAbsent = (path: string, contents: string) => { if (FS.analyzePath(path).exists) return; FS.writeFile(path, contents); diff --git a/web/standalone/src/wasm/libs/spike-provider.ts b/web/standalone/src/wasm/libs/spike-provider.ts index 7d33d60..0385d75 100644 --- a/web/standalone/src/wasm/libs/spike-provider.ts +++ b/web/standalone/src/wasm/libs/spike-provider.ts @@ -15,7 +15,16 @@ */ export const SPIKE_LIB_NICKNAME = "pcbjam-spike"; -export const SPIKE_LIB_URI = "pcbjam://spike"; + +/** + * pcbjam lib URIs are absolute POSIX paths under this prefix. Absolute so that + * KiCad's lib-table URI expansion (ExpandURI -> wxFileName::MakeAbsolute) is a + * no-op and the path reaches the plugin/provider unmangled — a "scheme://" URI + * gets rewritten to "/scheme:/..." against the cwd, which differs per project. + */ +export const PCBJAM_LIB_MOUNT = "/mnt/pcbjam"; +export const PCBJAM_LIB_PREFIX = `${PCBJAM_LIB_MOUNT}/`; +export const SPIKE_LIB_URI = `${PCBJAM_LIB_PREFIX}spike`; /** sym-lib-table row seeded at boot (see boot.ts seedKicadConfig). */ export const SPIKE_LIB_TABLE_ROW = ` (lib (name "${SPIKE_LIB_NICKNAME}")(type "PCBJAM")(uri "${SPIKE_LIB_URI}")(options "")(descr "pcbjam libs 0002 spike"))`; @@ -84,16 +93,11 @@ function artificialDelayMs(): number { const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)); -/** - * KiCad's lib-table path handling normalizes URIs as if they were file paths: - * "pcbjam://spike" arrives as "/pcbjam:/spike" or even - * "/pcbjam:/spike" (made absolute against the cwd). Recover the - * lib id after the "pcbjam:" marker. Finding for 0003: give the real plugin a - * path shape that survives normalization, or normalize C++-side. - */ -function libIdFromMangledUri(lib: string): string | null { - const m = lib.match(/pcbjam:\/*(.+)$/); - return m ? m[1] : null; +/** Recover the lib id from a "/mnt/pcbjam/" URI (arrives unmangled). */ +function libIdFromUri(lib: string): string | null { + return lib.startsWith(PCBJAM_LIB_PREFIX) + ? lib.slice(PCBJAM_LIB_PREFIX.length) + : null; } export function installSpikeLibsProvider(log: (msg: string) => void): void { @@ -104,7 +108,7 @@ export function installSpikeLibsProvider(log: (msg: string) => void): void { const request: KicadLibsRequest = async (op, lib, arg) => { log(`[libs] request op=${op} lib=${lib} arg=${arg} (delay=${delay}ms)`); - if (libIdFromMangledUri(lib) !== "spike") return null; + if (libIdFromUri(lib) !== "spike") return null; if (delay) await sleep(delay); switch (op) {