#!/usr/bin/env bash set -e trap clean_up_after_myself EXIT ORIGINAL_CCACHE_CONF="$HOME/.ccache/ccache.conf" SAVED_CCACHE_CONF="$HOME/.run-make-check-saved-ccache-conf" function in_jenkins() { test -n "$JENKINS_HOME" } function save_ccache_conf() { test -f $ORIGINAL_CCACHE_CONF && cp $ORIGINAL_CCACHE_CONF $SAVED_CCACHE_CONF || true } function restore_ccache_conf() { test -f $SAVED_CCACHE_CONF && mv $SAVED_CCACHE_CONF $ORIGINAL_CCACHE_CONF || true } function clean_up_after_myself() { rm -fr ${CEPH_BUILD_VIRTUALENV:-/tmp}/*virtualenv* restore_ccache_conf } function get_processors() { # get_processors() depends on coreutils nproc. if test -n "$NPROC" ; then echo $NPROC else if test $(nproc) -ge 2 ; then expr $(nproc) / 2 else echo 1 fi fi } function detect_ceph_dev_pkgs() { local cmake_opts="-DWITH_FMT_VERSION=9.0.0" local boost_root=/opt/ceph if test -f $boost_root/include/boost/config.hpp; then cmake_opts+=" -DWITH_SYSTEM_BOOST=ON -DBOOST_ROOT=$boost_root" else cmake_opts+=" -DBOOST_J=$(get_processors)" fi source /etc/os-release if [[ "$ID" == "ubuntu" ]]; then case "$VERSION" in *Xenial*) cmake_opts+=" -DWITH_RADOSGW_KAFKA_ENDPOINT=OFF";; *Focal*) cmake_opts+=" -DWITH_SYSTEM_ZSTD=ON";; esac fi echo "$cmake_opts" } function do_install() { local install_cmd local pkgs local ret install_cmd=$1 shift pkgs=$@ shift ret=0 $DRY_RUN sudo $install_cmd $pkgs || ret=$? if test $ret -eq 0 ; then return fi # try harder if apt-get, and it was interrutped if [[ $install_cmd == *"apt-get"* ]]; then if test $ret -eq 100 ; then # dpkg was interrupted $DRY_RUN sudo dpkg --configure -a in_jenkins && echo "CI_DEBUG: Running 'sudo $install_cmd $pkgs'" $DRY_RUN sudo $install_cmd $pkgs else return $ret fi fi } function prepare() { local install_cmd local which_pkg="which" source /etc/os-release if test -f /etc/redhat-release ; then if ! type bc > /dev/null 2>&1 ; then echo "Please install bc and re-run." exit 1 fi if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0; then install_cmd="dnf -y install" else install_cmd="yum install -y" fi elif type zypper > /dev/null 2>&1 ; then install_cmd="zypper --gpg-auto-import-keys --non-interactive install --no-recommends" elif type apt-get > /dev/null 2>&1 ; then install_cmd="apt-get install -y" which_pkg="debianutils" fi if ! type sudo > /dev/null 2>&1 ; then echo "Please install sudo and re-run. This script assumes it is running" echo "as a normal user with the ability to run commands as root via sudo." exit 1 fi if [ -n "$install_cmd" ]; then in_jenkins && echo "CI_DEBUG: Running '$install_cmd ccache $which_pkg clang'" do_install "$install_cmd" ccache $which_pkg clang else echo "WARNING: Don't know how to install packages" >&2 echo "This probably means distribution $ID is not supported by run-make-check.sh" >&2 fi if ! type ccache > /dev/null 2>&1 ; then echo "ERROR: ccache could not be installed" exit 1 fi if test -f ./install-deps.sh ; then in_jenkins && echo "CI_DEBUG: Running install-deps.sh" $DRY_RUN source ./install-deps.sh || return 1 trap clean_up_after_myself EXIT fi cat <& 2 exit 2;; esac done prepare configure "$cmake_args" build "$@" fi