#!/bin/bash set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" PYTHON="$ROOT/.build-tools/bin/python" if [ ! -x "$PYTHON" ]; then echo "请先使用 Python 3.12 创建 .build-tools 虚拟环境并安装 native-engine/requirements.txt。" >&2 exit 1 fi export PYINSTALLER_CONFIG_DIR="$ROOT/.build-tools/pyinstaller-cache" cd "$ROOT/native-engine" SOURCE_HASH="$(bash "$ROOT/native-engine/engine-fingerprint.sh")" "$PYTHON" -m PyInstaller --noconfirm --clean --onedir --windowed --name receipt-engine-helper \ --osx-bundle-identifier test.reimburse.engine \ --distpath "$ROOT/native-engine/dist" --workpath "$ROOT/native-engine/build" \ --collect-all rapidocr_onnxruntime --collect-all onnxruntime \ --collect-all pypdfium2 --collect-all pypdfium2_raw \ --add-data "personal-expense-template.xlsx:." engine.py BINARY="$ROOT/native-engine/dist/receipt-engine-helper.app/Contents/MacOS/receipt-engine-helper" RECEIPT_ENGINE_BINARY="$BINARY" "$PYTHON" -m unittest discover -s tests -p test_exports.py -k engine_process -v if [ "$SOURCE_HASH" != "$(bash "$ROOT/native-engine/engine-fingerprint.sh")" ]; then echo "error: 打包期间引擎源码发生变化,请重新构建。" >&2 exit 1 fi BINARY_HASH="$(shasum -a 256 "$BINARY" | cut -d ' ' -f 1)" printf '%s\n%s\n' "$SOURCE_HASH" "$BINARY_HASH" > "$ROOT/native-engine/dist/receipt-engine-helper.source.sha256" echo "本地处理引擎已打包,可以在 Xcode 中运行 reimburse。"