提交 82396742 编写于 作者: S storypku

Build: apollo6.sh: scripts/apollo_build.sh

上级 e21e4ba7
......@@ -9,6 +9,7 @@ SUPPORTED_ARCHS=" x86_64 aarch64 "
APOLLO_VERSION="@non-git"
APOLLO_ENV=""
USE_ESD_CAN=false
: ${USE_GPU:=0}
: ${STAGE:=dev}
......@@ -58,6 +59,16 @@ function determine_gpu_use() {
USE_GPU="${use_gpu}"
}
function determine_esdcan_use() {
local esdcan_dir="${APOLLO_ROOT_DIR}/third_party/can_card_library/esd_can"
local use_esd=false
if [ -f "${esdcan_dir}/include/ntcan.h" -a \
-f "${esdcan_dir}/lib/libntcan.so.4" ]; then
use_esd=true
fi
USE_ESD_CAN="${use_esd}"
}
function check_apollo_version() {
local branch="$(git_branch)"
if [ "${branch}" == "${APOLLO_VERSION}" ]; then
......@@ -69,14 +80,17 @@ function check_apollo_version() {
}
function apollo_env_setup() {
check_apollo_version
check_architecture_support
check_platform_support
check_minimal_memory_requirement
determine_gpu_use
check_apollo_version
determine_esdcan_use
APOLLO_ENV="${APOLLO_ENV} USE_GPU=${USE_GPU}"
APOLLO_ENV="${APOLLO_ENV} STAGE=${STAGE}"
APOLLO_ENV="${APOLLO_ENV} USE_ESD_CAN=${USE_ESD_CAN}"
# Add more here ...
info "Apollo Environment Settings:"
......@@ -96,10 +110,26 @@ function main() {
if [ "$#" -eq 0 ]; then
exit 0
fi
local build_sh="${APOLLO_ROOT_DIR}/scripts/apollo_build.sh"
local cmd="$1"; shift
case "${cmd}" in
build)
env ${APOLLO_ENV} bash ${APOLLO_ROOT_DIR}/scripts/apollo_build.sh "$@"
env ${APOLLO_ENV} bash "${build_sh}" "$@"
;;
build_opt)
env ${APOLLO_ENV} bash "${build_sh}" -c opt "$@"
;;
build_dbg)
env ${APOLLO_ENV} bash "${build_sh}" -c dbg "$@"
;;
build_cpu)
env ${APOLLO_ENV} bash "${build_sh}" --mode build_cpu "$@"
;;
build_gpu)
env ${APOLLO_ENV} bash "${build_sh}" --mode build_gpu "$@"
;;
build_opt_gpu)
env ${APOLLO_ENV} bash "${build_sh}" --mode build_gpu -c opt "$@"
;;
buildify)
env ${APOLLO_ENV} bash ${APOLLO_ROOT_DIR}/scripts/apollo_buildify.sh
......
......@@ -171,3 +171,8 @@ function read_one_char_from_stdin() {
echo "${answer}" | tr '[:upper:]' '[:lower:]'
}
function optarg_check_for_opt() {
local opt="$1"
local optarg="$2"
! [[ -z "${optarg}" || "${optarg}" =~ ^-.* ]]
}
......@@ -4,22 +4,152 @@ set -e
TOP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
source "${TOP_DIR}/scripts/apollo.bashrc"
ARCH="$(uname -m)"
# STAGE="${STAGE:-dev}"
: ${STAGE:=dev}
: ${USE_GPU:=0}
: ${USE_ESD_CAN:=false}
function bazel_build() {
local allowed_cmodes=" fastbuild dbg opt "
local cmode="fastbuild"
if [ "$1" == "-c" ] || [ "$1" == "--compilation_cmode" ]; then
cmode="$2"; shift 2
if [[ "${allowed_cmodes}" != *" ${cmode} "* ]]; then
error "Unknown compilation mode: ${cmode}"
exit 1
COMMAND_LINE_OPTIONS=
BUILD_TARGETS=
function determine_disabled_targets() {
local disabled=
local compo="$1"
if [[ -z "${compo}" || "${compo}" == "drivers" ]]; then
if ! ${USE_ESD_CAN} ; then
warning "ESD CAN library supplied by ESD Electronics doesn't exist."
warning "If you need ESD CAN, please refer to:"
warning " third_party/can_card_library/esd_can/README.md"
disabled="${disabled} except //modules/drivers/canbus/can_client/esd/..."
fi
elif [[ "${compo}" == "localization" && "${ARCH}" != "x86_64" ]]; then
# Skip msf for non-x86_64 platforms
disabled="${disabled} except //modules/localization/msf/..."
fi
echo "${disabled}"
# DISABLED_CYBER_MODULES="except //cyber/record:record_file_integration_test"
}
# components="$(echo -e "${@// /\\n}" | sort -u)"
function determine_targets() {
local targets=
local compo="$1"
if [[ -z "${compo}" || "${compo}" == "drivers" ]]; then
local exceptions=
if ! ${USE_ESD_CAN}; then
exceptions="$(determine_disabled_targets ${compo})"
fi
if [ -z "${compo}" ]; then
targets="//... ${exceptions}"
else
targets="//modules/drivers/... ${exceptions}"
fi
elif [[ "${compo}" == "cyber" ]]; then
if [[ "${ARCH}" == "x86_64" ]]; then
targets="//cyber/... union //modules/tools/visualizer/..."
else
targets="//cyber/..."
fi
elif [[ -d "${APOLLO_ROOT_DIR}/modules/${compo}" ]]; then
targets="//modules/${compo}/..."
else
error "Oops, no such component under <APOLLO_ROOT_DIR>/modules/ . Exiting ..."
exit 1
fi
echo "${targets}"
}
function parse_cmdline_options() {
local build_mode="build"
local compilation_mode="fastbuild"
local args_to_pass_on=""
while [ "$#" -gt 0 ]; do
local option="$1"
case "${option}" in
--mode)
build_mode="$(_check_build_mode $2)"; shift 2
;;
-c|--compilation_mode)
compilation_mode="$(_check_compilation_mode $2)"; shift 2
;;
*)
# Pass arguments we don't handle to bazel
args_to_pass_on="${args_to_pass_on} ${option}"; shift
;;
esac
done
local myopts=""
if [ "${compilation_mode}" != "fastbuild" ]; then
myopts="${myopts} -c ${compilation_mode}"
fi
# TODO(all):
# Corner cases: build_gpu if env USE_GPU=0, build_cpu if env USE_GPU=1
# And, interaction with apollo.bazelrc
if [ "${build_mode}" == "build_cpu" ]; then
myopts="${myopts} --cxxopt=-DCPU_ONLY"
elif [ "${USE_GPU}" -eq 1 ]; then
myopts="${myopts} --config=gpu"
fi
myopts="${myopts} --cxxopt=-DUSE_ESD_CAN=${USE_ESD_CAN}"
local targets
targets="$(determine_targets ${args_to_pass_on})"
COMMAND_LINE_OPTIONS="${myopts}"
BUILD_TARGETS="${targets}"
info "Build Overview: "
info "${TAB}Bazel Options: ${GREEN}${COMMAND_LINE_OPTIONS}${NO_COLOR}"
info "${TAB}Build Targets: ${GREEN}${BUILD_TARGETS}${NO_COLOR}"
}
function _check_build_mode() {
local supported_modes=" build build_cpu build_gpu "
local mode="$1"
if ! optarg_check_for_opt "--mode" "${mode}" ; then
exit 1
fi
if [[ "${supported_modes}" != *" ${mode} "* ]]; then
error "Unknown build mode: ${mode}. Supported values:"
error " ${supported_modes}"
exit 1
fi
local modules="$@"
#bazel build -c "${cmode}" --distdir=${APOLLO_CACHE_DIR} "$@"
echo "${mode}"
}
function _check_compilation_mode() {
local supported_modes=" fastbuild dbg opt "
local mode="$1"
if ! optarg_check_for_opt "-c" "${mode}" ; then
exit 1
fi
if [[ "${supported_modes}" != *" ${mode} "* ]]; then
error "Unknown compilation mode: ${mode}. Supported values:"
error " ${supported_modes}"
exit 1
fi
echo "${mode}"
}
function bazel_build() {
parse_cmdline_options "$@"
if ! "${APOLLO_IN_DOCKER}" ; then
error "The build operation must be run from within docker container"
exit 1
fi
run bazel build --distdir="${APOLLO_CACHE_DIR}" "${COMMAND_LINE_OPTIONS}" "${BUILD_TARGETS}"
}
function main() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册