apollo.sh 19.2 KB
Newer Older
D
Dong Li 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/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
#=================================================

S
siyangy 已提交
23 24 25
function source_apollo_base() {
  DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  cd "${DIR}"
D
Dong Li 已提交
26

S
siyangy 已提交
27 28
  source "${DIR}/scripts/apollo_base.sh"
}
29 30 31

function apollo_check_system_config() {
  # check operating system
32
  OP_SYSTEM=$(uname -s)
33
  case $OP_SYSTEM in
34 35
    "Linux")
      echo "System check passed. Build continue ..."
36 37 38 39 40 41 42

      # 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
43 44 45 46
      ;;
    "Darwin")
      warning "Mac OS is not officially supported in the current version. Build could fail. We recommend using Ubuntu 14.04."
      ;;
47
    *)
48 49 50 51
      error "Unsupported system: ${OP_SYSTEM}."
      error "Please use Linux, we recommend Ubuntu 14.04."
      exit 1
      ;;
52 53 54
  esac
}

S
siyangy 已提交
55 56 57
function check_machine_arch() {
  # the machine type, currently support x86_64, aarch64
  MACHINE_ARCH=$(uname -m)
D
Dong Li 已提交
58

S
siyangy 已提交
59 60 61 62 63 64 65 66 67
  # 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
68 69 70

  #setup vtk folder name for different systems.
  VTK_VERSION=$(find /usr/include/ -type d  -name "vtk-*" | cut -d '-' -f 2)
71
  sed -i "s/VTK_VERSION/${VTK_VERSION}/g" WORKSPACE
S
siyangy 已提交
72
}
D
Dong Li 已提交
73 74

function check_esd_files() {
S
siyangy 已提交
75 76
  CAN_CARD="fake_can"

D
Dong Li 已提交
77 78 79 80
  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
L
Lei Wang 已提交
81
      CAN_CARD="esd_can"
D
Dong Li 已提交
82
  else
83
      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."
D
Dong Li 已提交
84 85 86 87 88
      USE_ESD_CAN=false
  fi
}

function generate_build_targets() {
S
siyangy 已提交
89
  if [ -z $NOT_BUILD_PERCEPTION ] ; then
90 91 92
    BUILD_TARGETS=`bazel query //...`
  else
    info 'Skip building perception module!'
L
Lei Wang 已提交
93
    BUILD_TARGETS=`bazel query //... except //modules/perception/... except //modules/calibration/lidar_ex_checker/...`
94 95
  fi

C
Calvin Miao 已提交
96 97 98
  if [ $? -ne 0 ]; then
    fail 'Build failed!'
  fi
D
Dong Li 已提交
99
  if ! $USE_ESD_CAN; then
Q
Qi Luo 已提交
100
     BUILD_TARGETS=$(echo $BUILD_TARGETS |tr ' ' '\n' | grep -v "modules\/monitor\/hwmonitor\/hw\/esdcan" | grep -v "esd")
D
Dong Li 已提交
101 102 103 104 105 106 107
  fi
}

#=================================================
#              Build functions
#=================================================

S
siyangy 已提交
108
function build() {
S
siyangy 已提交
109
  START_TIME=$(get_now)
D
Dong Li 已提交
110

111
  info "Start building, please wait ..."
D
Dong Li 已提交
112
  generate_build_targets
113 114
  info "Building on $MACHINE_ARCH..."

115 116 117 118 119 120
  MACHINE_ARCH=$(uname -m)
  JOB_ARG=""
  if [ "$MACHINE_ARCH" == 'aarch64' ]; then
    JOB_ARG="--jobs=3"
  fi
  echo "$BUILD_TARGETS" | xargs bazel build $JOB_ARG $DEFINES -c $@
D
Dong Li 已提交
121 122 123 124 125
  if [ $? -eq 0 ]; then
    success 'Build passed!'
  else
    fail 'Build failed!'
  fi
S
siyangy 已提交
126 127

  # Build python proto
L
Lei Wang 已提交
128
  build_py_proto
129

130
  # Update task info template on compiling.
A
Aaron Xiao 已提交
131
  bazel-bin/modules/data/util/update_task_info --commit_id=$(git rev-parse HEAD)
D
Dong Li 已提交
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
function cibuild() {
  START_TIME=$(get_now)

  echo "Start building, please wait ..."
  generate_build_targets
  echo "Building on $MACHINE_ARCH..."
  BUILD_TARGETS="
  //modules/control
  //modules/dreamview
  //modules/localization
  //modules/perception
  //modules/planning
  //modules/prediction
  //modules/routing
  "
  bazel build $DEFINES -c dbg $@ $BUILD_TARGETS
  if [ $? -eq 0 ]; then
    success 'Build passed!'
  else
    fail 'Build failed!'
  fi
}

157
function apollo_build_dbg() {
158
  build "dbg" $@
S
siyangy 已提交
159 160
}

161
function apollo_build_opt() {
162
  build "opt" $@
S
siyangy 已提交
163 164
}

L
Lei Wang 已提交
165 166 167 168 169 170
function build_py_proto() {
  if [ -d "./py_proto" ];then
    rm -rf py_proto
  fi
  mkdir py_proto
  PROTOC='./bazel-out/host/bin/external/com_google_protobuf/protoc'
171 172 173
  find modules/ -name "*.proto" \
      | grep -v modules/drivers/gnss \
      | xargs ${PROTOC} --python_out=py_proto
L
Lei Wang 已提交
174 175 176
  find py_proto/* -type d -exec touch "{}/__init__.py" \;
}

D
Dong Li 已提交
177
function check() {
S
siyangy 已提交
178
  local check_start_time=$(get_now)
179
  apollo_build_dbg $@ && run_test && run_lint
D
Dong Li 已提交
180 181 182 183 184 185 186 187 188 189 190 191

  START_TIME=$check_start_time
  if [ $? -eq 0 ]; then
    success 'Check passed!'
    return 0
  else
    fail 'Check failed!'
    return 1
  fi
}

function warn_proprietary_sw() {
192 193 194 195 196 197
  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}"
D
Dong Li 已提交
198 199 200
}

function release() {
L
Lei Wang 已提交
201 202 203
  RELEASE_DIR=$HOME/.cache/release
  if [ -d $RELEASE_DIR ];then
    rm -rf $RELEASE_DIR
204
  fi
L
Lei Wang 已提交
205
  mkdir -p $RELEASE_DIR
D
Dong Li 已提交
206

S
siyangy 已提交
207
  # modules
L
Lei Wang 已提交
208
  MODULES_DIR=$RELEASE_DIR/modules
D
Dong Li 已提交
209
  mkdir -p $MODULES_DIR
J
Jiangtao Hu 已提交
210
  for m in control canbus localization decision perception \
211
       prediction planning routing calibration third_party_perception monitor
D
Dong Li 已提交
212 213 214
  do
    TARGET_DIR=$MODULES_DIR/$m
    mkdir -p $TARGET_DIR
J
Jiangtao Hu 已提交
215 216 217
     if [ -e bazel-bin/modules/$m/$m ]; then
         cp bazel-bin/modules/$m/$m $TARGET_DIR
     fi
D
Dong Li 已提交
218 219 220 221
    if [ -d modules/$m/conf ];then
        cp -r modules/$m/conf $TARGET_DIR
    fi
    if [ -d modules/$m/data ];then
222
        cp -r modules/$m/data $TARGET_DIR
D
Dong Li 已提交
223 224
    fi
  done
S
siyangy 已提交
225 226

  # control tools
D
Dong Li 已提交
227 228
  mkdir $MODULES_DIR/control/tools
  cp bazel-bin/modules/control/tools/pad_terminal $MODULES_DIR/control/tools
S
siyangy 已提交
229

230
  # remove all pyc file in modules/
D
Dong Li 已提交
231 232
  find modules/ -name "*.pyc" | xargs -I {} rm {}
  cp -r modules/tools $MODULES_DIR
S
siyangy 已提交
233 234

  # ros
L
Lei Wang 已提交
235 236
  cp -Lr bazel-apollo/external/ros $RELEASE_DIR/
  rm -f ${RELEASE_DIR}/ros/*.tar.gz
S
siyangy 已提交
237 238

  # scripts
L
Lei Wang 已提交
239
  cp -r scripts $RELEASE_DIR
S
siyangy 已提交
240

D
Dong Li 已提交
241 242 243
  #dreamview
  cp -Lr bazel-bin/modules/dreamview/dreamview.runfiles/apollo/modules/dreamview $MODULES_DIR
  cp -r modules/dreamview/conf $MODULES_DIR/dreamview
S
siyangy 已提交
244

245 246 247 248
  # map
  mkdir $MODULES_DIR/map
  cp -r modules/map/data $MODULES_DIR/map

S
siyangy 已提交
249
  # common data
D
Dong Li 已提交
250 251
  mkdir $MODULES_DIR/common
  cp -r modules/common/data $MODULES_DIR/common
S
siyangy 已提交
252

L
Lei Wang 已提交
253 254 255
  # perception
  cp -r modules/perception/model/ $MODULES_DIR/perception

L
Lei Wang 已提交
256 257 258 259
  # gnss config
  mkdir -p $MODULES_DIR/drivers/gnss
  cp -r modules/drivers/gnss/conf/ $MODULES_DIR/drivers/gnss

L
Lei Wang 已提交
260 261 262 263
  # velodyne launch
  mkdir -p $MODULES_DIR/drivers/velodyne/velodyne
  cp -r modules/drivers/velodyne/velodyne/launch $MODULES_DIR/drivers/velodyne/velodyne

Y
yibingl 已提交
264 265 266 267
  # usb_cam launch
  mkdir -p $MODULES_DIR/drivers/usb_cam
  cp -r modules/drivers/usb_cam/launch $MODULES_DIR/drivers/usb_cam

D
Dong Li 已提交
268
  # lib
L
Lei Wang 已提交
269
  LIB_DIR=$RELEASE_DIR/lib
D
Dong Li 已提交
270 271
  mkdir $LIB_DIR
  if $USE_ESD_CAN; then
L
Lei Wang 已提交
272
    warn_proprietary_sw
D
Dong Li 已提交
273 274 275 276 277
    for m in esd_can
    do
        cp third_party/can_card_library/$m/lib/* $LIB_DIR
    done
  fi
L
Lei Wang 已提交
278 279
  cp -r bazel-genfiles/external $LIB_DIR
  cp -r py_proto/modules $LIB_DIR
280

D
Dong Li 已提交
281
  # doc
L
Lei Wang 已提交
282 283 284
  cp -r docs $RELEASE_DIR
  cp LICENSE $RELEASE_DIR
  cp third_party/ACKNOWLEDGEMENT.txt $RELEASE_DIR
S
siyangy 已提交
285

286 287 288 289 290 291 292 293
  # mobileye drivers
  mkdir -p $MODULES_DIR/drivers/delphi_esr
  cp bazel-bin/modules/drivers/delphi_esr/delphi_esr $MODULES_DIR/drivers/delphi_esr
  cp -r modules/drivers/delphi_esr/conf $MODULES_DIR/drivers/delphi_esr
  mkdir -p $MODULES_DIR/drivers/mobileye
  cp bazel-bin/modules/drivers/mobileye/mobileye $MODULES_DIR/drivers/mobileye
  cp -r modules/drivers/mobileye/conf  $MODULES_DIR/drivers/mobileye

L
Lei Wang 已提交
294 295 296 297 298
  # conti_radar
  mkdir -p $MODULES_DIR/drivers/conti_radar
  cp bazel-bin/modules/drivers/conti_radar/conti_radar $MODULES_DIR/drivers/conti_radar
  cp -r modules/drivers/conti_radar/conf $MODULES_DIR/drivers/conti_radar

S
siyangy 已提交
299
  # release info
L
Lei Wang 已提交
300 301 302 303 304
  META=${RELEASE_DIR}/meta.ini
  echo "[Release]" > $META
  echo "git_commit: $(git rev-parse HEAD)" >> $META
  echo "car_type : LINCOLN.MKZ" >> $META
  echo "arch : ${MACHINE_ARCH}" >> $META
D
Dong Li 已提交
305 306 307 308
}

function gen_coverage() {
  bazel clean
309
  generate_build_targets
L
Lei Wang 已提交
310
  echo "$BUILD_TARGETS" | grep -v "cnn_segmentation_test" | xargs bazel test $DEFINES -c dbg --config=coverage $@
D
Dong Li 已提交
311 312 313
  if [ $? -ne 0 ]; then
    fail 'run test failed!'
  fi
S
siyangy 已提交
314

D
Dong Li 已提交
315 316 317 318 319 320 321 322
  COV_DIR=data/cov
  rm -rf $COV_DIR
  files=$(find bazel-out/local-dbg/bin/modules/ -iname "*.gcda" -o -iname "*.gcno" | grep -v external)
  for f in $files; do
    target="$COV_DIR/objs/modules/${f##*modules}"
    mkdir -p "$(dirname "$target")"
    cp "$f" "$target"
  done
323 324 325 326 327 328 329 330

  files=$(find bazel-out/local-opt/bin/modules/ -iname "*.gcda" -o -iname "*.gcno" | grep -v external)
  for f in $files; do
    target="$COV_DIR/objs/modules/${f##*modules}"
    mkdir -p "$(dirname "$target")"
    cp "$f" "$target"
  done

D
Dong Li 已提交
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
  lcov --capture --directory "$COV_DIR/objs" --output-file "$COV_DIR/conv.info"
  if [ $? -ne 0 ]; then
    fail 'lcov failed!'
  fi
  lcov --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() {
S
siyangy 已提交
347
  START_TIME=$(get_now)
D
Dong Li 已提交
348

349
  generate_build_targets
350 351
  if [ "$USE_GPU" == "1" ]; then
    echo -e "${RED}Need GPU to run the tests.${NO_COLOR}"
L
Lei Wang 已提交
352
    echo "$BUILD_TARGETS" | xargs bazel test $DEFINES --config=unit_test -c dbg --test_verbose_timeout_warnings $@
353
  else
L
Lei Wang 已提交
354
    echo "$BUILD_TARGETS" | grep -v "cnn_segmentation_test" | xargs bazel test $DEFINES --config=unit_test -c dbg --test_verbose_timeout_warnings $@
355
  fi
S
siyangy 已提交
356
  if [ $? -eq 0 ]; then
D
Dong Li 已提交
357 358 359 360 361 362 363 364
    success 'Test passed!'
    return 0
  else
    fail 'Test failed!'
    return 1
  fi
}

365 366 367 368 369 370 371
function citest() {
  START_TIME=$(get_now)
  BUILD_TARGETS="
  //modules/planning/integration_tests:garage_test
  //modules/planning/integration_tests:sunnyvale_loop_test
  //modules/control/integration_tests:simple_control_test
  //modules/prediction/container/obstacles:obstacle_test
372
  //modules/dreamview/backend/simulation_world:simulation_world_service_test
373 374 375 376 377 378 379 380 381 382 383
  "
  bazel test $DEFINES --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
}

D
Dong Li 已提交
384
function run_cpp_lint() {
385 386
  generate_build_targets
  echo "$BUILD_TARGETS" | xargs bazel test --config=cpplint -c dbg
D
Dong Li 已提交
387 388 389
}

function run_bash_lint() {
S
siyangy 已提交
390
  FILES=$(find "${APOLLO_ROOT_DIR}" -type f -name "*.sh" | grep -v ros)
D
Dong Li 已提交
391 392 393 394
  echo "${FILES}" | xargs shellcheck
}

function run_lint() {
S
siyangy 已提交
395
  START_TIME=$(get_now)
D
Dong Li 已提交
396

C
Calvin Miao 已提交
397 398 399 400 401 402 403 404
  # Add cpplint rule to BUILD files that do not contain it.
  for file in $(find modules -name BUILD | \
    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

S
siyangy 已提交
405 406
  run_cpp_lint

D
Dong Li 已提交
407 408 409 410 411 412 413 414
  if [ $? -eq 0 ]; then
    success 'Lint passed!'
  else
    fail 'Lint failed!'
  fi
}

function clean() {
415
  bazel clean --async
D
Dong Li 已提交
416 417 418
}

function buildify() {
419 420 421 422 423
  START_TIME=$(get_now)

  local buildifier_url=https://github.com/bazelbuild/buildtools/releases/download/0.4.5/buildifier
  wget $buildifier_url -O ~/.buildifier
  chmod +x ~/.buildifier
424
  find . -name '*BUILD' -type f -exec ~/.buildifier -showlog -mode=fix {} +
425 426 427 428 429 430
  if [ $? -eq 0 ]; then
    success 'Buildify worked!'
  else
    fail 'Buildify failed!'
  fi
  rm ~/.buildifier
D
Dong Li 已提交
431 432
}

S
siyangy 已提交
433 434 435 436 437
function build_fe() {
  cd modules/dreamview/frontend
  yarn build
}

D
Dong Li 已提交
438 439 440 441 442 443 444 445 446 447 448 449
function gen_doc() {
  rm -rf docs/doxygen
  doxygen apollo.doxygen
}

function version() {
  commit=$(git log -1 --pretty=%H)
  date=$(git log -1 --pretty=%cd)
  echo "Commit: ${commit}"
  echo "Date: ${date}"
}

S
siyangy 已提交
450
function build_gnss() {
451
  CURRENT_PATH=$(pwd)
F
fengkaiwen01 已提交
452 453
  if [ -d "${ROS_ROOT}" ]; then
    ROS_PATH="${ROS_ROOT}/../.."
L
Lei Wang 已提交
454 455 456 457
  else
    warning "ROS not found. Run apolllo.sh build first."
    exit 1
  fi
458

L
Lei Wang 已提交
459
  source "${ROS_PATH}/setup.bash"
460 461 462 463 464 465 466 467 468 469 470

  protoc modules/common/proto/error_code.proto --cpp_out=./
  protoc modules/common/proto/header.proto --cpp_out=./
  protoc modules/common/proto/geometry.proto --cpp_out=./

  protoc modules/localization/proto/imu.proto --cpp_out=./
  protoc modules/localization/proto/gps.proto --cpp_out=./
  protoc modules/localization/proto/pose.proto --cpp_out=./

  protoc modules/drivers/gnss/proto/gnss.proto --cpp_out=./
  protoc modules/drivers/gnss/proto/imu.proto --cpp_out=./
F
fengkaiwen01 已提交
471
  protoc modules/drivers/gnss/proto/ins.proto --cpp_out=./ --python_out=./
472
  protoc modules/drivers/gnss/proto/config.proto --cpp_out=./
F
fengkaiwen01 已提交
473
  protoc modules/drivers/gnss/proto/gnss_status.proto --cpp_out=./ --python_out=./
474
  protoc modules/drivers/gnss/proto/gpgga.proto --cpp_out=./
475 476
  protoc modules/drivers/gnss/proto/gnss_raw_observation.proto --cpp_out=./ --python_out=./
  protoc modules/drivers/gnss/proto/gnss_best_pose.proto --cpp_out=./ --python_out=./
477 478

  cd modules
F
fengkaiwen01 已提交
479
  catkin_make_isolated --install --source drivers/gnss \
L
Lei Wang 已提交
480
    --install-space "${ROS_PATH}" -DCMAKE_BUILD_TYPE=Release \
481
    --cmake-args --no-warn-unused-cli
L
Lei Wang 已提交
482
  find "${ROS_PATH}" -name "*.pyc" -print0 | xargs -0 rm -rf
483 484 485 486 487 488
  cd -

  rm -rf modules/common/proto/*.pb.cc
  rm -rf modules/common/proto/*.pb.h
  rm -rf modules/drivers/gnss/proto/*.pb.cc
  rm -rf modules/drivers/gnss/proto/*.pb.h
F
fengkaiwen01 已提交
489
  rm -rf modules/drivers/gnss/proto/*_pb2.py
490 491 492 493 494 495
  rm -rf modules/localization/proto/*.pb.cc
  rm -rf modules/localization/proto/*.pb.h

  rm -rf modules/.catkin_workspace
  rm -rf modules/build_isolated/
  rm -rf modules/devel_isolated/
D
Dong Li 已提交
496 497
}

F
fengkaiwen01 已提交
498 499
function build_velodyne() {
  CURRENT_PATH=$(pwd)
F
fengkaiwen01 已提交
500 501
  if [ -d "${ROS_ROOT}" ]; then
    ROS_PATH="${ROS_ROOT}/../.."
F
fengkaiwen01 已提交
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
  else
    warning "ROS not found. Run apolllo.sh build first."
    exit 1
  fi

  source "${ROS_PATH}/setup.bash"

  cd modules
  catkin_make_isolated --install --source drivers/velodyne \
    --install-space "${ROS_PATH}" -DCMAKE_BUILD_TYPE=Release \
    --cmake-args --no-warn-unused-cli
  find "${ROS_PATH}" -name "*.pyc" -print0 | xargs -0 rm -rf
  cd -

  rm -rf modules/.catkin_workspace
  rm -rf modules/build_isolated/
  rm -rf modules/devel_isolated/
}

Y
yibingl 已提交
521 522
function build_usbcam() {
  CURRENT_PATH=$(pwd)
F
fengkaiwen01 已提交
523 524
  if [ -d "${ROS_ROOT}" ]; then
    ROS_PATH="${ROS_ROOT}/../.."
Y
yibingl 已提交
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
  else
    warning "ROS not found. Run apolllo.sh build first."
    exit 1
  fi

  source "${ROS_PATH}/setup.bash"

  cd modules
  catkin_make_isolated --install --source drivers/usb_cam \
    --install-space "${ROS_PATH}" -DCMAKE_BUILD_TYPE=Release \
    --cmake-args --no-warn-unused-cli
  find "${ROS_PATH}" -name "*.pyc" -print0 | xargs -0 rm -rf
  cd -

  rm -rf modules/.catkin_workspace
  rm -rf modules/build_isolated/
  rm -rf modules/devel_isolated/
}

544
function config() {
545
  ${APOLLO_ROOT_DIR}/scripts/configurator.sh
546 547
}

548
function print_usage() {
C
Calvin Miao 已提交
549 550 551 552 553 554 555 556 557 558
  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
559
  ${BLUE}build_opt${NONE}: build optimized binary for the code
J
Jun Zhu 已提交
560
  ${BLUE}build_gpu${NONE}: run build only with Caffe GPU mode support
F
fengkaiwen01 已提交
561 562 563
  ${BLUE}build_gnss${NONE}: build gnss driver
  ${BLUE}build_velodyne${NONE}: build velodyne driver
  ${BLUE}build_usbcam${NONE}: build velodyne driver
J
Jun Zhu 已提交
564
  ${BLUE}build_opt_gpu${NONE}: build optimized binary with Caffe GPU mode support
C
Calvin Miao 已提交
565
  ${BLUE}build_fe${NONE}: compile frontend javascript code, this requires all the node_modules to be installed already
566
  ${BLUE}build_no_perception [dbg|opt]${NONE}: run build build skip building perception module, useful when some perception dependencies are not satisified, e.g., CUDA, CUDNN, LIDAR, etc.
567
  ${BLUE}build_prof${NONE}: build for gprof support.
C
Calvin Miao 已提交
568 569 570 571 572 573 574 575 576 577 578 579
  ${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
  "
580 581
}

S
siyangy 已提交
582 583 584 585 586 587
function main() {
  source_apollo_base
  apollo_check_system_config
  check_machine_arch
  check_esd_files

588 589 590 591 592
  DEFINES="--define ARCH=${MACHINE_ARCH} --define CAN_CARD=${CAN_CARD} --cxxopt=-DUSE_ESD_CAN=${USE_ESD_CAN}"

  if [ ${MACHINE_ARCH} == "x86_64" ]; then
    DEFINES="${DEFINES} --copt=-mavx2"
  fi
S
siyangy 已提交
593

594 595 596 597
  local cmd=$1
  shift

  case $cmd in
S
siyangy 已提交
598
    check)
599
      DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
600
      check $@
S
siyangy 已提交
601 602
      ;;
    build)
L
Lei Wang 已提交
603
      DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
604
      apollo_build_dbg $@
S
siyangy 已提交
605
      ;;
606
    build_prof)
D
Dong Li 已提交
607
      DEFINES="${DEFINES} --config=cpu_prof --cxxopt=-DCPU_ONLY"
608 609
      apollo_build_dbg $@
      ;;
610
    build_no_perception)
S
siyangy 已提交
611
      DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
612
      NOT_BUILD_PERCEPTION=true
613 614 615 616 617 618 619
      if [ "$1" == "opt" ]; then
        shift
        apollo_build_opt $@
      elif [ "$1" == "dbg" ]; then
        shift
        apollo_build_dbg $@
      fi
620
      ;;
621 622 623 624
    cibuild)
      DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
      cibuild $@
      ;;
625
    build_opt)
L
Lei Wang 已提交
626
      DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
627
      apollo_build_opt $@
S
siyangy 已提交
628
      ;;
629
    build_gpu)
630
      DEFINES="${DEFINES} --cxxopt=-DUSE_CAFFE_GPU"
631
      apollo_build_dbg $@
J
Jun Zhu 已提交
632
      ;;
J
Jun Zhu 已提交
633
    build_opt_gpu)
634
      DEFINES="${DEFINES} --cxxopt=-DUSE_CAFFE_GPU"
635
      apollo_build_opt $@
S
siyangy 已提交
636
      ;;
S
siyangy 已提交
637 638 639
    build_fe)
      build_fe
      ;;
S
siyangy 已提交
640 641 642
    buildify)
      buildify
      ;;
F
fengkaiwen01 已提交
643
    build_gnss)
S
siyangy 已提交
644 645
      build_gnss
      ;;
L
Lei Wang 已提交
646 647 648
    build_py)
      build_py_proto
      ;;
F
fengkaiwen01 已提交
649
    build_velodyne)
F
fengkaiwen01 已提交
650 651
      build_velodyne
      ;;
F
fengkaiwen01 已提交
652
    build_usbcam)
Y
yibingl 已提交
653 654
      build_usbcam
      ;;
655 656 657
    config)
      config
      ;;
S
siyangy 已提交
658 659 660 661 662 663 664
    doc)
      gen_doc
      ;;
    lint)
      run_lint
      ;;
    test)
665
      DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
L
Lei Wang 已提交
666
      run_test $@
S
siyangy 已提交
667
      ;;
668 669 670 671
    citest)
      DEFINES="${DEFINES} --cxxopt=-DCPU_ONLY"
      citest $@
      ;;
672 673 674
    test_gpu)
      DEFINES="${DEFINES} --cxxopt=-DUSE_CAFFE_GPU"
      USE_GPU="1"
L
Lei Wang 已提交
675
      run_test $@
676
      ;;
S
siyangy 已提交
677 678 679 680 681 682 683
    release)
      release 1
      ;;
    release_noproprietary)
      release 0
      ;;
    coverage)
L
Lei Wang 已提交
684
      gen_coverage $@
S
siyangy 已提交
685 686 687 688 689 690 691
      ;;
    clean)
      clean
      ;;
    version)
      version
      ;;
C
Calvin Miao 已提交
692 693 694
    usage)
      print_usage
      ;;
S
siyangy 已提交
695 696 697 698 699 700 701
    *)
      print_usage
      ;;
  esac
}

main $@