From bfc10e1584b424240480c599a2d2c4dac75252c5 Mon Sep 17 00:00:00 2001 From: Erik Lundell Date: Thu, 16 Jan 2025 16:04:51 +0100 Subject: [PATCH] Add git hook suggestions for Arm development Pre-commit runs lintrunner on commited files, tries applying the changes. Pre-push does not push if lintrunner or a simple license check does not pass. If WIP is included in commit header, no checks are done. setup-env.sh symlinks the hooks to your .git/hooks. install-editable.sh contains commands needed to do an editable install. Change-Id: I4c52a1c9d67945b71701f79e8f0913f927d7ea4f Signed-off-by: Erik Lundell --- backends/arm/scripts/pre-commit | 13 ++++++++ backends/arm/scripts/pre-push | 45 +++++++++++++++++++++++++++ backends/arm/scripts/setup-dev-env.sh | 9 ++++++ 3 files changed, 67 insertions(+) create mode 100755 backends/arm/scripts/pre-commit create mode 100755 backends/arm/scripts/pre-push create mode 100755 backends/arm/scripts/setup-dev-env.sh diff --git a/backends/arm/scripts/pre-commit b/backends/arm/scripts/pre-commit new file mode 100755 index 00000000000..2000585f930 --- /dev/null +++ b/backends/arm/scripts/pre-commit @@ -0,0 +1,13 @@ +#!/bin/bash +# Copyright 2025 Arm Limited and/or its affiliates. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# Check 1: If commit header contains WIP, everything is ok +git rev-list --format=%s --max-count=1 HEAD | grep -q WIP && exit 0 + +# Check 2: lintunner on latest patch. +lintrunner -a --revision 'HEAD^' --skip MYPY +commit_files=$(git diff-tree --no-commit-id --name-only --diff-filter=M HEAD -r) +git add $commit_files || true \ No newline at end of file diff --git a/backends/arm/scripts/pre-push b/backends/arm/scripts/pre-push new file mode 100755 index 00000000000..c51138b8ec7 --- /dev/null +++ b/backends/arm/scripts/pre-push @@ -0,0 +1,45 @@ +#!/bin/bash +# Copyright 2025 Arm Limited and/or its affiliates. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# Check 1: If commit header contains WIP, everything is ok +git rev-list --format=%s --max-count=1 HEAD | grep -q WIP && exit 0 + +# Check 2: lintunner on latest patches. +lintrunner --revision 'HEAD^' +if [[ $? != 0 ]] + then + echo "Failed linting" + exit 1 +fi + +# Check 3: License headers +# We do a simple check of if all committed headers contain "$current_year Arm". +# This does not guarantee OK in ci but should be ok most of the time. + +current_year=$(date +%Y) +failed_license_check=false +commit_files=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMR HEAD -r) + + +for commited_file in $commit_files; do + head $commited_file | grep -q "$current_year Arm" + if [[ $? != 0 ]] + then + echo "Header in $commited_file did not contain '$current_year Arm'" + failed_license_check=true + else + echo "$commited_file passed license check" + fi +done + +if [[ $failed_license_check == true ]] + then + exit 1 + else + echo "Passed simple license check" +fi + +exit 0 diff --git a/backends/arm/scripts/setup-dev-env.sh b/backends/arm/scripts/setup-dev-env.sh new file mode 100755 index 00000000000..b8c9b3b44cd --- /dev/null +++ b/backends/arm/scripts/setup-dev-env.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# Copyright 2025 Arm Limited and/or its affiliates. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +git_dir=$(git rev-parse --git-dir) +ln $git_dir/../backends/arm/scripts/pre-push $git_dir/hooks +ln $git_dir/../backends/arm/scripts/pre-commit $git_dir/hooks \ No newline at end of file