refactor(build): fold calculator into unified docker/build.sh dispatch

Convert the calculator port (commit 0464470) from the parallel/copy-paste
pattern to the dispatch pattern used by pcbnew + eeschema.

- docker/build.sh: <app> is now required (no pcbnew default); missing,
  unknown, and --help paths all print "pcbnew | eeschema | calculator | all".
  Adds calculator to build_app() via kicad_subdir_for() (pcb_calculator
  inner subdir, calculator.* output basename). Also fixes the
  EMSDK=/emsdkkicad-wasm-builder typo that snuck in during the calc merge.
- scripts/kicad/build-kicad-target.sh: accepts calculator; introduces
  KICAD_TARGET (pcb_calculator for calc, == APP_NAME otherwise) used for
  the make target, embind include path, and final-log line.
- scripts/kicad/build-calculator.sh: 305-line copy of build-pcbnew.sh
  collapsed to a 7-line wrapper around build-kicad-target.sh.
- tests/scripts/setup-kicad-wasm.sh: copy_app calculator added with the
  same pcb_calculator subdir mapping for the docker-volume fallback path.
- tests/package.json: test:calculator* routed through the shared
  playwright-kicad.config.ts kicad/calculator.spec.ts (mirrors eeschema).
- Delete: docker/build-calculator.sh, tests/scripts/setup-calculator-wasm.sh,
  tests/playwright-calculator.config.ts.

Bumps wxwidgets d1d1627 -> 6fb2eac (origin/wasm-port). The new sha includes
"unic/combobox: add GetCurrentSelection() inline default" which calc's
kicad/pcb_calculator/widgets/unit_selector.cpp needs to compile. Without
this bump the unified dispatch would expose calc as a buildable target but
the build itself would fail. Verified: build.sh all completes clean across
all three apps; pcbnew/eeschema e2e pass; calc compiles and launches (test
stability separate from this refactor).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Gergő Törcsvári 2026-05-29 12:01:44 +02:00
commit d6d743340d
No known key found for this signature in database
GPG key ID: 8E75F2CDE64E5322
9 changed files with 108 additions and 587 deletions

View file

@ -9,21 +9,20 @@
"build-wasm": "cd apps && make -f Makefile.wasm",
"serve": "npx serve apps -p 8080 -c ../serve.json",
"setup:kicad": "./scripts/setup-kicad-wasm.sh",
"setup:calculator": "./scripts/setup-calculator-wasm.sh",
"test:kicad:firefox": "npm run setup:kicad && playwright test --config=playwright-kicad.config.ts --project=firefox",
"test:kicad:chrome": "npm run setup:kicad && playwright test --config=playwright-kicad.config.ts --project=chromium --headed",
"test:kicad": "npm run test:kicad:firefox",
"test:kicad:headed": "npm run test:kicad:chrome",
"test:pcbnew:firefox": "npm run setup:kicad && playwright test --config=playwright-kicad.config.ts --project=firefox kicad/pcbnew.spec.ts",
"test:pcbnew:chrome": "npm run setup:kicad && playwright test --config=playwright-kicad.config.ts --project=chromium --headed kicad/pcbnew.spec.ts",
"test:calculator:firefox": "npm run setup:calculator && playwright test --config=playwright-calculator.config.ts --project=firefox",
"test:calculator:chrome": "npm run setup:calculator && playwright test --config=playwright-calculator.config.ts --project=chromium --headed",
"test:calculator": "npm run test:calculator:firefox",
"test:calculator:headed": "npm run test:calculator:chrome",
"test:eeschema:firefox": "npm run setup:kicad && playwright test --config=playwright-kicad.config.ts --project=firefox kicad/eeschema.spec.ts",
"test:eeschema:chrome": "npm run setup:kicad && playwright test --config=playwright-kicad.config.ts --project=chromium --headed kicad/eeschema.spec.ts",
"test:eeschema": "npm run test:eeschema:firefox",
"test:eeschema:headed": "npm run test:eeschema:chrome",
"test:calculator:firefox": "npm run setup:kicad && playwright test --config=playwright-kicad.config.ts --project=firefox kicad/calculator.spec.ts",
"test:calculator:chrome": "npm run setup:kicad && playwright test --config=playwright-kicad.config.ts --project=chromium --headed kicad/calculator.spec.ts",
"test:calculator": "npm run test:calculator:firefox",
"test:calculator:headed": "npm run test:calculator:chrome",
"test:coroutine:firefox": "playwright test --config=playwright-coroutine.config.ts --project=firefox",
"test:coroutine:chrome": "playwright test --config=playwright-coroutine.config.ts --project=chromium --headed"
},

View file

@ -1,90 +0,0 @@
import { defineConfig, devices } from '@playwright/test';
import { execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
// Mirrors playwright-kicad.config.ts. The only structural difference is
// testMatch — calculator.spec.ts lives next to pcbnew.spec.ts under ./kicad,
// and we filter to it so running `npm run test:calculator` doesn't drag in
// the pcbnew suite.
const PORT_FILE = path.join(__dirname, '.test-port');
// NOTE: Chrome headless crashes on ARM Mac due to SwiftShader WebGL bug
// (Chromium issues #1416283, #338414704). Firefox headless works reliably.
// Use --project=firefox for headless, --project=chromium for headed debugging.
function getOrFindPort(): number {
try {
const stat = fs.statSync(PORT_FILE);
const age = Date.now() - stat.mtimeMs;
if (age < 60000) {
const port = parseInt(fs.readFileSync(PORT_FILE, 'utf-8').trim());
if (port > 0 && port < 65536) {
return port;
}
}
} catch {
// File doesn't exist or can't be read
}
const port = findFreePort();
fs.writeFileSync(PORT_FILE, port.toString());
return port;
}
function findFreePort(): number {
try {
const result = execSync(
'python3 -c "import socket; s=socket.socket(); s.bind((\'\',0)); print(s.getsockname()[1]); s.close()"',
{ encoding: 'utf-8' }
);
return parseInt(result.trim());
} catch {
return 9000 + Math.floor(Math.random() * 1000);
}
}
const port = getOrFindPort();
export default defineConfig({
globalSetup: './global-setup.ts',
testDir: './kicad',
testMatch: 'calculator.spec.ts',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
timeout: 180000, // KiCad WASM needs more time to load (3 minutes)
use: {
baseURL: `http://localhost:${port}`,
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
},
projects: [
{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
viewport: { width: 1280, height: 720 },
},
},
{
// Uses system Chrome (not bundled Chromium) so WebGL runs on the real GPU.
name: 'chromium',
use: {
channel: 'chrome',
viewport: { width: 1280, height: 720 },
},
},
],
webServer: {
command: `npx serve apps -p ${port} -c ../serve.json`,
port: port,
reuseExistingServer: !process.env.CI,
},
});

View file

@ -1,58 +0,0 @@
#!/bin/bash
# Copy PCB Calculator WASM build output to the test directory.
# Mirrors setup-kicad-wasm.sh; differences:
# - copies calculator.{js,wasm,wasm.map,worker.js} instead of pcbnew.*
#
# Priority: use local output/ (populated by docker/build-calculator.sh).
# Fallback: copy from the Docker volume directly.
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
KICAD_TEST="$PROJECT_ROOT/tests/apps/kicad"
OUTPUT_DIR="$PROJECT_ROOT/output"
mkdir -p "$KICAD_TEST"
if [ -f "$OUTPUT_DIR/calculator.js" ] && [ -f "$OUTPUT_DIR/calculator.wasm" ]; then
echo "Copying Calculator WASM files from output directory..."
cp "$OUTPUT_DIR/calculator.js" "$KICAD_TEST/"
cp "$OUTPUT_DIR/calculator.wasm" "$KICAD_TEST/"
# Source map for debug symbols (optional)
cp "$OUTPUT_DIR/calculator.wasm.map" "$KICAD_TEST/" 2>/dev/null || true
# Worker file for pthreads (optional)
cp "$OUTPUT_DIR/calculator.worker.js" "$KICAD_TEST/" 2>/dev/null || true
# Bitmap resources for KiCad icons (shared with pcbnew; optional)
cp "$OUTPUT_DIR/images.tar.gz" "$KICAD_TEST/" 2>/dev/null || true
else
echo "Output directory not found, copying from Docker build..."
SRC=/workspace/build-wasm/kicad-calculator/pcb_calculator
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
"kicad-wasm-builder:${SRC}/pcb_calculator.js" "$KICAD_TEST/calculator.js"
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
"kicad-wasm-builder:${SRC}/pcb_calculator.wasm" "$KICAD_TEST/calculator.wasm"
# Optional artifacts (best-effort).
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
"kicad-wasm-builder:${SRC}/pcb_calculator.wasm.map" "$KICAD_TEST/calculator.wasm.map" 2>/dev/null || true
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
"kicad-wasm-builder:${SRC}/pcb_calculator.worker.js" "$KICAD_TEST/calculator.worker.js" 2>/dev/null || true
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
kicad-wasm-builder:/workspace/build-wasm/kicad-calculator/resources/images.tar.gz "$KICAD_TEST/" 2>/dev/null || true
fi
# wxWidgets WASM glue code (shared with pcbnew).
echo "Copying wxWidgets WASM glue code..."
if [ -f "$OUTPUT_DIR/wx.js" ]; then
cp "$OUTPUT_DIR/wx.js" "$KICAD_TEST/"
else
if docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
kicad-wasm-builder:/workspace/build-wasm/wxwidgets/build/wasm/wx.js "$KICAD_TEST/" 2>/dev/null; then
:
else
cp "$PROJECT_ROOT/wxwidgets/build/wasm/wx.js" "$KICAD_TEST/"
fi
fi
echo "Calculator WASM files copied to $KICAD_TEST"
ls -lh "$KICAD_TEST"

View file

@ -4,7 +4,7 @@
# Priority: Use local output/ directory (populated by docker/build.sh)
# Fallback: Copy from Docker volume directly
#
# Copies whichever editors are present (pcbnew, eeschema).
# Copies whichever apps are present (pcbnew, eeschema, calculator).
set -e
@ -15,10 +15,22 @@ OUTPUT_DIR="$PROJECT_ROOT/output"
mkdir -p "$KICAD_TEST"
# Copy one editor's artifacts (js, wasm, optional debug/map/worker). Returns 0
# if the editor was present, 1 if neither output/ nor the docker volume has it.
# Map an app name to its inner CMake build subdirectory. Most apps share their
# subdir name with the app name; pcb_calculator emits OUTPUT_NAME=calculator
# but lives under the pcb_calculator/ subtree of the build dir.
kicad_subdir_for() {
case "$1" in
calculator) echo "pcb_calculator" ;;
*) echo "$1" ;;
esac
}
# Copy one app's artifacts (js, wasm, optional debug/map/worker). Returns 0
# if the app was present, 1 if neither output/ nor the docker volume has it.
copy_app() {
local app="$1"
local subdir
subdir=$(kicad_subdir_for "$app")
if [ -f "$OUTPUT_DIR/${app}.js" ] && [ -f "$OUTPUT_DIR/${app}.wasm" ]; then
echo "Copying ${app} WASM files from output directory..."
@ -32,13 +44,13 @@ copy_app() {
echo "Output ${app} not found locally, trying Docker volume..."
if docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${app}/${app}.js "$KICAD_TEST/" 2>/dev/null \
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.js "$KICAD_TEST/" 2>/dev/null \
&& docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${app}/${app}.wasm "$KICAD_TEST/" 2>/dev/null; then
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.wasm "$KICAD_TEST/" 2>/dev/null; then
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${app}/${app}.wasm.map "$KICAD_TEST/" 2>/dev/null || true
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.wasm.map "$KICAD_TEST/" 2>/dev/null || true
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${app}/${app}.worker.js "$KICAD_TEST/" 2>/dev/null || true
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.worker.js "$KICAD_TEST/" 2>/dev/null || true
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/resources/images.tar.gz "$KICAD_TEST/" 2>/dev/null || true
return 0
@ -49,11 +61,12 @@ copy_app() {
}
found_any=0
copy_app pcbnew && found_any=1
copy_app eeschema && found_any=1
copy_app pcbnew && found_any=1
copy_app eeschema && found_any=1
copy_app calculator && found_any=1
if [ "$found_any" -eq 0 ]; then
echo "Error: neither pcbnew nor eeschema artifacts found in output/ or docker volume" >&2
echo "Error: no pcbnew/eeschema/calculator artifacts found in output/ or docker volume" >&2
exit 1
fi