Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # |
| 4 | # Copyright (c) 2015 Wind River Systems, Inc. |
| 5 | # |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 6 | # SPDX-License-Identifier: Apache-2.0 |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 7 | # |
| 8 | |
| 9 | exe_name=$(basename $0) |
| 10 | |
| 11 | # check the last n patches patches from the current branch for errors |
| 12 | # usage: maintainer-checkpatch.bash [(-n <num commits>) | (-c <commit>)] [-s] |
| 13 | # where: -n <num commits> selects the last n commits (default: 1) |
| 14 | # -c <commit> selects the "since" commit |
| 15 | # -s asks for a summary instead of details |
| 16 | # |
| 17 | # -c and -n are mutually exclusive |
| 18 | |
| 19 | checkpatch_switches="\ |
| 20 | --patch \ |
| 21 | --no-tree \ |
| 22 | --show-types \ |
| 23 | --max-line-length=100 \ |
| 24 | " |
Peter Mitsis | e65534c | 2015-06-25 12:14:31 -0400 | [diff] [blame] | 25 | ignore_list=BRACES,PRINTK_WITHOUT_KERN_LEVEL,SPLIT_STRING,FILE_PATH_CHANGES,GERRIT_CHANGE_ID |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 26 | |
Anas Nashif | fdadb501 | 2018-04-02 14:19:39 -0500 | [diff] [blame] | 27 | timestamp_bin=${ZEPHYR_BASE}/scripts/checkpatch/timestamp |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 28 | timestamp="${timestamp_bin} -u" |
Anas Nashif | b882377 | 2015-06-05 22:46:00 -0400 | [diff] [blame] | 29 | checkpatch_bin=${ZEPHYR_BASE}/scripts/checkpatch.pl |
Inaky Perez-Gonzalez | 8ddf82c | 2015-04-10 16:44:37 -0700 | [diff] [blame] | 30 | checkpatch="${checkpatch_bin} ${checkpatch_switches} --ignore ${ignore_list}" |
| 31 | |
| 32 | ts=$(${timestamp}) |
| 33 | outdir=/tmp/${exe_name}-${ts} |
| 34 | |
| 35 | declare num_commits=1 |
| 36 | declare summary=n |
| 37 | declare since_commit="" |
| 38 | |
| 39 | function usage { |
| 40 | printf "usage: %s [(-n <num commits>) | (-c <commit>)] [-s]\n" $exe_name >&2 |
| 41 | } |
| 42 | |
| 43 | function fail { |
| 44 | usage |
| 45 | exit -1 |
| 46 | } |
| 47 | |
| 48 | function format_patch_fail { |
| 49 | printf "'git format-patch' failed\n" |
| 50 | exit -1 |
| 51 | } |
| 52 | |
| 53 | function verify_needed { |
| 54 | needed="\ |
| 55 | ${timestamp_bin} \ |
| 56 | ${checkpatch_bin} \ |
| 57 | " |
| 58 | for i in $needed; do |
| 59 | type $i &>/dev/null |
| 60 | if [ $? != 0 ]; then |
| 61 | printf "need '%s' but not found in PATH\n" $i >&2 |
| 62 | exit -1 |
| 63 | fi |
| 64 | done |
| 65 | } |
| 66 | |
| 67 | function get_opts { |
| 68 | declare -r optstr="n:c:sh" |
| 69 | while getopts ${optstr} opt; do |
| 70 | case ${opt} in |
| 71 | n) num_commits=${OPTARG} ;; |
| 72 | c) since_commit=${OPTARG} ;; |
| 73 | s) summary=y ;; |
| 74 | h) usage; exit 0 ;; |
| 75 | *) fail ;; |
| 76 | esac |
| 77 | done |
| 78 | |
| 79 | if [ ${num_commits} != 1 -a "x${since_commit}" != x ]; then |
| 80 | fail |
| 81 | fi |
| 82 | } |
| 83 | |
| 84 | verify_needed |
| 85 | get_opts $@ |
| 86 | |
| 87 | if [ x${since_commit} != x ]; then |
| 88 | since=${since_commit} |
| 89 | else |
| 90 | since=HEAD~${num_commits} |
| 91 | fi |
| 92 | git format-patch ${since} -o ${outdir} 2>/dev/null >/dev/null |
| 93 | [ $? = 0 ] || format_patch_fail |
| 94 | |
| 95 | for i in $(ls ${outdir}/*); do |
| 96 | printf "\n$(basename ${i})\n" |
| 97 | if [ ${summary} = y ]; then |
| 98 | ${checkpatch} $i | grep "total:" |
| 99 | else |
| 100 | ${checkpatch} $i |
| 101 | fi |
| 102 | done |
| 103 | |
| 104 | rm -rf ${outdir} |