diff options
-rwxr-xr-x | scripts/command/copyright-checker.sh | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/command/copyright-checker.sh b/scripts/command/copyright-checker.sh new file mode 100755 index 000000000..9f2201f07 --- /dev/null +++ b/scripts/command/copyright-checker.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +check_copyright_year() { + DIRECTORIES_NOT_TO_BE_TESTED=$2 + YEAR=`date +"%Y"` + CORRECT_COPYRIGHT="Copyright (c) $YEAR Samsung Electronics Co" + FILE_EXT_TO_SEARCH="\.h$\|\.hpp$\|\.cc$\|\.cpp$\|\.cl$" + + # Check newly added files + #this also includes files, that were moved here from another dir + NEW_FILES_OF_SUBDIR_TO_CHECK=$(git whatchanged --diff-filter=A --since "01/01/2019"\ + --oneline --name-only --pretty=format: . | sort | uniq\ + | grep $FILE_EXT_TO_SEARCH) + ARR=($NEW_FILES_OF_SUBDIR_TO_CHECK) + for s in ${DIRECTORIES_NOT_TO_BE_TESTED[@]}; do + if [[ $s = $TEST_DIR* ]]; then + skip=${s#$TEST_DIR/}/ + ARR=(${ARR[*]//$skip*}) + fi + done + NEW_FILES_OF_SUBDIR_TO_CHECK=${ARR[*]} + if [[ ${#NEW_FILES_OF_SUBDIR_TO_CHECK} -ne 0 ]]; then + for f in $NEW_FILES_OF_SUBDIR_TO_CHECK; do + [[ -f "$f" ]] || continue + + CREATED_YEAR=$(git log --follow --format=%aD $f | tail -1) + [[ $CREATED_YEAR != *"$YEAR"* ]] && continue + + COPYRIGHT_YEAR=$(sed -rn '0,/.*Copyright \(c\) ([^ ]+).*/ s//\1/p' $f) + if [[ $COPYRIGHT_YEAR != $YEAR ]]; then + [[ -z "$COPYRIGHT_YEAR" ]] && COPYRIGHT_YEAR="None" + echo "Copyright year of $f is incorrect: expected $YEAR, found $COPYRIGHT_YEAR" + elif ! grep -q "$CORRECT_COPYRIGHT" $f; then + echo "Copyright format of $f is incorrect: expected $CORRECT_COPYRIGHT" + fi + done + fi +} + +DIRECTORIES_NOT_TO_BE_TESTED=() + +for DIR_NOT_TO_BE_TESTED in $(find -name '.FORMATDENY' -exec dirname {} \;); do + DIRECTORIES_NOT_TO_BE_TESTED+=("$DIR_NOT_TO_BE_TESTED") +done + +check_copyright_year $DIRECTORIES_NOT_TO_BE_TESTED |