forked from yidiwang21/apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apollo.sh
executable file
·907 lines (801 loc) · 25.7 KB
/
apollo.sh
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
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
#!/usr/bin/env bash
###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
#
# 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.
###############################################################################
#=================================================
# Utils
#=================================================
DISABLED_CYBER_MODULES="except //cyber/record:record_file_integration_test"
function source_apollo_base() {
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${DIR}"
source ${DIR}/scripts/apollo_base.sh $1
}
function apollo_check_system_config() {
# check docker environment
if [ ${MACHINE_ARCH} == "x86_64" ] && [ ${APOLLO_IN_DOCKER} != "true" ]; then
echo -e "${RED}Must run $0 in dev docker or release docker${NO_COLOR}"
exit 0
fi
# check operating system
OP_SYSTEM=$(uname -s)
case $OP_SYSTEM in
"Linux")
echo "System check passed. Build continue ..."
# check system configuration
DEFAULT_MEM_SIZE="2.0"
MEM_SIZE=$(free | grep Mem | awk '{printf("%0.2f", $2 / 1024.0 / 1024.0)}')
if (( $(echo "$MEM_SIZE < $DEFAULT_MEM_SIZE" | bc -l) )); then
warning "System memory [${MEM_SIZE}G] is lower than minimum required memory size [2.0G]. Apollo build could fail."
fi
;;
"Darwin")
warning "Mac OS is not officially supported in the current version. Build could fail. We recommend using Ubuntu 14.04."
;;
*)
error "Unsupported system: ${OP_SYSTEM}."
error "Please use Linux, we recommend Ubuntu 14.04."
exit 1
;;
esac
}
function check_machine_arch() {
# the machine type, currently support x86_64, aarch64
MACHINE_ARCH=$(uname -m)
# Generate WORKSPACE file based on marchine architecture
if [ "$MACHINE_ARCH" == 'x86_64' ]; then
sed "s/MACHINE_ARCH/x86_64/g" WORKSPACE.in > WORKSPACE
elif [ "$MACHINE_ARCH" == 'aarch64' ]; then
sed "s/MACHINE_ARCH/aarch64/g" WORKSPACE.in > WORKSPACE
else
fail "Unknown machine architecture $MACHINE_ARCH"
exit 1
fi
#setup vtk folder name for different systems.
VTK_VERSION=$(find /usr/include/ -type d -name "vtk-*" | tail -n1 | cut -d '-' -f 2)
sed -i "s/VTK_VERSION/${VTK_VERSION}/g" WORKSPACE
}
function check_esd_files() {
CAN_CARD="fake_can"
if [ -f ./third_party/can_card_library/esd_can/include/ntcan.h \
-a -f ./third_party/can_card_library/esd_can/lib/libntcan.so.4 \
-a -f ./third_party/can_card_library/esd_can/lib/libntcan.so.4.0.1 ]; then
USE_ESD_CAN=true
CAN_CARD="esd_can"
else
warning "ESD CAN library supplied by ESD Electronics does not exist. If you need ESD CAN, please refer to third_party/can_card_library/esd_can/README.md."
USE_ESD_CAN=false
fi
}
function generate_build_targets() {
COMMON_TARGETS="//cyber/... union //modules/common/kv_db/... union //modules/dreamview/... $DISABLED_CYBER_MODULES"
case $BUILD_FILTER in
cyber)
BUILD_TARGETS=`bazel query //cyber/... union //modules/tools/visualizer/...`
;;
drivers)
BUILD_TARGETS=`bazel query //cyber/... union //modules/tools/visualizer/... union //modules/drivers/... except //modules/drivers/tools/... except //modules/drivers/canbus/... except //modules/drivers/video/...`
;;
control)
BUILD_TARGETS=`bazel query $COMMON_TARGETS union //modules/control/... `
;;
planning)
BUILD_TARGETS=`bazel query $COMMON_TARGETS union //modules/routing/... union //modules/planning/...`
;;
prediction)
BUILD_TARGETS=`bazel query $COMMON_TARGETS union //modules/routing/... union //modules/prediction/...`
;;
pnc)
BUILD_TARGETS=`bazel query $COMMON_TARGETS union //modules/routing/... union //modules/prediction/... union //modules/planning/... union //modules/control/...`
;;
no_perception)
BUILD_TARGETS=`bazel query //modules/... except //modules/perception/... union //cyber/...`
;;
*)
# BUILD_TARGETS=`bazel query //modules/... union //cyber/...`
# FIXME(all): temporarily disable modules doesn't compile in 18.04
BUILD_TARGETS=`bazel query //modules/... union //cyber/... except //modules/tools/visualizer/... except //modules/v2x/... except //modules/map/tools/map_datachecker/... $DISABLE_CYBER_MODULES`
esac
if [ $? -ne 0 ]; then
fail 'Build failed!'
fi
if ! $USE_ESD_CAN; then
BUILD_TARGETS=$(echo $BUILD_TARGETS |tr ' ' '\n' | grep -v "esd")
fi
#skip msf for non x86_64 platforms
if [ ${MACHINE_ARCH} != "x86_64" ]; then
BUILD_TARGETS=$(echo $BUILD_TARGETS |tr ' ' '\n' | grep -v "msf")
fi
}
#=================================================
# Build functions
#=================================================
function build() {
if [ "${USE_GPU}" = "1" ] ; then
echo -e "${YELLOW}Running build under GPU mode. GPU is required to run the build.${NO_COLOR}"
else
echo -e "${YELLOW}Running build under CPU mode. No GPU is required to run the build.${NO_COLOR}"
fi
info "Start building, please wait ..."
generate_build_targets
info "Building on $MACHINE_ARCH..."
MACHINE_ARCH=$(uname -m)
JOB_ARG="--jobs=$(nproc) --ram_utilization_factor 80"
if [ "$MACHINE_ARCH" == 'aarch64' ]; then
JOB_ARG="--jobs=3"
fi
info "Building with $JOB_ARG for $MACHINE_ARCH"
bazel build $JOB_ARG $DEFINES -c $@ $BUILD_TARGETS
if [ ${PIPESTATUS[0]} -ne 0 ]; then
fail 'Build failed!'
fi
# Build python proto
build_py_proto
# Clear KV DB and update commit_id after compiling.
if [ "$BUILD_FILTER" == 'cyber' ] || [ "$BUILD_FILTER" == 'drivers' ]; then
info "Skipping revision recording"
else
bazel build $JOB_ARG $DEFINES -c $@ $BUILD_TARGETS
if [ ${PIPESTATUS[0]} -ne 0 ]; then
fail 'Build failed!'
fi
rm -fr data/kv_db*
REVISION=$(get_revision)
./bazel-bin/modules/common/kv_db/kv_db_tool --op=put \
--key="apollo:data:commit_id" --value="$REVISION"
fi
if [ -d /apollo-simulator ] && [ -e /apollo-simulator/build.sh ]; then
cd /apollo-simulator && bash build.sh build
if [ $? -ne 0 ]; then
fail 'Build failed!'
fi
fi
if [ $? -eq 0 ]; then
success 'Build passed!'
else
fail 'Build failed'
fi
}
function cibuild_extended() {
info "Building framework ..."
cd /apollo
info "Building modules ..."
JOB_ARG="--jobs=12"
if [ "$MACHINE_ARCH" == 'aarch64' ]; then
JOB_ARG="--jobs=3"
fi
info "Building with $JOB_ARG for $MACHINE_ARCH"
# FIXME(all): temporarily disable modules doesn't compile in 18.04
BUILD_TARGETS=`
bazel query //cyber/... \
union //modules/perception/... \
union //modules/dreamview/... \
union //modules/drivers/radar/conti_radar/... \
union //modules/drivers/radar/racobit_radar/... \
union //modules/drivers/radar/ultrasonic_radar/... \
union //modules/drivers/gnss/... \
union //modules/drivers/velodyne/... \
union //modules/drivers/camera/... \
union //modules/guardian/... \
union //modules/localization/... \
union //modules/map/... \
union //modules/third_party_perception/... \
except //modules/map/tools/map_datachecker/...
`
bazel build $JOB_ARG $DEFINES $@ $BUILD_TARGETS
if [ $? -eq 0 ]; then
success 'Build passed!'
else
fail 'Build failed!'
fi
}
function cibuild() {
info "Building framework ..."
cd /apollo
info "Building modules ..."
JOB_ARG="--jobs=12"
if [ "$MACHINE_ARCH" == 'aarch64' ]; then
JOB_ARG="--jobs=3"
fi
info "Building with $JOB_ARG for $MACHINE_ARCH"
BUILD_TARGETS="
//modules/canbus/...
//modules/common/...
//modules/control/...
//modules/planning/...
//modules/prediction/...
//modules/routing/...
//modules/transform/..."
# The data module is lightweight and rarely changed. If it fails, it's
# most-likely an environment mess. So we try `bazel clean` and then initial
# the building process.
bazel build $JOB_ARG $DEFINES $@ "//modules/data/..." || bazel clean
bazel build $JOB_ARG $DEFINES $@ $BUILD_TARGETS
if [ $? -eq 0 ]; then
success 'Build passed!'
else
fail 'Build failed!'
fi
}
function apollo_build_dbg() {
build "dbg" $@
}
function apollo_build_opt() {
build "opt" $@
}
function build_py_proto() {
if [ -d "./py_proto" ];then
rm -rf py_proto
fi
mkdir py_proto
find modules/ cyber/ -name "*.proto" \
| grep -v node_modules \
| xargs protoc --python_out=py_proto
find py_proto/* -type d -exec touch "{}/__init__.py" \;
}
function check() {
bash $0 build && bash $0 "test" && bash $0 lint
if [ $? -eq 0 ]; then
success 'Check passed!'
return 0
else
fail 'Check failed!'
return 1
fi
}
function warn_proprietary_sw() {
echo -e "${RED}The release built contains proprietary software provided by other parties.${NO_COLOR}"
echo -e "${RED}Make sure you have obtained proper licensing agreement for redistribution${NO_COLOR}"
echo -e "${RED}if you intend to publish the release package built.${NO_COLOR}"
echo -e "${RED}Such licensing agreement is solely between you and the other parties,${NO_COLOR}"
echo -e "${RED}and is not covered by the license terms of the apollo project${NO_COLOR}"
echo -e "${RED}(see file license).${NO_COLOR}"
}
function release() {
RELEASE_DIR="${HOME}/.cache/apollo_release"
if [ -d "${RELEASE_DIR}" ]; then
rm -rf "${RELEASE_DIR}"
fi
APOLLO_RELEASE_DIR="${RELEASE_DIR}/apollo"
mkdir -p "${APOLLO_RELEASE_DIR}"
# cp built dynamic libraries
LIBS=$(find bazel-out/* -name "*.so" )
for LIB in ${LIBS}; do
cp -a --parent ${LIB} ${APOLLO_RELEASE_DIR}
done
mkdir ${APOLLO_RELEASE_DIR}/bazel-bin
mv ${APOLLO_RELEASE_DIR}/bazel-out/local-opt/bin/* ${APOLLO_RELEASE_DIR}/bazel-bin/
rm -rf ${APOLLO_RELEASE_DIR}/bazel-out
# reset softlinks
cd ${APOLLO_RELEASE_DIR}/bazel-bin
LIST=("_solib_k8")
for DIR in "${LIST[@]}"; do
LINKS=$(find ${DIR}/* -name "*.so" -type l | sed '/.*@.*/d')
for LINK in $LINKS; do
LIB=$(echo $LINK | sed 's/_S/\//g' | sed 's/_U/_/g')
if [[ $LIB == *"_solib_k8/lib"* ]]; then
LIB="/apollo/bazel-bin/$(echo $LIB | awk -F "_solib_k8/lib" '{print $NF}')"
elif [[ $LIB == *"___"* ]]; then
LIB="/apollo/bazel-bin/$(echo $LIB | awk -F "___" '{print $NF}')"
else
LIB="/apollo/bazel-bin/$(echo $LIB | awk -F "apollo/" '{print $NF}')"
fi
ln -sf $LIB $LINK
done
done
cd -
# setup cyber binaries and convert from //path:target to path/target
CYBERBIN=$(bazel query "kind(cc_binary, //cyber/... //modules/tools/visualizer/...)" | sed 's/^\/\///' | sed 's/:/\//' | sed '/.*.so$/d')
for BIN in ${CYBERBIN}; do
cp -P --parent "bazel-bin/${BIN}" ${APOLLO_RELEASE_DIR}
done
cp --parent "cyber/setup.bash" "${APOLLO_RELEASE_DIR}"
cp --parent -a "cyber/tools/cyber_launch" "${APOLLO_RELEASE_DIR}"
cp --parent -a "cyber/tools/cyber_tools_auto_complete.bash" "${APOLLO_RELEASE_DIR}"
cp --parent -a "cyber/python" "${APOLLO_RELEASE_DIR}"
# setup tools
TOOLSBIN=$(bazel query "kind(cc_binary, //modules/tools/...)" | sed 's/^\/\///' | sed 's/:/\//' | sed '/.*.so$/d')
for BIN in ${TOOLSBIN}; do
cp -P --parent "bazel-bin/${BIN}" ${APOLLO_RELEASE_DIR}
done
TOOLSPY=$(find modules/tools/* -name "*.py")
for PY in ${TOOLSPY}; do
cp -P --parent "${PY}" "${APOLLO_RELEASE_DIR}/bazel-bin"
done
# modules data, conf and dag
CONFS=$(find modules/ cyber/ -name "conf")
DATAS=$(find modules/ -name "data" | grep -v "testdata")
DAGS=$(find modules/ -name "dag")
LAUNCHS=$(find modules/ -name "launch")
PARAMS=$(find modules/ -name "params" | grep -v "testdata")
rm -rf test/*
for CONF in $CONFS; do
cp -P --parent -a "${CONF}" "${APOLLO_RELEASE_DIR}"
done
for DATA in $DATAS; do
if [[ $DATA != *"map"* ]]; then
cp -P --parent -a "${DATA}" "${APOLLO_RELEASE_DIR}"
fi
done
for DAG in $DAGS; do
cp -P --parent -a "${DAG}" "${APOLLO_RELEASE_DIR}"
done
for LAUNCH in $LAUNCHS; do
cp -P --parent -a "${LAUNCH}" "${APOLLO_RELEASE_DIR}"
done
for PARAM in $PARAMS; do
cp -P --parent -a "${PARAM}" "${APOLLO_RELEASE_DIR}"
done
# perception model
MODEL="modules/perception/model"
cp -P --parent -a "${MODEL}" "${APOLLO_RELEASE_DIR}"
# dreamview frontend
cp -a modules/dreamview/frontend $APOLLO_RELEASE_DIR/modules/dreamview
# remove all pyc file in modules/
find modules/ -name "*.pyc" | xargs -I {} rm {}
# scripts
cp -r scripts ${APOLLO_RELEASE_DIR}
# manual traffic light tool
mkdir -p ${APOLLO_RELEASE_DIR}/modules/tools
cp -r modules/tools/manual_traffic_light ${APOLLO_RELEASE_DIR}/modules/tools
# remove mounted models
rm -rf ${APOLLO_RELEASE_DIR}/modules/perception/model/yolo_camera_detector/
# lib
LIB_DIR="${APOLLO_RELEASE_DIR}/lib"
mkdir "${LIB_DIR}"
if $USE_ESD_CAN; then
warn_proprietary_sw
fi
THIRDLIBS=$(find third_party/* -name "*.so*")
for LIB in ${THIRDLIBS}; do
cp -a "${LIB}" $LIB_DIR
done
cp -r py_proto/modules $LIB_DIR
# doc
cp LICENSE "${APOLLO_RELEASE_DIR}"
cp third_party/ACKNOWLEDGEMENT.txt "${APOLLO_RELEASE_DIR}"
# release info
META="${APOLLO_RELEASE_DIR}/meta.ini"
echo "git_commit: $(get_revision)" >> $META
echo "git_branch: $(get_branch)" >> $META
echo "car_type: LINCOLN.MKZ" >> $META
echo "arch: ${MACHINE_ARCH}" >> $META
}
function gen_coverage() {
bazel clean
generate_build_targets
echo "$BUILD_TARGETS" | grep -v "cnn_segmentation_test" | xargs bazel test $DEFINES -c dbg --config=coverage $@
if [ $? -ne 0 ]; then
fail 'run test failed!'
fi
COV_DIR=data/cov
rm -rf $COV_DIR
files=$(find bazel-out/local-dbg/bin/ -iname "*.gcda" -o -iname "*.gcno" | grep -v external | grep -v third_party)
for f in $files; do
if [ "$f" != "${f##*cyber}" ]; then
target="$COV_DIR/objs/cyber${f##*cyber}"
else
target="$COV_DIR/objs/modules${f##*modules}"
fi
mkdir -p "$(dirname "$target")"
cp "$f" "$target"
done
lcov --rc lcov_branch_coverage=1 --base-directory "/apollo/bazel-apollo" --capture --directory "$COV_DIR/objs" --output-file "$COV_DIR/conv.info"
if [ $? -ne 0 ]; then
fail 'lcov failed!'
fi
lcov --rc lcov_branch_coverage=1 --remove "$COV_DIR/conv.info" \
"external/*" \
"/usr/*" \
"bazel-out/*" \
"*third_party/*" \
"tools/*" \
-o $COV_DIR/stripped_conv.info
genhtml $COV_DIR/stripped_conv.info --output-directory $COV_DIR/report
echo "Generated coverage report in $COV_DIR/report/index.html"
}
function run_test() {
JOB_ARG="--jobs=$(nproc) --ram_utilization_factor 80"
generate_build_targets
if [ "$USE_GPU" == "1" ]; then
echo -e "${YELLOW}Running tests under GPU mode. GPU is required to run the tests.${NO_COLOR}"
bazel test $DEFINES $JOB_ARG --config=unit_test -c dbg --test_verbose_timeout_warnings $@ $BUILD_TARGETS
else
echo -e "${YELLOW}Running tests under CPU mode. No GPU is required to run the tests.${NO_COLOR}"
BUILD_TARGETS="`echo "$BUILD_TARGETS" | grep -v "cnn_segmentation_test\|yolo_camera_detector_test\|unity_recognize_test\|perception_traffic_light_rectify_test\|cuda_util_test"`"
bazel test $DEFINES $JOB_ARG --config=unit_test -c dbg --test_verbose_timeout_warnings $@ $BUILD_TARGETS
fi
if [ $? -ne 0 ]; then
fail 'Test failed!'
return 1
fi
if [ $? -eq 0 ]; then
success 'Test passed!'
return 0
fi
}
function citest_basic() {
set -e
info "Building framework ..."
cd /apollo
source cyber/setup.bash
# FIXME(all): temporarily disable modules doesn't compile in 18.04
# BUILD_TARGETS="
# `bazel query //modules/... union //cyber/...`
# "
BUILD_TARGETS=`bazel query //modules/... union //cyber/... except //modules/tools/visualizer/... except //modules/v2x/... except //modules/drivers/video/tools/decode_video/... except //modules/map/tools/map_datachecker/... `
JOB_ARG="--jobs=12 --ram_utilization_factor 80"
BUILD_TARGETS="`echo "$BUILD_TARGETS" | grep "modules\/" | grep "test" \
| grep -v "modules\/planning" \
| grep -v "modules\/prediction" \
| grep -v "modules\/control" \
| grep -v "modules\/common" \
| grep -v "can_client" \
| grep -v "blob_test" \
| grep -v "pyramid_map" \
| grep -v "ndt_lidar_locator_test" \
| grep -v "syncedmem_test" | grep -v "blob_test" \
| grep -v "perception_inference_operators_test" \
| grep -v "cuda_util_test" \
| grep -v "modules\/perception"`"
bazel test $DEFINES $JOB_ARG --config=unit_test -c dbg --test_verbose_timeout_warnings $@ $BUILD_TARGETS
if [ $? -eq 0 ]; then
success 'Test passed!'
return 0
else
fail 'Test failed!'
return 1
fi
}
function citest_extended() {
set -e
info "Building framework ..."
cd /apollo
source cyber/setup.bash
BUILD_TARGETS="
`bazel query //modules/planning/... union //modules/common/... union //cyber/... $DISABLED_CYBER_MODULES`
`bazel query //modules/prediction/... union //modules/control/...`
"
JOB_ARG="--jobs=12 --ram_utilization_factor 80"
BUILD_TARGETS="`echo "$BUILD_TARGETS" | grep "test"`"
bazel test $DEFINES $JOB_ARG --config=unit_test -c dbg --test_verbose_timeout_warnings $@ $BUILD_TARGETS
if [ $? -eq 0 ]; then
success 'Test passed!'
return 0
else
fail 'Test failed!'
return 1
fi
}
function citest() {
info "Building framework ..."
cd /apollo
source cyber/setup.bash
citest_basic
citest_extended
if [ $? -eq 0 ]; then
success 'Test passed!'
return 0
else
fail 'Test failed!'
return 1
fi
}
function run_cpp_lint() {
BUILD_TARGETS="`bazel query //modules/... except //modules/tools/visualizer/... union //cyber/...`"
bazel test --config=cpplint -c dbg $BUILD_TARGETS
}
function run_bash_lint() {
FILES=$(find "${APOLLO_ROOT_DIR}" -type f -name "*.sh" | grep -v ros)
echo "${FILES}" | xargs shellcheck
}
function run_lint() {
# Add cpplint rule to BUILD files that do not contain it.
for file in $(find cyber modules -name BUILD | \
grep -v gnss/third_party | grep -v modules/teleop/encoder/nvenc_sdk6 | \
xargs grep -l -E 'cc_library|cc_test|cc_binary' | xargs grep -L 'cpplint()')
do
sed -i '1i\load("//tools:cpplint.bzl", "cpplint")\n' $file
sed -i -e '$a\\ncpplint()' $file
done
run_cpp_lint
if [ $? -eq 0 ]; then
success 'Lint passed!'
else
fail 'Lint failed!'
fi
}
function clean() {
# Remove bazel cache.
bazel clean --async
# Remove bazel cache in associated directories
if [ -d /apollo-simulator ]; then
cd /apollo-simulator && bazel clean --async
fi
# Remove cmake cache.
rm -fr framework/build
}
function buildify() {
local buildifier_url=https://github.com/bazelbuild/buildtools/releases/download/0.4.5/buildifier
wget $buildifier_url -O ~/.buildifier
chmod +x ~/.buildifier
find . -name '*BUILD' -type f -exec ~/.buildifier -showlog -mode=fix {} +
if [ $? -eq 0 ]; then
success 'Buildify worked!'
else
fail 'Buildify failed!'
fi
rm ~/.buildifier
}
function build_fe() {
cd modules/dreamview/frontend
yarn build
}
function gen_doc() {
rm -rf docs/doxygen
doxygen apollo.doxygen
}
function version() {
rev=$(get_revision)
if [ "$rev" = "unknown" ];then
echo "Version: $rev"
return
fi
commit=$(git log -1 --pretty=%H)
date=$(git log -1 --pretty=%cd)
echo "Commit: ${commit}"
echo "Date: ${date}"
}
function get_revision() {
git rev-parse --is-inside-work-tree &> /dev/null
if [ $? = 0 ];then
REVISION=$(git rev-parse HEAD)
else
warning "Could not get the version number, maybe this is not a git work tree." >&2
REVISION="unknown"
fi
echo "$REVISION"
}
function get_branch() {
git branch &> /dev/null
if [ $? = 0 ];then
BRANCH=$(git rev-parse --abbrev-ref HEAD)
else
warning "Could not get the branch name, maybe this is not a git work tree." >&2
BRANCH="unknown"
fi
echo "$BRANCH"
}
function config() {
${APOLLO_ROOT_DIR}/scripts/configurator.sh
}
function set_use_gpu() {
if [ "${USE_GPU}" = "1" ] ; then
DEFINES="${DEFINES} --define USE_GPU=true"
else
DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
fi
}
function print_usage() {
RED='\033[0;31m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NONE='\033[0m'
echo -e "\n${RED}Usage${NONE}:
.${BOLD}/apollo.sh${NONE} [OPTION]"
echo -e "\n${RED}Options${NONE}:
${BLUE}build${NONE}: run build only
${BLUE}build_opt${NONE}: build optimized binary for the code
${BLUE}build_cpu${NONE}: dbg build with CPU
${BLUE}build_gpu${NONE}: run build only with Caffe GPU mode support
${BLUE}build_opt_gpu${NONE}: build optimized binary with Caffe GPU mode support
${BLUE}build_fe${NONE}: compile frontend javascript code, this requires all the node_modules to be installed already
${BLUE}build_cyber [dbg|opt]${NONE}: build Cyber RT only
${BLUE}build_drivers [dbg|opt]${NONE}: build drivers only
${BLUE}build_planning${NONE}: compile planning and its dependencies.
${BLUE}build_control${NONE}: compile control and its dependencies.
${BLUE}build_prediction${NONE}: compile prediction and its dependencies.
${BLUE}build_pnc${NONE}: compile pnc and its dependencies.
${BLUE}build_no_perception [dbg|opt]${NONE}: run build, skip building perception module, useful when some perception dependencies are not satisfied, e.g., CUDA, CUDNN, LIDAR, etc.
${BLUE}build_prof${NONE}: build for gprof support.
${BLUE}buildify${NONE}: fix style of BUILD files
${BLUE}check${NONE}: run build/lint/test, please make sure it passes before checking in new code
${BLUE}clean${NONE}: run Bazel clean
${BLUE}config${NONE}: run configurator tool
${BLUE}coverage${NONE}: generate test coverage report
${BLUE}doc${NONE}: generate doxygen document
${BLUE}lint${NONE}: run code style check
${BLUE}usage${NONE}: print this menu
${BLUE}release${NONE}: build release version
${BLUE}test${NONE}: run all unit tests
${BLUE}version${NONE}: display current commit and date
"
}
function main() {
source_apollo_base
check_machine_arch
apollo_check_system_config
check_esd_files
DEFINES="--define ARCH=${MACHINE_ARCH} --define CAN_CARD=${CAN_CARD} --cxxopt=-DUSE_ESD_CAN=${USE_ESD_CAN}"
# Enable bazel's feature to compute md5 checksums in parallel
DEFINES="${DEFINES} --experimental_multi_threaded_digest"
if [ ${MACHINE_ARCH} == "x86_64" ]; then
DEFINES="${DEFINES} --copt=-mavx2"
fi
local cmd=$1
shift
START_TIME=$(get_now)
case $cmd in
check)
DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
check $@
;;
build)
set_use_gpu
apollo_build_dbg $@
;;
build_cpu)
DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
apollo_build_dbg $@
;;
build_prof)
DEFINES="${DEFINES} --config=cpu_prof --cxxopt=-DCPU_ONLY"
apollo_build_dbg $@
;;
build_no_perception)
DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
BUILD_FILTER="no_perception"
if [ "$1" == "opt" ]; then
shift
apollo_build_opt $@
else
shift
apollo_build_dbg $@
fi
;;
clean_cyber)
export LD_PRELOAD=
clean
;;
build_cyber)
export LD_PRELOAD=
BUILD_FILTER="cyber"
if [ "$1" == "opt" ]; then
shift
apollo_build_opt $@
else
shift
apollo_build_dbg $@
fi
;;
build_drivers)
export LD_PRELOAD=
BUILD_FILTER="drivers"
if [ "$1" == "opt" ]; then
shift
apollo_build_opt $@
else
shift
apollo_build_dbg $@
fi
;;
build_control)
BUILD_FILTER="control"
apollo_build_dbg $@
;;
build_planning)
BUILD_FILTER="planning"
apollo_build_dbg $@
;;
build_prediction)
BUILD_FILTER="prediction"
apollo_build_dbg $@
;;
build_pnc)
BUILD_FILTER="pnc"
apollo_build_dbg $@
;;
cibuild)
DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
cibuild $@
;;
cibuild_extended)
DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
cibuild_extended $@
;;
build_opt)
DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY --copt=-fpic"
apollo_build_opt $@
;;
build_gpu)
set_use_gpu
apollo_build_dbg $@
;;
build_opt_gpu)
set_use_gpu
DEFINES="${DEFINES} --copt=-fpic"
apollo_build_opt $@
;;
build_teleop)
set_use_gpu
DEFINES="${DEFINES} --copt=-fpic --define WITH_TELEOP=1 --cxxopt=-DTELEOP"
apollo_build_opt $@
;;
build_fe)
build_fe
;;
buildify)
buildify
;;
build_py)
build_py_proto
;;
config)
config
;;
doc)
gen_doc
;;
lint)
run_lint
;;
test)
set_use_gpu
run_test $@
;;
test_cpu)
DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
run_test $@
;;
citest)
DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
citest $@
;;
citest_basic)
DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
citest_basic $@
;;
citest_extended)
DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
citest_extended $@
;;
test_gpu)
set_use_gpu
run_test $@
;;
release)
release 1
;;
release_noproprietary)
release 0
;;
coverage)
gen_coverage $@
;;
clean)
clean
;;
version)
version
;;
usage)
print_usage
;;
*)
print_usage
;;
esac
}
main $@