]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | #!/usr/bin/env bash |
2 | ||
3 | set -e | |
4 | ||
5 | trap clean_up_after_myself EXIT | |
6 | ||
7 | ORIGINAL_CCACHE_CONF="$HOME/.ccache/ccache.conf" | |
8 | SAVED_CCACHE_CONF="$HOME/.run-make-check-saved-ccache-conf" | |
9 | ||
1e59de90 TL |
10 | function in_jenkins() { |
11 | test -n "$JENKINS_HOME" | |
12 | } | |
13 | ||
9f95a23c TL |
14 | function save_ccache_conf() { |
15 | test -f $ORIGINAL_CCACHE_CONF && cp $ORIGINAL_CCACHE_CONF $SAVED_CCACHE_CONF || true | |
16 | } | |
17 | ||
18 | function restore_ccache_conf() { | |
19 | test -f $SAVED_CCACHE_CONF && mv $SAVED_CCACHE_CONF $ORIGINAL_CCACHE_CONF || true | |
20 | } | |
21 | ||
22 | function clean_up_after_myself() { | |
23 | rm -fr ${CEPH_BUILD_VIRTUALENV:-/tmp}/*virtualenv* | |
24 | restore_ccache_conf | |
25 | } | |
26 | ||
27 | function get_processors() { | |
28 | # get_processors() depends on coreutils nproc. | |
29 | if test -n "$NPROC" ; then | |
30 | echo $NPROC | |
31 | else | |
32 | if test $(nproc) -ge 2 ; then | |
33 | expr $(nproc) / 2 | |
34 | else | |
35 | echo 1 | |
36 | fi | |
37 | fi | |
38 | } | |
39 | ||
40 | function detect_ceph_dev_pkgs() { | |
1e59de90 | 41 | local cmake_opts="-DWITH_FMT_VERSION=9.0.0" |
9f95a23c TL |
42 | local boost_root=/opt/ceph |
43 | if test -f $boost_root/include/boost/config.hpp; then | |
44 | cmake_opts+=" -DWITH_SYSTEM_BOOST=ON -DBOOST_ROOT=$boost_root" | |
45 | else | |
46 | cmake_opts+=" -DBOOST_J=$(get_processors)" | |
47 | fi | |
48 | ||
49 | source /etc/os-release | |
20effc67 TL |
50 | if [[ "$ID" == "ubuntu" ]]; then |
51 | case "$VERSION" in | |
52 | *Xenial*) | |
53 | cmake_opts+=" -DWITH_RADOSGW_KAFKA_ENDPOINT=OFF";; | |
54 | *Focal*) | |
55 | cmake_opts+=" -DWITH_SYSTEM_ZSTD=ON";; | |
56 | esac | |
9f95a23c TL |
57 | fi |
58 | echo "$cmake_opts" | |
59 | } | |
60 | ||
20effc67 TL |
61 | function do_install() { |
62 | local install_cmd | |
63 | local pkgs | |
64 | local ret | |
65 | install_cmd=$1 | |
66 | shift | |
67 | pkgs=$@ | |
68 | shift | |
69 | ret=0 | |
70 | $DRY_RUN sudo $install_cmd $pkgs || ret=$? | |
71 | if test $ret -eq 0 ; then | |
72 | return | |
73 | fi | |
74 | # try harder if apt-get, and it was interrutped | |
75 | if [[ $install_cmd == *"apt-get"* ]]; then | |
76 | if test $ret -eq 100 ; then | |
77 | # dpkg was interrupted | |
78 | $DRY_RUN sudo dpkg --configure -a | |
1e59de90 | 79 | in_jenkins && echo "CI_DEBUG: Running 'sudo $install_cmd $pkgs'" |
20effc67 TL |
80 | $DRY_RUN sudo $install_cmd $pkgs |
81 | else | |
82 | return $ret | |
83 | fi | |
84 | fi | |
85 | } | |
9f95a23c TL |
86 | function prepare() { |
87 | local install_cmd | |
88 | local which_pkg="which" | |
89 | source /etc/os-release | |
90 | if test -f /etc/redhat-release ; then | |
91 | if ! type bc > /dev/null 2>&1 ; then | |
92 | echo "Please install bc and re-run." | |
93 | exit 1 | |
94 | fi | |
95 | if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0; then | |
96 | install_cmd="dnf -y install" | |
97 | else | |
98 | install_cmd="yum install -y" | |
99 | fi | |
100 | elif type zypper > /dev/null 2>&1 ; then | |
101 | install_cmd="zypper --gpg-auto-import-keys --non-interactive install --no-recommends" | |
102 | elif type apt-get > /dev/null 2>&1 ; then | |
103 | install_cmd="apt-get install -y" | |
104 | which_pkg="debianutils" | |
105 | fi | |
106 | ||
107 | if ! type sudo > /dev/null 2>&1 ; then | |
108 | echo "Please install sudo and re-run. This script assumes it is running" | |
109 | echo "as a normal user with the ability to run commands as root via sudo." | |
110 | exit 1 | |
111 | fi | |
112 | if [ -n "$install_cmd" ]; then | |
1e59de90 | 113 | in_jenkins && echo "CI_DEBUG: Running '$install_cmd ccache $which_pkg clang'" |
20effc67 | 114 | do_install "$install_cmd" ccache $which_pkg clang |
9f95a23c TL |
115 | else |
116 | echo "WARNING: Don't know how to install packages" >&2 | |
117 | echo "This probably means distribution $ID is not supported by run-make-check.sh" >&2 | |
118 | fi | |
119 | ||
120 | if ! type ccache > /dev/null 2>&1 ; then | |
121 | echo "ERROR: ccache could not be installed" | |
122 | exit 1 | |
123 | fi | |
124 | ||
125 | if test -f ./install-deps.sh ; then | |
1e59de90 TL |
126 | in_jenkins && echo "CI_DEBUG: Running install-deps.sh" |
127 | $DRY_RUN source ./install-deps.sh || return 1 | |
9f95a23c TL |
128 | trap clean_up_after_myself EXIT |
129 | fi | |
130 | ||
131 | cat <<EOM | |
132 | Note that the binaries produced by this script do not contain correct time | |
133 | and git version information, which may make them unsuitable for debugging | |
134 | and production use. | |
135 | EOM | |
136 | save_ccache_conf | |
137 | # remove the entropy generated by the date/time embedded in the build | |
138 | $DRY_RUN export SOURCE_DATE_EPOCH="946684800" | |
139 | $DRY_RUN ccache -o sloppiness=time_macros | |
140 | $DRY_RUN ccache -o run_second_cpp=true | |
1e59de90 | 141 | if in_jenkins; then |
9f95a23c TL |
142 | # Build host has plenty of space available, let's use it to keep |
143 | # various versions of the built objects. This could increase the cache hit | |
144 | # if the same or similar PRs are running several times | |
145 | $DRY_RUN ccache -o max_size=100G | |
146 | else | |
147 | echo "Current ccache max_size setting:" | |
148 | ccache -p | grep max_size | |
149 | fi | |
150 | $DRY_RUN ccache -sz # Reset the ccache statistics and show the current configuration | |
151 | } | |
152 | ||
153 | function configure() { | |
154 | local cmake_build_opts=$(detect_ceph_dev_pkgs) | |
1e59de90 | 155 | in_jenkins && echo "CI_DEBUG: Running do_cmake.sh" |
9f95a23c TL |
156 | $DRY_RUN ./do_cmake.sh $cmake_build_opts $@ || return 1 |
157 | } | |
158 | ||
159 | function build() { | |
160 | local targets="$@" | |
20effc67 TL |
161 | if test -n "$targets"; then |
162 | targets="--target $targets" | |
163 | fi | |
9f95a23c TL |
164 | $DRY_RUN cd build |
165 | BUILD_MAKEOPTS=${BUILD_MAKEOPTS:-$DEFAULT_MAKEOPTS} | |
166 | test "$BUILD_MAKEOPTS" && echo "make will run with option(s) $BUILD_MAKEOPTS" | |
20effc67 | 167 | # older cmake does not support --parallel or -j, so pass it to underlying generator |
1e59de90 | 168 | in_jenkins && echo "CI_DEBUG: Running cmake" |
20effc67 | 169 | $DRY_RUN cmake --build . $targets -- $BUILD_MAKEOPTS || return 1 |
9f95a23c TL |
170 | $DRY_RUN ccache -s # print the ccache statistics to evaluate the efficiency |
171 | } | |
172 | ||
173 | DEFAULT_MAKEOPTS=${DEFAULT_MAKEOPTS:--j$(get_processors)} | |
174 | ||
175 | if [ "$0" = "$BASH_SOURCE" ]; then | |
176 | # not sourced | |
177 | if [ `uname` = FreeBSD ]; then | |
178 | GETOPT=/usr/local/bin/getopt | |
179 | else | |
180 | GETOPT=getopt | |
181 | fi | |
182 | ||
183 | options=$(${GETOPT} --name "$0" --options "" --longoptions "cmake-args:" -- "$@") | |
184 | if [ $? -ne 0 ]; then | |
185 | exit 2 | |
186 | fi | |
187 | eval set -- "${options}" | |
188 | while true; do | |
189 | case "$1" in | |
190 | --cmake-args) | |
191 | cmake_args=$2 | |
192 | shift 2;; | |
193 | --) | |
194 | shift | |
195 | break;; | |
196 | *) | |
197 | echo "bad option $1" >& 2 | |
198 | exit 2;; | |
199 | esac | |
200 | done | |
201 | prepare | |
202 | configure "$cmake_args" | |
203 | build "$@" | |
204 | fi |