Skip to content

Commit 9ff54ca

Browse files
committed
scripts: support local tidy/format/license check for developers
1 parent a1858db commit 9ff54ca

File tree

2 files changed

+100
-2
lines changed

2 files changed

+100
-2
lines changed

scripts/full_check.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#! /bin/bash -x
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+
while [[ $# -gt 0 ]]; do
24+
case $1 in
25+
--format)
26+
CHECK_FORMAT=1
27+
shift
28+
;;
29+
--tidy)
30+
CHECK_TIDY=1
31+
shift
32+
;;
33+
--license)
34+
CHECK_LICENSE=1
35+
shift
36+
;;
37+
*) # Handle other unknown options
38+
echo "Unknown option: $1"
39+
exit 1
40+
;;
41+
esac
42+
done
43+
44+
# set PR_REF if your pr target is not main
45+
: ${PR_REF:=main}
46+
47+
48+
PROJECT_ROOT=$(pwd)/$(dirname "${BASH_SOURCE[0]}")/../
49+
cd $PROJECT_ROOT
50+
51+
MERGE_BASE=$(git merge-base $PR_REF HEAD)
52+
CHANGED_FILES=$(git diff --name-only $MERGE_BASE HEAD)
53+
54+
# if you do not have clang/clang++/clang-tidy/clang-format
55+
# please install it
56+
# conda install -c conda-forge clangxx cxx-compiler clang-tools
57+
58+
if [ -n "$CHECK_TIDY" ]; then
59+
echo "start tidy check..."
60+
if [ -z "${MLIR_DIR}" ]; then
61+
echo "The environment variable MLIR_DIR is not set."
62+
exit 1
63+
fi
64+
TIDY_ROOT=${PROJECT_ROOT}/build/tidy
65+
mkdir -p ${TIDY_ROOT}
66+
cd ${TIDY_ROOT}
67+
cmake ../../ \
68+
-DCMAKE_BUILD_TYPE=Release \
69+
-DMLIR_DIR=${MLIR_DIR} \
70+
-DCMAKE_EXPORT_COMPILE_COMMANDS=True \
71+
-DCMAKE_C_COMPILER=$(which clang) \
72+
-DCMAKE_CXX_COMPILER=$(which clang++) \
73+
-DLLVM_EXTERNAL_LIT=$(which lit)
74+
75+
for f in $(find ./include -name Makefile); do
76+
target=$(make -f $f help |grep IncGen);
77+
if [[ $? -eq 0 ]]; then
78+
cd ${f%Makefile} && make ${target#...} && cd -;
79+
fi ;
80+
done
81+
82+
[ -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
83+
[ -f .clang-tidy ] || wget https://raw.githubusercontent.com/llvm/llvm-project/main/mlir/.clang-tidy -O .clang-tidy
84+
85+
python3 run-clang-tidy.py -warnings-as-errors=* -p ./ -config-file .clang-tidy -clang-tidy-binary $(which clang-tidy) $CHANGED_FILES
86+
fi
87+
88+
if [ -n "$CHECK_FORMAT" ]; then
89+
echo "start format check..."
90+
cd $PROJECT_ROOT
91+
echo "$CHANGED_FILES" | egrep "*\\.(h|hpp|c|cpp)$" | xargs clang-format --dry-run --Werror -style=file
92+
fi
93+
94+
if [ -n "$CHECK_LICENSE" ]; then
95+
echo "start license check..."
96+
cd $PROJECT_ROOT
97+
python3 scripts/license.py --files $(echo $CHANGED_FILES | tr ' ' ',')
98+
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)