feat: libs 0002 — /mnt/pcbjam lib URIs + mount point seed; bump kicad
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
7e454104aa
commit
29a7dcc233
3 changed files with 22 additions and 13 deletions
2
kicad
2
kicad
|
|
@ -1 +1 @@
|
||||||
Subproject commit 378b502e27bb84d2135464691abbfe5dc74661e3
|
Subproject commit 51743e6c7981d4349adaabc9416eb35469a8c0d6
|
||||||
|
|
@ -7,6 +7,7 @@ import {
|
||||||
} from "./constants";
|
} from "./constants";
|
||||||
import {
|
import {
|
||||||
installSpikeLibsProvider,
|
installSpikeLibsProvider,
|
||||||
|
PCBJAM_LIB_MOUNT,
|
||||||
SPIKE_LIB_TABLE_ROW,
|
SPIKE_LIB_TABLE_ROW,
|
||||||
} from "./libs/spike-provider";
|
} from "./libs/spike-provider";
|
||||||
|
|
||||||
|
|
@ -163,6 +164,10 @@ async function doBoot(opts: BootOptions): Promise<void> {
|
||||||
const seedKicadConfig = () => {
|
const seedKicadConfig = () => {
|
||||||
const FS = moduleFS();
|
const FS = moduleFS();
|
||||||
FS.mkdirTree(KICAD_CONFIG_DIR);
|
FS.mkdirTree(KICAD_CONFIG_DIR);
|
||||||
|
// libs: the mount point that pcbjam lib URIs (/mnt/pcbjam/<lib>) 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) => {
|
const writeIfAbsent = (path: string, contents: string) => {
|
||||||
if (FS.analyzePath(path).exists) return;
|
if (FS.analyzePath(path).exists) return;
|
||||||
FS.writeFile(path, contents);
|
FS.writeFile(path, contents);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const SPIKE_LIB_NICKNAME = "pcbjam-spike";
|
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). */
|
/** 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"))`;
|
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));
|
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
||||||
|
|
||||||
/**
|
/** Recover the lib id from a "/mnt/pcbjam/<id>" URI (arrives unmangled). */
|
||||||
* KiCad's lib-table path handling normalizes URIs as if they were file paths:
|
function libIdFromUri(lib: string): string | null {
|
||||||
* "pcbjam://spike" arrives as "/pcbjam:/spike" or even
|
return lib.startsWith(PCBJAM_LIB_PREFIX)
|
||||||
* "<project-dir>/pcbjam:/spike" (made absolute against the cwd). Recover the
|
? lib.slice(PCBJAM_LIB_PREFIX.length)
|
||||||
* lib id after the "pcbjam:" marker. Finding for 0003: give the real plugin a
|
: null;
|
||||||
* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function installSpikeLibsProvider(log: (msg: string) => void): void {
|
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) => {
|
const request: KicadLibsRequest = async (op, lib, arg) => {
|
||||||
log(`[libs] request op=${op} lib=${lib} arg=${arg} (delay=${delay}ms)`);
|
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);
|
if (delay) await sleep(delay);
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue