forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bazel-format.sh
executable file
·50 lines (44 loc) · 1.11 KB
/
bazel-format.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
# Before running this script, please make sure golang is installed
# and buildifier is also installed. The example is showed in .travis.yml.
set -e
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)
function usage()
{
echo "Usage: bazel-format.sh [<args>]"
echo
echo "Options:"
echo " -h|--help print the help info"
echo " -c|--check check whether there are format issues in bazel files"
echo " -f|--fix fix all the format issue directly"
echo
}
RUN_TYPE="diff"
# Parse options
while [ $# -gt 0 ]; do
key="$1"
case $key in
-h|--help)
usage
exit 0
;;
-c|--check)
RUN_TYPE="diff"
;;
-f|--fix)
RUN_TYPE=fix
;;
*)
echo "ERROR: unknown option \"$key\""
echo
usage
exit 1
;;
esac
shift
done
pushd "$ROOT_DIR"/../..
BAZEL_FILES=(bazel/BUILD bazel/BUILD.arrow bazel/ray.bzl BUILD.bazel java/BUILD.bazel \
cpp/BUILD.bazel streaming/BUILD.bazel streaming/java/BUILD.bazel WORKSPACE)
buildifier -mode=$RUN_TYPE -diff_command="diff -u" "${BAZEL_FILES[@]}"
popd