#!/usr/bin/env bash # Builds the solution with warnings as errors (SPEC ยง19). # scripts/build.sh [-c Debug|Release] build # scripts/build.sh --icon [X.Y] also generate the versioned icon (ADR 0016); X.Y from the last tag set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$root" configuration=Release icon="" while (( $# > 0 )); do case "$1" in -c | --configuration) configuration="${2:?manca la configurazione}"; shift 2 ;; --icon) if [[ "${2:-}" =~ ^[0-9]+\.[0-9]+$ ]]; then icon="$2"; shift 2; else icon="auto"; shift; fi ;; -h | --help) sed -n '2,5p' "$0"; exit 0 ;; *) echo "argomento sconosciuto: $1" >&2; exit 2 ;; esac done # Generates assets/icon-v.svg from the template by string replacement, then the PNGs if a rasterizer exists. generate_icon() { local version="$1" svg png size tool="" if [[ "$version" == "auto" ]]; then version="$(git describe --tags --match 'v[0-9]*' --abbrev=0 2>/dev/null || true)" [[ -n "$version" ]] || { echo "nessun tag vX.Y.Z: indica la versione, es. --icon 1.0" >&2; exit 2; } version="${version#v}" version="${version%.*}" fi svg="assets/icon-v${version}.svg" if [[ "$version" != "1.0" ]]; then sed "s/v 1\.0/v ${version}/" assets/icon-v1.0.svg > "$svg" grep -q "v ${version}" "$svg" || { echo "il modello assets/icon-v1.0.svg non contiene il testo 'v 1.0'" >&2; exit 1; } fi echo "icona: $svg" for candidate in rsvg-convert inkscape magick; do if command -v "$candidate" > /dev/null 2>&1; then tool="$candidate"; break; fi done if [[ -z "$tool" ]]; then echo "nessun rasterizzatore (rsvg-convert, inkscape, magick): genera i PNG su una macchina che ne ha uno (ADR 0016)." >&2 return 0 fi for size in 128 256 512; do png="assets/icon-v${version}-${size}.png" case "$tool" in rsvg-convert) rsvg-convert -w "$size" -h "$size" -o "$png" "$svg" ;; inkscape) inkscape "$svg" --export-type=png --export-filename="$png" -w "$size" -h "$size" > /dev/null ;; magick) magick -background none -density 384 "$svg" -resize "${size}x${size}" "$png" ;; esac echo "icona: $png ($tool)" done echo "Committa i file generati su main prima del tag che li usa (ADR 0016)." } bash scripts/check-packages.sh dotnet build Khaemhat.sln -c "$configuration" -warnaserror if [[ -n "$icon" ]]; then generate_icon "$icon" fi