-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBuildCLI.sh
More file actions
295 lines (217 loc) Β· 7.13 KB
/
BuildCLI.sh
File metadata and controls
295 lines (217 loc) Β· 7.13 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
#!/bin/bash
OS=$1
TARGET=$2
set -e
set -x
set -o pipefail
currentStep="INIT"
step() {
currentStep="$1"
echo
echo "=============================="
echo "βΆ STEP: $currentStep"
echo "=============================="
}
currentDir="$(pwd)"
parentDir="$(dirname "$currentDir")"
export PATH="$HOME/.cargo/bin:$PATH"
downloadPyapp() {
currentDir="$(pwd)"
parentDir="$(dirname "$currentDir")"
echo "Download, unzip and rename pyapp folder"
curl -L https://github.com/ofek/pyapp/releases/latest/download/source.tar.gz -o pyapp-source.tar.gz
rm -rf pyapp_$OS
mkdir -p pyapp_$OS
tar -xzf pyapp-source.tar.gz --strip-components=1 -C pyapp_$OS
echo "Delete pyapp-source.tar.gz"
rm -f pyapp-source.tar.gz
}
createWheel() {
echo "Copy Setup.py"
cp "$currentDir/dist/CLI/Setup.py" "$parentDir/"
cd "$parentDir"
echo "Build wheel"
python3 Setup.py bdist_wheel
cd dist
echo "Get wheel filename"
wheelFile=""
for f in ffl*.whl; do
wheelFile="$f"
break
done
if [ -z "$wheelFile" ]; then
echo "No wheel file found!"
exit 1
fi
echo "Installing wheel: $wheelFile"
python3 -m pip install "$wheelFile" --force-reinstall --no-warn-script-location
cd ../FileShare
echo "Copy wheel file to pyapp folder"
cp "../dist/$wheelFile" "$currentDir/pyapp_$OS/"
export wheelFile
cd ..
echo "Delete unused files"
rm -rf dist
rm -rf build
rm -rf ffl.egg-info
rm -f Setup.py
cd FileShare
}
createPythonTarGz() {
local platform="${1:-native}"
unset CONDA_SUBDIR
envName="ffl_python_temp"
if [ "$OS" = "darwin" ] && [ "$platform" = "x86_64" ]; then
export CONDA_SUBDIR=osx-64
envName="ffl_python_temp_x86_64"
fi
if [ "$OS" = "linux" ]; then
source "$HOME/miniconda3/etc/profile.d/conda.sh"
fi
eval "$(conda shell.bash hook)"
rm -rf "$envName"
echo "Activating conda environment: $envName"
conda create -n "$envName" python=3.12 -y
conda activate "$envName"
export PYTHONIOENCODING=utf-8
if [ "$OS" = "linux" ]; then
cp REQUIREMENTS.txt REQUIREMENTS.txt.bak
grep -vi -e "Gooey==1.0.8.1" -e "pyinstaller" REQUIREMENTS.txt > REQUIREMENTS.txt.tmp
mv REQUIREMENTS.txt.tmp REQUIREMENTS.txt
fi
python3 -m pip install -r REQUIREMENTS.txt
# Used only for DistUtil.py not bundled in final executable.
python3 -m pip install pefile conda-pack setuptools wheel pip
if [ "$OS" = "linux" ]; then
mv REQUIREMENTS.txt.bak REQUIREMENTS.txt
fi
createWheel
rm -f "$envName.tar.gz"
conda pack -n "$envName" -o "$envName.tar.gz"
mkdir -p "$envName"
tar -xzf "$envName.tar.gz" -C "$envName"
echo "Clean python environment"
python DistUtils.py pyapp clean --target-dir "$envName"
cd $envName
if [ "$OS" = "darwin" ]; then
python3 -m compileall --invalidation-mode=unchecked-hash -b -q lib || true
elif [ "$TARGET" = "manyLinux" ]; then
cd ..
cp "$currentDir/dist/CLI/linux/RemoveSym.py" "$currentDir/"
python RemoveSym.py "$envName"
cd "$envName"
python3 -m compileall --invalidation-mode=unchecked-hash -b -q lib
else
python3 -m compileall --invalidation-mode=unchecked-hash -b -q lib
fi
find . -type f -name "*.py" -exec rm -f {} +
mv bin/python3.12 bin/ffl
if [ "$OS" = "darwin" ] && [ "$platform" = "x86_64" ]; then
tarGzName="ffl_python_x86_64.tar.gz"
else
tarGzName="ffl_python.tar.gz"
fi
tar -czf "../$tarGzName" .
cd ..
cp "$tarGzName" "$currentDir/pyapp_$OS/"
unset CONDA_SUBDIR
}
copyServerStatic() {
echo "Copy server static folders (js, client, css, locales) to FileShare/static"
serverStaticDir="$parentDir/FileShareServer/static"
targetStaticDir="$currentDir/static"
if [ -d "$serverStaticDir" ]; then
for folder in js client css locales; do
if [ -d "$serverStaticDir/$folder" ]; then
echo "Copying server static folder: $folder"
cp -r "$serverStaticDir/$folder" "$targetStaticDir/"
else
echo "Warning: Server static folder not found: $serverStaticDir/$folder"
fi
done
else
echo "Warning: Server static directory not found: $serverStaticDir"
fi
}
createApp() {
local platform="${1:-native}"
cd pyapp_$OS
cargo clean
echo "$wheelFile"
export PYAPP_PROJECT_PATH="./$wheelFile"
export PYAPP_SKIP_INSTALL='1'
export PYAPP_DISTRIBUTION_SITE_PACKAGES_PATH='./lib/python3.12/site-packages'
export PYAPP_DISTRIBUTION_PATH='./ffl_python.tar.gz'
export PYAPP_DISTRIBUTION_PYTHON_PATH='./bin/ffl'
export PYAPP_DISTRIBUTION_EMBED='1'
export PYAPP_FULL_ISOLATION='1'
export PYAPP_PROJECT_NAME='ffl'
export PYAPP_EXEC_SPEC='FileShare.Core:main'
export PYAPP_PASS_LOCATION='1'
if [ "$OS" = "darwin" ] && [ "$platform" = "x86_64" ]; then
export PYAPP_DISTRIBUTION_PATH='./ffl_python_x86_64.tar.gz'
rustup target add x86_64-apple-darwin
cargo build --target=x86_64-apple-darwin --release
cp "target/x86_64-apple-darwin/release/pyapp" \
"../dist/CLI/$OS/ffl_x86_64"
chmod +x ../dist/CLI/$OS/ffl_x86_64
else
export PYAPP_DISTRIBUTION_PATH='./ffl_python.tar.gz'
if [ "$OS" = "darwin" ]; then
rustup target add aarch64-apple-darwin
cargo build --target=aarch64-apple-darwin --release
cp "target/aarch64-apple-darwin/release/pyapp" \
"../dist/CLI/$OS/ffl_aarch64"
chmod +x ../dist/CLI/$OS/ffl_aarch64
else
rustup target add x86_64-unknown-linux-musl
cargo build --target=x86_64-unknown-linux-musl --release
cp "target/x86_64-unknown-linux-musl/release/pyapp" "../dist/CLI/$OS/ffl"
fi
fi
cd ..
}
cleanEnvironment() {
rm -rf ffl_python_temp
rm -rf pyapp_$OS
rm -f ffl_python_temp.tar.gz
rm -f ffl_python_temp_x86_64.tar.gz
rm -f ffl_python.tar.gz
rm -f ffl_python_x86_64.tar.gz
conda deactivate
conda remove -n ffl_python_temp --all -y
echo "β
Build complete: dist/CLI/$OS/ffl"
}
step "START build OS=$OS TARGET=${TARGET:-none}"
step "Download pyapp"
downloadPyapp
if [ "$OS" = "darwin" ]; then
step "Copy server static"
copyServerStatic
step "Create Python env (darwin native)"
createPythonTarGz "aarch"
step "Create Python env (darwin x86_64)"
createPythonTarGz "x86_64"
step "Build app (darwin aarch64)"
createApp "aarch"
step "Build app (darwin x86_64)"
createApp "x86_64"
step "Cleanup"
cleanEnvironment
elif [ "$OS" = "linux" ]; then
step "Copy server static"
copyServerStatic
step "Create Conda env (linux${TARGET:+ / $TARGET})"
createPythonTarGz "x86_64"
step "Build app (linux)"
createApp "x86_64"
step "Cleanup"
cleanEnvironment
else
echo "β Unknown OS: $OS"
echo "Usage:"
echo " BuildCLI.sh darwin"
echo " BuildCLI.sh linux"
echo " BuildCLI.sh linux manyLinux"
exit 1
fi