From 9335b36738cecaa84f7424d56f8061733ff6e997 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 24 Jun 2019 13:25:34 +0900 Subject: [PATCH] Add check-copyright command (#3927) This commit adds check-copyright command which checkes whether the copyrigh notice is present or not. Signed-off-by: Jonghyun Park --- scripts/command/check-copyright | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scripts/command/check-copyright diff --git a/scripts/command/check-copyright b/scripts/command/check-copyright new file mode 100644 index 0000000..bf332b9 --- /dev/null +++ b/scripts/command/check-copyright @@ -0,0 +1,55 @@ +#!/bin/bash + +# HOW TO USE +# +# Create .COPYRIGHT file at the root of your project (contrib/[PROJECT]/.COPYRIGHT) +# with the copyright pattern required for your project. +# +# echo "Copyright (c) [0-9]\+ Samsung Electronics Co., Ltd. All Rights Reserved" > contrib/[PROJECT]/.COPYRIGHT +# +# DISCLAIMER +# +# This check works only when your copyright notice is of the following form: +# +# /** +# * [Copyright notice] +# ... +# */ +# +# NOTE +# +# The current implementation does not validate YEAR in the copyright notice. +# +# TODO Validate YEAR without FALSE POSTIVIES +# +# It already turns out that checking the initial commit year introduces +# FALSE POSITIVES if there are relocated files. +INVALID_FILES=() + +for COPYRIGHT_PATH in $(ls ${NNCC_PROJECT_PATH}/contrib/*/.COPYRIGHT); do + PROJECT_PATH="$(dirname ${COPYRIGHT_PATH})" + PROJECT_NAME="$(basename ${PROJECT_PATH})" + + CANDIDATE_FILES=$(find "${PROJECT_PATH}" -iname '*.h' -o -iname '*.hpp' -o -iname '*.cpp' -o -iname '*.c') + + for TRACKED_FILE in $(git ls-files $CANDIDATE_FILES); do + MATCHED=$(cat "${NNCC_PROJECT_PATH}/${TRACKED_FILE}" | head -n2 | tail -n1 | sed 's/^ \* //g' | grep -f "${COPYRIGHT_PATH}" | wc -l) + + if [[ ${MATCHED} -ne 1 ]]; then + INVALID_FILES+=(${TRACKED_FILE}) + fi + done +done + +if [[ ${#INVALID_FILES[@]} -ne 0 ]]; then + echo ">> FAILED <<" + echo + echo "PLEASE CHECK THE FOLLOWING FILES" + for INVALID_FILE in "${INVALID_FILES[@]}"; do + echo "- ${INVALID_FILE}" + done + exit 255 +fi + +echo ">> PASSED <<" +exit 0 -- 2.7.4