|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +: "${CARGO_BUILD_TARGET:=x86_64-pc-windows-gnu}" |
| 5 | +: "${ODOO_WINDOWS_BUILD:=true}" |
| 6 | +: "${SKIP_SERVER_PYTHON:=true}" |
| 7 | +: "${WINEPREFIX:=/home/odoo/.wine}" |
| 8 | +: "${WINEARCH:=win64}" |
| 9 | + |
| 10 | +PYTHON_DIR="$WINEPREFIX/drive_c/Program Files/Python314" |
| 11 | +PYTHON_WIN="C:\\Program Files\\Python314\\python.exe" |
| 12 | +PIP_WIN="C:\\Program Files\\Python314\\Scripts\\pip.exe" |
| 13 | +AW_SOURCE="${HOME}/activitywatch" |
| 14 | + |
| 15 | +export CARGO_BUILD_TARGET ODOO_WINDOWS_BUILD SKIP_SERVER_PYTHON |
| 16 | +export WINEPREFIX WINEARCH WINEDEBUG=-all |
| 17 | +export XDG_RUNTIME_DIR=/run/user/1000 |
| 18 | +export DISPLAY=${DISPLAY:-:99} |
| 19 | + |
| 20 | +# Python venv wrappers needed for make subshells |
| 21 | +export VIRTUAL_ENV=/home/odoo/awvenv |
| 22 | +export PATH="/home/odoo/awvenv/bin:$PATH" |
| 23 | +mkdir -p /tmp/awvenv-wrappers |
| 24 | +cat > /tmp/awvenv-wrappers/pip << 'EOF' |
| 25 | +#!/bin/bash |
| 26 | +exec /home/odoo/awvenv/bin/pip "$@" |
| 27 | +EOF |
| 28 | +cat > /tmp/awvenv-wrappers/python << 'EOF' |
| 29 | +#!/bin/bash |
| 30 | +exec /home/odoo/awvenv/bin/python "$@" |
| 31 | +EOF |
| 32 | +chmod +x /tmp/awvenv-wrappers/{pip,python} |
| 33 | +export PATH="/tmp/awvenv-wrappers:$PATH" |
| 34 | +export PYTHON="wine '$PYTHON_WIN'" |
| 35 | +export WINE_PYTHON="wine '$PYTHON_WIN'" |
| 36 | + |
| 37 | +# Xvfb start and stop functions |
| 38 | +XVFB_PID="" |
| 39 | +_start_xvfb() { |
| 40 | + if ! pgrep -x Xvfb > /dev/null 2>&1; then |
| 41 | + Xvfb $DISPLAY -screen 0 1024x768x24 & |
| 42 | + XVFB_PID=$! |
| 43 | + sleep 2 |
| 44 | + echo "[Xvfb] started (PID $XVFB_PID)" |
| 45 | + fi |
| 46 | +} |
| 47 | + |
| 48 | +_stop_xvfb() { |
| 49 | + if [[ -n "$XVFB_PID" ]] && kill -0 "$XVFB_PID" 2>/dev/null; then |
| 50 | + kill "$XVFB_PID" |
| 51 | + wait "$XVFB_PID" 2>/dev/null || true |
| 52 | + echo "[Xvfb] stopped" |
| 53 | + fi |
| 54 | +} |
| 55 | + |
| 56 | +trap _stop_xvfb EXIT |
| 57 | +_start_xvfb |
| 58 | + |
| 59 | +# Wine Python helpers |
| 60 | +wine_pip() { |
| 61 | + xvfb-run --auto-servernum wine "$PIP_WIN" "$@" |
| 62 | +} |
| 63 | + |
| 64 | +wine_python() { |
| 65 | + xvfb-run --auto-servernum wine "$PYTHON_WIN" "$@" |
| 66 | +} |
| 67 | + |
| 68 | +echo "[Wine] initializing prefix..." |
| 69 | +wineboot --init 2>/dev/null || true |
| 70 | +wineserver -w |
| 71 | + |
| 72 | +echo "[Build] Starting ActivityWatch build..." |
| 73 | +export AW_VERSION="0.13.2" |
| 74 | +cd "$AW_SOURCE" |
| 75 | +make build |
| 76 | + |
| 77 | +echo "[PyInstaller] Installing dependencies ..." |
| 78 | +wine_pip install --no-warn-script-location pystray pillow pynput wmi |
| 79 | + |
| 80 | +echo "[PyInstaller] Installing aw packages in Wine..." |
| 81 | +wine_pip install --no-warn-script-location \ |
| 82 | + "$AW_SOURCE/aw-core" \ |
| 83 | + "$AW_SOURCE/aw-client" |
| 84 | + |
| 85 | +echo "[PyInstaller] Building aw-systray-odoo.exe..." |
| 86 | +wine_python -m PyInstaller --clean --noconfirm odoo-setup/aw-systray-odoo.spec |
| 87 | + |
| 88 | +echo "[PyInstaller] Building aw-watcher-afk.exe..." |
| 89 | +cd "$AW_SOURCE/aw-watcher-afk" |
| 90 | +wine_python -m PyInstaller --clean --noconfirm aw-watcher-afk.spec |
| 91 | + |
| 92 | +echo "[PyInstaller] Building aw-watcher-window.exe..." |
| 93 | +cd "$AW_SOURCE/aw-watcher-window" |
| 94 | +wine_python -m PyInstaller --clean --noconfirm aw-watcher-window.spec |
| 95 | + |
| 96 | +cd "$AW_SOURCE" |
| 97 | +STAGING_DIR="$AW_SOURCE/staging-watcher-build" |
| 98 | +mkdir -p "$STAGING_DIR" |
| 99 | +cp "$AW_SOURCE/dist/aw-systray-odoo.exe" "$STAGING_DIR/" |
| 100 | +cp -r "$AW_SOURCE/aw-watcher-afk/dist/aw-watcher-afk" "$STAGING_DIR/" |
| 101 | +cp -r "$AW_SOURCE/aw-watcher-window/dist/aw-watcher-window" "$STAGING_DIR/" |
| 102 | + |
| 103 | +export AW_VERSION="odoo-$(date +%Y-%m-%d)" |
| 104 | +export AW_PLATFORM=windows |
| 105 | +export INNOSETUPDIR="C:\Program Files (x86)\Inno Setup 6" |
| 106 | +echo "[Package] Creating package..." |
| 107 | +rm -rf "$AW_SOURCE/dist" |
| 108 | +mkdir -p "$AW_SOURCE/dist/activitywatch" |
| 109 | +for dir in aw-server-rust; do |
| 110 | + make --directory="$AW_SOURCE/$dir" package |
| 111 | + cp -r "$AW_SOURCE/$dir/dist/$dir" "$AW_SOURCE/dist/activitywatch/" |
| 112 | +done |
| 113 | +cp -r "$STAGING_DIR/aw-watcher-afk" "$AW_SOURCE/dist/activitywatch/" |
| 114 | +cp -r "$STAGING_DIR/aw-watcher-window" "$AW_SOURCE/dist/activitywatch/" |
| 115 | +cp "$STAGING_DIR/aw-systray-odoo.exe" "$AW_SOURCE/dist/activitywatch/" |
| 116 | +rm -rf "$STAGING_DIR" |
| 117 | + |
| 118 | +# Remove problem-causing binaries (see original Makefile) |
| 119 | +rm -f "$AW_SOURCE/dist/activitywatch/libdrm.so.2" |
| 120 | +rm -f "$AW_SOURCE/dist/activitywatch/libharfbuzz.so.0" |
| 121 | +rm -f "$AW_SOURCE/dist/activitywatch/libfontconfig.so.1" |
| 122 | +rm -f "$AW_SOURCE/dist/activitywatch/libfreetype.so.6" |
| 123 | +rm -rf "$AW_SOURCE/dist/activitywatch/pytz" |
| 124 | + |
| 125 | +# Build zip and installer |
| 126 | +bash "$AW_SOURCE/scripts/package/package-all.sh" |
| 127 | + |
| 128 | +echo "" |
| 129 | +echo "=== Build finished 🎉 ===" |
| 130 | +find "$AW_SOURCE/dist" -name "*.exe" -o -name "*.zip" 2>/dev/null | head -20 |
0 commit comments