Files
2026-09-08 11:40:15 +08:00

159 lines
6.0 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
project_root="$(cd "$(dirname "$0")/.." && pwd)"
python_bin="${PYINSTALLER_PYTHON:-$project_root/.venv-build/bin/python}"
companion_root="$project_root/video_companion"
if [[ "$(uname -s)" != "Darwin" ]]; then
echo "The macOS bundle must be built on macOS." >&2
exit 2
fi
if [[ ! -x "$python_bin" ]]; then
echo "Build Python was not found: $python_bin" >&2
exit 2
fi
if [[ "${SKIP_FRONTEND_INSTALL:-0}" != "1" ]]; then
npm ci --prefix "$companion_root" --no-audit --no-fund
fi
npm run build --prefix "$companion_root"
"$python_bin" -m PyInstaller \
--noconfirm \
--clean \
"$project_root/packaging/doctor_workstation.spec"
artifact="$project_root/dist/DoctorWorkstation.app"
helper="$(find "$artifact" -type f -name 'QtWebEngineProcess' -print -quit)"
resources="$(find "$artifact" -type f -name 'qtwebengine_resources*.pak' -print -quit)"
companion="$(find "$artifact" -type f -path '*video_companion_dist/index.html' -print -quit)"
executable="$artifact/Contents/MacOS/DoctorWorkstation"
qt_multimedia_module="$(find "$artifact" -type f -name 'QtMultimedia*.so' \
! -name 'QtMultimediaWidgets*.so' -print -quit)"
qt_multimedia_widgets_module="$(find "$artifact" -type f -name 'QtMultimediaWidgets*.so' -print -quit)"
qt_multimedia_framework="$(find "$artifact" -type d -name 'QtMultimedia.framework' -print -quit)"
qt_multimedia_widgets_framework="$(find "$artifact" -type d -name 'QtMultimediaWidgets.framework' -print -quit)"
qt_multimedia_dylib="$(find "$artifact" -type f -name '*Qt6Multimedia*.dylib' \
! -name '*Widgets*' ! -name '*Quick*' -print -quit)"
qt_multimedia_widgets_dylib="$(find "$artifact" -type f -name '*Qt6MultimediaWidgets*.dylib' -print -quit)"
multimedia_plugin_dir="$(find "$artifact" -type d -path '*/plugins/multimedia' -print -quit)"
multimedia_backend=""
if [[ -n "$multimedia_plugin_dir" ]]; then
multimedia_backend="$(find "$multimedia_plugin_dir" -type f \
\( -name '*mediaplugin*.dylib' -o -name '*mediaplugin*.so' \) -print -quit)"
fi
[[ -n "$helper" ]] || { echo "QtWebEngineProcess is missing from the app." >&2; exit 1; }
[[ -n "$resources" ]] || { echo "QtWebEngine resources are missing from the app." >&2; exit 1; }
[[ -n "$companion" ]] || { echo "video_companion_dist is missing from the app." >&2; exit 1; }
[[ -x "$executable" ]] || { echo "Frozen application entry point is missing." >&2; exit 1; }
[[ -n "$qt_multimedia_module" ]] || {
echo "PySide6.QtMultimedia is missing from the app." >&2; exit 1;
}
[[ -n "$qt_multimedia_widgets_module" ]] || {
echo "PySide6.QtMultimediaWidgets is missing from the app." >&2; exit 1;
}
[[ -n "$qt_multimedia_framework" || -n "$qt_multimedia_dylib" ]] || {
echo "Qt6Multimedia framework/dylib is missing from the app." >&2; exit 1;
}
[[ -n "$qt_multimedia_widgets_framework" || -n "$qt_multimedia_widgets_dylib" ]] || {
echo "Qt6MultimediaWidgets framework/dylib is missing from the app." >&2; exit 1;
}
[[ -n "$multimedia_plugin_dir" ]] || {
echo "PySide6 plugins/multimedia is missing from the app." >&2; exit 1;
}
[[ -n "$multimedia_backend" ]] || {
echo "A Qt multimedia platform/FFmpeg backend plugin is missing from the app." >&2; exit 1;
}
echo "Frozen Qt multimedia file gate passed."
codesign --verify --deep --strict --verbose=2 "$artifact"
temp_root="${TMPDIR:-/tmp}"
temp_root="${temp_root%/}"
smoke_root="$(mktemp -d "$temp_root/doctor-workstation-smoke.XXXXXX")"
cleanup_smoke() {
case "$smoke_root" in
"$temp_root"/doctor-workstation-smoke.*) rm -rf -- "$smoke_root" ;;
*) echo "Refusing to remove unsafe smoke-test directory: $smoke_root" >&2 ;;
esac
}
trap cleanup_smoke EXIT
mkdir -p \
"$smoke_root/Library/Application Support" \
"$smoke_root/Library/Caches" \
"$smoke_root/xdg/config" \
"$smoke_root/xdg/state" \
"$smoke_root/xdg/cache" \
"$smoke_root/tmp"
run_frozen_gate() {
local gate_slug="$1"
local gate_label="$2"
local gate_argument="$3"
local stdout_file="$smoke_root/$gate_slug-stdout.txt"
local stderr_file="$smoke_root/$gate_slug-stderr.txt"
local diagnostics="$smoke_root/$gate_slug-diagnostics.txt"
local smoke_pid smoke_running smoke_status
env \
TMPDIR="$smoke_root/tmp" \
XDG_CONFIG_HOME="$smoke_root/xdg/config" \
XDG_STATE_HOME="$smoke_root/xdg/state" \
XDG_CACHE_HOME="$smoke_root/xdg/cache" \
DOCTOR_CONFIG_DIR="$smoke_root/doctor/config" \
DOCTOR_LOG_DIR="$smoke_root/doctor/logs" \
DOCTOR_API_BASE_URL="https://127.0.0.1:9" \
DOCTOR_DEMO_MODE="true" \
DOCTOR_VIDEO_MODE="embedded" \
DOCTOR_VIDEO_WEB_URL="" \
DOCTOR_VERIFY_SSL="true" \
DOCTOR_LOG_LEVEL="INFO" \
DOCTOR_SMOKE_TEST="1" \
HTTP_PROXY="http://127.0.0.1:9" \
HTTPS_PROXY="http://127.0.0.1:9" \
ALL_PROXY="http://127.0.0.1:9" \
NO_PROXY="" \
QT_QPA_PLATFORM="offscreen" \
"$executable" "$gate_argument" >"$stdout_file" 2>"$stderr_file" &
smoke_pid=$!
smoke_running=1
for _ in {1..300}; do
if ! kill -0 "$smoke_pid" 2>/dev/null; then
smoke_running=0
break
fi
sleep 0.1
done
if [[ "$smoke_running" == "1" ]]; then
kill "$smoke_pid" 2>/dev/null || true
wait "$smoke_pid" 2>/dev/null || true
smoke_status=124
elif wait "$smoke_pid"; then
smoke_status=0
else
smoke_status=$?
fi
if [[ "$smoke_status" -ne 0 ]]; then
cat "$stderr_file" >&2
echo "$gate_label failed with exit code $smoke_status." >&2
exit 1
fi
cat "$stdout_file" "$stderr_file" >"$diagnostics"
find "$smoke_root" -type f -name '*.log' -exec cat {} + >>"$diagnostics"
if grep -Eiq 'traceback \(most recent call last\)|unhandled exception|uncaught exception|fatal python error' "$diagnostics"; then
cat "$diagnostics" >&2
echo "$gate_label logs contain an unhandled exception." >&2
exit 1
fi
echo "$gate_label passed ($gate_argument, isolated offscreen mode)."
}
run_frozen_gate \
"media" "Frozen Qt multimedia smoke gate" "--media-smoke-test"
run_frozen_gate \
"entry" "Frozen application entry smoke gate" "--smoke-test"
echo "Build complete: $artifact"