11#! /usr/bin/env bash
22# SPDX-License-Identifier: BSD-3-Clause
3- # Copyright 2016-2020 , Intel Corporation
3+ # Copyright 2016-2021 , Intel Corporation
44
55# check-headers.sh - check copyright and license in source files
66
77SELF=$0
88
99function usage() {
1010 echo " Usage: $SELF <source_root_path> <license_tag> [-h|-v|-a]"
11- echo " -h, --help this help message"
12- echo " -v, --verbose verbose mode"
13- echo " -a, --all check all files (only modified files are checked by default)"
11+ echo " -h, --help this help message"
12+ echo " -v, --verbose verbose mode"
13+ echo " -a, --all check all files (only modified files are checked by default)"
14+ echo " -d, --update_dates change Copyright dates in all analyzed files (rather not use with -a)"
1415}
1516
1617if [ " $# " -lt 2 ]; then
4950
5051VERBOSE=0
5152CHECK_ALL=0
53+ UPDATE_DATES=0
5254while [ " $1 " != " " ]; do
5355 case $1 in
5456 -v|--verbose)
@@ -57,6 +59,9 @@ while [ "$1" != "" ]; do
5759 -a|--all)
5860 CHECK_ALL=1
5961 ;;
62+ -d|--update_dates)
63+ UPDATE_DATES=1
64+ ;;
6065 esac
6166 shift
6267done
8893
8994FILES=$( $GIT $GIT_COMMAND | ${SOURCE_ROOT} /utils/check_license/file-exceptions.sh | \
9095 grep -E -e ' *\.[chs]$' -e ' *\.[ch]pp$' -e ' *\.sh$' \
91- -e ' *\.py$ ' -e ' *\. link$' -e ' Makefile*' -e ' TEST*' \
96+ -e ' *\.link$' -e ' Makefile*' -e ' TEST*' \
9297 -e ' /common.inc$' -e ' /match$' -e ' /check_whitespace$' \
9398 -e ' LICENSE$' -e ' CMakeLists.txt$' -e ' *\.cmake$' | \
9499 xargs)
@@ -104,7 +109,7 @@ for file in $FILES ; do
104109 iconv -f $ENCODING -t " UTF-8" $src_path > $TEMPFILE
105110
106111 if ! grep -q " SPDX-License-Identifier: $LICENSE " $src_path ; then
107- echo >&2 " $src_path :1: no $LICENSE SPDX tag found "
112+ echo >&2 " error: no $LICENSE SPDX tag in file: $src_path "
108113 RV=1
109114 fi
110115
@@ -135,7 +140,7 @@ for file in $FILES ; do
135140s/.*Copyright \([0-9]\+\)-\([0-9]\+\),.*/\1-\2/
136141s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path `
137142 if [ -z " $YEARS " ]; then
138- echo >&2 " $src_path :1: No copyright years found "
143+ echo >&2 " No copyright years in $src_path "
139144 RV=1
140145 continue
141146 fi
@@ -156,11 +161,15 @@ s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path`
156161 else
157162 NEW=$COMMIT_FIRST -$COMMIT_LAST
158163 fi
159- echo " $file :1: error: wrong copyright date: (is: $YEARS , should be: $NEW )" >&2
160- RV=1
164+ if [ ${UPDATE_DATES} -eq 1 ]; then
165+ sed -i " s/Copyright ${YEARS} /Copyright ${NEW} /g" " ${src_path} "
166+ else
167+ echo " $file :1: error: wrong copyright date: (is: $YEARS , should be: $NEW )" >&2
168+ RV=1
169+ fi
161170 fi
162171 else
163- echo " $file :1: unknown commit dates" >&2
172+ echo " error: unknown commit dates in file: $file " >&2
164173 RV=1
165174 fi
166175done
0 commit comments