blob: 669bd77a447e46396b8ccc99b5b39a6f2d26c447 [file] [log] [blame]
Geoffrey Martin-Noble916c6f92021-11-23 16:52:13 -08001#!/bin/bash
2
3# Copyright 2021 The IREE Authors
4#
5# Licensed under the Apache License v2.0 with LLVM Exceptions.
6# See https://llvm.org/LICENSE.txt for license information.
7# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
9# Runs all the lint checks that we run on GitHub locally. Skips checks if the
10# relevant tool doesn't exist.
11
12# Keep this in sync with .github/workflows/lint.yml
13
14# WARNING: this script *makes changes* to the working directory and the index.
15
16set -uo pipefail
17
18FINAL_RET=0
19LATEST_RET=0
20
21function update_ret() {
22 LATEST_RET="$?"
23 if [[ "${LATEST_RET}" -gt "${FINAL_RET}" ]]; then
24 FINAL_RET="${LATEST_RET}"
25 fi
26}
27
28# Update the exit code after every command
29function enable_update_ret() {
30 trap update_ret DEBUG
31}
32
33function disable_update_ret() {
34 trap - DEBUG
35}
36
37function exists() {
38 command -v "${1}" > /dev/null
39}
40
41
42echo "***** Uncommitted changes *****"
43git add -A
44git diff HEAD --exit-code
45
46if [[ $? -ne 0 ]]; then
47 echo "Found uncomitted changes in working directory. This script requires" \
48 "all changes to be committed. All changes have been added to the" \
49 "index. Please commit or clean all changes and try again."
50 exit 1
51fi
52
53enable_update_ret
54
55echo "***** Bazel -> CMake *****"
56./build_tools/bazel_to_cmake/bazel_to_cmake.py
57./build_tools/bazel_to_cmake/bazel_to_cmake.py --root_dir=integrations/tensorflow/e2e
58git add -A
59git diff HEAD --exit-code
60trap - DEBUG
61
62echo "***** buildifier *****"
63# Don't fail script if condition is false
64disable_update_ret
65if exists buildifier; then
66 enable_update_ret
67 ./scripts/run_buildifier.sh
68 git diff --exit-code
69else
70 enable_update_ret
71 echo "'buildifier' not found. Skipping check"
72fi
73
74echo "***** yapf *****"
75# Don't fail script if condition is false
76disable_update_ret
77if exists yapf > /dev/null; then
78 enable_update_ret
79 git diff -U0 main | ./third_party/format_diff/format_diff.py yapf -i
80else
81 enable_update_ret
82 echo "'yapf' not found. Skipping check"
83fi
84
85echo "***** pytype *****"
86# Don't fail script if condition is false
87disable_update_ret
88if exists pytype; then
89 enable_update_ret
90 ./build_tools/pytype/check_diff.sh
91else
92 enable_update_ret
93 echo "'pytype' not found. Skipping check"
94fi
95
96echo "***** clang-format *****"
97# Don't fail script if condition is false
98disable_update_ret
99if exists git-clang-format; then
100 enable_update_ret
101 git-clang-format --style=file
102 git diff --exit-code
103else
104 enable_update_ret
105 echo "'git-clang-format' not found. Skipping check"
106fi
107
108echo "***** submodules *****"
109./scripts/git/submodule_versions.py check
110
111echo "***** tabs *****"
112./scripts/check_tabs.sh
113
114echo "***** yamllint *****"
115echo "'yamllint' check not yet implemented. Skipping check"
116
117if [[ "${FINAL_RET}" -ne 0 ]]; then
118 echo "Encountered failures. Check error messages and changes to the working" \
119 "directory and git index (which may contain fixes) and try again."
120fi
121
122exit "${FINAL_RET}"