Skip to content

Commit f157cbe

Browse files
WangJialei-Azhczhong
authored andcommitted
scripts: support local check for developers (#113)
1 parent 9374c45 commit f157cbe

File tree

2 files changed

+115
-2
lines changed

2 files changed

+115
-2
lines changed

scripts/full_check.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#! /bin/bash
2+
3+
# Copyright (C) 2024 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions
15+
# and limitations under the License.
16+
#
17+
# SPDX-License-Identifier: Apache-2.0
18+
19+
20+
# this is for developer local check only.
21+
# not used by github action
22+
23+
check_tool() {
24+
which $1 &> /dev/null || (echo "$1 not found!" && exit 1)
25+
}
26+
27+
for arg in "$@"; do
28+
case $arg in
29+
-f|--format)
30+
CHECK_FORMAT=1
31+
;;
32+
-t|--tidy)
33+
CHECK_TIDY=1
34+
;;
35+
-l|--license)
36+
CHECK_LICENSE=1
37+
;;
38+
-a|--all)
39+
CHECK_FORMAT=1
40+
CHECK_TIDY=1
41+
CHECK_LICENSE=1
42+
;;
43+
-c|--clean)
44+
CLEANUP=1
45+
;;
46+
*) # Handle other unknown options
47+
echo "Unknown option: $1"
48+
exit 1
49+
;;
50+
esac
51+
done
52+
53+
# set PR_REF if your pr target is not main
54+
: ${PR_REF:=main}
55+
56+
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
57+
cd "$PROJECT_ROOT"
58+
59+
MERGE_BASE=$(git merge-base $PR_REF HEAD)
60+
CHANGED_FILES=$(git diff --name-only $MERGE_BASE HEAD)
61+
62+
# if you do not have clang/clang++/clang-tidy/clang-format/openmp
63+
# please install it
64+
# conda install -c conda-forge clangxx cxx-compiler clang-tools llvm-openmp
65+
66+
if [ -n "$CHECK_TIDY" ]; then
67+
echo "start tidy check..."
68+
if [ -z "${MLIR_DIR}" ]; then
69+
echo "The environment variable MLIR_DIR is not set."
70+
exit 1
71+
fi
72+
check_tool "clang"
73+
check_tool "clang++"
74+
check_tool "clang-tidy"
75+
check_tool "lit"
76+
77+
TIDY_ROOT="${PROJECT_ROOT}/build/tidy"
78+
[ -n "$CLEANUP" ] && rm -rf "${TIDY_ROOT}"
79+
mkdir -p "${TIDY_ROOT}"
80+
cd "${TIDY_ROOT}"
81+
82+
cmake ../../ \
83+
-DCMAKE_BUILD_TYPE=Release \
84+
-DMLIR_DIR="${MLIR_DIR}" \
85+
-DCMAKE_EXPORT_COMPILE_COMMANDS=True \
86+
-DCMAKE_C_COMPILER=$(which clang) \
87+
-DCMAKE_CXX_COMPILER=$(which clang++) \
88+
-DLLVM_EXTERNAL_LIT=$(which lit)
89+
90+
for f in $(find ./include -name Makefile); do
91+
for target in $(make -f $f help |grep IncGen); do
92+
cd ${f%Makefile} && make ${target#...} && cd -;
93+
done
94+
done
95+
96+
[ -f run-clang-tidy.py ] || wget https://raw.githubusercontent.com/llvm/llvm-project/main/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py -O run-clang-tidy.py
97+
[ -f .clang-tidy ] || wget https://raw.githubusercontent.com/llvm/llvm-project/main/mlir/.clang-tidy -O .clang-tidy
98+
99+
python3 run-clang-tidy.py -warnings-as-errors=* -p ./ -config-file .clang-tidy -clang-tidy-binary $(which clang-tidy) $CHANGED_FILES
100+
fi
101+
102+
if [ -n "$CHECK_FORMAT" ]; then
103+
echo "start format check..."
104+
check_tool "clang-format"
105+
cd "$PROJECT_ROOT"
106+
echo "$CHANGED_FILES" | egrep "*\\.(h|hpp|c|cpp)$" | xargs clang-format --dry-run --Werror -style=file
107+
fi
108+
109+
if [ -n "$CHECK_LICENSE" ]; then
110+
echo "start license check..."
111+
cd "$PROJECT_ROOT"
112+
python3 scripts/license.py --files $(echo $CHANGED_FILES | tr ' ' ',')
113+
fi

scripts/license.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def use_llvm_license(path: str) -> bool:
107107

108108
year: int = datetime.datetime.now().year
109109
success: bool = True
110-
111-
parser = argparse.ArgumentParser(prog = "benchgc license checker")
110+
111+
parser = argparse.ArgumentParser(prog = "license.py")
112112
parser.add_argument("--files", required=True, type = str, help = "comma seperated file list")
113113
args = parser.parse_args()
114114

0 commit comments

Comments
 (0)