forked from aosedge/aos_core_lib_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·201 lines (156 loc) · 3.93 KB
/
build.sh
File metadata and controls
executable file
·201 lines (156 loc) · 3.93 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
#!/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"
echo " --aos-service <services> specifies services (e.g., sm,mp,iam)"
echo " --ci uses build-wrapper for CI analysis (SonarQube)"
echo
}
error_with_usage() {
echo >&2 "ERROR: $1"
echo
print_usage
exit 1
}
clean_build() {
print_next_step "Clean artifacts"
rm -rf ./build/
conan remove 'gtest*' -c
conan remove 'grpc*' -c
conan remove 'poco*' -c
conan remove 'libcu*' -c
conan remove 'opens*' -c
conan remove 'pkcs11provider*' -c
}
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=Debug --build=missing
}
build_project() {
print_next_step "Run cmake configure"
cmake -S . -B build \
-DCMAKE_TOOLCHAIN_FILE=./conan_toolchain.cmake \
-DCMAKE_BUILD_TYPE=Debug \
-G "Unix Makefiles" \
-DCoverage_SONARQUBE=ON \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DWITH_TEST=ON \
-DWITH_COVERAGE=ON \
-DWITH_MBEDTLS=ON \
-DWITH_OPENSSL=ON
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 Debug --parallel
else
print_next_step "Run build"
cmake --build ./build/ --config Debug --parallel
fi
echo
echo "Build succeeded!"
}
parse_arguments() {
while [[ $# -gt 0 ]]; do
case $1 in
--clean)
ARG_CLEAN_FLAG=true
shift
;;
--ci)
ARG_CI_FLAG=true
shift
;;
*)
error_with_usage "Unknown option: $1"
;;
esac
done
}
build_target() {
if [ "$ARG_CLEAN_FLAG" == "true" ]; then
clean_build
return
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/*' \
--file-filter='tests/*' --file-filter='include/*'
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
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