-
Notifications
You must be signed in to change notification settings - Fork 3
/
.gitlab-ci.yml
328 lines (313 loc) · 12.5 KB
/
.gitlab-ci.yml
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# Copyright 2023, Victor Chavez
# SPDX-License-Identifier: Apache-2.0
stages:
- compile
- quality
- style
- usage
- static_analysis
- pages
variables:
SRC_DIR: src
NORDIC_CONNECT_SDK_VERSION: v2.3.0
ZEPHYR_TOOLCHAIN_VERSION: 0.14.1
ZEPHYR_BOARD: nrf52dk_nrf52832
# Paths defined in docker image nordicplayground/nrfconnect-sdk:main
PROJ_PATH: /workdir/project
SDK_PATH: /workdir/zephyr-sdk
COMPILATION_FILE: $PROJ_PATH/build/compile_commands.json
Usage Analysis:
image: registry.git.fh-aachen.de/embeddedtools/static-analysis/embedded-sa-docker:nrf-connect
tags:
- shared
stage: usage
needs:
["Compile"]
before_script:
- tar -xf zephyr_build.tar.xz -C $PROJ_PATH
- cd $PROJ_PATH
- export ZEPHYR_ELF=$(find -type f -name 'zephyr.elf')
- mv $ZEPHYR_ELF ${CI_PROJECT_DIR}/zephyr.elf
- pip3 install requests
- pip3 install -Iv puncover==0.2.2
- cd ${CI_PROJECT_DIR}
- git clone https://github.com/vChavezB/puncover_html
- git clone https://git.fh-aachen.de/embedded-guidelines/utils/puncover-toolchain-find
- export GCC_BASE=$(python3 puncover-toolchain-find/puncover-toolchain-find.py "${COMPILATION_FILE}")
script:
- echo $GCC_BASE
- puncover --elf_file ${CI_PROJECT_DIR}/zephyr.elf --gcc_tools_base $GCC_BASE --build_dir $PROJ_PATH/build > /dev/null &
- sleep 5
- python3 puncover_html/puncover_html.py usage_analysis
artifacts:
name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- usage_analysis
Halstead Metrics:
image: registry.git.fh-aachen.de/embeddedtools/ccccc-docker:latest
tags:
- shared
needs:
["Compile"]
variables:
OUT_DIR: ${CI_PROJECT_DIR}/html_out
stage: quality
before_script:
- export SRC_FILES=$(find ${SRC_DIR} -name '*.c' -o -name '*.cpp' -type f | paste -sd " ")
- mkdir -p $PROJ_PATH
- tar -xf zephyr_build.tar.xz -C $PROJ_PATH
script:
- mv $COMPILATION_FILE compile_commands.json
- mkdir ${OUT_DIR}
- ccccc ${SRC_FILES} -t $HTML_STATIC/template/html/template.tpl > ${OUT_DIR}/index.html
- cp -a $HTML_STATIC/* ${OUT_DIR}
- cd ${OUT_DIR}
- rm -rf 3rd/doctest
- sed -i 's!file:////usr/bin/ccccc/!!g' index.html
artifacts:
name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- $OUT_DIR
Style:
image: registry.git.fh-aachen.de/embeddedtools/embedded-quality-docker:latest
tags:
- shared
stage: style
before_script:
- wget -nv https://git.fh-aachen.de/embedded-guidelines/cfg/kwstyle_config/-/raw/main/kwstyle_embedded_guidelines.xml
- wget -nv https://git.fh-aachen.de/embedded-guidelines/cfg/vera-fh-profile/-/raw/main/FH.tcl
- mv FH.tcl /usr/lib/vera++/profiles/FH.tcl
script:
# Creat input file with all c/c++ sources
- find ${SRC_DIR} -type f -regex '.*\.\(ino\|c\|cpp\|hpp\|h\)' > input_files.txt
- KWStyle -D input_files.txt -xml kwstyle_embedded_guidelines.xml -html kwsytle_html
- vera++ -p FH.tcl -i input_files.txt -o vera.log -P max-line-length=125 -e
artifacts:
when: on_failure
name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- vera.log
- kwsytle_html
Security:
image: registry.git.fh-aachen.de/embeddedtools/embedded-quality-docker:latest
tags:
- shared
stage: quality
script:
- flawfinder ${SRC_DIR}/ > flaws.out
- cat flaws.out
artifacts:
name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- flaws.out
Complexity:
image: registry.git.fh-aachen.de/embeddedtools/embedded-quality-docker:latest
tags:
- shared
stage: quality
script:
- lizard ${SRC_DIR} -l cpp -o complexity.html
- cppclean ${SRC_DIR} > cppclean.txt || true
artifacts:
name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- complexity.html
- cppclean.txt
Duplicates:
image: registry.git.fh-aachen.de/embeddedtools/embedded-quality-docker:latest
tags:
- shared
stage: quality
variables:
MIN_DUP_TOKEN: 50 #minimum tokens to detect as duplicates for cpd
script:
#Change name of sketch so it can be detected by tools
- $PMD_RUN cpd --minimum-tokens $MIN_DUP_TOKEN --files $SRC_DIR --language cpp --fail-on-violation false --format xml > cpd.xml
- xsltproc $PMD_PATH/cpdhtml.xslt cpd.xml > cpd_duplicates.html
#Lizard
- lizard -l cpp -Eduplicate ${SRC_DIR} > lizard_duplicates.txt || true
#Remove the complexity report and just get the duplicate info
- sed -i '1,/^Duplicates$/d' lizard_duplicates.txt
artifacts:
name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- cpd_duplicates.html
- lizard_duplicates.txt
Metrics:
image: registry.git.fh-aachen.de/embeddedtools/embedded-quality-docker:latest
tags:
- shared
stage: quality
variables:
#More info about the metrics here https://metrixplusplus.github.io/metrixplusplus/docs/01-u-overview
METRIC_ARGS: --std.code.filelines.total --std.code.lines.preprocessor --std.code.lines.comments --std.code.complexity.maxindent --std.code.todo.strings --std.code.lines.code --std.code.complexity.cyclomatic --std.code.maintindex.simple
before_script:
- apk add --no-cache git
script:
- cd /tmp/
- git clone $CI_REPOSITORY_URL main_branch
- cd main_branch
#If on the main branch,checkout one commit before
- |-
if [[ $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH ]]; then
git checkout ${CI_COMMIT_SHA}^
fi
- metrix++ collect ${METRIC_ARGS} -- ${SRC_DIR}
- cd $CI_PROJECT_DIR/
- metrix++ collect ${METRIC_ARGS} -- ${SRC_DIR}
- metrix++ view --db-file=metrixpp.db --db-file-prev=/tmp/main_branch/metrixpp.db > metrics.txt
- cat metrics.txt
artifacts:
name: "${CI_PROJECT_NAME}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- metrics.txt
Compile:
image: registry.git.fh-aachen.de/embeddedtools/nrf-docker:$NORDIC_CONNECT_SDK_VERSION
tags:
- shared
stage: compile
script:
- cd $PROJ_PATH
- west build $CI_PROJECT_DIR/samples/uptime --board $ZEPHYR_BOARD
#- sed -i 's!--param=min-pagesize=0 !!g' $COMPILATION_FILE
# Build files required for static analysis
- tar -cJf $CI_PROJECT_DIR/zephyr_build.tar.xz build
artifacts:
name: "${CI_PROJECT_NAME}-${CI_JOB_STAGE}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- zephyr_build.tar.xz
Cppcheck:
needs:
- job: Compile
image: registry.git.fh-aachen.de/embeddedtools/static-analysis/cppcheck-docker:latest
tags:
- shared
stage: static_analysis
variables:
REPORT_DIR: cppcheck_report
script:
#Analyze src dir and generate xml output
- wget -nv https://git.fh-aachen.de/embedded-guidelines/cfg/cppcheck-cfg/-/raw/main/cppcheck_suppresion.txt
- export CPPCHECK_ARGS="--suppressions-list=cppcheck_suppresion.txt --force --enable=all --inline-suppr"
- cppcheck ${CPPCHECK_ARGS} --xml --xml-version=2 ${SRC_DIR} 2>cpp_check_report.xml
#convert xml output to html
- cppcheck-htmlreport --source-dir=. --title=$project_name --file=cpp_check_report.xml --report-dir=$REPORT_DIR
#After checking errors, make the ci/cd fail if cppcheck found errors
- cppcheck ${CPPCHECK_ARGS} --error-exitcode=1 ${SRC_DIR}
artifacts:
when: on_failure
name: "${CI_PROJECT_NAME}-${CI_JOB_STAGE}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- $REPORT_DIR
PVS Studio:
image: registry.git.fh-aachen.de/embeddedtools/static-analysis/embedded-sa-docker:nrf-connect
needs:
- job: Compile
tags:
- shared
stage: static_analysis
variables:
REPORT_DIR: PVS_report
ZEPHYR_SYSLIB: /usr/lib/gcc/arm-zephyr-eabi
before_script:
#Add PVS Studio comments for free analysis, refer to:
#https://pvs-studio.com/en/docs/warnings/v009/
- git clone https://git.fh-aachen.de/embeddedutils/pvs-free #utility to add pvs free comments
- tar -xf zephyr_build.tar.xz -C $PROJ_PATH
script:
# Add comments to use academic license
- python3 pvs-free/pvs-free.py . --add
# PVS studio cant detect zephyr arm compiler, replace with vanilla arm-none-eabi
#- sed -i 's/arm-zephyr-eabi-gcc/arm-none-eabi-gcc/g' $COMPILATION_FILE
#- sed -i 's/arm-zephyr-eabi-g++/arm-none-eabi-g++/g' $COMPILATION_FILE
#- sed -i 's!workdir/zephyr-sdk/arm-zephyr-eabi/bin!usr/bin!g' $COMPILATION_FILE
- pvs-studio-analyzer analyze -f $COMPILATION_FILE -o project.log -e \*$PROJ_PATH/\*
- plog-converter -t fullhtml project.log -o $REPORT_DIR
- |-
if ! grep -q Congratulations "$REPORT_DIR/index.html"; then
>&2 echo "PVS Studio found issues!"
exit 1
fi
artifacts:
when: on_failure
name: "${CI_PROJECT_NAME}-${CI_JOB_STAGE}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- $REPORT_DIR
CodeChecker:
image: registry.git.fh-aachen.de/embeddedtools/static-analysis/embedded-sa-docker:nrf-connect
needs:
- job: Compile
tags:
- shared
stage: static_analysis
variables:
CODECHECKER_ANALYZER_OUT: /tmp
REPORT_DIR: codechecker_report
before_script:
- wget -nv https://git.fh-aachen.de/embedded-guidelines/cfg/codechecker-cfg/-/raw/main/FH-Codechecker.json
- mkdir $REPORT_DIR
# Build files required for static analysis
- tar -xf zephyr_build.tar.xz -C $PROJ_PATH
script:
#Activating python env for codechecker
- source $CODECHECKER_ACTIVATE
#Env Variable that tells codechecker to analyze compiler calls for arm toolchain
- export CC_LOGGER_GCC_LIKE="arm-zephyr-eabi-gcc:arm-zephyr-eabi-g++"
#Create Skip file for analyzing project, only src of the project
# more information about the skip file format:
# https://codechecker.readthedocs.io/en/latest/analyzer/user_guide/#skip
#- echo -e "+*/$SRC_DIR\n" >> skip.file #only analyze the source files
- echo -e "-$PROJ_PATH*\n" >> skip.file
- echo -e "-$SDK_PATH*" >> skip.file
- echo -e "-D__WCHAR_MIN__=0 -m32 -I/workdir/zephyr-sdk/arm-zephyr-eabi/lib/gcc/arm-zephyr-eabi/10.3.0/include/" >> sa_flags.txt
- echo -e "-extra-arg-before='-m32' -extra-arg-before='-I/workdir/zephyr-sdk/arm-zephyr-eabi/lib/gcc/arm-zephyr-eabi/10.3.0/include/'" >> tidy_flags.txt
#Analyze the files
- CodeChecker analyze $COMPILATION_FILE --tidyargs tidy_flags.txt --saargs sa_flags.txt --ctu -i skip.file --enable extreme --output $CODECHECKER_ANALYZER_OUT --config FH-Codechecker.json > /dev/null
#Parse the analysis as html
- CodeChecker parse --export html --output ${REPORT_DIR} $CODECHECKER_ANALYZER_OUT --verbose debug
artifacts:
when: on_failure
name: "${CI_PROJECT_NAME}-${CI_JOB_STAGE}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- $REPORT_DIR
pages:
variables:
# allows retrieving commits far away from last tag for proj number in doxygen
GIT_DEPTH: "50"
image: registry.git.fh-aachen.de/embeddedtools/docs:latest
tags:
- shared
stage: pages
script:
- mkdir public
- GIT_VERSION=$(git describe --long --always --tags)
- git clone https://git.fh-aachen.de/embedded-guidelines/cfg/doxygen_cfg.git --recurse-submodules --branch v1.2.0
- cd doxygen_cfg
#change name for project in doxyfile
- sed -i "s!ProjectName!$CI_PROJECT_NAME!g" Doxyfile.in
#Replace input files in template
- sed -i "s!README_FILE!${CI_PROJECT_DIR}/README.md!g" Doxyfile.in
- sed -i "s!PROJ_NUM!${GIT_VERSION}!g" Doxyfile.in
- sed -i "s!INPUT_FILES!${CI_PROJECT_DIR}/${SRC_DIR}!g" Doxyfile.in
- doxygen Doxyfile.in
- mv html/* ${CI_PROJECT_DIR}/public
artifacts:
name: "${CI_PROJECT_NAME}-${CI_JOB_STAGE}-${CI_JOB_NAME}_${CI_COMMIT_SHORT_SHA}"
expire_in: 10 mins
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == "main"
- if: $CI_COMMIT_BRANCH == "master"
- if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/'