#!/bin/sh
set -eu
export AVALONIA_TELEMETRY_OPTOUT=1
ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
cd "$ROOT_DIR"
APP_PROJ="GC-BOOT/GC-BOOT.csproj"
SAVEDOG_PROJ="GC-SAVEDOG/GC-SAVEDOG.csproj"
PREVIEW_PROJ="model/_engine/PreviewGen/PreviewGen.csproj"
STAMP_PROJ="model/_engine/VersionStamp/VersionStamp.csproj"
TEST_PROJ="GC/src/test/dotnet/GC.Tests/GC.Tests.csproj"
SLN="GC.sln"
VERSION=$(sed -n 's/.*<Version>\(.*\)<\/Version>.*/\1/p' Directory.Build.props | head -1)
[ -n "$VERSION" ] || VERSION="1.0.0"
TASK="${1:-build}"
shift 2>/dev/null || true
CLI_VERSION=""
for arg in "$@"; do
case "$arg" in
-version=*|--version=*) CLI_VERSION="${arg#*=}" ;;
esac
done
if [ -n "$CLI_VERSION" ]; then
VERSION="$CLI_VERSION"
if [ -f Directory.Build.props ]; then
sed -i.bak "s|<Version>[^<]*</Version>|<Version>${VERSION}</Version>|" Directory.Build.props
rm -f Directory.Build.props.bak
fi
echo "==> 版本号设为 ${VERSION}"
fi
mkdir -p "$ROOT_DIR/build/logs"
. "$ROOT_DIR/buildsh/lib/progress.sh"
. "$ROOT_DIR/buildsh/lib/build_funcs.sh"
. "$ROOT_DIR/buildsh/build.sh"
. "$ROOT_DIR/buildsh/check.sh"
. "$ROOT_DIR/buildsh/tools.sh"
case "$TASK" in
build) bs_build "$ROOT_DIR" ;;
check) bs_check "$ROOT_DIR" ;;
*) bs_tools "$ROOT_DIR" "$TASK" ;;
esac