11#! /usr/bin/env bash
2- # SPDX-License-Identifier: BSD-3-Clause
3- # Copyright 2016-2022, Intel Corporation
2+ # Copyright (C) 2024 Intel Corporation
3+ # Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
4+ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
45
56# check-headers.sh - check copyright and license in source files
67
78SELF=$0
89
910function usage() {
10- echo " Usage: $SELF <source_root_path> <license_tag> [-h|-v|-a]"
11+ echo " Usage: $SELF <source_root_path> <license_tag> [-h|-v|-a|-d ]"
1112 echo " -h, --help this help message"
1213 echo " -v, --verbose verbose mode"
1314 echo " -a, --all check all files (only modified files are checked by default)"
8384 GIT_COMMAND=" diff --name-only $MERGE_BASE $CURRENT_COMMIT "
8485fi
8586
86- FILES=$( $GIT $GIT_COMMAND | ${SOURCE_ROOT} /utils/check_license/file-exceptions.sh | \
87- grep -E -e ' *\.[chs]$' -e ' *\.[ch]pp$' -e ' *\.sh$' -e ' *\.py$' \
88- -e ' TEST*' -e ' Makefile*' -e ' CMakeLists.txt$' -e ' *\.cmake$' \
89- -e ' *\.link$' -e ' *\.map$' -e ' *\.Dockerfile$' -e ' LICENSE$' \
90- -e ' /common.inc$' -e ' /match$' -e ' /check_whitespace$' -e ' /cppstyle$' | \
91- xargs)
87+ FILES=$( $GIT $GIT_COMMAND | ${SOURCE_ROOT} /check_license/file-exceptions.sh)
9288
9389RV=0
90+
9491for file in $FILES ; do
9592 if [ $VERBOSE -eq 1 ]; then
9693 echo " Checking file: $file "
9794 fi
95+
9896 # The src_path is a path which should be used in every command except git.
9997 # git is called with -C flag so filepaths should be relative to SOURCE_ROOT
10098 src_path=" ${SOURCE_ROOT} /$file "
@@ -130,10 +128,10 @@ for file in $FILES ; do
130128 FIRST=` head -n1 $TMP2 `
131129 LAST=` tail -n1 $TMP2 `
132130
133- YEARS=` sed '
134- /Copyright [0-9-]\+.*, Intel Corporation/!d
135- s/.*Copyright \([0-9]\+\)-\([0-9]\+\), .*/\1-\2/
136- s/.*Copyright \([0-9]\+\), .*/\1-\1 /' $src_path `
131+ YEARS=$( sed '
132+ /.* Copyright (C) \+.* [0-9-]\+ Intel Corporation/!d
133+ s/.*Copyright (C) \([0-9]\+\)-\([0-9]\+\).*/\1-\2/
134+ s/.*Copyright (C) \([0-9]\+\).*/\1/' " $src_path " )
137135 if [ -z " $YEARS " ]; then
138136 echo >&2 " No copyright years in $src_path "
139137 RV=1
@@ -145,22 +143,36 @@ s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path`
145143
146144 COMMIT_FIRST=` echo $FIRST | cut -d" -" -f1`
147145 COMMIT_LAST=` echo $LAST | cut -d" -" -f1`
146+
148147 if [ " $COMMIT_FIRST " != " " -a " $COMMIT_LAST " != " " ]; then
149- if [ $HEADER_LAST -lt $COMMIT_LAST ]; then
150- if [ $HEADER_FIRST -lt $COMMIT_FIRST ]; then
151- COMMIT_FIRST=$HEADER_FIRST
148+ if [[ -n " $COMMIT_FIRST " && -n " $COMMIT_LAST " ]]; then
149+ FL=0
150+ if [[ $HEADER_FIRST -lt $COMMIT_FIRST ]]; then
151+ FL=1
152152 fi
153+
153154 COMMIT_LAST=` date +%G`
154- if [ $COMMIT_FIRST -eq $COMMIT_LAST ]; then
155- NEW=$COMMIT_LAST
155+
156+ if [[ $FL -eq 1 ]]; then
157+ NEW=$HEADER_FIRST -$COMMIT_LAST
156158 else
157- NEW=$COMMIT_FIRST -$COMMIT_LAST
159+
160+ if [[ $COMMIT_FIRST -eq $COMMIT_LAST ]]; then
161+ NEW=$COMMIT_LAST
162+ else
163+ NEW=$COMMIT_FIRST -$COMMIT_LAST
164+ fi
158165 fi
159- if [ ${UPDATE_DATES} -eq 1 ]; then
160- sed -i " s/Copyright ${YEARS} /Copyright ${NEW} /g" " ${src_path} "
161- else
162- echo " $file :1: error: wrong copyright date: (is: $YEARS , should be: $NEW )" >&2
163- RV=1
166+
167+ if [[ " $YEARS " == " $NEW " ]]; then
168+ echo " No change needed: $YEARS "
169+ else
170+ if [[ ${UPDATE_DATES} -eq 1 ]]; then
171+ sed -i " s/Copyright ${YEARS} /Copyright ${NEW} /g" " ${src_path} "
172+ else
173+ echo " $file :1: error: wrong copyright date: (is: $YEARS , should be: $NEW )" >&2
174+ RV=1
175+ fi
164176 fi
165177 fi
166178 else
0 commit comments