format_bazel.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. # Copyright 2019 The gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set=-ex
  16. VIRTUAL_ENV=bazel_format_virtual_environment
  17. CONFIG_PATH="$(dirname ${0})/bazel_style.cfg"
  18. python -m virtualenv ${VIRTUAL_ENV}
  19. PYTHON=${VIRTUAL_ENV}/bin/python
  20. "$PYTHON" -m pip install --upgrade pip==19.3.1
  21. "$PYTHON" -m pip install --upgrade futures
  22. "$PYTHON" -m pip install yapf==0.30.0
  23. pushd "$(dirname "${0}")/../.."
  24. FILES=$(find . -path ./third_party -prune -o -name '*.bzl' -print)
  25. echo "${FILES}" | xargs "$PYTHON" -m yapf -i --style="${CONFIG_PATH}"
  26. if ! which buildifier &>/dev/null; then
  27. echo 'buildifer must be installed.' >/dev/stderr
  28. exit 1
  29. fi
  30. echo "${FILES}" | xargs buildifier --type=bzl
  31. popd