Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 14677b5

Browse files
Merge pull request #1171 from karczex/copyright_format
Add copyright-format target to CMakeLists
2 parents 9f17a83 + 42bc49b commit 14677b5

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ add_custom_target(check-license
183183
COMMAND ${LIBPMEMOBJCPP_ROOT_DIR}/utils/check_license/check-headers.sh
184184
${LIBPMEMOBJCPP_ROOT_DIR}
185185
BSD-3-Clause)
186+
add_custom_target(copyright-format
187+
COMMAND ${LIBPMEMOBJCPP_ROOT_DIR}/utils/check_license/check-headers.sh
188+
${LIBPMEMOBJCPP_ROOT_DIR}
189+
BSD-3-Clause -d)
190+
186191

187192
if(CHECK_CPP_STYLE)
188193
find_program(CLANG_FORMAT NAMES clang-format clang-format-9 clang-format-9.0)

utils/check_license/check-headers.sh

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
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

77
SELF=$0
88

99
function 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

1617
if [ "$#" -lt 2 ]; then
@@ -49,6 +50,7 @@ fi
4950

5051
VERBOSE=0
5152
CHECK_ALL=0
53+
UPDATE_DATES=0
5254
while [ "$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
6267
done
@@ -88,7 +93,7 @@ fi
8893

8994
FILES=$($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
135140
s/.*Copyright \([0-9]\+\)-\([0-9]\+\),.*/\1-\2/
136141
s/.*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
166175
done

0 commit comments

Comments
 (0)