summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorДилшоджон Умронхонович Пошшоев/AI Tools Lab /SRR/Engineer/삼성전자 <d.poshshoev@samsung.com>2019-04-09 07:11:19 +0300
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>2019-04-09 13:11:19 +0900
commitb7ee7320906921ec879b55a9410294ca8e643268 (patch)
treeb63946ddab0bf0570b6c86c20d1a4828cc94f6c6
parent8df8a728f5f9cd61ba7804b0f09457d6168a85c0 (diff)
downloadnnfw-b7ee7320906921ec879b55a9410294ca8e643268.tar.gz
nnfw-b7ee7320906921ec879b55a9410294ca8e643268.tar.bz2
nnfw-b7ee7320906921ec879b55a9410294ca8e643268.zip
Add copyright checker for newly added files (#4214)
* Add copyright checker for newly added files Add copyright checker for newly added files Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com> * Update command that lists newly added files Update command that lists newly added files Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com> * Check just listed directories Check just listed directories by skipping exluded ones Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com> * Check all files, that were added this year This prevents from updating copyright year of a file, that were added with correct copyright, but later on somehow was updated incorrectly. Also, this addresses feedbacks of @hseok82-oh Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com> * Fix Copyright grep command Fix Copyright grep command Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com> * Move checker to seperate file and change checking method Also fixed files, that have wrong copyright Checks just `.h, .hpp, .cc, .cpp, .cl` files Check each files of subdir, that were added to git, or moved from other directory in current year. If a file is added (not merged into master) in this year and its copyright has incorrect format or copyright year isn't current year, then print it. Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com> * Rebase Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com> * Remove unused pushd and popd Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com> * Revert fixed copyrights Signed-off-by: Poshshoev Dilshodzhon <d.poshshoev@samsung.com>
-rwxr-xr-xscripts/command/copyright-checker.sh46
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