Compare commits
No commits in common. '38bf981652d49b0187136c2796011f99491ad1cf' and 'cd538abd9a3084c974c9b43ea7de2f8e19e8db36' have entirely different histories.
38bf981652
...
cd538abd9a
@ -1,135 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
app_name="m9zCtrlTty"
|
||||
app_package="./apps/m9zCtrlTty"
|
||||
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
repo_root="$(cd -- "${script_dir}/../.." && pwd)"
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage:
|
||||
./apps/m9zCtrlTty/build.sh <goos> <goarch> [goarm]
|
||||
|
||||
Examples:
|
||||
./apps/m9zCtrlTty/build.sh linux arm 7
|
||||
./apps/m9zCtrlTty/build.sh linux arm64
|
||||
./apps/m9zCtrlTty/build.sh windows amd64
|
||||
./apps/m9zCtrlTty/build.sh darwin arm64
|
||||
|
||||
Arguments:
|
||||
goos Target operating system accepted by "go tool dist list".
|
||||
goarch Target CPU architecture accepted by "go tool dist list".
|
||||
goarm ARM generation for 32-bit GOARCH=arm: 5, 6, or 7 (default: 7).
|
||||
Soft-float targets may use 5,softfloat, 6,softfloat, or 7,softfloat.
|
||||
|
||||
Environment variables:
|
||||
OUTPUT_ROOT Output root directory (default: dist).
|
||||
CGO_ENABLED CGO mode (default: 0 for cross-compilation).
|
||||
BUILD_TAGS Optional Go build tags.
|
||||
BUILD_LDFLAGS Go linker flags (default: -s -w; set to an empty value to keep symbols).
|
||||
EOF
|
||||
}
|
||||
|
||||
if [[ $# -lt 2 || $# -gt 3 ]]; then
|
||||
usage >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if ! command -v go >/dev/null 2>&1; then
|
||||
printf 'Go toolchain was not found in PATH.\n' >&2
|
||||
exit 127
|
||||
fi
|
||||
|
||||
target_os="$1"
|
||||
target_arch="$2"
|
||||
target_pair="${target_os}/${target_arch}"
|
||||
|
||||
supported_target=false
|
||||
while IFS= read -r candidate; do
|
||||
if [[ "$candidate" == "$target_pair" ]]; then
|
||||
supported_target=true
|
||||
break
|
||||
fi
|
||||
done < <(go tool dist list)
|
||||
|
||||
if [[ "$supported_target" != true ]]; then
|
||||
printf 'Unsupported Go build target: %s\n' "$target_pair" >&2
|
||||
printf 'Run "go tool dist list" to see supported targets.\n' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
arch_label="$target_arch"
|
||||
if [[ "$target_arch" == "arm" ]]; then
|
||||
target_goarm="${3:-${GOARM:-7}}"
|
||||
case "$target_goarm" in
|
||||
5|6|7|5,softfloat|6,softfloat|7,softfloat) ;;
|
||||
*)
|
||||
printf 'Invalid GOARM value: %s\n' "$target_goarm" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
export GOARM="$target_goarm"
|
||||
arm_generation="${target_goarm%%,*}"
|
||||
arch_label="armv${arm_generation}"
|
||||
if [[ "$target_goarm" == *,softfloat ]]; then
|
||||
arch_label="${arch_label}-softfloat"
|
||||
fi
|
||||
elif [[ $# -eq 3 ]]; then
|
||||
printf 'The third argument (goarm) is only valid when GOARCH=arm.\n' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
output_root="${OUTPUT_ROOT:-dist}"
|
||||
if [[ "$output_root" != /* ]]; then
|
||||
output_root="${repo_root}/${output_root}"
|
||||
fi
|
||||
output_dir="${output_root}/${target_os}-${arch_label}"
|
||||
|
||||
extension=""
|
||||
case "$target_os" in
|
||||
windows) extension=".exe" ;;
|
||||
js|wasip1)
|
||||
if [[ "$target_arch" == "wasm" ]]; then
|
||||
extension=".wasm"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
output_path="${output_dir}/${app_name}${extension}"
|
||||
mkdir -p "$output_dir"
|
||||
|
||||
export GOOS="$target_os"
|
||||
export GOARCH="$target_arch"
|
||||
export CGO_ENABLED="${CGO_ENABLED:-0}"
|
||||
|
||||
if [[ "${BUILD_LDFLAGS+x}" == "x" ]]; then
|
||||
build_ldflags="$BUILD_LDFLAGS"
|
||||
else
|
||||
build_ldflags="-s -w"
|
||||
fi
|
||||
|
||||
build_args=(build -mod=readonly -trimpath -o "$output_path")
|
||||
if [[ -n "${BUILD_TAGS:-}" ]]; then
|
||||
build_args+=(-tags "$BUILD_TAGS")
|
||||
fi
|
||||
if [[ -n "$build_ldflags" ]]; then
|
||||
build_args+=(-ldflags "$build_ldflags")
|
||||
fi
|
||||
build_args+=("$app_package")
|
||||
|
||||
printf 'Building %s for %s (CGO_ENABLED=%s)\n' "$app_name" "$target_pair" "$CGO_ENABLED"
|
||||
if [[ "$target_arch" == "arm" ]]; then
|
||||
printf 'Using GOARM=%s\n' "$GOARM"
|
||||
fi
|
||||
|
||||
(
|
||||
cd "$repo_root"
|
||||
go "${build_args[@]}"
|
||||
)
|
||||
|
||||
printf 'Build complete: %s\n' "$output_path"
|
||||
if command -v file >/dev/null 2>&1; then
|
||||
file "$output_path"
|
||||
fi
|
||||
@ -1,49 +0,0 @@
|
||||
package m9zApi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"tgk-touch/internal/library/m9z"
|
||||
)
|
||||
|
||||
func TestApplySolarTaskTime(t *testing.T) {
|
||||
sunrise := time.Date(2026, 8, 21, 5, 32, 0, 0, time.Local)
|
||||
sunset := time.Date(2026, 8, 21, 18, 41, 0, 0, time.Local)
|
||||
sunTimes := &m9z.SunTimes{Sunrise: sunrise, Sunset: sunset}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
apply func(*m9z.ControlTask, *m9z.SunTimes)
|
||||
want time.Time
|
||||
}{
|
||||
{name: "start task uses sunset", apply: applyStartTaskSolarTime, want: sunset},
|
||||
{name: "stop task uses sunrise", apply: applyStopTaskSolarTime, want: sunrise},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
task := &m9z.ControlTask{TimeType: 1}
|
||||
tt.apply(task, sunTimes)
|
||||
if !task.ExecTime.Equal(tt.want) {
|
||||
t.Fatalf("ExecTime = %v, want %v", task.ExecTime, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplySolarTaskTimeKeepsScheduledTime(t *testing.T) {
|
||||
scheduled := time.Date(2026, 8, 21, 20, 0, 0, 0, time.Local)
|
||||
task := &m9z.ControlTask{TimeType: 0, ExecTime: scheduled}
|
||||
sunTimes := &m9z.SunTimes{
|
||||
Sunrise: scheduled.Add(-14 * time.Hour),
|
||||
Sunset: scheduled.Add(-time.Hour),
|
||||
}
|
||||
|
||||
applyStartTaskSolarTime(task, sunTimes)
|
||||
applyStopTaskSolarTime(task, sunTimes)
|
||||
|
||||
if !task.ExecTime.Equal(scheduled) {
|
||||
t.Fatalf("ExecTime = %v, want scheduled time %v", task.ExecTime, scheduled)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue