-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun-make-check.sh
executable file
·137 lines (125 loc) · 4.5 KB
/
run-make-check.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
#!/usr/bin/env bash
#
# Ceph distributed storage system
#
# Copyright (C) 2014 Red Hat <[email protected]>
#
# Author: Loic Dachary <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
#
# Return MAX(1, (number of processors / 2)) by default or NPROC
#
function get_processors() {
if test -n "$NPROC" ; then
echo $NPROC
else
if test $(nproc) -ge 2 ; then
expr $(nproc) / 2
else
echo 1
fi
fi
}
function run() {
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
$DRY_RUN sudo $install_cmd ccache jq $which_pkg
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 test -f ./install-deps.sh ; then
$DRY_RUN source ./install-deps.sh || return 1
fi
# Init defaults after deps are installed. get_processors() depends on coreutils nproc.
DEFAULT_MAKEOPTS=${DEFAULT_MAKEOPTS:--j$(get_processors)}
BUILD_MAKEOPTS=${BUILD_MAKEOPTS:-$DEFAULT_MAKEOPTS}
CHECK_MAKEOPTS=${CHECK_MAKEOPTS:-$DEFAULT_MAKEOPTS}
CMAKE_PYTHON_OPTS=
if ! type python2 > /dev/null 2>&1 ; then
CMAKE_PYTHON_OPTS="-DWITH_PYTHON2=OFF -DWITH_PYTHON3=ON -DMGR_PYTHON_VERSION=3"
fi
CMAKE_BUILD_OPTS="-DWITH_FIO=ON -DWITH_GTEST_PARALLEL=ON"
# Are we in the CI ?
if [ -n "$JENKINS_HOME" ]; then
echo "Jenkins got detected, let's tune the build"
# The following settings are made for improving ccache efficiency
# by removing the entropy generated by the date/time embedded in the build
CMAKE_BUILD_OPTS="$CMAKE_BUILD_OPTS -D ENABLE_GIT_VERSION=OFF"
export SOURCE_DATE_EPOCH=$(date +%D |date -f- +%s)
ccache -o sloppiness=time_macros
ccache -o run_second_cpp=true
# Build host has plenty of space available, let's use it to keep
# various versions of the built objects. This could increase the cache hit
# if the same or similar PRs are running several times
ccache -o max_size=100G
ccache -z # Reset the ccache statistics
fi
$DRY_RUN ./do_cmake.sh $CMAKE_BUILD_OPTS $CMAKE_PYTHON_OPTS $@ || return 1
$DRY_RUN cd build
$DRY_RUN make $BUILD_MAKEOPTS tests || return 1
if [ -n "$JENKINS_HOME" ]; then
ccache -s # print the ccache statistics to evaluate the efficiency
fi
# prevent OSD EMFILE death on tests, make sure large than 1024
$DRY_RUN ulimit -n $(ulimit -Hn)
if [ $(ulimit -n) -lt 1024 ];then
echo "***ulimit -n too small, better bigger than 1024 for test***"
return 1
fi
if ! $DRY_RUN ctest $CHECK_MAKEOPTS --output-on-failure; then
rm -fr ${TMPDIR:-/tmp}/ceph-asok.*
return 1
fi
}
function main() {
if [[ $EUID -eq 0 ]] ; then
echo "For best results, run this script as a normal user configured"
echo "with the ability to run commands as root via sudo."
fi
echo -n "Checking hostname sanity... "
if hostname --fqdn >/dev/null 2>&1 ; then
echo "OK"
else
echo "NOT OK"
echo "Please fix 'hostname --fqdn', otherwise 'make check' will fail"
return 1
fi
if run "$@" ; then
rm -fr ${CEPH_BUILD_VIRTUALENV:-/tmp}/*virtualenv*
echo "cmake check: successful run on $(git rev-parse HEAD)"
return 0
else
rm -fr ${CEPH_BUILD_VIRTUALENV:-/tmp}/*virtualenv*
return 1
fi
}
main "$@"