-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·265 lines (209 loc) · 5.67 KB
/
build.sh
File metadata and controls
executable file
·265 lines (209 loc) · 5.67 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
#!/bin/bash
set +x
set -euo pipefail
print_next_step() {
echo
echo "====================================="
echo " $1"
echo "====================================="
echo
}
print_usage() {
echo
echo "Usage: ./build.sh <command> [options]"
echo
echo "Commands:"
echo " build builds target"
echo " test runs tests only"
echo " coverage runs tests with coverage"
echo " lint runs static analysis (cppcheck)"
echo " doc generates documentation"
echo
echo "Options:"
echo " --clean cleans build artifacts before building"
echo " --aos-service <services> specifies services (e.g., sm,mp,iam)"
echo " --ci uses build-wrapper for CI analysis (SonarQube)"
echo " --core-dir <path> specifies path to core libs directory"
echo " --parallel <N> specifies number of parallel jobs for build (default: all available cores)"
echo " --build-type <type> specifies build type (default: Debug, other options: Release, RelWithDebInfo, MinSizeRel)"
echo
}
error_with_usage() {
echo >&2 "ERROR: $1"
echo
print_usage
exit 1
}
clean_build() {
print_next_step "Clean artifacts"
rm -rf ./build/
}
conan_setup() {
print_next_step "Setting up conan default profile"
conan profile detect --force
print_next_step "Generate conan toolchain"
conan install ./conan/ --output-folder build --settings=build_type="$ARG_BUILD_TYPE" --build=missing
}
build_project() {
local with_cm="ON"
local with_iam="ON"
local with_mp="ON"
local with_sm="ON"
if [[ -n "$ARG_AOS_SERVICES" ]]; then
with_cm="OFF"
with_iam="OFF"
with_mp="OFF"
with_sm="OFF"
local services_lower
services_lower=$(echo "$ARG_AOS_SERVICES" | tr '[:upper:]' '[:lower:]')
IFS=',' read -ra service_array <<<"$services_lower"
for service in "${service_array[@]}"; do
service=$(echo "$service" | xargs) # trim whitespace
case "$service" in
"cm")
with_cm="ON"
;;
"iam")
with_iam="ON"
;;
"mp")
with_mp="ON"
;;
"sm")
with_sm="ON"
;;
*)
error_with_usage "Unknown service: $service"
;;
esac
done
fi
print_next_step "Run cmake configure"
cmake -S . -B build \
-DCMAKE_BUILD_TYPE="$ARG_BUILD_TYPE" \
${ARG_CORE_DIR+-DAOS_CORE_DIR="$ARG_CORE_DIR"} \
-DWITH_VCHAN=OFF \
-DWITH_COVERAGE=ON \
-DWITH_TEST=ON \
-DWITH_CM="$with_cm" \
-DWITH_IAM="$with_iam" \
-DWITH_MP="$with_mp" \
-DWITH_SM="$with_sm" \
-DCMAKE_TOOLCHAIN_FILE=./conan_toolchain.cmake \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-G "Unix Makefiles"
if [ "$ARG_CI_FLAG" == "true" ]; then
print_next_step "Run build-wrapper and build (CI mode)"
build-wrapper-linux-x86-64 --out-dir "$BUILD_WRAPPER_OUT_DIR" cmake --build ./build/ --config "$ARG_BUILD_TYPE" --parallel "$ARG_PARALLEL_JOBS"
else
print_next_step "Run build"
cmake --build ./build/ --config "$ARG_BUILD_TYPE" --parallel "$ARG_PARALLEL_JOBS"
fi
echo
echo "Build succeeded!"
}
parse_arguments() {
while [[ $# -gt 0 ]]; do
case $1 in
--clean)
ARG_CLEAN_FLAG=true
shift
;;
--aos-service)
if [[ -n "$ARG_AOS_SERVICES" ]]; then
ARG_AOS_SERVICES="$ARG_AOS_SERVICES,$2"
else
ARG_AOS_SERVICES="$2"
fi
shift 2
;;
--ci)
ARG_CI_FLAG=true
shift
;;
--core-dir)
ARG_CORE_DIR="$2"
shift 2
;;
--parallel)
ARG_PARALLEL_JOBS="$2"
shift 2
;;
--build-type)
ARG_BUILD_TYPE="$2"
shift 2
;;
*)
error_with_usage "Unknown option: $1"
;;
esac
done
}
build_target() {
if [ "$ARG_CLEAN_FLAG" == "true" ]; then
clean_build
fi
conan_setup
build_project
}
run_tests() {
print_next_step "Run tests"
cd ./build
make test
echo
echo "Tests completed!"
}
run_coverage() {
print_next_step "Run tests with coverage"
cd ./build
make coverage
echo
echo "Coverage completed!"
}
run_lint() {
print_next_step "Run static analysis (cppcheck)"
cppcheck --enable=all --inline-suppr --std=c++17 --error-exitcode=1 \
--suppressions-list=./suppressions.txt --project=build/compile_commands.json --file-filter='src/*'
echo
echo "Static analysis completed!"
}
build_doc() {
print_next_step "Build documentation"
cd ./build
cmake -DWITH_DOC=ON ../
make doc
echo
echo "Documentation generated!"
}
#=======================================================================================================================
if [ $# -lt 1 ]; then
error_with_usage "Missing command"
fi
command="$1"
shift
ARG_CLEAN_FLAG=false
ARG_AOS_SERVICES=""
ARG_CI_FLAG=false
ARG_PARALLEL_JOBS=$(nproc)
ARG_BUILD_TYPE="Debug"
case "$command" in
build)
parse_arguments "$@"
build_target
;;
test)
run_tests
;;
coverage)
run_coverage
;;
lint)
run_lint
;;
doc)
build_doc
;;
*)
error_with_usage "Unknown command: $command"
;;
esac