From 16b43dae162831f1fc7cf24e77ed511566253650 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 4 Feb 2025 12:37:10 +0100 Subject: [PATCH 01/11] Add a script to check the correct usage of T8_ENABLE-Macros --- scripts/check_makros.scp | 12 ++++++++++++ scripts/pre-commit | 9 +++++++++ 2 files changed, 21 insertions(+) create mode 100755 scripts/check_makros.scp diff --git a/scripts/check_makros.scp b/scripts/check_makros.scp new file mode 100755 index 0000000000..0aab7f72ab --- /dev/null +++ b/scripts/check_makros.scp @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +file_path=$1 + +grep -n '#ifdef T8_ENABLE_' "$file_path" | while IFS=: read -r line_number line; do + echo "Macro found in $file_path on line $line_number: $line" +done diff --git a/scripts/pre-commit b/scripts/pre-commit index 63430b9282..78f6d702e5 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -34,6 +34,8 @@ # This is the indent script in the project's directory CHECK_INDENT=./scripts/check_if_file_indented.scp +CHECK_MAKROS=./scripts/check_makros.scp + TYPOS=`which typos 2> /dev/null` TYPOS_CONFIG_FILE=./.typos.toml @@ -92,6 +94,13 @@ do echo "File $file is not indented." nocontinue=1 fi + + $CHECK_MAKROS $file > /dev/null 2>&1 + status=$? + if test $status -ne 0 + then + echo "File $file uses #ifdef T8_ENABLE_. Use #if T8_ENABLE_ instead." + nocontinue=1 fi done From a92f82bb9e3e77c7a59bd07b6e4006a4cb7cb991 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 4 Feb 2025 12:38:14 +0100 Subject: [PATCH 02/11] clean-up --- scripts/{check_makros.scp => check_macros.scp} | 0 scripts/pre-commit | 5 +++-- 2 files changed, 3 insertions(+), 2 deletions(-) rename scripts/{check_makros.scp => check_macros.scp} (100%) diff --git a/scripts/check_makros.scp b/scripts/check_macros.scp similarity index 100% rename from scripts/check_makros.scp rename to scripts/check_macros.scp diff --git a/scripts/pre-commit b/scripts/pre-commit index 78f6d702e5..955605db31 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -34,7 +34,7 @@ # This is the indent script in the project's directory CHECK_INDENT=./scripts/check_if_file_indented.scp -CHECK_MAKROS=./scripts/check_makros.scp +CHECK_MACROS=./scripts/check_makros.scp TYPOS=`which typos 2> /dev/null` TYPOS_CONFIG_FILE=./.typos.toml @@ -95,12 +95,13 @@ do nocontinue=1 fi - $CHECK_MAKROS $file > /dev/null 2>&1 + $CHECK_MACROS $file > /dev/null 2>&1 status=$? if test $status -ne 0 then echo "File $file uses #ifdef T8_ENABLE_. Use #if T8_ENABLE_ instead." nocontinue=1 + fi fi done From 7e24670027494cc4b4e8e8a386eff58d5602ece2 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 4 Feb 2025 15:09:29 +0100 Subject: [PATCH 03/11] update return value and print full macro name --- scripts/check_macros.scp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/check_macros.scp b/scripts/check_macros.scp index 0aab7f72ab..384da31c0b 100755 --- a/scripts/check_macros.scp +++ b/scripts/check_macros.scp @@ -7,6 +7,30 @@ fi file_path=$1 +# +# This script searches for lines containing the macro definition '#ifdef T8_ENABLE_' +# in the specified file and processes each matching line. +# # It uses 'grep' to find all occurrences of '#ifdef T8_ENABLE_' in the file located +# at the path stored in the variable 'file_path'. The '-n' option with 'grep' +# ensures that the line numbers of the matching lines are included in the output. +# # The output of 'grep' is then piped into a 'while' loop, which reads each line +# and splits it into the line number and the line content using ':' as the delimiter. +# # Variables: +# - file_path: The path to the file to be searched. +# - line_number: The line number where the macro definition is found. +# - line: The content of the line where the macro definition is found. +# + +found_macros=FALSE + grep -n '#ifdef T8_ENABLE_' "$file_path" | while IFS=: read -r line_number line; do - echo "Macro found in $file_path on line $line_number: $line" + macro_name=$(echo "$line" | grep -o 'T8_ENABLE_[^ ]*') + echo "Macro found in $file_path on line $line_number: $macro_name" + found_macros=TRUE done + +if [ "$found_macros" = "TRUE" ]; then + exit 1 +else + exit 0 +fi From 512ff0daa5612b55e63492300a93887e1372cfd8 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 4 Feb 2025 15:12:39 +0100 Subject: [PATCH 04/11] udpate documentation --- scripts/check_macros.scp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_macros.scp b/scripts/check_macros.scp index 384da31c0b..99445754e8 100755 --- a/scripts/check_macros.scp +++ b/scripts/check_macros.scp @@ -8,7 +8,7 @@ fi file_path=$1 # -# This script searches for lines containing the macro definition '#ifdef T8_ENABLE_' +# This script searches for lines containing a macro definition in the style of '#ifdef T8_ENABLE_' # in the specified file and processes each matching line. # # It uses 'grep' to find all occurrences of '#ifdef T8_ENABLE_' in the file located # at the path stored in the variable 'file_path'. The '-n' option with 'grep' From 8c72b4718411d7f23c502c043acf996ee585178c Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 4 Feb 2025 15:15:46 +0100 Subject: [PATCH 05/11] print output of check_macro.scp in pre-commit execution --- scripts/pre-commit | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 955605db31..3308a4605b 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -95,11 +95,16 @@ do nocontinue=1 fi - $CHECK_MACROS $file > /dev/null 2>&1 + # This script checks for the usage of #ifdef T8_ENABLE_ macros in the specified file. + # If such macros are found, it suggests using #if T8_ENABLE_ instead and sets a flag to indicate the issue. + # - $CHECK_MACROS: Command or script to check the macros in the file. + # - $file: The file being checked. + # - status: The exit status of the $CHECK_MACROS command. + # - nocontinue: Flag set to 1 if the incorrect macro usage is found. + $CHECK_MACROS $file status=$? if test $status -ne 0 then - echo "File $file uses #ifdef T8_ENABLE_. Use #if T8_ENABLE_ instead." nocontinue=1 fi fi From 1d9396ab186fd2eeace24830e062533e472fdebb Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 4 Feb 2025 15:41:32 +0100 Subject: [PATCH 06/11] execute check_macros on git diff --- .github/workflows/spell_check.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/spell_check.yml b/.github/workflows/spell_check.yml index 035aa4e7aa..e9b1916646 100644 --- a/.github/workflows/spell_check.yml +++ b/.github/workflows/spell_check.yml @@ -17,3 +17,12 @@ jobs: uses: actions/checkout@v4 - name: Check spelling uses: crate-ci/typos@master + - name: check macros + run: | + git diff --name-only --diff-filter=A | xargs ./scripts/check_macros.scp &> >(tee -a indent_script_output.txt) + - name: Archive script output + if: failure() + uses: actions/upload-artifact@v4 + with: + name: t8code indentation report + path: indent_script_output.txt From 6f84e5b3269c8af37bcba7bc204525074bfc347d Mon Sep 17 00:00:00 2001 From: David Knapp Date: Tue, 4 Feb 2025 15:44:26 +0100 Subject: [PATCH 07/11] bug-fix --- .github/workflows/spell_check.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/spell_check.yml b/.github/workflows/spell_check.yml index e9b1916646..a726ed5c77 100644 --- a/.github/workflows/spell_check.yml +++ b/.github/workflows/spell_check.yml @@ -19,7 +19,9 @@ jobs: uses: crate-ci/typos@master - name: check macros run: | - git diff --name-only --diff-filter=A | xargs ./scripts/check_macros.scp &> >(tee -a indent_script_output.txt) + for file in $(git diff --name-only --diff-filter=A); do + ./scripts/check_macros.scp "$file" &>> indent_script_output.txt + done - name: Archive script output if: failure() uses: actions/upload-artifact@v4 From 260ebf064b24846f6b347297f834b27af5a06b35 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Mon, 10 Feb 2025 12:33:42 +0100 Subject: [PATCH 08/11] update script --- scripts/check_macros.scp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/check_macros.scp b/scripts/check_macros.scp index 99445754e8..379225ba52 100755 --- a/scripts/check_macros.scp +++ b/scripts/check_macros.scp @@ -23,14 +23,18 @@ file_path=$1 found_macros=FALSE -grep -n '#ifdef T8_ENABLE_' "$file_path" | while IFS=: read -r line_number line; do +if grep -n '#ifdef T8_ENABLE_' "$file_path" | while IFS=: read -r line_number line; do macro_name=$(echo "$line" | grep -o 'T8_ENABLE_[^ ]*') echo "Macro found in $file_path on line $line_number: $macro_name" found_macros=TRUE -done +done; then + found_macros=FALSE +fi if [ "$found_macros" = "TRUE" ]; then + echo "Incorrect macro usage found in $file_path. Please use '#if T8_ENABLE_' instead." exit 1 else + echo "No incorrect macro usage found in $file_path." exit 0 fi From 0a77c2b3c83b825f4ad8343c9ebf1da86d8b74bb Mon Sep 17 00:00:00 2001 From: David Knapp Date: Wed, 12 Feb 2025 09:52:58 +0100 Subject: [PATCH 09/11] use found_macros before it was only updated in a subshell. This way the variable is updated correctly --- scripts/check_macros.scp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/check_macros.scp b/scripts/check_macros.scp index 379225ba52..5c058e0457 100755 --- a/scripts/check_macros.scp +++ b/scripts/check_macros.scp @@ -23,13 +23,11 @@ file_path=$1 found_macros=FALSE -if grep -n '#ifdef T8_ENABLE_' "$file_path" | while IFS=: read -r line_number line; do +while IFS=: read -r line_number line; do macro_name=$(echo "$line" | grep -o 'T8_ENABLE_[^ ]*') echo "Macro found in $file_path on line $line_number: $macro_name" found_macros=TRUE -done; then - found_macros=FALSE -fi +done < <(grep -n '#ifdef T8_ENABLE_' "$file_path") if [ "$found_macros" = "TRUE" ]; then echo "Incorrect macro usage found in $file_path. Please use '#if T8_ENABLE_' instead." From d08e8922e0bf1adde531846467d35071bb20a70e Mon Sep 17 00:00:00 2001 From: Johannes Holke Date: Wed, 19 Feb 2025 22:52:39 +0100 Subject: [PATCH 10/11] Apply suggestions from code review/Remove duplicate '#' in comment. --- scripts/check_macros.scp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/check_macros.scp b/scripts/check_macros.scp index 5c058e0457..549b75e78f 100755 --- a/scripts/check_macros.scp +++ b/scripts/check_macros.scp @@ -10,12 +10,12 @@ file_path=$1 # # This script searches for lines containing a macro definition in the style of '#ifdef T8_ENABLE_' # in the specified file and processes each matching line. -# # It uses 'grep' to find all occurrences of '#ifdef T8_ENABLE_' in the file located +# It uses 'grep' to find all occurrences of '#ifdef T8_ENABLE_' in the file located # at the path stored in the variable 'file_path'. The '-n' option with 'grep' # ensures that the line numbers of the matching lines are included in the output. -# # The output of 'grep' is then piped into a 'while' loop, which reads each line +# The output of 'grep' is then piped into a 'while' loop, which reads each line # and splits it into the line number and the line content using ':' as the delimiter. -# # Variables: +# Variables: # - file_path: The path to the file to be searched. # - line_number: The line number where the macro definition is found. # - line: The content of the line where the macro definition is found. From 7291056592f221c9d0a9b3897db839566eb8c2c5 Mon Sep 17 00:00:00 2001 From: David Knapp Date: Thu, 20 Feb 2025 09:00:44 +0100 Subject: [PATCH 11/11] write output to check_macros.txt --- .github/workflows/spell_check.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/spell_check.yml b/.github/workflows/spell_check.yml index a726ed5c77..3cb0d20f41 100644 --- a/.github/workflows/spell_check.yml +++ b/.github/workflows/spell_check.yml @@ -20,11 +20,11 @@ jobs: - name: check macros run: | for file in $(git diff --name-only --diff-filter=A); do - ./scripts/check_macros.scp "$file" &>> indent_script_output.txt + ./scripts/check_macros.scp "$file" &>> check_macros.txt done - name: Archive script output if: failure() uses: actions/upload-artifact@v4 with: - name: t8code indentation report - path: indent_script_output.txt + name: t8code check macros report + path: check_macros.txt