Repository Public
1#!/usr/bin/env bash2# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : SP Keyboard8# File : Scripts/build.sh9# Description : Reproducible local builds and tests. usage: build.sh list10# | shared | debug | release-sim | test [only] | headers11# "shared" runs the Swift package tests on macOS (fast);12# "test" runs everything on the simulator.13# Module : Scripts14# Repository : https://git.spboucher.ai/sp-keyboard15# Created : 2026-12-0116# Last Modified : 2026-12-0117#18# Author : Simon-Pierre Boucher19# Position : Professor of Finance20# Institution : Université du Québec en Outaouais (UQO)21# Organization : SP Boucher22# Website : https://spboucher.ai23# Git : https://git.spboucher.ai24#25# Preferred Contact: support@spboucher.ai26# Technical Contact: dev@spboucher.ai27# Security/Admin : admin@spboucher.ai28#29# Copyright (c) 202630# Simon-Pierre Boucher31# All rights reserved where applicable. This file is governed by the32# applicable project license, copyright notices and relevant law.33# Existing third-party rights and notices remain unaffected.34#35# License : None specified (no license file in this repository)36#37# Do not embed credentials, private keys, access tokens,38# certificates or confidential personal information.39#40# =============================================================================41# END OF SP BOUCHER SOURCE HEADER42# =============================================================================4344set -euo pipefail45cd "$(dirname "$0")/.."46SIM="${SPK_SIMULATOR:-SPKeyboard iPhone}"47DEST="platform=iOS Simulator,name=$SIM"48mkdir -p build/logs49report() { grep -E "error:|warning: unre|\*\* (BUILD|TEST)|Executed [0-9]+ tests" "$1" | sed "s|$PWD/||" | sort -u | tail -25; }50case "${1:-}" in51list)52 xcodegen generate --quiet53 xcodebuild -list -project SPKeyboard.xcodeproj54 xcodebuild -showdestinations -project SPKeyboard.xcodeproj -scheme SPKeyboard | grep -E "platform:" | head -12 ;;55shared)56 (cd Shared && swift test --scratch-path "${SPK_SCRATCH:-/tmp/spk-main}" 2>&1 | tee ../build/logs/shared-tests.log | grep -E "error:|failed|Executed [0-9]+ tests" | sort -u | tail -20) ;;57debug)58 xcodegen generate --quiet59 xcodebuild build -project SPKeyboard.xcodeproj -scheme SPKeyboard -configuration Debug -destination "$DEST" -derivedDataPath build/dd > build/logs/build-debug.log 2>&1 || { report build/logs/build-debug.log; exit 1; }60 report build/logs/build-debug.log ;;61release-sim)62 xcodegen generate --quiet63 xcodebuild build -project SPKeyboard.xcodeproj -scheme SPKeyboard -configuration Release -destination "$DEST" -derivedDataPath build/dd-relsim > build/logs/build-release-sim.log 2>&1 || { report build/logs/build-release-sim.log; exit 1; }64 report build/logs/build-release-sim.log ;;65test)66 xcodegen generate --quiet67 ONLY=(); [ -n "${2:-}" ] && ONLY=(-only-testing:"$2")68 xcodebuild test -project SPKeyboard.xcodeproj -scheme SPKeyboard -configuration Debug -destination "$DEST" -derivedDataPath build/dd "${ONLY[@]}" > build/logs/test.log 2>&1 || { report build/logs/test.log; exit 1; }69 report build/logs/test.log ;;70headers)71 # Every first-party source file starts with the house header.72 missing=073 while IFS= read -r file; do74 head -3 "$file" | grep -q "SP Keyboard" || { echo "missing header: $file"; missing=1; }75 done < <(git ls-files '*.swift' '*.sh' '*.py' '*.js' '*.applescript' '*.yml')76 [ "$missing" = 0 ] && echo "headers: ok" || exit 1 ;;77*) echo "usage: $0 list|shared|debug|release-sim|test [only]|headers"; exit 2 ;;78esac79