Geoffrey Martin-Noble | 916c6f9 | 2021-11-23 16:52:13 -0800 | [diff] [blame] | 1 | #!/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 | |
| 16 | set -uo pipefail |
| 17 | |
| 18 | FINAL_RET=0 |
| 19 | LATEST_RET=0 |
| 20 | |
| 21 | function 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 |
| 29 | function enable_update_ret() { |
| 30 | trap update_ret DEBUG |
| 31 | } |
| 32 | |
| 33 | function disable_update_ret() { |
| 34 | trap - DEBUG |
| 35 | } |
| 36 | |
| 37 | function exists() { |
| 38 | command -v "${1}" > /dev/null |
| 39 | } |
| 40 | |
| 41 | |
| 42 | echo "***** Uncommitted changes *****" |
| 43 | git add -A |
| 44 | git diff HEAD --exit-code |
| 45 | |
| 46 | if [[ $? -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 |
| 51 | fi |
| 52 | |
| 53 | enable_update_ret |
| 54 | |
| 55 | echo "***** 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 |
| 58 | git add -A |
| 59 | git diff HEAD --exit-code |
| 60 | trap - DEBUG |
| 61 | |
| 62 | echo "***** buildifier *****" |
| 63 | # Don't fail script if condition is false |
| 64 | disable_update_ret |
| 65 | if exists buildifier; then |
| 66 | enable_update_ret |
| 67 | ./scripts/run_buildifier.sh |
| 68 | git diff --exit-code |
| 69 | else |
| 70 | enable_update_ret |
| 71 | echo "'buildifier' not found. Skipping check" |
| 72 | fi |
| 73 | |
| 74 | echo "***** yapf *****" |
| 75 | # Don't fail script if condition is false |
| 76 | disable_update_ret |
| 77 | if exists yapf > /dev/null; then |
| 78 | enable_update_ret |
| 79 | git diff -U0 main | ./third_party/format_diff/format_diff.py yapf -i |
| 80 | else |
| 81 | enable_update_ret |
| 82 | echo "'yapf' not found. Skipping check" |
| 83 | fi |
| 84 | |
| 85 | echo "***** pytype *****" |
| 86 | # Don't fail script if condition is false |
| 87 | disable_update_ret |
| 88 | if exists pytype; then |
| 89 | enable_update_ret |
| 90 | ./build_tools/pytype/check_diff.sh |
| 91 | else |
| 92 | enable_update_ret |
| 93 | echo "'pytype' not found. Skipping check" |
| 94 | fi |
| 95 | |
| 96 | echo "***** clang-format *****" |
| 97 | # Don't fail script if condition is false |
| 98 | disable_update_ret |
| 99 | if exists git-clang-format; then |
| 100 | enable_update_ret |
| 101 | git-clang-format --style=file |
| 102 | git diff --exit-code |
| 103 | else |
| 104 | enable_update_ret |
| 105 | echo "'git-clang-format' not found. Skipping check" |
| 106 | fi |
| 107 | |
| 108 | echo "***** submodules *****" |
| 109 | ./scripts/git/submodule_versions.py check |
| 110 | |
| 111 | echo "***** tabs *****" |
| 112 | ./scripts/check_tabs.sh |
| 113 | |
| 114 | echo "***** yamllint *****" |
| 115 | echo "'yamllint' check not yet implemented. Skipping check" |
| 116 | |
| 117 | if [[ "${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." |
| 120 | fi |
| 121 | |
| 122 | exit "${FINAL_RET}" |