blob: c6bbd5d63e882efee81a454c862fffaa2b046cab [file] [log] [blame]
Philipp Schradercc016b32021-12-30 08:59:58 -08001#!/bin/bash
2
3# --- begin runfiles.bash initialization v2 ---
4# Copy-pasted from the Bazel Bash runfiles library v2.
5set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
6source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
7 source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
8 source "$0.runfiles/$f" 2>/dev/null || \
9 source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
10 source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
11 { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
12# --- end runfiles.bash initialization v2 ---
13
14readonly BUILDIFIER="$(rlocation com_github_bazelbuild_buildtools/buildifier/buildifier_/buildifier)"
15
16# Run everything from the root of the tree.
17cd "${BUILD_WORKSPACE_DIRECTORY}"
18
19# Find all the Starlark files in the repo.
20starlark_files=($(git ls-tree --name-only --full-tree -r @ \
21 | grep -v '^third_party/' \
22 | (grep \
23 -e '\.bzl$' \
24 -e '\.BUILD$' \
25 -e '^BUILD$' \
26 -e '/BUILD$' \
27 -e '/BUILD.bazel$' \
28 -e '^WORKSPACE$' \
29 || :)))
30
31# If we have any Starlark files, format them.
32if ((${#starlark_files[@]} > 0)); then
33 "${BUILDIFIER}" --lint=fix "${starlark_files[@]}"
34 "${BUILDIFIER}" --lint=warn \
35 --warnings=-module-docstring,-function-docstring,-function-docstring-args,-rule-impl-return,-no-effect,-provider-params,-unnamed-macro,-positional-args \
36 "${starlark_files[@]}"
37fi