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