]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | #!/bin/bash |
2 | if [[ ! -e tools/format.sh ]]; then | |
3 | echo "This tool must be run from the topmost directory." >&2 | |
4 | exit 1 | |
5 | fi | |
6 | ||
7 | set -e | |
8 | ||
9 | FIND="find . -name third_party -prune -o -name tools -prune -o -name .git -prune -o -name _deps -prune -o -name .build -prune -o -name out -prune -o -name .vs -prune -o -name opentelemetry_logo.png -prune -o -name TraceLoggingDynamic.h -prune -o -name thrift-gen -prune -o" | |
10 | ||
11 | # GNU syntax. | |
12 | SED=(sed -i) | |
13 | if [[ "$(uname)" = "Darwin" ]]; then | |
14 | SED=(sed -i "") | |
15 | fi | |
16 | ||
17 | # Correct common miscapitalizations. | |
18 | "${SED[@]}" 's/Open[t]elemetry/OpenTelemetry/g' $($FIND -type f -print) | |
19 | # No CRLF line endings, except Windows files. | |
20 | "${SED[@]}" 's/\r$//' $($FIND -name '*.ps1' -prune -o \ | |
21 | -name '*.cmd' -prune -o -type f -print) | |
22 | # No trailing spaces. | |
23 | "${SED[@]}" 's/ \+$//' $($FIND -type f -print) | |
24 | ||
25 | # If not overridden, try to use clang-format-8 or clang-format. | |
26 | if [[ -z "$CLANG_FORMAT" ]]; then | |
27 | CLANG_FORMAT=clang-format | |
28 | if which clang-format-10 >/dev/null; then | |
29 | CLANG_FORMAT=clang-format-10 | |
30 | fi | |
31 | fi | |
32 | ||
33 | $CLANG_FORMAT -version | |
34 | $CLANG_FORMAT -i -style=file \ | |
35 | $($FIND -name '*.cc' -print -o -name '*.h' -print) | |
36 | ||
37 | if which cmake-format >/dev/null; then | |
38 | echo "Running cmake-format $(cmake-format --version 2>&1)." | |
39 | cmake-format -i $($FIND -name 'CMakeLists.txt' -print -name '*.cmake' -print -name '*.cmake.in' -print) | |
40 | else | |
41 | echo "Can't find cmake-format. It can be installed with:" | |
42 | echo " pip install --user cmake_format" | |
43 | exit 1 | |
44 | fi | |
45 | ||
46 | if [[ -z "$BUILDIFIER" ]]; then | |
47 | BUILDIFIER="$HOME/go/bin/buildifier" | |
48 | if ! which "$BUILDIFIER" >/dev/null; then | |
49 | BUILDIFIER=buildifier | |
50 | fi | |
51 | fi | |
52 | if which "$BUILDIFIER" >/dev/null; then | |
53 | echo "Running $BUILDIFIER" | |
54 | "$BUILDIFIER" $($FIND -name WORKSPACE -print -o -name BUILD -print -o \ | |
55 | -name '*.BUILD' -o -name '*.bzl' -print) | |
56 | else | |
57 | echo "Can't find buildifier. It can be installed with:" | |
58 | echo " go get github.com/bazelbuild/buildtools/buildifier" | |
59 | exit 1 | |
60 | fi |