forked from NASA-AMMOS/BSL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·238 lines (209 loc) · 5.87 KB
/
build.sh
File metadata and controls
executable file
·238 lines (209 loc) · 5.87 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
#!/bin/bash
##
## Copyright (c) 2025 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
source setenv.sh
export SELFDIR=$(realpath $(dirname "${BASH_SOURCE[0]}"))
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 " 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 after rpm-prep"
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 {
./resources/check_format.sh
}
function cmd_apply_format {
./resources/apply_format.sh
}
function cmd_apply_license {
./resources/apply_license.sh
}
function cmd_check {
cmake --build ${BUILDDIR} --target test
}
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 {
./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
./resources/prep.sh "$@"
}
function cmd_rpm_build {
if ! git describe 2>/dev/null >/dev/null
then
git config --global --add safe.directory ${PWD}
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 {
# testroot installed files
DESTDIR=${DESTDIR:-${SELFDIR}/testroot}
PREFIX=${PREFIX:-/usr}
if [ -n "${DESTDIR}" -o -n "${PREFIX}" ]
then
export LD_LIBRARY_PATH=${DESTDIR}${PREFIX}/lib:${DESTDIR}${PREFIX}/lib64
export PATH=${PATH}:${DESTDIR}${PREFIX}/bin
fi
shift
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
;;
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