2025-12-12 15:34:15 +01:00
|
|
|
#!/bin/bash
|
2025-12-13 22:13:31 +01:00
|
|
|
# Copies KiCad WASM build output to test directory
|
|
|
|
|
#
|
|
|
|
|
# Priority: Use local output/ directory (populated by docker/build.sh)
|
|
|
|
|
# Fallback: Copy from Docker volume directly
|
2026-05-29 06:39:23 +02:00
|
|
|
#
|
2026-05-29 12:01:44 +02:00
|
|
|
# Copies whichever apps are present (pcbnew, eeschema, calculator).
|
2025-12-12 15:34:15 +01:00
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
2025-12-27 14:06:23 +01:00
|
|
|
KICAD_TEST="$PROJECT_ROOT/tests/apps/kicad"
|
2025-12-13 22:13:31 +01:00
|
|
|
OUTPUT_DIR="$PROJECT_ROOT/output"
|
2025-12-12 15:34:15 +01:00
|
|
|
|
|
|
|
|
mkdir -p "$KICAD_TEST"
|
|
|
|
|
|
2026-05-29 12:01:44 +02:00
|
|
|
# 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.
|
2026-05-29 06:39:23 +02:00
|
|
|
copy_app() {
|
|
|
|
|
local app="$1"
|
2026-05-29 12:01:44 +02:00
|
|
|
local subdir
|
|
|
|
|
subdir=$(kicad_subdir_for "$app")
|
2026-05-29 06:39:23 +02:00
|
|
|
|
|
|
|
|
if [ -f "$OUTPUT_DIR/${app}.js" ] && [ -f "$OUTPUT_DIR/${app}.wasm" ]; then
|
|
|
|
|
echo "Copying ${app} WASM files from output directory..."
|
|
|
|
|
cp "$OUTPUT_DIR/${app}.js" "$KICAD_TEST/"
|
|
|
|
|
cp "$OUTPUT_DIR/${app}.wasm" "$KICAD_TEST/"
|
|
|
|
|
cp "$OUTPUT_DIR/${app}.wasm.map" "$KICAD_TEST/" 2>/dev/null || true
|
|
|
|
|
cp "$OUTPUT_DIR/${app}.worker.js" "$KICAD_TEST/" 2>/dev/null || true
|
|
|
|
|
cp "$OUTPUT_DIR/images.tar.gz" "$KICAD_TEST/" 2>/dev/null || true
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Output ${app} not found locally, trying Docker volume..."
|
|
|
|
|
if docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
|
2026-05-29 12:01:44 +02:00
|
|
|
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.js "$KICAD_TEST/" 2>/dev/null \
|
2026-05-29 06:39:23 +02:00
|
|
|
&& docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
|
2026-05-29 12:01:44 +02:00
|
|
|
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.wasm "$KICAD_TEST/" 2>/dev/null; then
|
2026-05-29 06:39:23 +02:00
|
|
|
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
|
2026-05-29 12:01:44 +02:00
|
|
|
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.wasm.map "$KICAD_TEST/" 2>/dev/null || true
|
2026-05-29 06:39:23 +02:00
|
|
|
docker compose -f "$PROJECT_ROOT/docker/docker-compose.yml" cp \
|
2026-05-29 12:01:44 +02:00
|
|
|
kicad-wasm-builder:/workspace/build-wasm/kicad-${app}/${subdir}/${app}.worker.js "$KICAD_TEST/" 2>/dev/null || true
|
2026-05-29 06:39:23 +02:00
|
|
|
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
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo " (no ${app} artifacts found — skipping)"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
found_any=0
|
2026-05-29 12:01:44 +02:00
|
|
|
copy_app pcbnew && found_any=1
|
|
|
|
|
copy_app eeschema && found_any=1
|
|
|
|
|
copy_app calculator && found_any=1
|
2026-05-29 06:39:23 +02:00
|
|
|
|
|
|
|
|
if [ "$found_any" -eq 0 ]; then
|
2026-05-29 12:01:44 +02:00
|
|
|
echo "Error: no pcbnew/eeschema/calculator artifacts found in output/ or docker volume" >&2
|
2026-05-29 06:39:23 +02:00
|
|
|
exit 1
|
2025-12-13 22:13:31 +01:00
|
|
|
fi
|
2025-12-12 15:34:15 +01:00
|
|
|
|
|
|
|
|
# wxWidgets WASM JavaScript glue code (defines JS functions called from WASM)
|
|
|
|
|
echo "Copying wxWidgets WASM glue code..."
|
2026-03-22 12:48:05 +01:00
|
|
|
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
|
2025-12-12 15:34:15 +01:00
|
|
|
|
|
|
|
|
echo "KiCad WASM files copied to $KICAD_TEST"
|
|
|
|
|
ls -lh "$KICAD_TEST"
|