diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 0000000000000000000000000000000000000000..9a7271b10475925fcb646873e3efa0b216eb67c6 --- /dev/null +++ b/.bazelignore @@ -0,0 +1,4 @@ +.cache +docs +docker +scripts diff --git a/.gitignore b/.gitignore index 046b8eceb5a4c01d9387efd12e7b68e75ec322bf..47d02c12dc32e5dcc8d4933689403e77146c3c03 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,6 @@ docs/demo_guide/*.record # Bash Environment .dev_bash_hist + +# bazel cache and others +.cache/ diff --git a/apollo.sh b/apollo.sh index f5b83913c1b7a19b879d27afe6f0786ee5cc25d3..a2459463649e1e14d784a5aaed107318c54abe62 100755 --- a/apollo.sh +++ b/apollo.sh @@ -298,7 +298,8 @@ function warn_proprietary_sw() { } function release() { - RELEASE_DIR="${HOME}/.cache/apollo_release" + CACHE_DIR="/apollo/.cache" + RELEASE_DIR="${CACHE_DIR}/apollo_release" if [ -d "${RELEASE_DIR}" ]; then rm -rf "${RELEASE_DIR}" fi diff --git a/apollo_docker.sh b/apollo_docker.sh index b970dea2f218536682bb94a79c1285a1f76b341e..7241dc9a68501eb3da4e306a6f8866fc869c8051 100755 --- a/apollo_docker.sh +++ b/apollo_docker.sh @@ -79,8 +79,8 @@ function start_build_docker() { function gen_docker() { IMG="apolloauto/apollo:run-${MACHINE_ARCH}-20181017_1330" - RELEASE_DIR=${HOME}/.cache/apollo_release - APOLLO_DIR="${RELEASE_DIR}/apollo" + CACHE_ROOT_DIR="${DIR}/.cache" + APOLLO_DIR="${CACHE_ROOT_DIR}/apollo_release/apollo" if [ ! -d "${APOLLO_DIR}" ]; then echo "Release directory does not exist!" @@ -102,7 +102,7 @@ function gen_docker() { -d \ --name apollo_release \ --net host \ - -v $HOME/.cache:/root/mnt \ + -v ${CACHE_ROOT_DIR}:/root/mnt \ -w /apollo \ "$IMG" @@ -112,16 +112,11 @@ function gen_docker() { RELEASE_TGZ="apollo_release.tar.gz" SEC_RELEASE_TGZ="sec_apollo_release.tar.gz" - if [ -e "$HOME/.cache/$RELEASE_TGZ" ]; then - rm $HOME/.cache/$RELEASE_TGZ - fi - - if [ -e "$HOME/.cache/$SEC_RELEASE_TGZ" ]; then - rm $HOME/.cache/$SEC_RELEASE_TGZ - fi + [ -e "${CACHE_ROOT_DIR}/${RELEASE_TGZ}" ] && rm -f "${CACHE_ROOT_DIR}/${RELEASE_TGZ}" + [ -e "${CACHE_ROOT_DIR}/${SEC_RELEASE_TGZ}" ] && rm -f "${CACHE_ROOT_DIR}/${SEC_RELEASE_TGZ}" # generate security release package - tar czf $HOME/.cache/$RELEASE_TGZ -C $HOME/.cache apollo_release + tar czf "${CACHE_ROOT_DIR}/${RELEASE_TGZ}" -C "${CACHE_ROOT_DIR}" apollo_release python modules/tools/ota/create_sec_package.py docker exec apollo_release cp /root/mnt/${SEC_RELEASE_TGZ} /root fi @@ -162,6 +157,7 @@ case $1 in gen_docker ;; *) + # TODO(storypku): fix user account issue docker exec -u $USER apollo_dev_$USER bash -c "./apollo.sh $@" ;; esac diff --git a/docker/scripts/cyber_start.sh b/docker/scripts/cyber_start.sh index f2a61e857ea11afd578ba235cad42105fc29333c..7fc8d34b1f7e1d4902e18563b4248d10c93f7ed9 100755 --- a/docker/scripts/cyber_start.sh +++ b/docker/scripts/cyber_start.sh @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### +APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd -P)" +CACHE_ROOT_DIR="${APOLLO_ROOT_DIR}/.cache" INCHINA="no" LOCAL_IMAGE="no" @@ -86,7 +88,6 @@ do done } -APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )" if [ ! -e /apollo ]; then sudo ln -sf ${APOLLO_ROOT_DIR} /apollo @@ -160,8 +161,7 @@ IMG=${DOCKER_REPO}:$VERSION function local_volumes() { # Apollo root and bazel cache dirs are required. - volumes="-v $APOLLO_ROOT_DIR:/apollo \ - -v $HOME/.cache:${DOCKER_HOME}/.cache" + volumes="-v $APOLLO_ROOT_DIR:/apollo" case "$(uname -s)" in Linux) case "$(lsb_release -r | cut -f2)" in @@ -179,8 +179,6 @@ function local_volumes() { -v /lib/modules:/lib/modules" ;; Darwin) - # MacOS has strict limitations on mapping volumes. - chmod -R a+wr ~/.cache/bazel ;; esac echo "${volumes}" @@ -223,8 +221,8 @@ function main(){ if [ "$USER" == "root" ];then DOCKER_HOME="/root" fi - if [ ! -d "$HOME/.cache" ];then - mkdir "$HOME/.cache" + if [ ! -d "${CACHE_ROOT_DIR}" ]; then + mkdir "${CACHE_ROOT_DIR}" fi info "Starting docker container \"${APOLLO_CYBER}\" ..." diff --git a/docker/scripts/dev_start.sh b/docker/scripts/dev_start.sh index 06618b4df465e7071d4005a8f3a46bca81e6d4eb..401eb0c346fdafbc9d42bbcbbf1b4ae54d5aab19 100755 --- a/docker/scripts/dev_start.sh +++ b/docker/scripts/dev_start.sh @@ -16,6 +16,9 @@ # limitations under the License. ############################################################################### +APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )" +CACHE_ROOT_DIR="${APOLLO_ROOT_DIR}/.cache" + LOCAL_IMAGE="no" FAST_BUILD_MODE="no" FAST_TEST_MODE="no" @@ -85,6 +88,7 @@ do fi done } + function set_registry_mirrors() { sed -i '$aDOCKER_OPTS=\"--registry-mirror=http://hub-mirror.c.163.com\"' /etc/default/docker @@ -92,7 +96,6 @@ sed -i '$i ,"registry-mirrors": [ "http://hub-mirror.c.163.com"]' /etc/docker/d service docker restart } -APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd -P )" if [ "$(readlink -f /apollo)" != "${APOLLO_ROOT_DIR}" ]; then sudo ln -snf ${APOLLO_ROOT_DIR} /apollo @@ -207,8 +210,7 @@ LOCAL_THIRD_PARTY_VOLUME_IMAGE=${DOCKER_REPO}:local_third_party_volume-${ARCH}-l function local_volumes() { set +x # Apollo root and bazel cache dirs are required. - volumes="-v $APOLLO_ROOT_DIR:/apollo \ - -v $HOME/.cache:${DOCKER_HOME}/.cache" + volumes="-v $APOLLO_ROOT_DIR:/apollo" APOLLO_TELEOP="${APOLLO_ROOT_DIR}/../apollo-teleop" if [ -d ${APOLLO_TELEOP} ]; then volumes="-v ${APOLLO_TELEOP}:/apollo/modules/teleop ${volumes}" @@ -231,8 +233,6 @@ function local_volumes() { -v /lib/modules:/lib/modules" ;; Darwin) - # MacOS has strict limitations on mapping volumes. - chmod -R a+wr ~/.cache/bazel ;; esac echo "${volumes}" @@ -280,7 +280,7 @@ function main(){ if [ $? == 0 ]; then if [[ "$(docker inspect --format='{{.Config.Image}}' $APOLLO_DEV 2> /dev/null)" != "$APOLLO_DEV_IMAGE" ]]; then rm -rf $APOLLO_ROOT_DIR/bazel-* - rm -rf $HOME/.cache/bazel/* + rm -rf ${CACHE_ROOT_DIR}/bazel/* fi docker stop $APOLLO_DEV 1>/dev/null docker rm -v -f $APOLLO_DEV 1>/dev/null @@ -350,8 +350,8 @@ function main(){ if [ "$USER" == "root" ];then DOCKER_HOME="/root" fi - if [ ! -d "$HOME/.cache" ];then - mkdir "$HOME/.cache" + if [ ! -d "${CACHE_ROOT_DIR}" ]; then + mkdir "${CACHE_ROOT_DIR}" fi info "Starting docker container \"${APOLLO_DEV}\" ..." diff --git a/docker/scripts/release_start.sh b/docker/scripts/release_start.sh index 8d32e288c450320c4b8d1c81d08019204825fd68..73aa9e572fa2349fdc6b6c821f07f513952d7ee8 100755 --- a/docker/scripts/release_start.sh +++ b/docker/scripts/release_start.sh @@ -18,6 +18,8 @@ APOLLO_ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")/../.." && pwd )" +CACHE_ROOT_DIR="${APOLLO_ROOT_DIR}/.cache" + # the machine type, currently support x86_64, aarch64 MACHINE_ARCH=$(uname -m) @@ -80,8 +82,8 @@ function main() { if [ "$USER" == "root" ];then DOCKER_HOME="/root" fi - if [ ! -d "$HOME/.cache" ];then - mkdir "$HOME/.cache" + if [ ! -d "${CACHE_ROOT_DIR}" ]; then + mkdir "${CACHE_ROOT_DIR}" fi DOCKER_CMD="nvidia-docker" @@ -96,7 +98,6 @@ function main() { -v ${HOME}/data:/apollo/data \ -v /tmp/.X11-unix:/tmp/.X11-unix:rw \ -v /etc/localtime:/etc/localtime:ro \ - -v $HOME/.cache:${DOCKER_HOME}/.cache \ -w /apollo \ -e DISPLAY=${display} \ -e RELEASE_DOCKER=1 \ diff --git a/scripts/ota.sh b/scripts/ota.sh index 6af78f0b47fcfb28e7232ef8428525c2030d4271..dcd4dd3c5aef1b4118d61b32b76b127c91ba11b1 100755 --- a/scripts/ota.sh +++ b/scripts/ota.sh @@ -17,6 +17,7 @@ ############################################################################### APOLLO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" +CACHE_DIR="${APOLLO_ROOT}/.cache" function update() { UPDATE_TAG=$(python ${APOLLO_ROOT}/modules/tools/ota/query_client.py) @@ -31,28 +32,26 @@ function update() { if [ "$user_agreed" != "y" ] && [ "$user_agreed" != "Y" ]; then exit 1 fi - cp ${APOLLO_ROOT}/scripts/ota.sh /home/$DOCKER_USER/.cache/ - ssh $DOCKER_USER@localhost bash /home/$DOCKER_USER/.cache/ota.sh download $UPDATE_TAG + cp ${APOLLO_ROOT}/scripts/ota.sh "${CACHE_DIR}" + ssh $DOCKER_USER@localhost bash ${CACHE_DIR}/ota.sh download $UPDATE_TAG python ${APOLLO_ROOT}/modules/tools/ota/verify_client.py if [ "$?" != "0" ]; then exit 1 fi - if [ -e "$HOME/.cache/apollo_release" ]; then - rm -rf "$HOME/.cache/apollo_release" - fi - tar xzf /home/$DOCKER_USER/.cache/apollo_release.tar.gz -C /home/$DOCKER_USER/.cache + [ -e "${CACHE_DIR}/apollo_release" ] && rm -rf "${CACHE_DIR}/apollo_release" + tar xzf ${CACHE_DIR}/apollo_release.tar.gz -C ${CACHE_DIR} NEW_TAG="${UPDATE_TAG}-local" - ssh $DOCKER_USER@localhost bash /home/$DOCKER_USER/.cache/ota.sh setup $NEW_TAG + ssh $DOCKER_USER@localhost bash ${CACHE_DIR}/ota.sh setup $NEW_TAG python ${APOLLO_ROOT}/modules/tools/ota/update_client.py ${UPDATE_TAG} } function clean() { - rm -rf $HOME/.cache/apollo_update - rm -rf $HOME/.cache/apollo_release.tar.gz - rm -rf $HOME/.cache/sec_apollo_release.tar.gz - rm -rf $HOME/.cache/ota.sh + rm -rf ${CACHE_DIR}/apollo_update + rm -rf ${CACHE_DIR}/apollo_release.tar.gz + rm -rf ${CACHE_DIR}/sec_apollo_release.tar.gz + rm -rf ${CACHE_DIR}/ota.sh docker stop test_container 1>/dev/null docker rm test_container 1>/dev/null } @@ -78,7 +77,7 @@ function download() { docker stop test_container 1>/dev/null docker rm -f test_container 1>/dev/null fi - docker run -d -it --name test_container -v $HOME/.cache:/root/mnt $UPDATE_TAG + docker run -d -it --name test_container -v ${CACHE_DIR}:/root/mnt $UPDATE_TAG docker exec test_container cp /root/sec_apollo_release.tar.gz /root/mnt } diff --git a/tools/bazel.rc b/tools/bazel.rc index c91e44908b3e439dd9b9011022c6ee04ca43da7b..f9b6b52a97918c36416c9a393ede97ef2b036aff 100644 --- a/tools/bazel.rc +++ b/tools/bazel.rc @@ -12,6 +12,7 @@ startup --batch_cpu_scheduling startup --host_jvm_args=-XX:-UseParallelGC +startup --output_user_root=/apollo/.cache/bazel # +------------------------------------------------------------+ # | Test Configurations | # +------------------------------------------------------------+