Repository navigation
Expand file tree
/
Copy pathrunner.bash.template
More file actions
89 lines (79 loc) · 2.35 KB
/
Copy pathrunner.bash.template
File metadata and controls
89 lines (79 loc) · 2.35 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
set -euo pipefail
BUILDIFIER_SHORT_PATH={BUILDIFIER_SHORT_PATH}
ARGS={ARGS}
WORKSPACE="{WORKSPACE}"
function resolve_runfile() {
local path=$1
local runfiles_path=${path#../}
local candidate
local manifest
local line
if [[ -e "$path" ]]; then
realpath "$path"
return 0
fi
if [[ -n "${RUNFILES_DIR:-}" ]]; then
candidate="${RUNFILES_DIR}/${runfiles_path}"
if [[ -e "$candidate" ]]; then
realpath "$candidate"
return 0
fi
fi
for manifest in \
"${RUNFILES_MANIFEST_FILE:-}" \
"$0.runfiles_manifest" \
"$0.exe.runfiles_manifest" \
"$0.runfiles/MANIFEST"; do
[[ -n "$manifest" && -f "$manifest" ]] || continue
while IFS= read -r line; do
if [[ "$line" == "${runfiles_path} "* ]]; then
printf '%s\n' "${line#* }"
return 0
elif [[ "$line" == "$runfiles_path" ]]; then
printf '%s\n' "$runfiles_path"
return 0
fi
done < "$manifest"
done
return 1
}
if ! buildifier_short_path=$(resolve_runfile "$BUILDIFIER_SHORT_PATH"); then
echo "Unable to locate buildifier runfile: $BUILDIFIER_SHORT_PATH" >&2
exit 1
fi
# Use TEST_WORKSPACE to determine if the script is being ran under a test
if [[ -n "${TEST_WORKSPACE+x}" && -z "${BUILD_WORKSPACE_DIRECTORY+x}" ]]; then
FIND_FILE_TYPE="l"
# If WORKSPACE was provided, then the script is being run under a test in no_sandbox mode
# cd to the directory containing the WORKSPACE file
if [[ -n "$WORKSPACE" ]]; then
FIND_FILE_TYPE="f"
WORKSPACE_PATH="$(dirname "$(realpath "$WORKSPACE")")"
if ! cd "$WORKSPACE_PATH" ; then
echo "Unable to change to workspace (WORKSPACE_PATH: ${WORKSPACE_PATH})"
fi
fi
else
# Change into the workspace directory if this is _not_ a test
if ! cd "$BUILD_WORKSPACE_DIRECTORY"; then
echo "Unable to change to workspace (BUILD_WORKSPACE_DIRECTORY: ${BUILD_WORKSPACE_DIRECTORY})"
exit 1
fi
fi
# Run buildifier on all starlark files
find . \
{EXCLUDE_PATTERNS} \
-type "${FIND_FILE_TYPE:-f}" \
\( -name '*.bzl' \
-o -name '*.sky' \
-o -name '*.star' \
-o -name '*.bazel' \
-o -name BUILD \
-o -name '*.BUILD' \
-o -name 'BUILD.*.oss' \
-o -name WORKSPACE \
-o -name WORKSPACE.bzlmod \
-o -name WORKSPACE.oss \
-o -name 'WORKSPACE.*.oss' \
\) -exec "$buildifier_short_path" "${ARGS[@]}" {} +