-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakeExe.sh
More file actions
executable file
·136 lines (120 loc) · 3.48 KB
/
Copy pathMakeExe.sh
File metadata and controls
executable file
·136 lines (120 loc) · 3.48 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
#!/usr/bin/env bash
set -Eeuo pipefail
# PyInstaller build helper for POSIX shells (Linux/macOS)
# Mirrors the workflow of MakeExe.bat
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd -P)"
ROOT="$SCRIPT_DIR"
VENV_PY="$ROOT/.venv/bin/python"
PYINSTALLER_CMD=()
uname_out="$(uname -s)"
case "$uname_out" in
Linux) platform_subdir="linux" ;;
Darwin) platform_subdir="macos" ;;
MINGW*|MSYS*|CYGWIN*) platform_subdir="windows" ;;
*) platform_subdir="$(printf '%s' "$uname_out" | tr '[:upper:]' '[:lower:]')" ;;
esac
DIST_ROOT="$ROOT/dist/$platform_subdir"
mkdir -p "$DIST_ROOT"
cd "$ROOT"
run_build() {
local spec="$1"
local out="${2:-}"
local exename="${3:-}"
local -a dist_args=()
if [[ -n "$out" ]]; then
dist_args=(--distpath "$out")
fi
echo
echo "Building with $spec ..."
local -a cmd
if [[ ${#PYINSTALLER_CMD[@]} -eq 0 ]]; then
if [[ -x "$VENV_PY" ]]; then
if "$VENV_PY" -m PyInstaller --version >/dev/null 2>&1; then
PYINSTALLER_CMD=("$VENV_PY" -m PyInstaller)
fi
fi
if [[ ${#PYINSTALLER_CMD[@]} -eq 0 ]]; then
if command -v pyinstaller >/dev/null 2>&1; then
PYINSTALLER_CMD=("pyinstaller")
fi
fi
fi
if [[ ${#PYINSTALLER_CMD[@]} -eq 0 ]]; then
echo "PyInstaller not found. Install it in .venv or add to PATH."
echo " python -m pip install pyinstaller"
return 1
fi
cmd=("${PYINSTALLER_CMD[@]}")
if ! "${cmd[@]}" --noconfirm --clean "${dist_args[@]}" "$spec" >/dev/null 2>&1; then
echo "Build failed for $spec."
return 1
fi
echo "Build succeeded for $spec."
if [[ -n "$exename" ]]; then
rm -f "$DIST_ROOT/${exename}.exe" "$DIST_ROOT/${exename}"
rm -f "dist/${exename}.exe" "dist/${exename}"
fi
}
choice=""
echo
echo "Select build type:"
echo " [1] One file (single EXE)"
echo " [2] One folder (onedir)"
echo " [3] Both (default)"
if ! read -r -p "Enter 1, 2, or 3 [3]: " choice; then
choice=""
fi
choice="${choice//[[:space:]]/}"
if [[ "$choice" != "1" && "$choice" != "2" && "$choice" != "3" ]]; then
choice="3"
fi
if [[ -z "$choice" ]]; then
choice="3"
fi
OUT_DIR=""
case "$choice" in
"1")
rm -rf "dist/SMDB-onefile"
rm -rf "$DIST_ROOT/SMDB-onefile"
if ! run_build "smdb/SMDB-onefile.spec" "$DIST_ROOT/SMDB-onefile"; then
echo "One or more builds failed."
exit 1
fi
OUT_DIR="$DIST_ROOT/SMDB-onefile"
;;
"2")
rm -rf "dist/SMDB-onedir"
rm -rf "$DIST_ROOT/SMDB-onedir"
rm -f "dist/SMDB.exe" "dist/SMDB" "$DIST_ROOT/SMDB.exe" "$DIST_ROOT/SMDB"
if ! run_build "smdb/SMDB-onefolder.spec" "$DIST_ROOT" "SMDB"; then
echo "One or more builds failed."
exit 1
fi
OUT_DIR="$DIST_ROOT/SMDB-onedir"
;;
*)
rm -rf "dist/SMDB-onefile"
rm -rf "$DIST_ROOT/SMDB-onefile"
if ! run_build "smdb/SMDB-onefile.spec" "$DIST_ROOT/SMDB-onefile"; then
echo "One or more builds failed."
exit 1
fi
rm -rf "dist/SMDB-onedir"
rm -rf "$DIST_ROOT/SMDB-onedir"
rm -f "dist/SMDB.exe" "dist/SMDB" "$DIST_ROOT/SMDB.exe" "$DIST_ROOT/SMDB"
if ! run_build "smdb/SMDB-onefolder.spec" "$DIST_ROOT" "SMDB"; then
echo "One or more builds failed."
exit 1
fi
OUT_DIR="$DIST_ROOT"
;;
esac
echo
echo "Opening $OUT_DIR ..."
if command -v xdg-open >/dev/null 2>&1; then
xdg-open "$OUT_DIR" >/dev/null 2>&1 &
elif command -v open >/dev/null 2>&1; then
open "$OUT_DIR" >/dev/null 2>&1 &
else
echo "Unable to automatically open $OUT_DIR; please open it manually."
fi