-
Notifications
You must be signed in to change notification settings - Fork 9
/
project
executable file
·204 lines (169 loc) · 5.14 KB
/
project
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
#!/bin/bash
PROGRAM=$(basename $0)
sub_help() {
echo "Usage: ${PROGRAM} <subcommand> [options]"
echo "Subcommands:"
echo " build - invoke cmake/make to build the code"
echo " clean - clean things up"
echo " deb - build a debian package"
echo " coverage - run the system test suite and collect coverage data"
echo " docker - build a docker image named gallocy-example"
echo " integration - run the system test suite"
echo " leakcheck - run the unit test suite under valgrind"
echo " stylecheck - run the style checker"
echo " test - run the unit test suite"
}
sub_build() {
if [ ! -f "Makefile" ]; then
echo "Running build with GENERATE_COVERAGE=${GENERATE_COVERAGE}"
cmake -G "Unix Makefiles" \
-DBUILD_CURL_EXE=OFF \
-DBUILD_CURL_TESTS=OFF \
-DCMAKE_USE_LIBSSH2=OFF \
-DCMAKE_USE_OPENLDAP=OFF \
-DCMAKE_USE_OPENSSL=OFF \
-DCURL_ZLIB=OFF \
-DHTTP_ONLY=ON \
-DGENERATE_COVERAGE="${GENERATE_COVERAGE:-OFF}" \
|| exit 1
fi
make || exit 1
make install || exit 1
sub_stylecheck || exit 1
sub_test || exit 1
}
sub_clean() {
git clean -fxd --exclude cthulhu-fixture
}
sub_test() {
if [[ "$OSTYPE" == "linux-gnu" ]]; then
LIBRARY_PATH="LD_LIBRARY_PATH"
elif [[ "$OSTYPE" == "darwin"* ]]; then
LIBRARY_PATH="DYLD_LIBRARY_PATH"
fi
INSTALL_PATH="$(pwd)/install"
export ${LIBRARY_PATH}="${INSTALL_PATH}/lib"
${INSTALL_PATH}/bin/gallocy_tests 2>/dev/null
}
sub_integration() {
BATS=./tools/bats/bin/bats
if [[ "$OSTYPE" == "linux-gnu" ]]; then
LIBRARY_PATH="LD_LIBRARY_PATH"
elif [[ "$OSTYPE" == "darwin"* ]]; then
LIBRARY_PATH="DYLD_LIBRARY_PATH"
fi
INSTALL_PATH="$(pwd)/install"
export ${LIBRARY_PATH}="${INSTALL_PATH}/lib"
${BATS} ./integration/test.sh
}
sub_coverage() {
if [ ! -f "Makefile" ]; then
cmake -G "Unix Makefiles" \
-DBUILD_CURL_EXE=OFF \
-DBUILD_CURL_TESTS=OFF \
-DCMAKE_USE_LIBSSH2=OFF \
-DCMAKE_USE_OPENLDAP=OFF \
-DCMAKE_USE_OPENSSL=OFF \
-DCURL_ZLIB=OFF \
-DHTTP_ONLY=ON \
-DGENERATE_COVERAGE=ON \
|| exit 1
fi
make clean
make || exit 1
make install || exit 1
make gallocy_coverage || exit 1
}
sub_leakcheck() {
if [[ "$OSTYPE" == "linux-gnu" ]]; then
LIBRARY_PATH="LD_LIBRARY_PATH"
elif [[ "$OSTYPE" == "darwin"* ]]; then
LIBRARY_PATH="DYLD_LIBRARY_PATH"
fi
INSTALL_PATH="$(pwd)/install"
export ${LIBRARY_PATH}="${INSTALL_PATH}/lib"
valgrind \
--leak-check=full \
--show-leak-kinds=all \
${INSTALL_PATH}/bin/gallocy_tests \
--gtest_filter="-ThreadsTest.*"
}
sub_stylecheck() {
LINT_ARGS=(
"--root=gallocy/include"
"--linelength=160"
"--filter=-legal/copyright,-runtime/references,-build/c++11"
)
echo "Using http://google.github.io/styleguide/cppguide.html as guide..."
if [ "$1" = "" ]; then
find gallocy \
-path gallocy/external -prune -o \
-type f -regex ".*\.\(cpp\|h\)$" \
-exec ./tools/cpplint.py ${LINT_ARGS[*]} {} +
else
./tools/cpplint.py ${LINT_ARGS[*]} $1
fi
}
sub_docker() {
sub_build
RUNNING_CONTAINERS=$(docker ps -q)
if [ "$RUNNING_CONTAINERS" != "" ]; then
OUT="$(docker stop -t 1 $RUNNING_CONTAINERS)"
fi
OLD_CONTAINERS="$(docker ps -a -q)"
if [ "$OLD_CONTAINERS" != "" ]; then
OUT="$(docker rm $OLD_CONTAINERS)"
fi
OLD_IMAGES="$(docker images -q)"
if [ "$OLD_IMAGES" != "" ]; then
OUT="$(docker rmi $OLD_IMAGES)"
fi
docker build -t gallocy-example -f tools/Dockerfile .
}
sub_deb() {
sub_build
IFS='.' read -ra VERSION <<< "$(cat VERSION)"
DEB_VERSION="${VERSION[0]}.${VERSION[1]}-${VERSION[2]}"
DEB_ROOT="gallocy_$DEB_VERSION"
mkdir "$DEB_ROOT"
mkdir -p "$DEB_ROOT/opt/gallocy/bin"
mkdir -p "$DEB_ROOT/opt/gallocy/lib"
mkdir -p "$DEB_ROOT/etc/gallocy"
mkdir -p "$DEB_ROOT/etc/init.d"
cp -r ./install/* "$DEB_ROOT/opt/gallocy"
cp ./sample-config.json "$DEB_ROOT/etc/gallocy/config.json"
cp ./tools/gallocy.init "$DEB_ROOT/etc/init.d/gallocy"
chmod 755 "$DEB_ROOT/etc/init.d/gallocy"
# Create the debian directory
mkdir -p "$DEB_ROOT/DEBIAN"
# Create the control file
echo "Package: gallocy" >> "$DEB_ROOT/DEBIAN/control"
echo "Version: $DEB_VERSION" >> "$DEB_ROOT/DEBIAN/control"
echo "Section: base" >> "$DEB_ROOT/DEBIAN/control"
echo "Priority: optional" >> "$DEB_ROOT/DEBIAN/control"
echo "Architecture: amd64" >> "$DEB_ROOT/DEBIAN/control"
echo "Depends: " >> "$DEB_ROOT/DEBIAN/control"
echo "Maintainer: Stephen Holsapple <sholsapp@gmail.com>" >> "$DEB_ROOT/DEBIAN/control"
echo "Description: The gallocy server." >> "$DEB_ROOT/DEBIAN/control"
echo "update-rc.d -f gallocy defaults" >> "$DEB_ROOT/DEBIAN/postinst"
# Create the post install script
chmod 755 "$DEB_ROOT/DEBIAN/postinst"
dpkg-deb --build "$DEB_ROOT"
dpkg -c "$DEB_ROOT.deb"
mkdir build
mv "$DEB_ROOT.deb" build
}
SUBCOMMAND=$1
case $SUBCOMMAND in
"" | "-h" | "--help")
sub_help
;;
*)
shift
sub_${SUBCOMMAND} $@
if [ $? = 127 ]; then
echo "Error: '$SUBCOMMAND' is not a known subcommand." >&2
exit 1
fi
;;
esac