-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlauncher.sh
More file actions
executable file
·371 lines (326 loc) · 9 KB
/
launcher.sh
File metadata and controls
executable file
·371 lines (326 loc) · 9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
SCRIPT_NAME="$(basename "$0")"
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
APP_BIN="pantograph"
RELEASE_BIN_CANDIDATES=(
"./target/release/${APP_BIN}"
"./target/release/${APP_BIN}.exe"
"./src-tauri/target/release/${APP_BIN}"
"./src-tauri/target/release/${APP_BIN}.exe"
)
VENV_DIR="$ROOT_DIR/.venv"
VENV_PYTHON="$VENV_DIR/bin/python3"
EXIT_SUCCESS=0
EXIT_OPERATION_FAILED=1
EXIT_USAGE_ERROR=2
EXIT_MISSING_DEP=3
EXIT_MISSING_RELEASE_ARTIFACT=4
INSTALL_DEPENDENCIES=("npm" "cargo" "python3" "node_modules" "venv" "python_base_requirements" "python_diffusion_requirements")
RUNTIME_DEPENDENCIES=("npm" "cargo" "python3" "node_modules" "venv")
# Raise file descriptor limits for local dev watchers where possible.
ulimit -n 65536 2>/dev/null || ulimit -n 16384 2>/dev/null || ulimit -n 4096 2>/dev/null || true
usage() {
cat <<EOF
Pantograph launcher for install, build, and runtime operations.
Usage:
./${SCRIPT_NAME} --help
./${SCRIPT_NAME} --install
./${SCRIPT_NAME} --build
./${SCRIPT_NAME} --build-release
./${SCRIPT_NAME} --release-smoke
./${SCRIPT_NAME} --test
./${SCRIPT_NAME} --run [-- <app args...>]
./${SCRIPT_NAME} --run-release [-- <app args...>]
Required action flags (choose exactly one):
--run Run the desktop app in development mode
--run-release Run the release binary artifact directly
--build Build development artifacts
--build-release Build release artifacts
--release-smoke Run the bounded redistributables smoke against a built release artifact
--test Run the canonical local quality gate
--install Install/verify dependencies
--help Print this help and exit
Examples:
./${SCRIPT_NAME} --install
./${SCRIPT_NAME} --build
./${SCRIPT_NAME} --build-release
./${SCRIPT_NAME} --release-smoke
./${SCRIPT_NAME} --test
./${SCRIPT_NAME} --run
./${SCRIPT_NAME} --run -- --verbose
./${SCRIPT_NAME} --run-release
./${SCRIPT_NAME} --run-release -- --help
Exit codes:
${EXIT_SUCCESS} success
${EXIT_OPERATION_FAILED} operation failed
${EXIT_USAGE_ERROR} usage error
${EXIT_MISSING_DEP} missing dependency for runtime
${EXIT_MISSING_RELEASE_ARTIFACT} missing release artifact for --run-release
130 interrupted
EOF
}
log() {
printf '[launcher] %s\n' "$*"
}
die() {
log "error: $*"
exit "$EXIT_OPERATION_FAILED"
}
die_usage() {
log "usage error: $*"
usage
exit "$EXIT_USAGE_ERROR"
}
check_requirements() {
local req_file="$1"
while IFS= read -r line; do
[[ "$line" =~ ^[[:space:]]*# ]] && continue
[[ -z "${line// /}" ]] && continue
local pkg
if [[ "$line" =~ ^https?:// ]]; then
local filename="${line##*/}"
pkg="${filename%%-*}"
else
pkg="${line%% @*}"
pkg="${pkg%%[>=<\[]*}"
pkg="${pkg// /}"
fi
case "$pkg" in
Pillow) pkg="PIL" ;;
*) pkg="${pkg//-/_}" ;;
esac
if ! "$VENV_PYTHON" -c "import $pkg" >/dev/null 2>&1; then
return 1
fi
done < "$req_file"
return 0
}
check_npm() { command -v npm >/dev/null 2>&1; }
install_npm() { die "npm is required. Install Node.js/npm, then rerun --install"; }
check_cargo() { command -v cargo >/dev/null 2>&1; }
install_cargo() { die "cargo is required. Install Rust toolchain, then rerun --install"; }
check_python3() { command -v python3 >/dev/null 2>&1; }
install_python3() { die "python3 is required. Install Python 3.10+, then rerun --install"; }
check_node_modules() { [[ -d "$ROOT_DIR/node_modules" ]]; }
install_node_modules() { npm install; }
check_venv() { [[ -x "$VENV_PYTHON" ]]; }
install_venv() {
check_python3 || return 1
python3 -m venv "$VENV_DIR"
"$VENV_PYTHON" -m pip install --upgrade pip -q
}
check_python_base_requirements() {
check_venv || return 1
check_requirements "$ROOT_DIR/requirements.txt"
}
install_python_base_requirements() {
check_venv || install_venv
"$VENV_PYTHON" -m pip install -r "$ROOT_DIR/requirements.txt"
}
check_python_diffusion_requirements() {
check_venv || return 1
check_requirements "$ROOT_DIR/requirements-diffusion.txt"
}
install_python_diffusion_requirements() {
check_venv || install_venv
"$VENV_PYTHON" -m pip install -r "$ROOT_DIR/requirements-diffusion.txt"
}
check_dep() { "check_$1"; }
install_dep() { "install_$1"; }
install_dependencies() {
local dep
for dep in "${INSTALL_DEPENDENCIES[@]}"; do
if check_dep "$dep"; then
log "[ok] $dep already satisfied"
continue
fi
log "[install] $dep missing; installing"
if install_dep "$dep"; then
if check_dep "$dep"; then
log "[done] $dep installed"
else
log "[error] $dep install failed verification"
exit "$EXIT_OPERATION_FAILED"
fi
else
log "[error] $dep install failed"
exit "$EXIT_OPERATION_FAILED"
fi
done
}
ensure_runtime_dependencies() {
local dep
for dep in "${RUNTIME_DEPENDENCIES[@]}"; do
if ! check_dep "$dep"; then
log "missing dependency: $dep"
log "run ./${SCRIPT_NAME} --install first"
exit "$EXIT_MISSING_DEP"
fi
done
}
activate_python_env() {
if check_venv; then
export PYO3_PYTHON="$VENV_PYTHON"
if [[ -z "${PANTOGRAPH_PYTHON_EXECUTABLE:-}" ]]; then
export PANTOGRAPH_PYTHON_EXECUTABLE="$VENV_PYTHON"
fi
export VIRTUAL_ENV="$VENV_DIR"
export PATH="$VENV_DIR/bin:$PATH"
fi
}
build_app() {
local mode="$1"
ensure_runtime_dependencies
activate_python_env
case "$mode" in
dev)
log "[build] building development artifacts"
npm run build
;;
release)
log "[build] building release artifacts"
npm run build:desktop
;;
*)
die_usage "invalid build mode: $mode"
;;
esac
}
run_app() {
ensure_runtime_dependencies
activate_python_env
log "[run] starting development runtime"
if [[ ${#RUN_ARGS[@]} -gt 0 ]]; then
exec npm run dev:desktop -- "${RUN_ARGS[@]}"
fi
exec npm run dev:desktop
}
run_release_app() {
ensure_runtime_dependencies
activate_python_env
local release_bin=""
if ! release_bin="$(resolve_release_artifact)"; then
log "missing release artifact"
log "expected one of:"
local candidate=""
for candidate in "${RELEASE_BIN_CANDIDATES[@]}"; do
log " $candidate"
done
log "run ./${SCRIPT_NAME} --build-release first"
exit "$EXIT_MISSING_RELEASE_ARTIFACT"
fi
log "[run] starting release binary: $release_bin"
if [[ ${#RUN_ARGS[@]} -gt 0 ]]; then
exec "$release_bin" "${RUN_ARGS[@]}"
fi
exec "$release_bin"
}
resolve_release_artifact() {
local candidate=""
for candidate in "${RELEASE_BIN_CANDIDATES[@]}"; do
if [[ -x "$candidate" ]]; then
printf '%s\n' "$candidate"
return 0
fi
done
return 1
}
run_release_smoke() {
ensure_runtime_dependencies
activate_python_env
local release_bin=""
if ! release_bin="$(resolve_release_artifact)"; then
log "missing release artifact"
log "expected one of:"
local candidate=""
for candidate in "${RELEASE_BIN_CANDIDATES[@]}"; do
log " $candidate"
done
log "run ./${SCRIPT_NAME} --build-release first"
exit "$EXIT_MISSING_RELEASE_ARTIFACT"
fi
log "[smoke] running runtime redistributables smoke against $release_bin"
"$ROOT_DIR/scripts/check-runtime-redistributables-smoke.sh" "$release_bin"
}
run_tests() {
ensure_runtime_dependencies
activate_python_env
log "[test] running critical frontend lint"
npm run lint:critical
log "[test] running TypeScript typecheck"
npm run typecheck
log "[test] running frontend unit tests"
npm run test:frontend
log "[test] checking Rust workspace with all features"
cargo check --workspace --all-features
log "[test] checking Rust workspace without default features"
cargo check --workspace --no-default-features
log "[test] running focused Rust unit tests"
cargo test -p node-engine --lib
cargo test -p workflow-nodes --lib
log "[test] local quality gate completed"
}
ACTION=""
RUN_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
--run|--run-release|--build|--build-release|--release-smoke|--test|--install|--help)
if [[ -n "$ACTION" ]]; then
die_usage "exactly one action flag is allowed"
fi
ACTION="$1"
shift
;;
--)
if [[ "$ACTION" != "--run" && "$ACTION" != "--run-release" ]]; then
die_usage "'--' is only valid with --run or --run-release"
fi
shift
RUN_ARGS=("$@")
break
;;
--*)
die_usage "unknown flag: $1"
;;
*)
die_usage "positional arguments are not allowed: $1"
;;
esac
done
if [[ -z "$ACTION" ]]; then
die_usage "missing action flag"
fi
case "$ACTION" in
--help)
usage
exit "$EXIT_SUCCESS"
;;
--install)
install_dependencies
exit "$EXIT_SUCCESS"
;;
--build)
build_app dev
;;
--build-release)
build_app release
;;
--release-smoke)
run_release_smoke
;;
--test)
run_tests
;;
--run)
run_app
;;
--run-release)
run_release_app
;;
*)
die_usage "invalid action: $ACTION"
;;
esac