提交 ec697b9a 编写于 作者: C changsh726 提交者: Chang Songhong

Scripts: aggregate format tools in apollo_format.sh

上级 1628d75b
......@@ -198,6 +198,9 @@ function main() {
doc)
env ${APOLLO_ENV} bash "${APOLLO_ROOT_DIR}/scripts/apollo_docs.sh" "$@"
;;
format)
env ${APOLLO_ENV} bash "${APOLLO_ROOT_DIR}/scripts/apollo_format.sh" "$@"
;;
usage)
_usage
;;
......
......@@ -132,15 +132,6 @@ function c_family_ext() {
return 1
}
function py_ext() {
local __ext
__ext="$(file_ext $1)"
if [ "${__ext}" == "py" ]; then
return 0
fi
return 1
}
function find_c_cpp_srcs() {
find "$@" -type f -name "*.h" \
-o -name "*.c" \
......@@ -153,10 +144,6 @@ function find_c_cpp_srcs() {
-o -name "*.cu"
}
function find_py_srcs() {
find "$@" -type f -name "*.py"
}
## Prevent multiple entries of my_bin_path in PATH
function add_to_path() {
if [ -z "$1" ]; then
......
#!/usr/bin/env bash
###############################################################################
# Copyright 2020 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.
###############################################################################
# Usage:
# apollo_format.sh <path/to/src/dir/or/files> [Options]
# Fail on error
set -e
TOP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
source "${TOP_DIR}/scripts/apollo.bashrc"
function print_usage() {
info "Usage: $0 <path/to/src/dir/or/files> [Options]"
info "Options:"
info "${TAB}py|python Format Python code"
info "${TAB}bazel Lint Bazel code"
info "${TAB}cpp Format cpp code"
info "${TAB}all Lint all (C++/Python/Bazel)"
}
function run_clang_format() {
bash "${TOP_DIR}/scripts/clang_format.sh" "$@"
}
function run_buildifier() {
bash "${TOP_DIR}/scripts/buildifier.sh" "$@"
}
function run_autopep8() {
bash "${TOP_DIR}/scripts/autopep8.sh" "$@"
}
function run_format_all() {
run_clang_format "$@"
run_buildifier "$@"
run_autopep8 "$@"
}
function main() {
if [ "$#" -eq 0 ]; then
print_usage
exit 1
fi
local path="$1"
shift
local option="$1"
case "${option}" in
py | python)
run_autopep8 "${path}"
;;
cpp)
run_clang_format "${path}"
;;
bazel)
run_buildifier "${path}"
;;
all)
run_format_all "${path}"
;;
*)
run_format_all "${path}"
;;
esac
}
main "$@"
#!/usr/bin/env bash
###############################################################################
# Copyright 2019 The Apollo Authors. All Rights Reserved.
# Copyright 2020 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.
......@@ -27,6 +27,19 @@ source "${TOP_DIR}/scripts/apollo.bashrc"
AUTOPEP8_CMD="autopep8"
function _find_py_srcs() {
find "$@" -type f -name "*.py"
}
function _py_ext() {
local __ext
__ext="$(file_ext $1)"
if [ "${__ext}" == "py" ]; then
return 0
fi
return 1
}
function check_autopep8() {
AUTOPEP8_CMD="$(command -v autopep8)"
if [ -z "${AUTOPEP8_CMD}" ]; then
......@@ -45,7 +58,7 @@ function autopep8_run() {
function run_autopep8() {
for target in "$@"; do
if [ -f "${target}" ]; then
if py_ext "${target}"; then
if _py_ext "${target}"; then
autopep8_run "${target}"
info "Done formatting ${target}"
else
......@@ -53,7 +66,7 @@ function run_autopep8() {
fi
else
local srcs
srcs="$(find_py_srcs ${target})"
srcs="$(_find_py_srcs ${target})"
if [ -z "${srcs}" ]; then
warning "Do nothing. No Python files found under ${target} ."
continue
......
......@@ -39,7 +39,7 @@ function check_clang_format() {
}
function clang_format_run() {
${CLANG_FORMAT_CMD} -i -style=Google "$@"
${CLANG_FORMAT_CMD} -i "$@"
}
function run_clang_format() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册