Add KiCad fork diff statistics script

- scripts/kicad-diff-stats.sh: Shows how far our KiCad fork has diverged
  from upstream (last non-our commit)
- Outputs: commit count, files changed, lines added/deleted, file list
- Logs to logs/kicad-diff/ with timestamps
- Update CLAUDE.md with script reference

Current status: 5 commits, 81 files, +1536/-395 lines on top of upstream

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Viktor Vaczi 2026-01-05 11:16:46 +01:00
commit c2a69cf9db
2 changed files with 188 additions and 11 deletions

View file

@ -1,19 +1,22 @@
The goal is to build kicad with wasm and run it in a browser
The original research docs are in /docs
A lot of native module have to be compiled to wasm, the most complex is wxwidgets
/kicad and /wxwidgets are git submodules from our own forks
The e2e tests are in /tests, with a README and WHATWORKS md files
The e2e tests are separated per feature
The tests depend on canvas, there's an app to find button positions, use that, don't find buttons by estimating pixels
The test have screenshots that are tracked with git, use compare-screenshots.sh to see what changed, update them when a new image is added
The tests have log files after each run where the js console and cpp logs are visible
Wxwidgets wasm port has hooks for finding positions of UI elements, tests use that
The test have screenshots that are tracked with git, use compare-screenshots.sh to see what changed
Update test images with /scripts/update-baseline-screenshots.sh when a new image is added
The tests have log files in tests/logs/{wxwidgets/kicad}/{test-name} after each run where the js console and cpp logs are visible
Always check screenshots for validating tests
Our current goal is to test every wxwidgets feature kicad uses, write the wasm layer and e2e tests, documented in WHATWORKS
Never run builds manually, we have scripts that run the builds in the /scripts folder
Build wxwidgets and tests with scripts, not manually
Don't change the wxwidgets core unless absolutely necessary, try to fix things in the wasm layer
Don't try to guess what's broken in wxwidgets, use debug tools / symbols, supported by the build script
Build wxwidgets with scripts/build-wxuniversal-wasm.sh
Build kicad with docker/build.sh
Build CPP wxwidgets tests with scripts/builds-wasm-test.sh
# Next up
porting kicad, with most of the dependencies shimmed out and load it in a browser
Don't change the wxwidgets core unless absolutely necessary, try to fix things in the wasm layer.
Don't change kicad unless absolutely necessary - keep our fork as close to upstream as possible.
Run scripts/kicad-diff-stats.sh to see how far our KiCad fork has diverged from upstream.
It's okay to add temporary logging that will be removed for debugging.
Don't try to guess what's broken , use debug tools / symbols, supported by the build scripts

174
scripts/kicad-diff-stats.sh Executable file
View file

@ -0,0 +1,174 @@
#!/bin/bash
# Show diff statistics between current KiCad HEAD and last upstream commit
#
# This helps track how far our KiCad fork has diverged from upstream.
# We want to keep changes minimal to ease future porting.
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
KICAD_DIR="$PROJECT_ROOT/kicad"
LOGS_DIR="$PROJECT_ROOT/logs/kicad-diff"
# Create logs directory
mkdir -p "$LOGS_DIR"
# Log file with timestamp
TIMESTAMP="$(date +%Y%m%d-%H%M%S)"
LOG_FILE="$LOGS_DIR/${TIMESTAMP}.log"
# Our commit authors (add more if needed)
OUR_AUTHORS=(
"viktor.vaczi@emergence-engineering.com"
"noreply@anthropic.com"
)
echo "=== KiCad Fork Diff Statistics ===" | tee "$LOG_FILE"
echo "Generated: $(date)" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"
cd "$KICAD_DIR"
# Find the last commit NOT made by us
echo "Finding last upstream commit..." | tee -a "$LOG_FILE"
# Build grep pattern for our authors
AUTHOR_PATTERN=""
for author in "${OUR_AUTHORS[@]}"; do
if [ -n "$AUTHOR_PATTERN" ]; then
AUTHOR_PATTERN="$AUTHOR_PATTERN\|"
fi
AUTHOR_PATTERN="$AUTHOR_PATTERN$author"
done
# Find first commit that doesn't match our authors
UPSTREAM_COMMIT=""
while read -r commit_hash author_email; do
is_ours=false
for our_author in "${OUR_AUTHORS[@]}"; do
if [[ "$author_email" == "$our_author" ]]; then
is_ours=true
break
fi
done
if [ "$is_ours" = false ]; then
UPSTREAM_COMMIT="$commit_hash"
UPSTREAM_AUTHOR="$author_email"
break
fi
done < <(git log --format="%H %ae" HEAD)
if [ -z "$UPSTREAM_COMMIT" ]; then
echo "ERROR: Could not find upstream commit" | tee -a "$LOG_FILE"
exit 1
fi
# Get commit info
UPSTREAM_SUBJECT=$(git log -1 --format="%s" "$UPSTREAM_COMMIT")
UPSTREAM_DATE=$(git log -1 --format="%ci" "$UPSTREAM_COMMIT")
echo "" | tee -a "$LOG_FILE"
echo "Current HEAD: $(git rev-parse --short HEAD)" | tee -a "$LOG_FILE"
echo "Last upstream commit: $(git rev-parse --short $UPSTREAM_COMMIT)" | tee -a "$LOG_FILE"
echo " Author: $UPSTREAM_AUTHOR" | tee -a "$LOG_FILE"
echo " Date: $UPSTREAM_DATE" | tee -a "$LOG_FILE"
echo " Subject: $UPSTREAM_SUBJECT" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"
# Count our commits on top
OUR_COMMIT_COUNT=$(git rev-list --count "$UPSTREAM_COMMIT"..HEAD)
echo "Our commits on top of upstream: $OUR_COMMIT_COUNT" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"
# Get diff statistics
echo "=== Diff Statistics ===" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"
# Overall stats
DIFF_STAT=$(git diff --stat "$UPSTREAM_COMMIT"..HEAD)
DIFF_SHORTSTAT=$(git diff --shortstat "$UPSTREAM_COMMIT"..HEAD)
echo "Summary: $DIFF_SHORTSTAT" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"
# Detailed breakdown
DIFF_NUMSTAT=$(git diff --numstat "$UPSTREAM_COMMIT"..HEAD)
# Count files by type
TOTAL_FILES=0
TOTAL_INSERTIONS=0
TOTAL_DELETIONS=0
MODIFIED_FILES=0
ADDED_FILES=0
DELETED_FILES=0
while IFS=$'\t' read -r added deleted filename; do
# Skip empty lines
[ -z "$filename" ] && continue
TOTAL_FILES=$((TOTAL_FILES + 1))
# Handle binary files (shown as -)
if [ "$added" = "-" ]; then
added=0
fi
if [ "$deleted" = "-" ]; then
deleted=0
fi
TOTAL_INSERTIONS=$((TOTAL_INSERTIONS + added))
TOTAL_DELETIONS=$((TOTAL_DELETIONS + deleted))
# Categorize file changes
if [ "$added" -gt 0 ] && [ "$deleted" -eq 0 ]; then
# Check if file exists in upstream
if git cat-file -e "$UPSTREAM_COMMIT:$filename" 2>/dev/null; then
MODIFIED_FILES=$((MODIFIED_FILES + 1))
else
ADDED_FILES=$((ADDED_FILES + 1))
fi
elif [ "$added" -eq 0 ] && [ "$deleted" -gt 0 ]; then
# Check if file exists in HEAD
if git cat-file -e "HEAD:$filename" 2>/dev/null; then
MODIFIED_FILES=$((MODIFIED_FILES + 1))
else
DELETED_FILES=$((DELETED_FILES + 1))
fi
else
MODIFIED_FILES=$((MODIFIED_FILES + 1))
fi
done <<< "$DIFF_NUMSTAT"
echo "Files changed: $TOTAL_FILES" | tee -a "$LOG_FILE"
echo " Added: $ADDED_FILES" | tee -a "$LOG_FILE"
echo " Modified: $MODIFIED_FILES" | tee -a "$LOG_FILE"
echo " Deleted: $DELETED_FILES" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"
echo "Lines changed:" | tee -a "$LOG_FILE"
echo " Insertions: +$TOTAL_INSERTIONS" | tee -a "$LOG_FILE"
echo " Deletions: -$TOTAL_DELETIONS" | tee -a "$LOG_FILE"
echo " Net change: $((TOTAL_INSERTIONS - TOTAL_DELETIONS))" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"
# List changed files
echo "=== Changed Files ===" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"
# Get list with change type
git diff --name-status "$UPSTREAM_COMMIT"..HEAD | while IFS=$'\t' read -r status filename; do
case "$status" in
A) status_text="[ADDED] " ;;
M) status_text="[MODIFIED] " ;;
D) status_text="[DELETED] " ;;
R*) status_text="[RENAMED] " ;;
C*) status_text="[COPIED] " ;;
*) status_text="[$status] " ;;
esac
echo "$status_text $filename" | tee -a "$LOG_FILE"
done
echo "" | tee -a "$LOG_FILE"
echo "=== End of Report ===" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"
echo "Full log saved to: $LOG_FILE"