-
Notifications
You must be signed in to change notification settings - Fork 17
scripts: support local check for developers #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
04275ba
scripts: support local tidy/format/license check for developers
WangJialei-A 5cab26a
scripts: add tool check
WangJialei-A 9cbd69d
scripts: strengthen script
WangJialei-A 2dd1479
scripts: fix script
WangJialei-A da55001
scripts: guide user to install openmp
WangJialei-A f43f5e8
scripts: support flag to check all
WangJialei-A File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#! /bin/bash | ||
|
||
# Copyright (C) 2024 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions | ||
# and limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|
||
# this is for developer local check only. | ||
# not used by github action | ||
|
||
check_tool() { | ||
which $1 &> /dev/null || (echo "$1 not found!" && exit 1) | ||
} | ||
|
||
for arg in "$@"; do | ||
case $arg in | ||
-f|--format) | ||
CHECK_FORMAT=1 | ||
;; | ||
-t|--tidy) | ||
CHECK_TIDY=1 | ||
;; | ||
-l|--license) | ||
CHECK_LICENSE=1 | ||
;; | ||
-a|--all) | ||
CHECK_FORMAT=1 | ||
CHECK_TIDY=1 | ||
CHECK_LICENSE=1 | ||
;; | ||
-c|--clean) | ||
CLEANUP=1 | ||
;; | ||
*) # Handle other unknown options | ||
echo "Unknown option: $1" | ||
exit 1 | ||
;; | ||
esac | ||
WangJialei-A marked this conversation as resolved.
Show resolved
Hide resolved
|
||
done | ||
|
||
# set PR_REF if your pr target is not main | ||
: ${PR_REF:=main} | ||
|
||
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)" | ||
cd "$PROJECT_ROOT" | ||
|
||
MERGE_BASE=$(git merge-base $PR_REF HEAD) | ||
CHANGED_FILES=$(git diff --name-only $MERGE_BASE HEAD) | ||
|
||
# if you do not have clang/clang++/clang-tidy/clang-format/openmp | ||
# please install it | ||
# conda install -c conda-forge clangxx cxx-compiler clang-tools llvm-openmp | ||
|
||
if [ -n "$CHECK_TIDY" ]; then | ||
echo "start tidy check..." | ||
if [ -z "${MLIR_DIR}" ]; then | ||
echo "The environment variable MLIR_DIR is not set." | ||
exit 1 | ||
fi | ||
check_tool "clang" | ||
check_tool "clang++" | ||
check_tool "clang-tidy" | ||
check_tool "lit" | ||
|
||
TIDY_ROOT="${PROJECT_ROOT}/build/tidy" | ||
[ -n "$CLEANUP" ] && rm -rf "${TIDY_ROOT}" | ||
mkdir -p "${TIDY_ROOT}" | ||
AndreyPavlenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cd "${TIDY_ROOT}" | ||
|
||
cmake ../../ \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DMLIR_DIR="${MLIR_DIR}" \ | ||
-DCMAKE_EXPORT_COMPILE_COMMANDS=True \ | ||
-DCMAKE_C_COMPILER=$(which clang) \ | ||
-DCMAKE_CXX_COMPILER=$(which clang++) \ | ||
-DLLVM_EXTERNAL_LIT=$(which lit) | ||
|
||
for f in $(find ./include -name Makefile); do | ||
for target in $(make -f $f help |grep IncGen); do | ||
cd ${f%Makefile} && make ${target#...} && cd -; | ||
done | ||
done | ||
|
||
[ -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 | ||
[ -f .clang-tidy ] || wget https://raw.githubusercontent.com/llvm/llvm-project/main/mlir/.clang-tidy -O .clang-tidy | ||
|
||
python3 run-clang-tidy.py -warnings-as-errors=* -p ./ -config-file .clang-tidy -clang-tidy-binary $(which clang-tidy) $CHANGED_FILES | ||
fi | ||
|
||
if [ -n "$CHECK_FORMAT" ]; then | ||
echo "start format check..." | ||
check_tool "clang-format" | ||
cd "$PROJECT_ROOT" | ||
echo "$CHANGED_FILES" | egrep "*\\.(h|hpp|c|cpp)$" | xargs clang-format --dry-run --Werror -style=file | ||
fi | ||
|
||
if [ -n "$CHECK_LICENSE" ]; then | ||
echo "start license check..." | ||
cd "$PROJECT_ROOT" | ||
python3 scripts/license.py --files $(echo $CHANGED_FILES | tr ' ' ',') | ||
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's usually better to use explicit
set -e
in case someone usesbash script
to launch the scriptThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
set -e
? I think, it's very useful for error checking.