From 4033365e00f5bd31e7e0dd01cd04e9c72432f752 Mon Sep 17 00:00:00 2001 From: brian khuu Date: Mon, 3 Feb 2025 22:01:47 +1100 Subject: [PATCH 1/2] ci: add bash script to check if llama-impl.h was included in example folder erronously --- .github/workflows/precompile-checks.yml | 21 ++++++++++++++++ Makefile | 6 ++++- scripts/precompile-checks.sh | 33 +++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/precompile-checks.yml create mode 100755 scripts/precompile-checks.sh diff --git a/.github/workflows/precompile-checks.yml b/.github/workflows/precompile-checks.yml new file mode 100644 index 0000000000000..f090cb75fe414 --- /dev/null +++ b/.github/workflows/precompile-checks.yml @@ -0,0 +1,21 @@ +name: Precompile Checks + +on: + push: + branches: + - master + paths: ['**/*.c', '**/*.cpp'] + pull_request: + types: [opened, synchronize, reopened] + paths: ['**/*.c', '**/*.cpp'] + +jobs: + precompile-check: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Run Forbidden Includes Check + run: bash scripts/precompile-checks.sh diff --git a/Makefile b/Makefile index dc3de3cb14e44..7d88a7ac707b8 100644 --- a/Makefile +++ b/Makefile @@ -211,7 +211,7 @@ ifdef GGML_VULKAN BUILD_TARGETS += vulkan-shaders-gen endif -default: $(BUILD_TARGETS) $(LEGACY_TARGETS_BUILD) +default: precompile_checks $(BUILD_TARGETS) $(LEGACY_TARGETS_BUILD) test: $(TEST_TARGETS) @failures=0; \ @@ -248,6 +248,10 @@ test: $(TEST_TARGETS) all: $(BUILD_TARGETS) $(TEST_TARGETS) $(LEGACY_TARGETS_BUILD) +# Run the forbidden includes check before every build +precompile_checks: + @bash ./scripts/precompile-checks.sh + ifdef RISCV_CROSS_COMPILE CC := riscv64-unknown-linux-gnu-gcc CXX := riscv64-unknown-linux-gnu-g++ diff --git a/scripts/precompile-checks.sh b/scripts/precompile-checks.sh new file mode 100755 index 0000000000000..f0be3a9f081a0 --- /dev/null +++ b/scripts/precompile-checks.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# This runs some pre compilation sanity checks that certain project rules and guidelines are kept +# This will not contain any signifiant logic, but mostly just obvious and easily greppable checks + +ERROR_FOUND=0 + + +## START OF INCLUDES EXCLUDED FROM EXAMPLES FOLDER ## +SRC_DIR="./examples" +FORBIDDEN_HEADERS=("llama-impl.h") +echo "🔍 Scanning for forbidden includes in $SRC_DIR..." +for HEADER in "${FORBIDDEN_HEADERS[@]}"; do + MATCHES=$(grep -rn --include=\*.{c,cpp} "#include \"$HEADER\"" "$SRC_DIR" 2>/dev/null) + + if [[ -n "$MATCHES" ]]; then + echo "❌ Forbidden include detected: $HEADER" + echo "$MATCHES" | while IFS=: read -r FILE LINE _; do + echo "::error file=$FILE,line=$LINE::Forbidden include: $HEADER in $FILE at line $LINE" + done + ERROR_FOUND=1 + fi + +done +## END OF INCLUDES EXCLUDED FROM EXAMPLES FOLDER ## + + +if [[ "$ERROR_FOUND" -eq 1 ]]; then + echo "❌ Forbidden includes found. Please remove!" + exit 1 +else + echo "✅ No forbidden includes found." +fi From a444c152092f89095319555cabf0945cc05fd0e0 Mon Sep 17 00:00:00 2001 From: brian khuu Date: Tue, 4 Feb 2025 07:06:08 +1100 Subject: [PATCH 2/2] ci: add bash script to check if llama-impl.h was included in example folder erronously --- Makefile | 6 +----- scripts/precompile-checks.sh | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 7d88a7ac707b8..dc3de3cb14e44 100644 --- a/Makefile +++ b/Makefile @@ -211,7 +211,7 @@ ifdef GGML_VULKAN BUILD_TARGETS += vulkan-shaders-gen endif -default: precompile_checks $(BUILD_TARGETS) $(LEGACY_TARGETS_BUILD) +default: $(BUILD_TARGETS) $(LEGACY_TARGETS_BUILD) test: $(TEST_TARGETS) @failures=0; \ @@ -248,10 +248,6 @@ test: $(TEST_TARGETS) all: $(BUILD_TARGETS) $(TEST_TARGETS) $(LEGACY_TARGETS_BUILD) -# Run the forbidden includes check before every build -precompile_checks: - @bash ./scripts/precompile-checks.sh - ifdef RISCV_CROSS_COMPILE CC := riscv64-unknown-linux-gnu-gcc CXX := riscv64-unknown-linux-gnu-g++ diff --git a/scripts/precompile-checks.sh b/scripts/precompile-checks.sh index f0be3a9f081a0..8fe62d4cad705 100755 --- a/scripts/precompile-checks.sh +++ b/scripts/precompile-checks.sh @@ -11,23 +11,23 @@ SRC_DIR="./examples" FORBIDDEN_HEADERS=("llama-impl.h") echo "🔍 Scanning for forbidden includes in $SRC_DIR..." for HEADER in "${FORBIDDEN_HEADERS[@]}"; do - MATCHES=$(grep -rn --include=\*.{c,cpp} "#include \"$HEADER\"" "$SRC_DIR" 2>/dev/null) + MATCHES=$(grep -rn --include=\*.{c,cpp} "#include \"$HEADER\"" "$SRC_DIR" 2>/dev/null) - if [[ -n "$MATCHES" ]]; then - echo "❌ Forbidden include detected: $HEADER" - echo "$MATCHES" | while IFS=: read -r FILE LINE _; do - echo "::error file=$FILE,line=$LINE::Forbidden include: $HEADER in $FILE at line $LINE" - done - ERROR_FOUND=1 - fi + if [[ -n "$MATCHES" ]]; then + echo "❌ Forbidden include detected: $HEADER" + echo "$MATCHES" | while IFS=: read -r FILE LINE _; do + echo "::error file=$FILE,line=$LINE::Forbidden include: $HEADER in $FILE at line $LINE" + done + ERROR_FOUND=1 + fi done ## END OF INCLUDES EXCLUDED FROM EXAMPLES FOLDER ## if [[ "$ERROR_FOUND" -eq 1 ]]; then - echo "❌ Forbidden includes found. Please remove!" - exit 1 + echo "❌ Forbidden includes found. Please remove!" + exit 1 else - echo "✅ No forbidden includes found." + echo "✅ No forbidden includes found." fi