提交 f9112c44 编写于 作者: S storypku 提交者: Liu Jiaming

Release: command line options for apollo_release.sh

[INFO] Usage: /apollo/scripts/apollo_release.sh [Options]
[INFO] Options:
[INFO]      -p, --prefix <DIR> Use absolute path <DIR> as install prefix instead of '/tmp/apollo'
[INFO]      -l, --list         Print the list of installed files; don't install anything
[INFO]      -c, --clean        Ensure clean install by removing prefix dir if exist before installing
[INFO]      -r, --resolve      Also resolve APT packages on which this release build depends
[INFO]      -h, --help         Show this message and exit
上级 6d24e56f
#! /usr/bin/env bash
set -e
: ${STAGE_DIR:=/tmp/apollo}
export STAGE_DIR
export APOLLO_DIR=/opt/apollo
TOP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
source "${TOP_DIR}/scripts/apollo.bashrc"
export OPT_APOLLO="$(dirname "${APOLLO_SYSROOT_DIR}")"
export PREFIX_DIR=/tmp/apollo
LIST_ONLY=0
RESOLVE_DEPS=0
PRE_CLEAN=0
BAZEL_OPTS="--config=opt --config=gpu"
function _usage() {
info "Usage: $0 [Options]"
info "Options:"
info "${TAB} -p, --prefix <DIR> Use absolute path <DIR> as install prefix instead of '/tmp/apollo'"
info "${TAB} -l, --list Print the list of installed files; don't install anything"
info "${TAB} -c, --clean Ensure clean install by removing prefix dir if exist before installing"
info "${TAB} -r, --resolve Also resolve APT packages on which this release build depends"
info "${TAB} -h, --help Show this message and exit"
}
function _check_arg_for_opt() {
local opt="$1"
local optarg="$2"
if [[ -z "${optarg}" || "${optarg}" =~ ^-.* ]]; then
error "Missing argument for ${opt}. Exiting..."
exit 2
fi
}
function parse_cmdline_args() {
local prefix_dir=
while [[ $# -gt 0 ]]; do
local opt="$1"
shift
case "${opt}" in
-p | --prefix)
_check_arg_for_opt "${opt}" "$1"
prefix_dir="$1"; shift
;;
-l | --list)
LIST_ONLY=1
;;
-r | --resolve)
RESOLVE_DEPS=1
;;
-c | --clean)
PRE_CLEAN=1
;;
-h | --help)
_usage
exit 0
;;
*)
error "Unknown option: ${opt}"
_usage
exit 1
;;
esac
done
if [[ "${RESOLVE_DEPS}" -gt 0 && "${LIST_ONLY}" -gt 0 ]]; then
error "'-l,--list' and '-r,--resolve' cannot be used together"
_usage
exit 1
fi
if [[ "${prefix_dir}" = /* ]]; then
PREFIX_DIR="${prefix_dir}"
elif [[ -n "${prefix_dir}" ]]; then
echo "Absolute prefix dir expected, got '${prefix_dir}'"
exit 1
fi
}
function retrieve_so_deps() {
ldd $1 | awk '/=>/ {print $3}' | sort -u | \
grep -Ev "^(${APOLLO_DIR}|/usr/local|${STAGE_DIR})/"
grep -Ev "^(${OPT_APOLLO}|/usr/local|${PREFIX_DIR})/"
}
export -f retrieve_so_deps
function generate_solibs() {
listing="$1"
SYSROOT=${APOLLO_DIR}/sysroot
find ${STAGE_DIR}/bin ${SYSROOT}/bin -executable -type f \
find ${PREFIX_DIR}/bin ${APOLLO_SYSROOT_DIR}/bin -executable -type f \
-exec bash -c 'retrieve_so_deps "$0"' {} \
>> ${listing} \;
find ${STAGE_DIR}/lib ${STAGE_DIR}/cyber ${STAGE_DIR}/modules \
find ${PREFIX_DIR}/lib ${PREFIX_DIR}/cyber ${PREFIX_DIR}/modules \
-name "*.so" -exec bash -c 'retrieve_so_deps "$0"' {} \
>> ${listing} \;
......@@ -24,7 +93,7 @@ function generate_solibs() {
/usr/local/fast-rtps/lib
/usr/local/libtorch_cpu/lib
/usr/local/libtorch_gpu/lib
${APOLLO_DIR}/sysroot/lib
${APOLLO_SYSROOT_DIR}/lib
)
for libdir in ${SYSLIB_DIRS[@]}; do
......@@ -48,7 +117,7 @@ function solib_locate() {
fi
}
PKGS_TXT="${STAGE_DIR}/pkgs.txt"
PKGS_TXT="${PREFIX_DIR}/pkgs.txt"
function generate_apt_pkgs() {
sudo apt-get -y update
listing="$(mktemp /tmp/syslibs.XXXXXX)"
......@@ -61,16 +130,31 @@ function generate_apt_pkgs() {
}
function main() {
# TODO(storypku):
# parse_cmdline_args
bazel run --config=opt --config=gpu //:install \
-- --pre_clean \
"${STAGE_DIR}"
parse_cmdline_args "$@"
find "${STAGE_DIR}" -name "*.dag" -exec \
sed -i 's@/apollo/bazel-bin@/apollo@g' {} \;
local install_opts=
if [[ "${LIST_ONLY}" -gt 0 ]]; then
install_opts="${install_opts} --list"
fi
if [[ "${PRE_CLEAN}" -gt 0 ]]; then
install_opts="${install_opts} --pre_clean"
fi
bazel run ${BAZEL_OPTS} //:install \
-- ${install_opts} "${PREFIX_DIR}"
generate_apt_pkgs
if [[ "${LIST_ONLY}" -gt 0 ]]; then
return
fi
info "Resolve directory path for Apollo binary distribution..."
find "${PREFIX_DIR}" -name "*.dag" -exec \
sed -i 's@/apollo/bazel-bin@/apollo@g' {} \;
ok "Done."
if [[ "${RESOLVE_DEPS}" -gt 0 ]]; then
info "Resolve runtime library dependencies and generate APT packages list..."
generate_apt_pkgs
ok "Done. Packages list has been writen to ${PKGS_TXT}"
fi
}
main "$@"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册