forked from Altinity/clickhouse-odbc-rpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·377 lines (294 loc) · 8.45 KB
/
build.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
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
372
373
374
375
376
#!/bin/bash
#
# Yandex ClickHouse DBMS ODBC driver build script for RHEL based distributions
#
# Tested on:
# - CentOS 7: 7.5
#
# Copyright (C) 2018 Altinity Ltd
# Git version that we package
CH_VERSION_GIT="${CH_VERSION_GIT:-1.0.0.20190611}"
# Base name of the RPM package
CH_RPM_PACKAGE_NAME="clickhouse-odbc"
# RPM-package name-friendly version of the version
CH_RPM_PACKAGE_VERSION=$(echo $CH_VERSION_GIT | sed -r 's/-+//g')
# User-field
CH_NAME_FULL="clickhouse-odbc-$CH_VERSION_GIT"
# Git https://github.com - relative URI to clone sources from
CH_GIT_URI="yandex/clickhouse-odbc"
# Full path on github to clone sources from
CH_GIT_PATH="https://github.com/$CH_GIT_URI"
# Current work dir
CWD_DIR=$(pwd)
# Source files dir
SRC_DIR="$CWD_DIR/src"
# Where RPMs would be built
RPMBUILD_DIR="$CWD_DIR/rpmbuild"
# Where build process will be run
BUILD_DIR="$RPMBUILD_DIR/BUILD"
# Where build RPM files would be kept
RPMS_DIR="$RPMBUILD_DIR/RPMS/x86_64"
# Where source files would be kept
SOURCES_DIR="$RPMBUILD_DIR/SOURCES"
# Where RPM spec file would be kept
SPECS_DIR="$RPMBUILD_DIR/SPECS"
# Where built SRPM files would be kept
SRPMS_DIR="$RPMBUILD_DIR/SRPMS"
# Where temp files would be kept
TMP_DIR="$RPMBUILD_DIR/TMP"
# Source libraries
. ./src/os.lib.sh
. ./src/publish_packagecloud.lib.sh
. ./src/publish_ssh.lib.sh
. ./src/util.lib.sh
##
##
##
function install_general_dependencies()
{
banner "Install general dependencies"
sudo yum install -y git wget curl zip unzip sed
}
##
##
##
function install_rpm_dependencies()
{
banner "RPM build dependencies"
sudo yum install -y rpm-build redhat-rpm-config createrepo
}
##
##
##
function install_build_process_dependencies()
{
banner "Install build tools"
sudo yum install -y m4 make
sudo yum install -y epel-release
sudo yum install -y cmake3
sudo yum install -y centos-release-scl
sudo yum install -y devtoolset-7
banner "Install CH dev dependencies"
sudo yum install -y unixODBC libtool-ltdl
sudo yum install -y unixODBC-devel libtool-ltdl-devel
}
##
##
##
function install_workarounds()
{
banner "Install workarounds"
# Now all workarounds are included into CMAKE_OPTIONS and MAKE_OPTIONS
}
##
## Install all required components before building RPMs
##
function install_dependencies()
{
banner "Install dependencies"
install_general_dependencies
install_rpm_dependencies
install_build_process_dependencies
install_workarounds
}
##
## Prepare $RPMBUILD_DIR/SOURCES/ClickHouse-$CH_VERSION-$CH_TAG.zip file
##
function prepare_sources()
{
banner "Ensure SOURCES dir is in place"
mkdirs
echo "Clean sources dir"
rm -rf "$SOURCES_DIR/$CH_NAME_FULL"
cd $SOURCES_DIR
echo "Cloning from $CH_GIT_PATH into $SOURCES_DIR/$CH_NAME_FULL"
# Go older way because older versions of git (CentOS 6.9, for example) do not understand new syntax of branches etc
git clone "$CH_GIT_PATH" "$CH_NAME_FULL"
cd "$CH_NAME_FULL"
echo "Checkout specific tag $CH_VERSION_GIT"
git checkout "$CH_VERSION_GIT"
echo "Update submodules"
git submodule update --init --recursive
cd "$SOURCES_DIR"
echo "Move files into .tar.gz"
tar -zcf "${CH_NAME_FULL}.tar.gz" "$CH_NAME_FULL"
echo "Ensure .tar.gz file is available"
ls -l "${CH_NAME_FULL}.tar.gz"
cd "$CWD_DIR"
}
##
##
##
function build_spec_file()
{
banner "Ensure SPECS dir is in place"
mkdirs
banner "Build .spec file"
CMAKE_OPTIONS="${CMAKE_OPTIONS}"
MAKE_OPTIONS="${MAKE_OPTIONS}"
# Create spec file from template
cat "$SRC_DIR/clickhouse.spec.in" | sed \
-e "s|@CH_VERSION_GIT@|$CH_VERSION_GIT|" \
-e "s|@CH_RPM_PACKAGE_NAME@|$CH_RPM_PACKAGE_NAME|" \
-e "s|@CH_RPM_PACKAGE_VERSION@|$CH_RPM_PACKAGE_VERSION|" \
-e "s|@CH_NAME_FULL@|$CH_NAME_FULL|" \
-e "s|@RPMBUILD_DIR@|$RPMBUILD_DIR|" \
-e "s|@TMP_DIR@|$TMP_DIR|" \
-e "s|@CMAKE_OPTIONS@|$CMAKE_OPTIONS|" \
-e "s|@MAKE_OPTIONS@|$MAKE_OPTIONS|" \
> "$SPECS_DIR/clickhouse.spec"
banner "Looking for .spec file"
ls -l "$SPECS_DIR/clickhouse.spec"
}
##
## Build RPMs
##
function build_RPMs()
{
banner "Ensure build dirs are in place"
mkdirs
banner "Setup path to compilers"
export CMAKE=cmake3
export CC=/opt/rh/devtoolset-7/root/usr/bin/gcc
export CXX=/opt/rh/devtoolset-7/root/usr/bin/g++
#export CXXFLAGS="${CXXFLAGS} -Wno-maybe-uninitialized"
echo "CMAKE=$CMAKE"
echo "CC=$CC"
echo "CXX=$CXX"
echo "cd into $CWD_DIR"
cd "$CWD_DIR"
banner "Build RPMs"
rpmbuild -v -bs "$SPECS_DIR/clickhouse.spec"
rpmbuild -v -bb "$SPECS_DIR/clickhouse.spec"
banner "Build RPMs completed"
# Display results
list_RPMs
list_SRPMs
}
##
## Build packages:
## 1. clean folders
## 2. prepare sources
## 3. build spec file
## 4. build RPMs
##
function build_packages()
{
banner "Ensure build dirs are in place"
mkdirs
echo "Clean up after previous run"
rm -f "$RPMS_DIR"/clickhouse*
rm -f "$SRPMS_DIR"/clickhouse*
rm -f "$SPECS_DIR"/clickhouse.spec
banner "Create RPM packages"
# Prepare $SOURCES_DIR/ClickHouse-$CH_VERSION-$CH_TAG.zip file
prepare_sources
# Build $SPECS_DIR/clickhouse.spec file
build_spec_file
# Compile sources and build RPMS
build_RPMs
}
##
##
##
function usage()
{
# disable commands print
set +x
echo "Usage:"
echo
echo "./build.sh version - display default version to build"
echo
echo "./build.sh all - most popular point of entry - the same as idep_all"
echo
echo "./build.sh idep_all - install dependencies from RPMs, download CH sources and build RPMs"
echo "./build.sh bdep_all - build dependencies from sources, download CH sources and build RPMs"
echo " !!! YOU MAY NEED TO UNDERSTAND INTERNALS !!!"
echo
echo "./build.sh install_deps - just install dependencies (do not download sources, do not build RPMs)"
echo "./build.sh build_deps - just build dependencies (do not download sources, do not build RPMs)"
echo "./build.sh src - just prepare sources (download with submodules and pack)"
echo "./build.sh spec - just create SPEC file (do not download sources, do not build RPMs)"
echo "./build.sh packages - download sources, create SPEC file and build RPMs (do not install dependencies)"
echo "./build.sh rpms - just build RPMs from sources in archive (tar.gz)"
echo " (do not download sources, do not create SPEC file, do not install dependencies)"
echo "MYSRC=yes ./build.sh rpms - just build RPMs from unpacked sources - most likely you have modified them"
echo " (do not download sources, do not create SPEC file, do not install dependencies)"
echo
echo "./build.sh publish packagecloud <packagecloud USER ID> - publish packages on packagecloud as USER"
echo "./build.sh delete packagecloud <packagecloud USER ID> - delete packages on packagecloud as USER"
echo
echo "./build.sh publish ssh - publish packages via SSH"
exit 0
}
if [ -z "$1" ]; then
usage
fi
COMMAND="$1"
if [ "$COMMAND" == "version" ]; then
echo "$CH_VERSION_GIT"
elif [ "$COMMAND" == "all" ]; then
ensure_os_rpm_based
set_print_commands
install_dependencies
build_packages
elif [ "$COMMAND" == "idep_all" ]; then
ensure_os_rpm_based
set_print_commands
install_dependencies
build_packages
elif [ "$COMMAND" == "bdep_all" ]; then
ensure_os_rpm_based
set_print_commands
build_dependencies
build_packages
elif [ "$COMMAND" == "install_deps" ]; then
ensure_os_rpm_based
set_print_commands
install_dependencies
elif [ "$COMMAND" == "build_deps" ]; then
ensure_os_rpm_based
set_print_commands
build_dependencies
elif [ "$COMMAND" == "src" ]; then
set_print_commands
prepare_sources
elif [ "$COMMAND" == "spec" ]; then
set_print_commands
build_spec_file
elif [ "$COMMAND" == "packages" ]; then
ensure_os_rpm_based
set_print_commands
build_packages
elif [ "$COMMAND" == "rpms" ]; then
ensure_os_rpm_based
set_print_commands
build_RPMs
elif [ "$COMMAND" == "publish" ]; then
PUBLISH_TARGET="$2"
ensure_os_rpm_based
if [ "$PUBLISH_TARGET" == "packagecloud" ]; then
# run publish script with all the rest of CLI params
publish_packagecloud ${*:3}
elif [ "$PUBLISH_TARGET" == "ssh" ]; then
publish_ssh
else
echo "Unknown publish target"
usage
fi
elif [ "$COMMAND" == "delete" ]; then
PUBLISH_TARGET="$2"
if [ "$PUBLISH_TARGET" == "packagecloud" ]; then
# run publish script with all the rest of CLI params
publish_packagecloud_delete ${*:3}
elif [ "$PUBLISH_TARGET" == "ssh" ]; then
echo "Not supported yet"
else
echo "Unknown publish target"
usage
fi
else
# unknown command
echo "Unknown command: $COMMAND"
usage
fi