-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·290 lines (258 loc) · 7.42 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·290 lines (258 loc) · 7.42 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/usr/bin/env bash
##
## Copyright (c) 2025-2026 The Johns Hopkins University Applied Physics
## Laboratory LLC.
##
## This file is part of the Bundle Protocol Security Library (BSL).
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
## http://www.apache.org/licenses/LICENSE-2.0
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
## This work was performed for the Jet Propulsion Laboratory, California
## Institute of Technology, sponsored by the United States Government under
## the prime contract 80NM0018D0004 between the Caltech and NASA under
## subcontract 1700763.
##
#
# From a fresh checkout perform a full build
#
set -e
set -o pipefail
export SELFDIR=$(realpath $(dirname "${BASH_SOURCE[0]}"))
source ${SELFDIR}/setenv.sh
BUILDDIR=${SELFDIR}/build/default
function usage {
echo "Usage: $0 [command] [args...]"
echo "Commands:"
echo " check-format - Apply and check format for all source code"
echo " apply-format - Apply format to all source code"
echo " apply-license - Apply/update license preamble to files"
echo " check - Run unit tests"
echo " check-install - Build a test executable linked to BSL"
echo " clean - Clean build artifacts"
echo " deps - Build dependend libraries"
echo " docs - Build HTML and/or PDF doxygen"
echo " install - Install"
echo " lint - Run clang-tidy code linter"
echo " prep [args...] - Generate makefiles with config options"
echo " rpm-build - Build RPM package with Tito"
echo " rpm-check - Check RPM packages after rpm-build"
echo " rpm-container - Build and check RPM packages inside container"
echo " run [args...] - Run a command with the environment vars"
}
function cmd_check_format {
exec ./resources/check_format.sh
}
function cmd_apply_format {
shift
exec ./resources/apply_format.sh "$@"
}
function cmd_apply_license {
shift
exec ./resources/apply_license.sh "$@"
}
function cmd_check {
shift
ctest --test-dir ${BUILDDIR} --output-on-failure "$@"
}
function cmd_check_install_pkgconfig {
# setenv.sh has aleady set DESTDIR and PREFIX
if [[ -n "${DESTDIR}" && -d "${DESTDIR}" ]]
then
export PKG_CONFIG_PATH=$(find ${DESTDIR}${PREFIX} -type d -name pkgconfig | tr '\n' ':')
PKG_PREFIX="--define-variable=prefix=${DESTDIR}${PREFIX}"
echo "Using prefix: ${PKG_PREFIX}"
else
PKG_PREFIX=""
fi
PKGS="bsl bsl-sample-pp"
echo "Provides:"
pkg-config --print-provides ${PKGS}
echo "Requires:"
pkg-config --print-requires ${PKGS}
echo -n "CFlags: "
pkg-config ${PKG_PREFIX} --cflags ${PKGS}
echo -n "Libs: "
pkg-config ${PKG_PREFIX} --libs ${PKGS}
cd "${SELFDIR}/lib-user-test"
mkdir -p build
gcc -c -o build/example.o main.c $(pkg-config ${PKG_PREFIX} --cflags ${PKGS})
gcc -o build/example build/example.o $(pkg-config ${PKG_PREFIX} --libs ${PKGS})
ldd ./build/example
./build/example
rm -rf build
}
function cmd_check_install_cmake {
# setenv.sh has aleady set DESTDIR and PREFIX
cd "${SELFDIR}/lib-user-test"
cmake -S . -B build \
-DCMAKE_FIND_DEBUG_MODE=OFF \
-DCMAKE_PREFIX_PATH=${DESTDIR}${PREFIX} \
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
-DCMAKE_BUILD_TYPE=Debug \
-G Ninja
cmake --build build
ldd ./build/example
./build/example
rm -rf build
}
function cmd_clean {
rm -rf build testroot deps/build
}
function cmd_coverage {
cmake --build ${BUILDDIR} -j1 --target \
coverage-html coverage-xml
}
function cmd_coverage_summary {
for DIRNAME in frontend backend crypto policy_provider security_context mock_bpa
do
if [[ ${DIRNAME} = "frontend" ]]
then
ATTRVAL="src"
else
ATTRVAL="src.${DIRNAME}"
fi
COV_XPATH="format-number(/coverage/packages/package[@name='${ATTRVAL}']/@line-rate * 100, '#.0')"
COV_PERC=$(xmlstarlet sel -t -v "${COV_XPATH}" -n build/default/coverage-xml.xml 2>/dev/null)
echo "Source ${DIRNAME} coverage: ${COV_PERC}%"
done
}
function cmd_deps {
exec ./resources/deps.sh
}
function cmd_docs {
cmake --build ${BUILDDIR} --target docs-api-html docs-api-misspelling
}
function cmd_install {
shift
cmake --install ${BUILDDIR} "$@"
}
function cmd_lint {
cmake --build build/default/ --target clang-tidy
}
function cmd_prep {
shift
exec ./resources/prep.sh "$@"
}
function cmd_rpm_build {
if ! git describe 2>/dev/null >/dev/null
then
git config --global --add safe.directory ${PWD}
for NAME in ${PWD}/deps/*
do
if [[ -d ${NAME} ]]
then
git config --global --add safe.directory ${NAME}
fi
done
fi
tito build -o build/default/pkg --test --srpm
tito build -o build/default/pkg --test --rpm
}
function cmd_rpm_check {
# Package scanning
pushd build/default/pkg
rpmlint --file=${SELFDIR}/pkg/rpmlintrc . | tee rpmlint.txt
# Trial install
dnf install -y x86_64/*.rpm
dnf repoquery -l 'bsl*'
}
function cmd_rpm_container {
DOCKER=${DOCKER:-docker}
DOCKEROPTS=""
if [[ ${#HOSTNAME} -lt 64 ]]
then
echo "Building on ${HOSTNAME}"
DOCKEROPTS="${DOCKEROPTS} -h ${HOSTNAME}"
fi
${DOCKER} image build -f pkg/rpmbuild.Containerfile -t localhost/bsl .
CID=$(${DOCKER} container create ${DOCKEROPTS} localhost/bsl)
rm -rf ${SELFDIR}/build ${SELFDIR}/testroot
mkdir -p ${SELFDIR}/build
${DOCKER} container cp ${SELFDIR}/. ${CID}:/usr/local/src/bsl
echo "Executing in container..."
${DOCKER} container start -a ${CID}
mkdir -p build/default/pkg
${DOCKER} container cp ${CID}:/usr/local/src/bsl/build/default/pkg/. ${SELFDIR}/build/default/pkg
echo "Removing container..."
${DOCKER} container rm ${CID}
}
function cmd_run {
shift
# Environment is already set by setenv.sh
exec $@
}
function cmd_default {
cmake --build ${BUILDDIR} "$@"
}
case "$1" in
echotest)
shift
echo "Test-after-shift: $@"
;;
check-format)
cmd_check_format
;;
apply-format)
cmd_apply_format "$@"
;;
apply-license)
cmd_apply_license "$@"
;;
check)
cmd_check "$@"
;;
check-install)
cmd_check_install_pkgconfig
cmd_check_install_cmake
;;
clean)
cmd_clean
;;
coverage)
cmd_coverage
;;
coverage-summary)
cmd_coverage_summary
;;
deps)
cmd_deps
;;
docs)
cmd_docs
;;
help|-h|--help)
usage
;;
install)
cmd_install "$@"
;;
lint)
cmd_lint;
;;
prep)
cmd_prep "$@"
;;
rpm-build)
cmd_rpm_build
;;
rpm-check)
cmd_rpm_check
;;
rpm-container)
cmd_rpm_container
;;
run)
cmd_run "$@"
;;
*)
cmd_default "$@"
;;
esac