-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·714 lines (624 loc) · 23.9 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·714 lines (624 loc) · 23.9 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
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Ensure that getopt starts from first option if ". <script.sh>" was used.
OPTIND=1
ret='exit'
# Ensure we dont end the user's terminal session if invoked from source (".").
if [[ $0 != "${BASH_SOURCE[0]}" ]]; then
ret='return'
else
ret='exit'
fi
warn() { echo -e "\033[1;33mWarning:\033[0m $*" >&2; }
error() { echo -e "\033[1;31mError:\033[0m $*" >&2; }
header() { echo -e "\e[4m\e[1m\e[1;32m$*\e[0m"; }
bullet() { echo -e "\e[1;34m*\e[0m $*"; }
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
root_dir=$script_dir/..
# Determine the git root directory
GITROOT="$(git rev-parse --show-toplevel 2> /dev/null)"
if [ -z "$GITROOT" ]; then
# If not in a git repo, use root_dir
GITROOT="$root_dir"
fi
build_clean=false
build_documentation=false
build_delta_handler=false
build_packages=false
verbose_build=false
platform_layer="linux"
trace_target_deps=false
step_handlers="microsoft/apt,microsoft/script,microsoft/simulator,microsoft/swupdate_v2"
use_test_root_keys=false
srvc_e2e_agent_build=false
build_type=Debug
adu_log_dir=""
default_log_dir=/var/log/adu
console_log=true
file_log=true
output_directory=$root_dir/out
build_unittests=false
enable_e2e_testing=false
declare -a static_analysis_tools=()
log_lib="zlog"
install_prefix=/usr/local
install_adu=false
work_folder="$root_dir/.workspace"
cmake_dir_path="${work_folder}/deviceupdate-cmake"
cmake_bin="cmake"
rootkeypkg_curl=true
enable_coverage=false
support_delivery_optimization=false
#
# Export the compiler settings in case VM is wonky
#
export CC=/usr/bin/gcc
export CXX=/usr/bin/g++
print_help() {
cat << EOS
Usage: build.sh [options...]
-c, --clean Does a clean build.
-t, --type <build_type> The type of build to produce. Passed to CMAKE_BUILD_TYPE. Default is Debug.
Options: Release Debug RelWithDebInfo MinSizeRel
-d, --build-docs Builds the documentation.
--delta-handler Builds the delta download handler.
-u, --build-unit-tests Builds unit tests.
--enable-e2e-testing Enables settings for the E2E test pipelines.
--build-packages Builds and packages the client in various package formats e.g debian.
-o, --out-dir <out_dir> Sets the build output directory. Default is out.
-v, --verbose Enables verbose compilation and linking output.
-s, --static-analysis <tools...> Runs static analysis as part of the build.
Tools is a comma delimited list of static analysis tools to run at build time.
Tools: clang-tidy cppcheck cpplint iwyu lwyu (or all)
-p, --platform-layer <layer> Specify the platform layer to build/use. Default is linux.
Option: linux
--trace-target-deps Traces dependencies of CMake targets debug info.
--log-lib <log_lib> Specify the logging library to build/use. Default is zlog.
Options: zlog xlog
-l, --log-dir <log_dir> Specify the directory where the ADU Agent will write logs.
Only valid for logging libraries that support file logging.
--install-prefix <prefix> Install prefix to pass to CMake.
--support-delivery-optimization Whether to build with Delivery Optimization support. By default, it is disabled.
Note: Delivery Optimization is only supported on certain older platforms and OS versions.
It is won't be enabled on Ubuntu 24.04 and Debian 13 (trixie) and newer OS even if this option is specified.
--install Install the following ADU components.
From source: deviceupdate-agent.service & adu-swupdate.sh.
From build output directory: AducIotAgent & adu-shell.
--content-handlers <handlers> [Deprecated] use '--step-handlers' option instead.
--step-handlers <handlers> Specify a comma-delimited list of the step handlers to build.
Default is '${step_handlers}'.
-f, --work-folder <work_folder> Specifies the folder where temp artifacts will be stored.
This folder contains temporary build artifacts for dependencies,
CMake/shellcheck installations, and test data.
Default is /tmp.
--cmake-path Override the cmake path such that CMake binary is at <cmake-path>/bin/cmake
--openssl-path Override the openssl path
--major-version Major version of ADU
--minor-version Minor version of ADU
--patch-version Patch version of ADU
--rootkeypkg-curl (Deprecated) Download the RootKey Package with curl instead of delivery optimization agent.
curl is now used by default for root key package download on all platforms.
--coverage Enable coverage mode in build.sh:
instrumented build, force unit tests, then run test+report workflow.
-h, --help Show this help message.
EOS
}
copyfile_exit_if_failed() {
bullet "Copying $1 to $2"
cp "$1" "$2"
ret_val=$?
if [[ $ret_val != 0 ]]; then
error "failed to copy $1 to $2 (exit code:$ret_val)"
$ret $ret_val
fi
}
install_adu_components() {
adu_lib_dir=/usr/lib/adu
adu_data_dir=/var/lib/adu
# Install adu components on this local development machine.
header "Installing ADU components..."
bullet "Create 'adu' user and 'adu' group..."
groupadd --system adu
useradd --system -p '' -g adu --no-create-home --shell /sbin/false adu
bullet "Add current user ('$USER') to 'adu' group, to allow launching deviceupdate-agent (for testing purposes only)"
usermod -a -G adu "$USER"
bullet "Current user info:"
id
copyfile_exit_if_failed "$output_directory/bin/AducIotAgent" /usr/bin
mkdir -p $adu_lib_dir
copyfile_exit_if_failed "$output_directory/bin/adu-shell" $adu_lib_dir
copyfile_exit_if_failed "$root_dir/src/adu-shell/scripts/adu-swupdate.sh" "$adu_lib_dir"
# Setup directories owner and/or permissions
# Logs directory
mkdir -p "$adu_log_dir"
chown adu:adu "$adu_log_dir"
chmod u=rwx,g=rx "$adu_log_dir"
# Data directory
mkdir -p "$adu_data_dir"
chown adu:adu "$adu_data_dir"
chmod u=rwx,g=rx "$adu_data_dir"
# Set the file permissions
chown root:adu "$adu_lib_dir/adu-shell"
chmod u=rwxs,g=rx,o= "$adu_lib_dir/adu-shell"
chmod u=rwx,g=rx,o=rx "$adu_lib_dir/adu-swupdate.sh"
# Only install deviceupdate-agent service on system that support systemd.
systemd_system_dir=/usr/lib/systemd/system/
if [ -d "$systemd_system_dir" ]; then
bullet "Install deviceupdate-agent systemd daemon..."
copyfile_exit_if_failed "$root_dir/daemon/deviceupdate-agent.service" "$systemd_system_dir"
systemctl daemon-reload
systemctl enable deviceupdate-agent
systemctl restart deviceupdate-agent
else
warn "Directory $systemd_system_dir does not exist. Skip deviceupdate-agent.service installation."
fi
echo "ADU components installation completed."
echo ""
}
OS=""
VER=""
determine_distro() {
# Checking distro name and version
if [ -r /etc/os-release ]; then
# freedesktop.org and systemd
OS=$(grep "^ID\s*=\s*" /etc/os-release | sed -e "s/^ID\s*=\s*//")
VER=$(grep "^VERSION_ID\s*=\s*" /etc/os-release | sed -e "s/^VERSION_ID\s*=\s*//")
VER=$(sed -e 's/^"//' -e 's/"$//' <<< "$VER")
elif type lsb_release > /dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
OS=$(grep "^DISTRIB_ID\s*=\s*" /etc/lsb-release | sed -e "s/^DISTRIB_ID\s*=\s*//")
VER=$(grep "^DISTRIB_RELEASE\s*=\s*" /etc/lsb-release | sed -e "s/^DISTRIB_RELEASE\s*=\s*//")
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi
OS="$(echo "$OS" | tr '[:upper:]' '[:lower:]')"
}
determine_distro
# Ensure work folder exists
if [[ ! -d $work_folder ]]; then
echo "Creating work folder: $work_folder"
mkdir -p "$work_folder" || $ret 1
fi
while [[ $1 != "" ]]; do
case $1 in
-c | --clean)
build_clean=true
;;
--step-handlers)
shift
if [[ -z $1 || $1 == -* ]]; then
error "--step-handlers parameter is mandatory."
$ret 1
fi
step_handlers=$1
;;
--content-handlers)
shift
if [[ -z $1 || $1 == -* ]]; then
error "--content-handlers parameter is mandatory."
$ret 1
fi
step_handlers=$1
;;
-t | --type)
shift
if [[ -z $1 || $1 == -* ]]; then
error "-t build type parameter is mandatory."
$ret 1
fi
build_type=$1
;;
-d | --build-docs)
build_documentation=true
;;
--delta-handler)
build_delta_handler=true
;;
-u | --build-unit-tests)
build_unittests=true
;;
--enable-e2e-testing)
enable_e2e_testing=true
;;
--build-packages)
build_packages=true
;;
-o | --out-dir)
shift
if [[ -z $1 || $1 == -* ]]; then
error "-o output directory parameter is mandatory."
$ret 1
fi
output_directory=$1
;;
-v | --verbose)
verbose_build=true
;;
-s | --static-analysis)
shift
if [[ -z $1 || $1 == -* ]]; then
error "-s static analysis tools parameter is mandatory."
$ret 1
fi
if [[ $1 == "all" ]]; then
declare -a static_analysis_tools=(clang-tidy cppcheck cpplint iwyu lwyu)
else
IFS=','
read -ra static_analysis_tools <<< "$1"
IFS=' '
fi
;;
-p | --platform-layer)
shift
if [[ -z $1 || $1 == -* ]]; then
error "-p platform layer parameter is mandatory."
$ret 1
fi
platform_layer=$1
;;
--trace-target-deps)
trace_target_deps=true
;;
--use-test-root-keys)
use_test_root_keys=true
;;
--build-service-e2e-agent)
srvc_e2e_agent_build=true
;;
--support-delivery-optimization)
support_delivery_optimization=true
;;
--log-lib)
shift
if [[ -z $1 || $1 == -* ]]; then
error "--log-lib parameter is mandatory."
$ret 1
fi
log_lib=$1
;;
-l | --log-dir)
shift
if [[ -z $1 || $1 == -* ]]; then
error "-l log directory parameter is mandatory."
$ret 1
fi
adu_log_dir=$1
;;
--disable-console-log)
console_log=false
;;
--disable-file-log)
file_log=false
;;
--install-prefix)
shift
if [[ -z $1 || $1 == -* ]]; then
error "--install-prefix parameter is mandatory."
$ret 1
fi
install_prefix=$1
;;
--install)
if [[ $EUID -ne 0 ]]; then
error "Super-user required to install ADU components."
$ret 1
fi
install_adu="true"
;;
-f | --work-folder)
shift
if [[ -z $1 || $1 == -* ]]; then
error "-f work folder parameter is mandatory."
$ret 1
fi
work_folder=$(realpath "$1" 2> /dev/null)
if [[ -z $work_folder ]]; then
error "Invalid or inaccessible work folder path: $1"
$ret 1
fi
;;
--cmake-path)
shift
if [[ -z $1 || $1 == -* ]]; then
error "--cmake-path parameter is mandatory."
$ret 1
fi
cmake_dir_path=$1
;;
--major-version)
shift
major_version=$1
;;
--minor-version)
shift
minor_version=$1
;;
--patch-version)
shift
patch_version=$1
;;
--rootkeypkg-curl)
rootkeypkg_curl="true"
;;
--coverage)
enable_coverage=true
;;
-h | --help)
print_help
$ret 0
;;
*)
error "Invalid argument: $*"
$ret 1
;;
esac
shift
done
# Set cmake_dir_path if not explicitly provided via --cmake-path.
# Note: This must be done after argument parsing is complete so that
# work_folder has been set if --work-folder was specified.
if [[ -z $cmake_dir_path ]]; then
cmake_dir_path="${work_folder}/deviceupdate-cmake"
fi
# Coverage mode is owned by build.sh. It forces unit-test build and
# applies instrumentation flags so the follow-up coverage step has data.
if [[ $enable_coverage == "true" ]]; then
build_unittests=true
build_type=Debug
export CFLAGS="--coverage -O0 -g ${CFLAGS:-}"
export CXXFLAGS="--coverage -O0 -g ${CXXFLAGS:-}"
export LDFLAGS="--coverage ${LDFLAGS:-}"
fi
# Source build environment from install-deps.sh if it exists
if [[ -f "$work_folder/.build-env" ]]; then
# shellcheck source=/dev/null
source "$work_folder/.build-env"
if [[ -n $ADU_CMAKE_BIN ]]; then
cmake_bin="$ADU_CMAKE_BIN"
bullet "Using cmake from build environment: $cmake_bin"
fi
fi
if [[ $build_documentation == "true" ]]; then
if ! [ -x "$(command -v doxygen)" ]; then
error "Can't build documentation - doxygen is not installed. Try: apt install doxygen"
$ret 1
fi
if ! [ -x "$(command -v dot)" ]; then
error "Can't build documentation - dot (graphviz) is not installed. Try: apt install graphviz"
$ret 1
fi
fi
# Set default log dir if not specified.
if [[ $adu_log_dir == "" ]]; then
adu_log_dir=$default_log_dir
fi
runtime_dir=${output_directory}/bin
library_dir=${output_directory}/lib
# Only set hardcoded cmake path if ADU_CMAKE_BIN wasn't set from .build-env
if [[ -z $ADU_CMAKE_BIN ]]; then
cmake_bin="${cmake_dir_path}/bin/cmake"
fi
shellcheck_bin="${work_folder}/deviceupdate-shellcheck"
if [[ $srvc_e2e_agent_build == "true" ]]; then
warn "BUILDING SERVICE E2E AGENT NEVER USE FOR PRODUCTION"
echo "Additionally implies: "
echo " --enable-e2e-testing , --use-test-root-keys, --build-packages"
use_test_root_keys=true
enable_e2e_testing=true
build_packages=true
fi
# Disable DO on Ubuntu 24.04 and newer
if [[ $OS == "ubuntu" && $VER == "24.04" ]]; then
echo "WARN: Disabling Delivery Optimization for Ubuntu 24.04"
support_delivery_optimization=false
rootkeypkg_curl=true
fi
# Disable DO on Debian 13 (trixie) - not yet supported
if [[ $OS == "debian" && $VER == "13" ]]; then
echo "WARN: Disabling Delivery Optimization for Debian 13 (not yet supported)"
support_delivery_optimization=false
rootkeypkg_curl=true
fi
# Output banner
echo ''
header "Building ADU Agent"
bullet "Clean build: $build_clean"
bullet "Documentation: $build_documentation"
bullet "Platform layer: $platform_layer"
bullet "Trace target deps: $trace_target_deps"
bullet "Step handlers: $step_handlers"
bullet "Build type: $build_type"
bullet "Log directory: $adu_log_dir"
bullet "Enable console log: $console_log"
bullet "Enable file log: $file_log"
bullet "Logging library: $log_lib"
bullet "Output directory: $output_directory"
bullet "Build unit tests: $build_unittests"
bullet "Coverage mode: $enable_coverage"
bullet "Enable E2E testing: $enable_e2e_testing"
bullet "Build packages: $build_packages"
bullet "CMake: $cmake_bin"
bullet "CMake version: $(${cmake_bin} --version | grep version | awk '{ print $3 }')"
bullet "shellcheck: $shellcheck_bin"
bullet "shellcheck version: $("$shellcheck_bin" --version | grep 'version:' | awk '{ print $2 }')"
if [[ ${#static_analysis_tools[@]} -eq 0 ]]; then
bullet "Static analysis: (none)"
else
bullet "Static analysis: " "${static_analysis_tools[@]}"
fi
bullet "Include Test Root Keys: $use_test_root_keys"
bullet "Use Curl, not DO, for RootKey Package Download? $rootkeypkg_curl"
bullet "Support Delivery Optimization: $support_delivery_optimization"
echo ''
CMAKE_OPTIONS=(
"-DADUC_BUILD_DOCUMENTATION:BOOL=$build_documentation"
"-DADUC_BUILD_UNIT_TESTS:BOOL=$build_unittests"
"-DADUC_BUILD_PACKAGES:BOOL=$build_packages"
"-DADUC_STEP_HANDLERS:STRING=$step_handlers"
"-DADUC_ENABLE_E2E_TESTING=$enable_e2e_testing"
"-DADUC_LOG_FOLDER:STRING=$adu_log_dir"
"-DADUC_ENABLE_CONSOLE_LOG:BOOL=$console_log"
"-DADUC_ENABLE_FILE_LOG:BOOL=$file_log"
"-DADUC_LOGGING_LIBRARY:STRING=$log_lib"
"-DADUC_PLATFORM_LAYER:STRING=$platform_layer"
"-DADUC_TRACE_TARGET_DEPS=$trace_target_deps"
"-DADUC_USE_TEST_ROOT_KEYS=$use_test_root_keys"
"-DADUC_ROOTKEY_PKG_DOWNLOAD_WITH_CURL=$rootkeypkg_curl"
"-DADUC_BUILD_WITH_DELIVERY_OPTIMIZATION:BOOL=$support_delivery_optimization"
"-DADUC_TMP_DIR_PATH:STRING=$work_folder"
"-DCMAKE_BUILD_TYPE:STRING=$build_type"
"-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON"
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY:STRING=$library_dir"
"-DCMAKE_RUNTIME_OUTPUT_DIRECTORY:STRING=$runtime_dir"
"-DCMAKE_INSTALL_PREFIX=$install_prefix"
"-DADUC_BUILD_DELTA_HANDLER:BOOL=$build_delta_handler"
)
if [[ $major_version != "" ]]; then
CMAKE_OPTIONS+=("-DADUC_VERSION_MAJOR=$major_version")
fi
if [[ $minor_version != "" ]]; then
CMAKE_OPTIONS+=("-DADUC_VERSION_MINOR=$minor_version")
fi
if [[ $patch_version != "" ]]; then
CMAKE_OPTIONS+=("-DADUC_VERSION_PATCH=$patch_version")
fi
echo "CMAKE Options:"
for opt in "${CMAKE_OPTIONS[@]}"; do
echo " $opt"
done
for i in "${static_analysis_tools[@]}"; do
case $i in
clang-tidy)
# http://clang.llvm.org/extra/clang-tidy/ (sudo apt install clang-tidy)
if ! [ -x "$(command -v clang-tidy)" ]; then
error "Can't run static analysis - clang-tidy is not installed. Try: apt install clang-tidy"
$ret 1
fi
# clang-tidy requires clang to be installed so that it can find clang headers.
if ! [ -x "$(command -v clang)" ]; then
error "Can't run static analysis - clang is not installed. Try: apt install clang"
$ret 1
fi
CMAKE_OPTIONS+=('-DCMAKE_C_CLANG_TIDY=/usr/bin/clang-tidy')
CMAKE_OPTIONS+=('-DCMAKE_CXX_CLANG_TIDY=/usr/bin/clang-tidy')
;;
cppcheck)
# http://cppcheck.sourceforge.net/ (sudo apt install cppcheck)
if ! [ -x "$(command -v cppcheck)" ]; then
error "Can't run static analysis - cppcheck is not installed. Try: apt install cppcheck"
$ret 1
fi
# --verbose;--check-config
# -I/usr/local/include/azureiot
# -I/usr/local/include -- catch
CMAKE_OPTIONS+=('-DCMAKE_CXX_CPPCHECK=/usr/bin/cppcheck;--template=''{file}:{line}: warning: ({severity}) {message}'';--platform=unix64;--inline-suppr;--std=c++11;--enable=all;--suppress=unusedFunction;--suppress=missingIncludeSystem;--suppress=unmatchedSuppression;-I/usr/include;-I/usr/include/openssl')
CMAKE_OPTIONS+=('-DCMAKE_C_CPPCHECK=/usr/bin/cppcheck;--template=''{file}:{line}: warning: ({severity}) {message}'';--platform=unix64;--inline-suppr;--std=c99;--enable=all;--suppress=unusedFunction;--suppress=missingIncludeSystem;--suppress=unmatchedSuppression;-I/usr/include;-I/usr/include/openssl')
;;
cpplint)
# https://github.com/cpplint/cpplint (sudo pip install --system cpplint)
#
# Filters being applied currently apart from the obvious --whitespace:
# legal/copyright - All source files need copyright header which will be added if we open source ADU Agent.
# build/include - Filtering out because CppLint forces header files to be included always with the path which seems unnecessary for ADU Agent.
# build/c++11 - CppLint calls out certain header files like <chrono> and <future> since Chromium has conflicting implementations.
if ! [ -x "$(command -v cpplint)" ]; then
error "Can't run static analysis - cpplint is not installed. Try: pip install --system cpplint"
error "If you are running a build on the pipelines you MUST use PipAuthenticate@1 with the proper config"
$ret 1
fi
CMAKE_OPTIONS+=('-DCMAKE_CXX_CPPLINT=/usr/local/bin/cpplint;--filter=-whitespace,-legal/copyright,-build/include,-build/c++11')
;;
iwyu)
# https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md
if ! [ -x "$(command -v include-what-you-use)" ]; then
error "Can't run static analysis - include-what-you-use is not installed. Try: apt install iwyu"
$ret 1
fi
CMAKE_OPTIONS+=('-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=/usr/bin/include-what-you-use')
;;
lwyu)
# Built into cmake.
CMAKE_OPTIONS+=('-DCMAKE_LINK_WHAT_YOU_USE=TRUE')
;;
*)
warn "Invalid static analysis tool \e[1m'$i'\e[0m. Ignoring."
;;
esac
done
if [[ $verbose_build == "true" ]]; then
# Verbose output (very verbose, but useful!):
CMAKE_OPTIONS+=('--trace-expand')
# See cmake dependencies (very verbose):
CMAKE_OPTIONS+=('--debug-output')
# See library search output:
CMAKE_OPTIONS+=('-DCMAKE_EXE_LINKER_FLAGS=--enable-extra-pep-debug')
fi
if [[ $build_clean == "true" ]]; then
rm -rf "$output_directory"
rm -rf "${work_folder}/adu/testdata"
fi
mkdir -p "$output_directory"
pushd "$output_directory" > /dev/null || $ret
# Generate build using cmake with options
# Only reconfigure if:
# - Clean build requested
# - CMakeCache.txt doesn't exist (first-time build)
if [ ! -f "$cmake_bin" ]; then
error "No '${cmake_bin}' file."
ret_val=1
elif [[ $build_clean == "true" ]] || [[ ! -f "$output_directory/CMakeCache.txt" ]]; then
if [[ $build_clean == "true" ]]; then
echo "Configuring build (clean build requested)..."
else
echo "Configuring build (first-time configuration)..."
fi
"$cmake_bin" -G Ninja "${CMAKE_OPTIONS[@]}" "$root_dir"
ret_val=$?
else
echo "Skipping CMake reconfiguration (build already configured, use -c to force)"
ret_val=0
fi
if [ $ret_val -ne 0 ]; then
error "CMake failed to generate Ninja build with exit code: $ret_val"
else
# Do the actual building with ninja
ninja
ret_val=$?
fi
if [[ $ret_val == 0 && $build_packages == "true" ]]; then
cpack
ret_val=$?
fi
popd > /dev/null || $ret
if [[ $ret_val == 0 && $enable_coverage == "true" ]]; then
coverage_script="$script_dir/run_coverage.sh"
if [[ ! -x $coverage_script ]]; then
error "Coverage script not found or not executable: $coverage_script"
$ret 1
fi
"$coverage_script" --out-dir "$output_directory"
ret_val=$?
if [[ $ret_val == 0 ]]; then
bullet "Generating Markdown coverage report..."
python3 "$script_dir/generate_coverage_report.py" "$output_directory/coverage/Cobertura.xml" "$output_directory/coverage/coverage-report.md"
ret_val=$?
if [[ $ret_val != 0 ]]; then
error "Coverage report generation failed with exit code: $ret_val"
fi
fi
fi
if [[ $ret_val == 0 && $install_adu == "true" ]]; then
install_adu_components
fi
$ret $ret_val