From 9aa3792f775084fefb85456ae994ad61ea4943eb Mon Sep 17 00:00:00 2001 From: storypku Date: Thu, 18 Jun 2020 09:04:54 +0800 Subject: [PATCH] Scripts: add indendent buildify.sh --- new_apollo.sh | 32 +-------------------------- scripts/apollo_buildify.sh | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 31 deletions(-) create mode 100755 scripts/apollo_buildify.sh diff --git a/new_apollo.sh b/new_apollo.sh index 24fe1ffadc..023077aba7 100755 --- a/new_apollo.sh +++ b/new_apollo.sh @@ -94,36 +94,6 @@ function apollo_env_setup() { info "${TAB}STAGE: ${STAGE}" } -function run_buildifier() { - local buildifier_cmd="$(command -v buildifier)" - if [ -z "${buildifier_cmd}" ]; then - local download_link="https://github.com/bazelbuild/buildtools/releases" - error "Command buildifier not found. You can download and install" \ - "(or build) it from:" - error "${TAB}${download_link}" - exit 1 - fi - - buildifier_cmd="${buildifier_cmd} -mode=fix" - - local build_dirs="cyber third_party tools external" - if [ "${STAGE}" == "dev" ]; then - build_dirs="modules ${build_dirs}" - fi - build_dirs=$(printf "${APOLLO_ROOT_DIR}/%s " $build_dirs) - - find ${build_dirs} -name "*BUILD" -or -name "*.bzl" -exec \ - ${buildifier_cmd} {} + - - success "buildifier run finished successfully." - if [ -f "${APOLLO_ROOT_DIR}/BUILD" ]; then - ${buildifier_cmd} "${APOLLO_ROOT_DIR}/BUILD" - fi - if [ -f "${APOLLO_ROOT_DIR}/WORKSPACE.in" ]; then - ${buildifier_cmd} "${APOLLO_ROOT_DIR}/WORKSPACE.in" - fi -} - function run_cleanup() { if ! "${APOLLO_IN_DOCKER}" ; then error "The clean operation must be run from within docker container" @@ -155,7 +125,7 @@ function main() { ${APOLLO_ROOT_DIR}/scripts/apollo_docs.sh "$@" ;; buildify) - run_buildifier + ${APOLLO_ROOT_DIR}/scripts/apollo_buildify.sh "$@" ;; clean) run_cleanup diff --git a/scripts/apollo_buildify.sh b/scripts/apollo_buildify.sh new file mode 100755 index 0000000000..0008071506 --- /dev/null +++ b/scripts/apollo_buildify.sh @@ -0,0 +1,44 @@ +#! /usr/bin/env bash + +set -e + +TOPDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" +source "${TOPDIR}/scripts/apollo.bashrc" + +function buildify() { + local stage="${1:-dev}" + + local buildifier_cmd="$(command -v buildifier)" + if [ -z "${buildifier_cmd}" ]; then + local download_link="https://github.com/bazelbuild/buildtools/releases" + error "Command buildifier not found. You can download and install" \ + "(or build) it from:" + error "${TAB}${download_link}" + exit 1 + fi + + buildifier_cmd="${buildifier_cmd} -mode=fix" + + local build_dirs="cyber third_party tools external" + if [ "${STAGE}" == "dev" ]; then + build_dirs="modules ${build_dirs}" + fi + build_dirs=$(printf "${APOLLO_ROOT_DIR}/%s " $build_dirs) + + run find ${build_dirs} -name "*BUILD" -or -name "*.bzl" -exec \ + ${buildifier_cmd} {} + + + success "buildifier run finished successfully." + if [ -f "${APOLLO_ROOT_DIR}/BUILD" ]; then + ${buildifier_cmd} "${APOLLO_ROOT_DIR}/BUILD" + fi + if [ -f "${APOLLO_ROOT_DIR}/WORKSPACE.in" ]; then + ${buildifier_cmd} "${APOLLO_ROOT_DIR}/WORKSPACE.in" + fi +} + +function main() { + buildify "$@" +} + +main "$@" -- GitLab