tfa-next: adapt for Rusted Copyright
The Rusted Firmware project requires a different copyright style.
Adapt the copyright scripts to support this as well.
Change-Id: I3aa1b9bb58a87fc6957cd9c737a5f776a36e3b49
Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
diff --git a/script/static-checks/check-copyright.py b/script/static-checks/check-copyright.py
index 0d2a832..f0c537f 100755
--- a/script/static-checks/check-copyright.py
+++ b/script/static-checks/check-copyright.py
@@ -66,10 +66,13 @@
# File must contain both lines to pass the check
COPYRIGHT_LINE = LINE_START + 'Copyright' + '.*' + TIME_PERIOD + '.*' + EOL
+RUST_COPYRIGHT_LINE = LINE_START + 'Copyright The Rusted Firmware-A Contributors.' + EOL
+
LICENSE_ID_LINE = LINE_START + 'SPDX-License-Identifier:' + LICENSE_ID + EOL
# Compiled license patterns
COPYRIGHT_PATTERN = re.compile(COPYRIGHT_LINE, re.MULTILINE)
+RUST_COPYRIGHT_PATTERN = re.compile(RUST_COPYRIGHT_LINE, re.MULTILINE)
LICENSE_ID_PATTERN = re.compile(LICENSE_ID_LINE, re.MULTILINE)
CURRENT_YEAR = str(datetime.datetime.now().year)
@@ -77,7 +80,7 @@
COPYRIGHT_OK = 0
COPYRIGHT_ERROR = 1
-def check_copyright(path, args, encoding='utf-8'):
+def check_copyright(path, args, rusted=False, encoding='utf-8'):
'''Checks a file for a correct copyright header.'''
result = COPYRIGHT_OK
@@ -85,11 +88,15 @@
with open(path, encoding=encoding) as file_:
file_content = file_.read()
- copyright_line = COPYRIGHT_PATTERN.search(file_content)
+ if rusted:
+ copyright_line = RUST_COPYRIGHT_PATTERN.search(file_content)
+ else:
+ copyright_line = COPYRIGHT_PATTERN.search(file_content)
+
if not copyright_line:
print("ERROR: Missing copyright in " + file_.name)
result = COPYRIGHT_ERROR
- elif CURRENT_YEAR not in copyright_line.group():
+ elif not rusted and CURRENT_YEAR not in copyright_line.group():
print("WARNING: Copyright is out of date in " + file_.name + ": '" +
copyright_line.group() + "'")
@@ -103,7 +110,10 @@
print("Checking the copyrights in the code...")
if args.verbose:
- print ("Copyright regexp: " + COPYRIGHT_LINE)
+ if args.rusted:
+ print ("Copyright regexp: " + RUST_COPYRIGHT_LINE)
+ else:
+ print ("Copyright regexp: " + COPYRIGHT_LINE)
print ("License regexp: " + LICENSE_ID_LINE)
if args.patch:
@@ -140,7 +150,7 @@
if args.verbose:
print("Checking file " + f)
- rc = check_copyright(f, args)
+ rc = check_copyright(f, args, rusted=args.rusted)
if rc == COPYRIGHT_OK:
count_ok += 1
@@ -171,6 +181,10 @@
help="Path to the source tree to check (default: %(default)s)",
default=os.curdir)
+ parser.add_argument("--rusted", "-r",
+ help="Check for Rusted Firmware CopyRight style (default: %(default)s)",
+ action='store_true', default=False)
+
parser.add_argument("--verbose", "-v",
help="Increase verbosity to the source tree to check (default: %(default)s)",
action='store_true', default=False)
diff --git a/script/static-checks/static-checks-check-copyright.sh b/script/static-checks/static-checks-check-copyright.sh
index 9759b5f..391c4dd 100755
--- a/script/static-checks/static-checks-check-copyright.sh
+++ b/script/static-checks/static-checks-check-copyright.sh
@@ -5,13 +5,14 @@
# SPDX-License-Identifier: BSD-3-Clause
#
-# test-package-check-copyright.sh DIRECTORY
+# test-package-check-copyright.sh DIRECTORY CPYRIGHT_FLAGS
this_dir="$(readlink -f "$(dirname "$0")")"
. $this_dir/common.sh
DIRECTORY="$1"
+CPYRIGHT_FLAGS="$2"
TEST_CASE="Copyright headers of files modified by this patch"
@@ -19,7 +20,7 @@
LOG_FILE=`mktemp -t common.XXXX`
-"$CI_ROOT"/script/static-checks/check-copyright.py --tree "$DIRECTORY" --patch --from-ref $(get_merge_base) &> "$LOG_FILE"
+"$CI_ROOT"/script/static-checks/check-copyright.py --tree "$DIRECTORY" "$CPYRIGHT_FLAGS" --patch --from-ref $(get_merge_base) &> "$LOG_FILE"
RES=$?
if [ -s "$LOG_FILE" ]; then