]> git.proxmox.com Git - ceph.git/blame - ceph/src/script/run-make.sh
buildsys: switch source download to quincy
[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
46 if [[ "$ID" == "ubuntu" ]] && [[ "$VERSION" =~ .*Xenial*. ]]; then
47 cmake_opts+=" -DWITH_RADOSGW_KAFKA_ENDPOINT=NO"
48 fi
49 echo "$cmake_opts"
50}
51
52function prepare() {
53 local install_cmd
54 local which_pkg="which"
55 source /etc/os-release
56 if test -f /etc/redhat-release ; then
57 if ! type bc > /dev/null 2>&1 ; then
58 echo "Please install bc and re-run."
59 exit 1
60 fi
61 if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0; then
62 install_cmd="dnf -y install"
63 else
64 install_cmd="yum install -y"
65 fi
66 elif type zypper > /dev/null 2>&1 ; then
67 install_cmd="zypper --gpg-auto-import-keys --non-interactive install --no-recommends"
68 elif type apt-get > /dev/null 2>&1 ; then
69 install_cmd="apt-get install -y"
70 which_pkg="debianutils"
71 fi
72
73 if ! type sudo > /dev/null 2>&1 ; then
74 echo "Please install sudo and re-run. This script assumes it is running"
75 echo "as a normal user with the ability to run commands as root via sudo."
76 exit 1
77 fi
78 if [ -n "$install_cmd" ]; then
79 $DRY_RUN sudo $install_cmd ccache $which_pkg
80 else
81 echo "WARNING: Don't know how to install packages" >&2
82 echo "This probably means distribution $ID is not supported by run-make-check.sh" >&2
83 fi
84
85 if ! type ccache > /dev/null 2>&1 ; then
86 echo "ERROR: ccache could not be installed"
87 exit 1
88 fi
89
90 if test -f ./install-deps.sh ; then
91 $DRY_RUN source ./install-deps.sh || return 1
92 trap clean_up_after_myself EXIT
93 fi
94
95 cat <<EOM
96Note that the binaries produced by this script do not contain correct time
97and git version information, which may make them unsuitable for debugging
98and production use.
99EOM
100 save_ccache_conf
101 # remove the entropy generated by the date/time embedded in the build
102 $DRY_RUN export SOURCE_DATE_EPOCH="946684800"
103 $DRY_RUN ccache -o sloppiness=time_macros
104 $DRY_RUN ccache -o run_second_cpp=true
105 if [ -n "$JENKINS_HOME" ]; then
106 # Build host has plenty of space available, let's use it to keep
107 # various versions of the built objects. This could increase the cache hit
108 # if the same or similar PRs are running several times
109 $DRY_RUN ccache -o max_size=100G
110 else
111 echo "Current ccache max_size setting:"
112 ccache -p | grep max_size
113 fi
114 $DRY_RUN ccache -sz # Reset the ccache statistics and show the current configuration
115}
116
117function configure() {
118 local cmake_build_opts=$(detect_ceph_dev_pkgs)
119 $DRY_RUN ./do_cmake.sh $cmake_build_opts $@ || return 1
120}
121
122function build() {
123 local targets="$@"
124 $DRY_RUN cd build
125 BUILD_MAKEOPTS=${BUILD_MAKEOPTS:-$DEFAULT_MAKEOPTS}
126 test "$BUILD_MAKEOPTS" && echo "make will run with option(s) $BUILD_MAKEOPTS"
127 $DRY_RUN make $BUILD_MAKEOPTS $targets || return 1
128 $DRY_RUN ccache -s # print the ccache statistics to evaluate the efficiency
129}
130
131DEFAULT_MAKEOPTS=${DEFAULT_MAKEOPTS:--j$(get_processors)}
132
133if [ "$0" = "$BASH_SOURCE" ]; then
134 # not sourced
135 if [ `uname` = FreeBSD ]; then
136 GETOPT=/usr/local/bin/getopt
137 else
138 GETOPT=getopt
139 fi
140
141 options=$(${GETOPT} --name "$0" --options "" --longoptions "cmake-args:" -- "$@")
142 if [ $? -ne 0 ]; then
143 exit 2
144 fi
145 eval set -- "${options}"
146 while true; do
147 case "$1" in
148 --cmake-args)
149 cmake_args=$2
150 shift 2;;
151 --)
152 shift
153 break;;
154 *)
155 echo "bad option $1" >& 2
156 exit 2;;
157 esac
158 done
159 prepare
160 configure "$cmake_args"
161 build "$@"
162fi