diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 13a06a6cb3db..f3f53a6d2f64 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -77,9 +77,9 @@ repos: language: system files: \.(c|cc|cpp|h|hpp)$ pass_filenames: false - - id: run-mypy - name: Type Checking with MyPY ... - entry: docker/lint.sh mypy - language: system - files: \.py$ - pass_filenames: false + # - id: run-mypy + # name: Type Checking with MyPY ... + # entry: docker/lint.sh mypy + # language: system + # files: \.py$ + # pass_filenames: false diff --git a/docker/lint.sh b/docker/lint.sh index 7225fa981fd9..c7cc5ad53b8f 100755 --- a/docker/lint.sh +++ b/docker/lint.sh @@ -52,7 +52,11 @@ function run_lint_step() { fi ;; cpplint) - cmd=( tests/lint/cpplint.sh ) + if [ $inplace_fix -eq 0 ]; then + cmd=( tests/lint/cpplint.sh ) + else + cmd=( tests/lint/cpplint.sh --rev origin/main ) + fi ;; flake8) if [ $inplace_fix -eq 0 ]; then diff --git a/tests/lint/cpplint.sh b/tests/lint/cpplint.sh index 84065e17b01d..063820a71d25 100755 --- a/tests/lint/cpplint.sh +++ b/tests/lint/cpplint.sh @@ -18,20 +18,67 @@ set -e -echo "Running 2 cpplints..." -python3 3rdparty/dmlc-core/scripts/lint.py --quiet tvm cpp \ - include src \ - examples/extension/src examples/graph_executor/src \ - tests/cpp tests/crt \ - --exclude_path "src/runtime/hexagon/rpc/hexagon_rpc.h" \ - "src/runtime/hexagon/rpc/hexagon_rpc_skel.c" \ - "src/runtime/hexagon/rpc/hexagon_rpc_stub.c" \ +LINT_ALL_FILES=true +REVISION= +while (( $# )); do + case "$1" in + --rev) + LINT_ALL_FILES=false + REVISION=$2 + shift 2 + ;; + *) + echo "Usage: tests/lint/cpplint.sh [--rev ]" + exit 1 + ;; + esac +done + +if [[ "$LINT_ALL_FILES" == "true" ]]; then + echo "Running 2 cpplints..." + python3 3rdparty/dmlc-core/scripts/lint.py --quiet tvm cpp \ + include src \ + examples/extension/src examples/graph_executor/src \ + tests/cpp tests/crt \ + --exclude_path "src/runtime/hexagon/rpc/hexagon_rpc.h" \ + "src/runtime/hexagon/rpc/hexagon_rpc_skel.c" \ + "src/runtime/hexagon/rpc/hexagon_rpc_stub.c" \ + +else + echo "Running cpplint on changed files..." + # Get changed files, filtering by the directories we care about + # We use git diff to find changes. + # We filter for the directories: include, src, examples/extension/src, examples/graph_executor/src, tests/cpp, tests/crt + + # grep pattern construction + DIRS="include|src|examples/extension/src|examples/graph_executor/src|tests/cpp|tests/crt" + + # Read files into array + IFS=$'\n' read -a FILES -d'\n' < <(git diff --name-only --diff-filter=ACMRTUX $REVISION | grep -E "^($DIRS)/" ) || true + + # Filter out excluded files + FILTERED_FILES=() + for f in "${FILES[@]}"; do + if [[ "$f" == "src/runtime/hexagon/rpc/hexagon_rpc.h" ]] || \ + [[ "$f" == "src/runtime/hexagon/rpc/hexagon_rpc_skel.c" ]] || \ + [[ "$f" == "src/runtime/hexagon/rpc/hexagon_rpc_stub.c" ]]; then + continue + fi + FILTERED_FILES+=("$f") + done + + if [ ${#FILTERED_FILES[@]} -eq 0 ]; then + echo "No changes in C++ files" + else + python3 3rdparty/dmlc-core/scripts/lint.py --quiet tvm cpp "${FILTERED_FILES[@]}" + fi +fi if find src -name "*.cc" -exec grep -Hn '^#include $' {} +; then echo "The header file may not be used in TVM," 1>&2 echo "because it causes ABI incompatibility with most pytorch installations." 1>&2 - echo "Pytorch packages on PyPI currently set `-DUSE_CXX11_ABI=0`," 1>&2 + echo "Pytorch packages on PyPI currently set \`-DUSE_CXX11_ABI=0\`," 1>&2 echo "which causes ABI compatibility when calling functions." 1>&2 echo "See https://github.com/pytorch/pytorch/issues/51039 for more details." 1>&2 exit 1