forked from iree-org/iree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint.sh
executable file
·126 lines (103 loc) · 2.88 KB
/
lint.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# Copyright 2021 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Runs all the lint checks that we run on GitHub locally. Skips checks if the
# relevant tool doesn't exist.
# Keep this in sync with .github/workflows/lint.yml
# WARNING: this script *makes changes* to the working directory and the index.
set -uo pipefail
FINAL_RET=0
LATEST_RET=0
function update_ret() {
LATEST_RET="$?"
if [[ "${LATEST_RET}" -gt "${FINAL_RET}" ]]; then
FINAL_RET="${LATEST_RET}"
fi
}
# Update the exit code after every command
function enable_update_ret() {
trap update_ret DEBUG
}
function disable_update_ret() {
trap - DEBUG
}
function exists() {
command -v "${1}" > /dev/null
}
echo "***** Uncommitted changes *****"
git add -A
git diff HEAD --exit-code
if [[ $? -ne 0 ]]; then
echo "Found uncomitted changes in working directory. This script requires" \
"all changes to be committed. All changes have been added to the" \
"index. Please commit or clean all changes and try again."
exit 1
fi
enable_update_ret
echo "***** Bazel -> CMake *****"
./build_tools/bazel_to_cmake/bazel_to_cmake.py
./build_tools/bazel_to_cmake/bazel_to_cmake.py --root_dir=integrations/tensorflow/e2e
git add -A
git diff HEAD --exit-code
trap - DEBUG
echo "***** buildifier *****"
# Don't fail script if condition is false
disable_update_ret
if exists buildifier; then
enable_update_ret
./scripts/run_buildifier.sh
git diff --exit-code
else
enable_update_ret
echo "'buildifier' not found. Skipping check"
fi
echo "***** yapf *****"
# Don't fail script if condition is false
disable_update_ret
if exists yapf; then
enable_update_ret
git diff -U0 main | ./third_party/format_diff/format_diff.py yapf -i
else
enable_update_ret
echo "'yapf' not found. Skipping check"
fi
echo "***** pytype *****"
# Don't fail script if condition is false
disable_update_ret
if exists pytype; then
enable_update_ret
./build_tools/pytype/check_diff.sh
else
enable_update_ret
echo "'pytype' not found. Skipping check"
fi
echo "***** clang-format *****"
# Don't fail script if condition is false
disable_update_ret
if exists git-clang-format; then
enable_update_ret
git-clang-format --style=file
git diff --exit-code
else
enable_update_ret
echo "'git-clang-format' not found. Skipping check"
fi
echo "***** tabs *****"
./scripts/check_tabs.sh
echo "***** yamllint *****"
disable_update_ret
if exists yamllint; then
enable_update_ret
./scripts/run_yamllint.sh
else
enable_update_ret
echo "'yamllint' not found. Skipping check"
fi
if (( "${FINAL_RET}" != 0 )); then
echo "Encountered failures. Check error messages and changes to the working" \
"directory and git index (which may contain fixes) and try again."
fi
exit "${FINAL_RET}"