Skip to content

Commit

Permalink
Merge pull request #1375 from DLR-AMR/ifdef-T8_ENABLE_script
Browse files Browse the repository at this point in the history
Ifdef t8 enable script
  • Loading branch information
holke authored Feb 20, 2025
2 parents 9d129bd + a3ee861 commit d24f60b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/spell_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ jobs:
uses: actions/checkout@v4
- name: Check spelling
uses: crate-ci/typos@master
- name: check macros
run: |
for file in $(git diff --name-only --diff-filter=A); do
./scripts/check_macros.scp "$file" &>> check_macros.txt
done
- name: Archive script output
if: failure()
uses: actions/upload-artifact@v4
with:
name: t8code check macros report
path: check_macros.txt
38 changes: 38 additions & 0 deletions scripts/check_macros.scp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <file_path>"
exit 1
fi

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
# 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

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 < <(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."
exit 1
else
echo "No incorrect macro usage found in $file_path."
exit 0
fi
15 changes: 15 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
# This is the indent script in the project's directory
CHECK_INDENT=./scripts/check_if_file_indented.scp

CHECK_MACROS=./scripts/check_makros.scp

TYPOS=`which typos 2> /dev/null`
TYPOS_CONFIG_FILE=./.typos.toml

Expand Down Expand Up @@ -92,6 +94,19 @@ do
echo "File $file is not indented."
nocontinue=1
fi

# 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
nocontinue=1
fi
fi
done

Expand Down

0 comments on commit d24f60b

Please sign in to comment.