forked from inotify-tools/inotify-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_and_test.sh
executable file
·237 lines (202 loc) · 5.25 KB
/
build_and_test.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/sh
set -ex
j=16
unit_test() {
if [ "$os" != "freebsd" ]; then
printf "\nunit test\n"
cd libinotifytools/src/
make -j$j test
./test
cd -
fi
}
integration_test() {
printf "\nintegration test\n"
cd t
make -j$j
cd -
}
tests() {
unit_test
integration_test
}
clean() {
make distclean || true
if [ "$arg1" = "clean" ]; then
git clean -fdx > /dev/null 2>&1
git reset --hard
fi
}
build() {
./autogen.sh
./configure --prefix=/usr $@
make -j$j
unset CFLAGS
unset CXXFLAGS
unset LDFLAGS
}
set_gcc() {
export CC=gcc
export CXX=g++
}
set_clang() {
export CC=clang
export CXX=clang++
}
set_flags() {
export CFLAGS="$1"
export CXXFLAGS="$1"
export LDFLAGS="$1"
}
rm_args() {
if [ "$os" = "freebsd" ]; then
sed -i '' -e "s/$1//g" ./libinotifytools/src/Makefile.am ./src/Makefile.am
else
sed -i "s/$1//g" ./libinotifytools/src/Makefile.am ./src/Makefile.am
fi
}
arg1="$1"
os=$(uname -o | sed "s#GNU/##g" | tr '[:upper:]' '[:lower:]')
uname_m=$(uname -m)
if command -v sudo; then
pre="sudo"
fi
if command -v apt; then
$pre apt update || true
$pre apt install -y gcc-arm-linux-gnueabihf || true
$pre apt install -y g++-arm-linux-gnueabihf || true
$pre apt install -y clang || true
$pre apt install -y gcc || true
$pre apt install -y g++ || true
$pre apt install -y clang-tidy || true
$pre apt install -y clang-format || true
$pre apt install -y clang-tools || true
$pre apt install -y clang-format-11 || true
$pre apt install -y doxygen || true
$pre apt install -y make || true
$pre apt install -y autoconf || true
$pre apt install -y libtool || true
$pre apt install -y curl || true
$pre apt install -y git || true
$pre apt install -y zip || true
elif command -v apk; then
apk add build-base alpine-sdk autoconf automake libtool bash coreutils clang \
clang-extra-tools lld linux-headers curl git zip gcompat
elif command -v dnf; then
$pre dnf install -y --allowerasing gcc-c++ autoconf automake doxygen make libtool clang curl git unzip
fi
#!/bin/bash
set -e
for i in {64..11}; do
if command -v "git-clang-format-$i" > /dev/null; then
CLANG_FMT_VER="clang-format-$i"
break
fi
done
if [ -n "$CLANG_FMT_VER" ]; then
printf "\nclang-format build\n"
if ! git $CLANG_FMT_VER HEAD^ | grep -q "modif"; then
echo -e "\nPlease change style to the format defined in the" \
".clang-format file:\n"
git diff --name-only
exit 1
fi
fi
printf "gcc build\n"
clean
set_gcc
build
tests
usr_inc="/usr/include"
inotifytools_inc="libinotifytools/src"
inotifytools_inc2="$inotifytools_inc/inotifytools"
inc="-I$usr_inc -I$inotifytools_inc -I$inotifytools_inc2"
if command -v doxygen > /dev/null; then
printf "rh build\n"
clean
set_gcc
./rh_build.sh
fi
printf "gcc static build\n"
clean
set_gcc
build --enable-static --disable-shared
tests
VER=$(gcc --version | awk '{print $3"\n"}' | head -n1)
VER=$(echo "$VER" | awk -F. '{print $1"\n"}')
if [ "$VER" -ge "11" ]; then
clean
set_gcc
set_flags "-fanalyzer"
rm_args " -Werror"
build
tests
fi
if [ "$os" != "freebsd" ] && ldconfig -p | grep -q libasan; then
printf "\ngcc address sanitizer build\n"
clean
set_gcc
set_flags "-fsanitize=address -O0 -ggdb"
rm_args " -nodefaultlibs -lc"
build
tests
fi
if command -v arm-linux-gnueabihf-gcc > /dev/null; then
printf "\ngcc arm32 build\n"
clean
export CC="arm-linux-gnueabihf-gcc"
export CXX="arm-linux-gnueabihf-g++"
build --host=arm-linux-gnueabihf
if [ "$uname_m" == "aarch64" ]; then
tests
fi
fi
printf "\nclang build\n"
clean
set_clang
build
tests
printf "\nclang static build\n"
clean
set_clang
build --enable-static --disable-shared
tests
printf "\ngcc coverage build\n"
clean
set_gcc
set_flags "--coverage"
rm_args " -nodefaultlibs -lc"
build --enable-static --disable-shared
tests
curl -s https://codecov.io/bash | /bin/bash
if [ "$os" != "freebsd" ] && [ "$(uname -m)" = "x86_64" ]; then
id=$(grep ^ID= /etc/os-release | sed "s/^ID=//g")
# Don't do sonarcloud on alpine
if [ "$id" = "alpine" ]; then
exit 0
fi
printf "\nsonar build\n"
# sonarcloud
export SONAR_TOKEN="0bc5d48614caa711d6b908f80c039464aff99611"
mkdir -p $HOME/.sonar
SONAR_SCANNER_VERSION="4.4.0.2170"
SONAR_SCANNER_DOWNLOAD_URL="https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip"
curl -sSLo $HOME/.sonar/sonar-scanner.zip $SONAR_SCANNER_DOWNLOAD_URL
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
PATH="$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux/bin:$PATH"
SONAR_SERVER_URL="https://sonarcloud.io"
BUILD_WRAPPER_DOWNLOAD_URL="$SONAR_SERVER_URL/static/cpp/build-wrapper-linux-x86.zip"
curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip $BUILD_WRAPPER_DOWNLOAD_URL
unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
PATH="$HOME/.sonar/build-wrapper-linux-x86:$PATH"
BUILD_WRAPPER_OUT_DIR="build_wrapper_output_directory"
clean
set_gcc
unset CFLAGS
unset CXXFLAGS
unset LDFLAGS
./autogen.sh
./configure
build-wrapper-linux-x86-64 --out-dir $BUILD_WRAPPER_OUT_DIR make -j$j
sonar-scanner --define sonar.host.url="$SONAR_SERVER_URL" --define sonar.cfamily.build-wrapper-output="$BUILD_WRAPPER_OUT_DIR"
fi