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
9490for file in $FILES ; do
@@ -130,10 +126,10 @@ for file in $FILES ; do
130126 FIRST=` head -n1 $TMP2 `
131127 LAST=` tail -n1 $TMP2 `
132128
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 `
129+ YEARS=$( sed '
130+ /.* Copyright (C) \+.* [0-9-]\+ Intel Corporation/!d
131+ s/.*Copyright (C) \([0-9]\+\)-\([0-9]\+\).*/\1-\2/
132+ s/.*Copyright (C) \([0-9]\+\).*/\1/' " $src_path " )
137133 if [ -z " $YEARS " ]; then
138134 echo >&2 " No copyright years in $src_path "
139135 RV=1
@@ -145,22 +141,36 @@ s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path`
145141
146142 COMMIT_FIRST=` echo $FIRST | cut -d" -" -f1`
147143 COMMIT_LAST=` echo $LAST | cut -d" -" -f1`
144+
148145 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
146+ if [[ -n " $COMMIT_FIRST " && -n " $COMMIT_LAST " ]]; then
147+ FL=0
148+ if [[ $HEADER_FIRST -lt $COMMIT_FIRST ]]; then
149+ FL=1
152150 fi
151+
153152 COMMIT_LAST=` date +%G`
154- if [ $COMMIT_FIRST -eq $COMMIT_LAST ]; then
155- NEW=$COMMIT_LAST
153+
154+ if [[ $FL -eq 1 ]]; then
155+ NEW=$HEADER_FIRST -$COMMIT_LAST
156156 else
157- NEW=$COMMIT_FIRST -$COMMIT_LAST
157+
158+ if [[ $COMMIT_FIRST -eq $COMMIT_LAST ]]; then
159+ NEW=$COMMIT_LAST
160+ else
161+ NEW=$COMMIT_FIRST -$COMMIT_LAST
162+ fi
158163 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
164+
165+ if [[ " $YEARS " == " $NEW " ]]; then
166+ echo " No change needed: $YEARS "
167+ else
168+ if [[ ${UPDATE_DATES} -eq 1 ]]; then
169+ sed -i " s/Copyright ${YEARS} /Copyright ${NEW} /g" " ${src_path} "
170+ else
171+ echo " $file :1: error: wrong copyright date: (is: $YEARS , should be: $NEW )" >&2
172+ RV=1
173+ fi
164174 fi
165175 fi
166176 else
0 commit comments