Repository Public MIT
1#!/usr/bin/env bash2# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : SP GlassKit8# File : Scripts/test-source-mode.sh9# Module : Scripts10# Repository : https://git.spboucher.ai/sp-glasskit11# Project Website : https://glass.spboucher.ai12# Created : 2026-12-0213# Last Modified : 2026-12-0214#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: contact@spboucher.ai23# Development : dev@spboucher.ai24# Support : support@spboucher.ai25# Security/Admin : admin@spboucher.ai26#27# Copyright (c) 202628# Simon-Pierre Boucher29# All rights reserved where applicable. This file is governed by the30# applicable project license, copyright notices and relevant law.31# Existing third-party rights and notices remain unaffected.32#33# License : MIT34#35# Do not embed credentials, private keys, access tokens,36# certificates or confidential personal information.37#38# =============================================================================39# END OF SP BOUCHER SOURCE HEADER40# =============================================================================4142# Installs each registry component into a blank Swift package with `spglass add` (source mode: no dependency43# on the GlassKit package) and compiles it. Usage: Scripts/test-source-mode.sh [id…] (default: every component)44# Environment: JOBS (parallel builds, default 4), KEEP=1 (keep the work directory).45set -euo pipefail46ROOT="$(cd "$(dirname "$0")/.." && pwd)"47WORK="$(mktemp -d "${TMPDIR:-/tmp}/spglass-source-mode.XXXXXX")"48JOBS="${JOBS:-4}"49swift build --package-path "$ROOT" --product spglass >/dev/null50SPGLASS="$(swift build --package-path "$ROOT" --show-bin-path)/spglass"51[ -x "$SPGLASS" ] || { echo "spglass binary not found" >&2; exit 1; }5253if [ "$#" -gt 0 ]; then IDS=("$@"); else54 IDS=()55 while IFS= read -r id; do IDS+=("$id"); done < <(python3 -c "56import json,sys57for item in json.load(open(sys.argv[1]))['items']:58 if item['kind'] != 'primitive': print(item['id'])" "$ROOT/Registry/registry.json")59fi6061build_one() {62 local id="$1" dir="$WORK/$1"63 mkdir -p "$dir/Sources/App"64 cat > "$dir/Package.swift" <<PKG65// swift-tools-version: 6.266import PackageDescription67let package = Package(68 name: "SourceModeFixture",69 defaultLocalization: "en",70 platforms: [.macOS(.v26), .iOS(.v26)],71 targets: [.target(name: "App", resources: [.process("GlassKit/Core/Resources")], swiftSettings: [.swiftLanguageMode(.v6)])]72)73PKG74 echo "public enum HostApp {}" > "$dir/Sources/App/HostApp.swift"75 {76 "$SPGLASS" init --cwd "$dir" --registry "$ROOT/Registry" &&77 "$SPGLASS" add "$id" --cwd "$dir" &&78 "$SPGLASS" verify --cwd "$dir" --strict &&79 ! grep -rlE '^import SPGlass' "$dir/Sources" &&80 swift build --package-path "$dir" 2>&181 } > "$dir/log.txt" 2>&1 && echo "ok $id" || { echo "FAIL $id"; grep -E "error" "$dir/log.txt" | head -5; return 1; }82}83export -f build_one; export WORK ROOT SPGLASS8485FAILED=086printf '%s\n' "${IDS[@]}" | xargs -P "$JOBS" -I{} bash -c 'build_one "$@"' _ {} || FAILED=187echo "components tested: ${#IDS[@]} work directory: $WORK"88if [ "${KEEP:-0}" != "1" ] && [ "$FAILED" = "0" ]; then rm -rf "$WORK"; fi89exit "$FAILED"90