Skip to content

Commit

Permalink
[larry-robotics#3] Add copyright header template and set license head…
Browse files Browse the repository at this point in the history
…er script
  • Loading branch information
elfenpiff committed Dec 12, 2023
1 parent 323f40e commit 8270ced
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
3 changes: 2 additions & 1 deletion scripts/ci_test_spdx_license_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

cd $(git rev-parse --show-toplevel)

REQUIRED_LICENSE_HEADER="SPDX-License-Identifier: Apache-2.0"
RET_VAL=0

check_license_header() {
FILES=$(find . -type f -iwholename "${FILE_SUFFIX}" )
CHECK_LICENSE="${COMMENT_SYMBOL} SPDX-License-Identifier: Apache-2.0"
CHECK_LICENSE="${COMMENT_SYMBOL} ${REQUIRED_LICENSE_HEADER}"

for FILE in $FILES
do
Expand Down
11 changes: 11 additions & 0 deletions scripts/copyright_header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright (c) {year} Contributors to the Eclipse Foundation

See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.

This program and the accompanying materials are made available under the
terms of the Apache Software License 2.0 which is available at
https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
which is available at https://opensource.org/licenses/MIT.

SPDX-License-Identifier: Apache-2.0 OR MIT
21 changes: 4 additions & 17 deletions scripts/set_license_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,21 @@

cd $(git rev-parse --show-toplevel)

LICENSE_PREFIX="SPDX-License-Identifier:"
LICENSE=$1
LICENSE_TEXT=$(cat copyright_header.txt)

set_license_header() {
LICENSE_CODE=$(echo $LICENSE_TEXT | sed "s/\(.*\)/$COMMENT_SYMBOL \1/")
FILES=$(find . -type f -iwholename "${FILE_SUFFIX}" )

for FILE in $FILES
do
HAS_LICENSE_IDENTIFIER=$(cat $FILE | head -n 1 | grep -E "^${COMMENT_SYMBOL} ${LICENSE_PREFIX}" | wc -l)
if [[ "$HAS_LICENSE_IDENTIFIER" == "1" ]]
then
sed -i "1c ${COMMENT_SYMBOL} ${LICENSE_PREFIX} ${LICENSE}" $FILE
else
sed -i "1i ${COMMENT_SYMBOL} ${LICENSE_PREFIX} ${LICENSE}" $FILE
fi

HAS_NEW_LINE=$(cat $FILE | head -n 2 | tail -n 1 | grep -E "^[ ]*\$" | wc -l)
if [[ "$HAS_NEW_LINE" == "0" ]]
then
sed -i '2i\
' $FILE
fi
sed -i "1c ${LICENSE_CODE}" $FILE
done
}

set_rust() {
FILE_SUFFIX="*.rs"
COMMENT_SYMBOL="//"
COMMENT_SYMBOL="\/\/"
set_license_header
}

Expand Down

0 comments on commit 8270ced

Please sign in to comment.