Skip to content

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 6 commits into from
Jun 13, 2024
Merged
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
113 changes: 113 additions & 0 deletions scripts/full_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#! /bin/bash
Copy link
Contributor

@AndreyPavlenko AndreyPavlenko Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#! /bin/bash
#! /bin/bash
set -e

Copy link
Contributor

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 uses bash script to launch the script

Copy link
Contributor

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.


# 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
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}"
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
4 changes: 2 additions & 2 deletions scripts/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def use_llvm_license(path: str) -> bool:

year: int = datetime.datetime.now().year
success: bool = True

parser = argparse.ArgumentParser(prog = "benchgc license checker")
parser = argparse.ArgumentParser(prog = "license.py")
parser.add_argument("--files", required=True, type = str, help = "comma seperated file list")
args = parser.parse_args()

Expand Down