diff --git a/scripts/add_license.sh b/scripts/add_license.sh index 43e69aa88..dd51ed0a1 100755 --- a/scripts/add_license.sh +++ b/scripts/add_license.sh @@ -2,40 +2,35 @@ # # Checks if the source code contains required license and adds it if necessary. # Returns 1 if there was a missing license, 0 otherwise. -COPYRIGHT_TXT=$(dirname $0)/copyright.txt - -# Any year is fine. We can update the year as a single PR in all files that have it up to last year. -PAT_PL=".*// Copyright 2021-202\d Protocol Labs.*" -# Files that were taken from ChainSafe and not modified can be left as-is. -PAT_CS=".*// Copyright 2019-2022 ChainSafe Systems.*" -PAT_SPDX="/*// SPDX-License-Identifier: Apache-2.0, MIT.*" - -# Look at enough lines so that we can include multiple copyright holders. -LINES=4 - +YEAR="$(date '+%Y')" ret=0 +set -e -x # Look for files without headers. -for file in $(git grep --cached -Il '' -- '*.rs'); do - header=$(head -$LINES "$file") - if ! echo "$header" | grep -q -P "$PAT_SPDX"; then - echo "$file was missing header" - cat $COPYRIGHT_TXT "$file" > temp - mv temp "$file" - ret=1 - fi -done +while read -r file; do + echo "$file was missing header" + sed -i "$file" -f - < temp - cat "$file" >> temp - mv temp "$file" - ret=1 - fi -done +while read -r file; do + if grep -q "^// Copyright \([0-9]\+-\)\?${YEAR} Filecoin Core Devs" "$file"; then + continue + fi + ret=1 + if grep -q "^// Copyright [0-9]\+\(-[0-9]\+\)\? Filecoin Core Devs" "$file"; then + # Update the copyright line if available. + script="s|^// Copyright \([0-9]\+\)\(-[0-9]\+\)\? Filecoin Core Devs|// Copyright \1-${YEAR} Filecoin Core Devs|" + else + # Otherwise, add the new one _AFTER_ the SDPX header. + script="/^\/\/ SPDX-License-Identifier: /a\ +// Copyright ${YEAR} Filecoin Core Devs +" + fi + sed -i "$file" -e "$script" +done < <(git diff --diff-filter=DM --name-only --merge-base master -- '*.rs') exit $ret diff --git a/scripts/copyright.txt b/scripts/copyright.txt deleted file mode 100644 index 163f7b93b..000000000 --- a/scripts/copyright.txt +++ /dev/null @@ -1,2 +0,0 @@ -// Copyright 2021-2023 Protocol Labs -// SPDX-License-Identifier: Apache-2.0, MIT