diff --git a/.licensure.yml b/.licensure.yml index 4d87b04..784d9ba 100644 --- a/.licensure.yml +++ b/.licensure.yml @@ -1,10 +1,31 @@ +# Copyright (C) 2023 - 2024: +# The Trinitrix Project +# SPDX-License-Identifier: LGPL-3.0-or-later +# +# +# This file is part of the Trixy crate for Trinitrix. +# +# Trixy is free software: you can redistribute it and/or modify +# it under the terms of the Lesser GNU General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# and the Lesser GNU General Public License along with this program. +# If not, see . + --- # Regexes which if matched by a file path will always be excluded from # getting a license header excludes: - .*lock + - expected.md - \.git/.* - - \.licensure\.yml - LICENSE.spdx - COPYING - COPYING.LESSER diff --git a/docs/grammar.ebnf b/docs/grammar.ebnf index 9435ee9..bc88075 100644 --- a/docs/grammar.ebnf +++ b/docs/grammar.ebnf @@ -1,6 +1,8 @@ #(* # Copyright (C) 2023 - 2024: # The Trinitrix Project +# SPDX-License-Identifier: LGPL-3.0-or-later +# # # This file is part of the Trixy crate for Trinitrix. # @@ -19,7 +21,6 @@ # If not, see . #*) - # (* # Trixy is fully whitespace independent, this means that you can # interleave whitespace in the definitions. diff --git a/flake.nix b/flake.nix index 49ae8e5..39cc559 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,7 @@ # Copyright (C) 2023 - 2024: # The Trinitrix Project +# SPDX-License-Identifier: LGPL-3.0-or-later +# # # This file is part of the Trixy crate for Trinitrix. # @@ -219,6 +221,9 @@ gdb ebnf2pdf.outputs.packages."${system}".default + + # for the ./scripts/renew_copyright_header.sh + yq ]; inherit nativeBuildInputs buildInputs; }; diff --git a/scripts/renew_copyright_header.sh b/scripts/renew_copyright_header.sh index d37c802..4ee5fae 100755 --- a/scripts/renew_copyright_header.sh +++ b/scripts/renew_copyright_header.sh @@ -1,43 +1,103 @@ #! /usr/bin/env sh +# Copyright (C) 2023 - 2024: +# The Trinitrix Project +# SPDX-License-Identifier: LGPL-3.0-or-later +# +# +# This file is part of the Trixy crate for Trinitrix. +# +# Trixy is free software: you can redistribute it and/or modify +# it under the terms of the Lesser GNU General Public License as +# published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# and the Lesser GNU General Public License along with this program. +# If not, see . -TEMPLATE_LINE_LENGHT=19 +TEMPLATE_LINE_LENGHT=20 +remove() { + extension="$1" + file="$2" -fd --type file . | while read -r file; do - if grep --quiet 'The Trinitrix Project ' "$file"; then - filename="$(basename -- "$file")" - extension="${filename##*.}" - filename="${filename%.*}" + # We need to differentiate, when removing the old copyright header, as some + # formatters do weird things to the file + case "$extension" in + # normal '#' comments (these are 19 lines long) + # the `config` file is the cargo config at `./example/main/.cargo/config`, which is + # toml + "Makefile" | "toml" | "envrc" | "config" | "yml") + sed --in-place "1,${TEMPLATE_LINE_LENGHT}d" "$file" + ;; + # normal '/* ... */' like comments (these are 21 lines long--'#' + 2) + "c" | "ebnf" | "h" | "md" | "rs" | "tri") + lenght="$((TEMPLATE_LINE_LENGHT + 2))" + sed --in-place "1,${lenght}d;" "$file" + ;; + # alejandra (the nix formatter) removes the blank line after the comment, + # thus only 18 lines + "nix") + lenght="$((TEMPLATE_LINE_LENGHT - 1))" + sed --in-place "1,${lenght}d;" "$file" + ;; + # Shell needs a shebang on the first line, only after the first line can we + # remove the 19 lines + "sh") + sed --in-place "2,${TEMPLATE_LINE_LENGHT}d;" "$file" + licensure --in-place "$file" - # We need to differentiate, when removing the old copyright header, as some - # formatters do weird things to the file - case "$extension" in - # normal '#' comments (these are 19 lines long) - "Makefile" | "toml") - sed --in-place "1,${TEMPLATE_LINE_LENGHT}d" "$file" - ;; - # normal '/* ... */' like comments (these are 21 lines long--'#' + 2) - "c" | "ebnf" | "h" | "md" | "rs" | "tri") - lenght="$((TEMPLATE_LINE_LENGHT + 2))" - sed --in-place "1,${lenght}d;" "$file" - ;; - # alejandra (the nix formatter) removes the blank line after the comment, - # thus only 18 lines - "nix") - lenght="$((TEMPLATE_LINE_LENGHT - 1))" - sed --in-place "1,${lenght}d;" "$file" - ;; - # Shell needs a shebang on the first line, only after the first line can we - # remove the 19 lines - "sh") - sed --in-place "2,${TEMPLATE_LINE_LENGHT}d;" "$file" - ;; - *) - echo "File '$file' with extension '$extension' is not know yet, please add it!" - ;; - esac + TEMPLATE_LINE_LENGHT_NEW="$(($(yq --raw-output '.licenses | map(.template) | join("")' ./.licensure.yml | wc -l) + $(yq '.comments | last | .commenter.trailing_lines' ./.licensure.yml)))" + + # delete the current shebang + to="$((TEMPLATE_LINE_LENGHT_NEW + 1))" + sed --in-place "${TEMPLATE_LINE_LENGHT_NEW},${to}d;" "$file" + + # add a new one + sed --in-place "1i#! /usr/bin/env sh" "$file" + ;; + *) + echo "File '$file' with extension '$extension' is not know yet, please add it!" + ;; + esac +} + +list() { + echo "$extension -> $file" +} + +if [ -f "$1" ]; then + file="$(realpath "$1")" + filename="$(basename -- "$file")" + extension="${filename##*.}" + filename="${filename%.*}" + + if [ -n "$DRY_RUN" ]; then + list "$extension" "$file" + else + remove "$extension" "$file" fi -done +else + fd --type file --hidden . | while read -r file; do + if grep --quiet 'The Trinitrix Project ' "$file"; then + filename="$(basename -- "$file")" + extension="${filename##*.}" + filename="${filename%.*}" -nix fmt + if [ -n "$DRY_RUN" ]; then + list "$extension" "$file" + else + remove "$extension" "$file" + fi + fi + done -licensure --in-place --project + if [ -z "$DRY_RUN" ]; then + licensure --in-place --project + nix fmt + fi +fi