forked from ip-gpu/KomodoOcean
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathbuild_releases.sh
executable file
·229 lines (188 loc) · 8.35 KB
/
build_releases.sh
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
#!/usr/bin/env bash
delete_linux_depends=false
force_rebuild_containers=false
build_xenial=false
build_focal=true
build_windows=true
build_macos=true
# we should rebuild linux depends before build for different linux os
if [[ $build_xenial == true && $build_focal == true ]]; then
delete_linux_depends=true
fi
download_and_check_macos_sdk() {
url="https://download.kmd.sh/depends-sources/Xcode-13.2.1-13C100-extracted-SDK-with-libcxx-headers.tar.gz"
output_file="Xcode-13.2.1-13C100-extracted-SDK-with-libcxx-headers.tar.gz"
expected_checksum="3d200832a74bc7401160043c92f68b11fcedba2d01353b5ab204f9e6a65653d1"
# Check if file exists
if [[ -f "$output_file" ]]; then
# Calculate checksum of the file
actual_checksum=$(sha256sum "$output_file" 2>/dev/null | awk '{print $1}')
if [[ -n $actual_checksum ]]; then
# Compare checksums
if [[ "$actual_checksum" == "$expected_checksum" ]]; then
echo "MacOS SDK already exists and has the correct checksum. Skipping download."
return
fi
fi
fi
echo "Downloading MacOS SDK ..."
# Download the file
curl -L -o "$output_file" "$url"
# Calculate checksum of the downloaded file
actual_checksum=$(sha256sum "$output_file" | awk '{print $1}')
# Compare checksums
if [[ "$actual_checksum" != "$expected_checksum" ]]; then
echo "ERROR: Downloaded MacOS SDK has an invalid checksum."
exit 1
fi
echo "MacOS SDK downloaded successfully and has a valid checksum."
}
delete_artefacts() {
local release_name=$1
if [[ "$release_name" = "windows" ]]; then
ext=".exe"
else
ext=""
fi
mkdir -p ${WORKSPACE}/releases/${release_name}
binaries=(
"src/komodod"
"src/wallet-utility"
"src/komodo-tx"
"src/komodo-cli"
"src/komodo-test"
"src/qt/komodo-qt"
)
for binary in "${binaries[@]}"
do
rm -f "${WORKSPACE}/${binary}${ext}" || false
done
echo "Deleting artefacts from ${WORKSPACE} ..."
# delete possible artefacts from previous build(s)
find ${WORKSPACE}/src \( -name "*.a" -o -name "*.la" -o -name "*.o" -o -name "*.lo" -o -name "*.Plo" -o -name "*.Po" -o -name "*.lai" -o -name "*.dirstamp" \) -delete
find ${WORKSPACE}/src \( -name "*.a" -o -name "*.la" -o -name "*.o" -o -name "*.lo" -o -name "*.Plo" -o -name "*.Po" -o -name "*.lai" -o -name "*.dirstamp" \) -path "*/.*" -delete
rm -f ${WORKSPACE}/src/qt/moc_*.cpp # delete meta object code files, otherwise we will have MacOS after Linux/Windows build error
}
copy_release() {
local release_name=$1
if [[ "$release_name" = "windows" ]]; then
ext=".exe"
else
ext=""
fi
mkdir -p ${WORKSPACE}/releases/${release_name}
binaries=(
"src/komodod"
"src/wallet-utility"
"src/komodo-tx"
"src/komodo-cli"
"src/qt/komodo-qt"
)
for binary in "${binaries[@]}"
do
case $release_name in
windows)
docker run -it -u $(id -u ${USER}):$(id -g ${USER}) -v $PWD:$PWD -w $PWD -e HOME=/root ocean_focal_builder /bin/bash -c "/usr/bin/x86_64-w64-mingw32-strip ${WORKSPACE}/${binary}${ext}" || false
;;
macos)
docker run -it -u $(id -u ${USER}):$(id -g ${USER}) -v $PWD:$PWD -w $PWD -e HOME=/root ocean_focal_builder /bin/bash -c "${WORKSPACE}/depends/x86_64-apple-darwin/native/bin/x86_64-apple-darwin-strip ${WORKSPACE}/${binary}${ext}" || false
;;
*)
strip "${WORKSPACE}/${binary}${ext}" || false
;;
esac
cp -f "${WORKSPACE}/${binary}${ext}" "${WORKSPACE}/releases/${release_name}/"
done
case $release_name in
xenial)
echo "Performing actions for Xenial..."
mv "${WORKSPACE}/releases/${release_name}/komodo-qt" "${WORKSPACE}/releases/${release_name}/komodo-qt-linux"
;;
focal)
echo "Performing actions for Focal..."
mv "${WORKSPACE}/releases/${release_name}/komodo-qt" "${WORKSPACE}/releases/${release_name}/komodo-qt-linux"
;;
windows)
echo "Performing actions for Windows..."
mv "${WORKSPACE}/releases/${release_name}/komodo-qt${ext}" "${WORKSPACE}/releases/${release_name}/komodo-qt-windows${ext}"
;;
macos)
echo "Performing actions for MacOS..."
docker run -it -u $(id -u ${USER}):$(id -g ${USER}) -v $PWD:$PWD -w $PWD -e HOME=/root ocean_focal_builder /bin/bash -c "make deploy" || false
cp -f ${WORKSPACE}/*.dmg "${WORKSPACE}/releases/${release_name}/"
mv "${WORKSPACE}/releases/${release_name}/komodo-qt${ext}" "${WORKSPACE}/releases/${release_name}/komodo-qt-mac${ext}"
;;
*)
echo "Unknown release name: $release_name"
;;
esac
}
check_image_focal() {
if [[ "${force_rebuild_containers}" == "true" || "$(docker images --format '{{.Repository}}' | grep -c ocean_focal_builder)" -eq 0 ]]; then
echo "Container 'ocean_focal_builder' rebuilding ..."
docker build --no-cache -f Dockerfile.focal.ci --build-arg BUILDER_NAME=$USER --build-arg BUILDER_UID=$(id -u) --build-arg BUILDER_GID=$(id -g) -t ocean_focal_builder .
fi
}
check_image_xenial() {
if [[ "${force_rebuild_containers}" == "true" || "$(docker images --format '{{.Repository}}' | grep -c ocean_xenial_builder)" -eq 0 ]]; then
echo "Container 'ocean_xenial_builder' rebuilding ..."
docker build --no-cache -f Dockerfile.xenial.ci --build-arg BUILDER_NAME=$USER --build-arg BUILDER_UID=$(id -u) --build-arg BUILDER_GID=$(id -g) -t ocean_xenial_builder .
fi
}
# https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
pushd ${SCRIPTPATH}
WORKSPACE=$(pwd)
echo "Workspace directory: ${WORKSPACE}"
# Check if awk command exists
command -v awk >/dev/null 2>&1 || { echo >&2 "ERROR: awk command not found."; exit 1; }
# Check if sha256sum command exists
command -v sha256sum >/dev/null 2>&1 || { echo >&2 "ERROR: sha256sum command not found."; exit 1; }
# Simple check if docker exists
command -v docker >/dev/null 2>&1 || { echo >&2 "ERROR: docker not found."; exit 1; }
### xenial
if [[ "${build_xenial}" = "true" ]]; then
# delete old depends binaries (from previous linux version, bcz it's x86_64-unknown-linux-gnu also)
if [[ "${delete_linux_depends}" = true ]]; then
rm -rf ${WORKSPACE}/depends/built/x86_64-unknown-linux-gnu
rm -rf ${WORKSPACE}/depends/x86_64-unknown-linux-gnu
rm -rf ${WORKSPACE}/depends/built/x86_64-pc-linux-gnu
rm -rf ${WORKSPACE}/depends/x86_64-pc-linux-gnu
fi
# delete possible artefacts from previous build(s)
delete_artefacts xenial
check_image_xenial
docker run -it -u $(id -u ${USER}):$(id -g ${USER}) -v $PWD:$PWD -w $PWD -e HOME=/root ocean_xenial_builder /bin/bash -c 'zcutil/build.sh -j'$(expr $(nproc) - 1)
copy_release xenial
fi
### focal
if [[ "${build_focal}" = "true" ]]; then
# delete old depends binaries (from previous linux version, bcz it's x86_64-unknown-linux-gnu also)
if [[ "${delete_linux_depends}" = true ]]; then
rm -rf ${WORKSPACE}/depends/built/x86_64-unknown-linux-gnu
rm -rf ${WORKSPACE}/depends/x86_64-unknown-linux-gnu
rm -rf ${WORKSPACE}/depends/built/x86_64-pc-linux-gnu
rm -rf ${WORKSPACE}/depends/x86_64-pc-linux-gnu
fi
# delete possible artefacts from previous build(s)
delete_artefacts focal
check_image_focal
docker run -it -u $(id -u ${USER}):$(id -g ${USER}) -v $PWD:$PWD -w $PWD -e HOME=/root ocean_focal_builder /bin/bash -c 'zcutil/build.sh -j'$(expr $(nproc) - 1)
copy_release focal
fi
### windows
if [[ "${build_windows}" = "true" ]]; then
delete_artefacts windows
check_image_focal
docker run -it -u $(id -u ${USER}):$(id -g ${USER}) -v $PWD:$PWD -w $PWD -e HOME=/root ocean_focal_builder /bin/bash -c 'zcutil/build-win.sh -j'$(expr $(nproc) - 1)
copy_release windows
fi
### macos
if [[ "${build_macos}" = "true" ]]; then
download_and_check_macos_sdk
delete_artefacts macos
check_image_focal
docker run -it -u $(id -u ${USER}):$(id -g ${USER}) -v $PWD:$PWD -w $PWD -e HOME=/root ocean_focal_builder /bin/bash -c 'zcutil/build-mac-cross.sh -j'$(expr $(nproc) - 1)
copy_release macos
fi
popd