Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion docker/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 56 additions & 9 deletions tests/lint/cpplint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <commit>]"
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 <regex>$' {} +; then
echo "The <regex> 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 <regex> functions." 1>&2
echo "See https://github.com/pytorch/pytorch/issues/51039 for more details." 1>&2
exit 1
Expand Down
Loading