From 2f542a656b1584ed3174ba49f5753cd8b48e970e Mon Sep 17 00:00:00 2001 From: Yogev Neumann Date: Sat, 31 Jan 2026 00:39:26 -0500 Subject: [PATCH] Add make pre-push command Signed-off-by: Yogev Neumann --- .github/copilot-instructions.md | 2 +- .github/pull_request_template.md | 4 +- CONTRIBUTING.md | 7 +- Makefile | 55 +++------ README.md | 1 + tests/Makefile | 186 +++++++++++++++++++------------ 6 files changed, 141 insertions(+), 114 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 4a42fc6..a171b21 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -42,6 +42,6 @@ The following actions require explicit user approval before execution: ## Definition of Done -- Code must compile using the Makefile with `make all`. +- Code must pass `make pre-push` (includes multi-compiler build, static analysis, sanitizers, valgrind). - Documentation must include "Wire Format" visual tables (IPv4 style). - All bit-widths must be verified against J2735_202409. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index f02772c..0331504 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -26,7 +26,5 @@ - [ ] I have read the [CONTRIBUTING.md](../CONTRIBUTING.md) guidelines - [ ] I have added/updated documentation as needed - [ ] I have added tests that prove my fix/feature works -- [ ] I have run tests locally (`make test`) -- [ ] I have run static analysis checks locally (`make check`) -- [ ] I have verified that my changes do not introduce new memory leaks (`make valgrind` and `make sanitize`) +- [ ] I have run `make pre-push` and all checks pass - [ ] I have signed my commits (DCO) using `git commit -s` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ffb5a5f..30364df 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,10 +16,9 @@ contributions from the community. 1. Fork the repository 2. Create a feature branch (`git checkout -b feature/my-improvement`) 3. Make your changes following our coding standards -4. Ensure all tests pass (`make test`) -5. Run quality checks (`make check`, `make sanitize`) -6. Commit with a signed-off message (see DCO below) -7. Submit a Pull Request to the `main` branch +4. Run all checks (`make pre-push`) +5. Commit with a signed-off message (see DCO below) +6. Submit a Pull Request to the `main` branch ## Developer Certificate of Origin (DCO) diff --git a/Makefile b/Makefile index 6a673fe..6f9dd91 100644 --- a/Makefile +++ b/Makefile @@ -26,57 +26,38 @@ ifeq ($(origin CC),default) CC := gcc endif -.PHONY: all test clean check sanitize valgrind format tidy help info +.PHONY: all check clean format help info pre-push sanitize test tidy valgrind # Default target all: @$(MAKE) -C tests CC='$(CC)' all -test: - @$(MAKE) -C tests CC='$(CC)' test - -clean: - @$(MAKE) -C tests CC='$(CC)' clean - check: @$(MAKE) -C tests CC='$(CC)' check -tidy: - @$(MAKE) -C tests CC='$(CC)' tidy +clean: + @$(MAKE) -C tests CC='$(CC)' clean format: @$(MAKE) -C tests CC='$(CC)' format +help: + @$(MAKE) -C tests CC='$(CC)' help + +info: + @$(MAKE) -C tests CC='$(CC)' info + +pre-push: + @$(MAKE) -C tests CC='$(CC)' pre-push + sanitize: @$(MAKE) -C tests CC='$(CC)' sanitize -valgrind: - @$(MAKE) -C tests CC='$(CC)' valgrind +test: + @$(MAKE) -C tests CC='$(CC)' test -info: - @$(MAKE) -C tests CC='$(CC)' info +tidy: + @$(MAKE) -C tests CC='$(CC)' tidy -help: - @echo "J2735 High-Performance Toolkit" - @echo "===============================" - @echo "" - @echo "All targets are delegated to tests/Makefile" - @echo "" - @echo "Build Targets:" - @echo " make Build all test binaries" - @echo " make test Build and run all tests" - @echo " make clean Remove build artifacts" - @echo "" - @echo "Quality Targets:" - @echo " make check Static analysis (cppcheck)" - @echo " make tidy Static analysis (clang-tidy)" - @echo " make format Format code (clang-format)" - @echo " make sanitize Build/run with ASan + UBSan" - @echo " make valgrind Memory leak check (valgrind)" - @echo "" - @echo "Info:" - @echo " make info Show build configuration" - @echo " make help This message" - @echo "" - @echo "Options:" - @echo " CC=clang Use Clang instead of GCC" +valgrind: + @$(MAKE) -C tests CC='$(CC)' valgrind diff --git a/README.md b/README.md index 4c72618..49b6504 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ Because this library is in active alpha, the code itself is the source of truth. make check # Static analysis (cppcheck) make clean # Clean build artifacts make format # Code formatting (clang-format) +make pre-push # Run ALL checks (recommended before pushing) make sanitize # ASan + UBSan make test # Build and run tests make tidy # Static analysis (clang-tidy) diff --git a/tests/Makefile b/tests/Makefile index 933b597..8ee3272 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -212,11 +212,24 @@ CFLAGS := -std=c17 -O3 $(WFLAGS) $(INCLUDES) # Debug flags for sanitizer/valgrind builds DBG_CFLAGS := -std=c17 -g -O1 -fno-omit-frame-pointer $(WFLAGS) $(INCLUDES) +# ----------------------------------------------------------------------------- +# Pre-push Compiler Detection +# Auto-detect available GCC (11+) and Clang (13+) versions for pre-push testing +# Uses 'which' with explicit path checking to avoid spurious output +# ----------------------------------------------------------------------------- +AVAILABLE_GCC := $(strip $(foreach v,11 12 13 14 15 16 17 18 19 20,$(if $(shell which gcc-$(v) 2>/dev/null),gcc-$(v)))) +AVAILABLE_CLANG := $(strip $(foreach v,13 14 15 16 17 18 19 20 21 22 23 24 25,$(if $(shell which clang-$(v) 2>/dev/null),clang-$(v)))) +GCC_MIN := $(firstword $(AVAILABLE_GCC)) +GCC_MAX := $(lastword $(AVAILABLE_GCC)) +CLANG_MIN := $(firstword $(AVAILABLE_CLANG)) +CLANG_MAX := $(lastword $(AVAILABLE_CLANG)) +PRE_PUSH_COMPILERS := $(sort $(GCC_MIN) $(GCC_MAX) $(CLANG_MIN) $(CLANG_MAX)) + # ============================================================================= # Targets # ============================================================================= -.PHONY: all test clean check sanitize valgrind format tidy help info +.PHONY: all check clean format help info pre-push sanitize test tidy valgrind # Create build directory $(BUILD_DIR): @@ -237,16 +250,6 @@ $(BUILD_DIR)/%_test.o: %_test.c $(HEADERS) | $(BUILD_DIR) $(TEST_BIN): $(TEST_MAIN) $(SUITE_OBJS) $(LIB_OBJS) $(HEADERS) | $(BUILD_DIR) $(CC) $(CFLAGS) $(TEST_SUPPRESS_WFLAGS) -o $@ $(TEST_MAIN) $(SUITE_OBJS) $(LIB_OBJS) -# Run all tests -test: $(TEST_BIN) - @echo "=== Running Tests ===" - $(TEST_BIN) - @echo "=== All Tests Passed ===" - -# Clean build artifacts -clean: - rm -rf $(BUILD_DIR)/* - # Static analysis with cppcheck # Note: -D__GNUC__ tells cppcheck to analyze only the GCC code path (not MSVC or unsupported) # Note: --library=gnu provides __builtin_bswap64 definition to avoid false MISRA 17.3 errors @@ -272,22 +275,9 @@ check: $(ALL_H_FILES) $(PROJECT_C_FILES) @echo "=== Static Analysis Complete ===" -# clang-tidy static analysis -tidy: - @echo "=== clang-tidy ===" - @clang-tidy \ - --checks=*,-altera-struct-pack-align,-altera-unroll-loops,-llvm-header-guard \ - --fix-notes \ - --fix-errors \ - --format-style=llvm \ - --header-filter=$(SRC_DIR)/.* \ - --warnings-as-errors=* \ - -p=./build/ \ - $(PROJECT_C_FILES) \ - -- \ - -std=c17 \ - -I$(SRC_DIR) - @echo "=== clang-tidy Complete ===" +# Clean build artifacts +clean: + rm -rf $(BUILD_DIR)/* # Format code with clang-format format: @@ -299,6 +289,83 @@ format: $(ALL_C_FILES) @echo "=== Formatting Complete ===" +# Help +help: + @echo "J2735 High-Performance Toolkit" + @echo "==============================" + @echo "" + @echo "Build Targets:" + @echo " make (all) Build all test binaries (build/)" + @echo " make test Build and run all tests" + @echo " make clean Remove build artifacts" + @echo "" + @echo "Quality Targets:" + @echo " make check Static analysis (cppcheck)" + @echo " make format Format code (clang-format)" + @echo " make pre-push Run ALL checks (use before pushing)" + @echo " make sanitize Build/run with ASan + UBSan" + @echo " make tidy Static analysis (clang-tidy)" + @echo " make valgrind Memory leak check (valgrind)" + @echo "" + @echo "Info:" + @echo " make help This message" + @echo " make info Show build configuration" + @echo "" + @echo "Options:" + @echo " CC=clang Use Clang instead of GCC" + +# Show build configuration +info: + @echo "J2735 Build Configuration" + @echo "=========================" + @echo "Compiler: $(CC)" + @echo "Compiler ID: $(COMPILER_ID)" + @echo "$(COMPILER_NAME) Version: $(COMPILER_VERSION) (minimum: $(MIN_VERSION))" + @echo "CFLAGS: $(CFLAGS)" + @echo "" + @echo "Autodiscovered:" + @echo " Headers: $(HEADERS)" + @echo " Test Main: $(TEST_MAIN)" + @echo " Test Suites: $(TEST_SUITES)" + @echo " Library: $(LIB_SRCS)" + @echo " Binary: $(TEST_BIN)" + +# Pre-push validation - auto-detects and tests with available compilers +pre-push: + @echo "=== Pre-push validation ===" + @echo "" + @echo "[1/7] Format check..." + @$(MAKE) CC='$(CC)' format >/dev/null 2>&1 || (echo "❌ FAIL: format"; exit 1) + @echo " ✅ Format applied" + @echo "[2/7] Build/Test with multiple compilers..." + @if [ -z "$(PRE_PUSH_COMPILERS)" ]; then \ + echo "❌ FAIL: No supported compilers found (need GCC 11+ or Clang 13+)"; \ + exit 1; \ + fi + @for compiler in $(PRE_PUSH_COMPILERS); do \ + echo " Testing with $$compiler..."; \ + $(MAKE) CC=$$compiler clean test >/dev/null 2>&1 || \ + (echo "❌ FAIL: $$compiler"; exit 1); \ + echo " ✅ $$compiler OK"; \ + done + @echo "[3/7] Static analysis (cppcheck)..." + @$(MAKE) CC='$(CC)' check >/dev/null 2>&1 || (echo "❌ FAIL: cppcheck"; exit 1) + @echo " ✅ cppcheck OK" + @echo "[4/7] Static analysis (clang-tidy)..." + @$(MAKE) CC='$(CC)' tidy >/dev/null 2>&1 || (echo "❌ FAIL: clang-tidy"; exit 1) + @echo " ✅ clang-tidy OK" + @echo "[5/7] Sanitizers (ASan + UBSan)..." + @$(MAKE) CC='$(CC)' sanitize >/dev/null 2>&1 || (echo "❌ FAIL: sanitizers"; exit 1) + @echo " ✅ Sanitizers OK" + @echo "[6/7] Valgrind memory check..." + @$(MAKE) CC='$(CC)' valgrind >/dev/null 2>&1 || (echo "❌ FAIL: valgrind"; exit 1) + @echo " ✅ Valgrind OK" + @echo "[7/7] Cleaning up..." + @$(MAKE) CC='$(CC)' clean >/dev/null 2>&1 + @echo " ✅ Clean" + @echo "" + @echo "=== Pre-push Complete (tested: $(PRE_PUSH_COMPILERS)) ===" + # Build and run with sanitizers sanitize: $(BUILD_DIR) $(SUITE_OBJS) $(LIB_OBJS) @echo "=== AddressSanitizer ===" @@ -313,6 +380,29 @@ sanitize: $(BUILD_DIR) $(SUITE_OBJS) $(LIB_OBJS) @echo "" @echo "=== Sanitizer Checks Complete ===" +# Run all tests +test: $(TEST_BIN) + @echo "=== Running Tests ===" + $(TEST_BIN) + @echo "=== All Tests Passed ===" + +# clang-tidy static analysis +tidy: + @echo "=== clang-tidy ===" + @clang-tidy \ + --checks=*,-altera-struct-pack-align,-altera-unroll-loops,-llvm-header-guard \ + --fix-notes \ + --fix-errors \ + --format-style=llvm \ + --header-filter=$(SRC_DIR)/.* \ + --warnings-as-errors=* \ + -p=./build/ \ + $(PROJECT_C_FILES) \ + -- \ + -std=c17 \ + -I$(SRC_DIR) + @echo "=== clang-tidy Complete ===" + # Memory check with Valgrind valgrind: $(BUILD_DIR) $(SUITE_OBJS) $(LIB_OBJS) @echo "=== Valgrind Memory Check ===" @@ -325,45 +415,3 @@ valgrind: $(BUILD_DIR) $(SUITE_OBJS) $(LIB_OBJS) --track-origins=yes \ $(TEST_BIN_VALGND) @echo "=== Valgrind Complete ===" - -# Show build configuration -info: - @echo "J2735 Build Configuration" - @echo "=========================" - @echo "Compiler: $(CC)" - @echo "Compiler ID: $(COMPILER_ID)" - @echo "$(COMPILER_NAME) Version: $(COMPILER_VERSION) (minimum: $(MIN_VERSION))" - @echo "CFLAGS: $(CFLAGS)" - @echo "" - @echo "Autodiscovered:" - @echo " Headers: $(HEADERS)" - @echo " Test Main: $(TEST_MAIN)" - @echo " Test Suites: $(TEST_SUITES)" - @echo " Library: $(LIB_SRCS)" - @echo " Binary: $(TEST_BIN)" - -# Help -help: - @echo "J2735 High-Performance Toolkit" - @echo "===============================" - @echo "" - @echo "Build Targets:" - @echo " make Build all test binaries (build/)" - @echo " make test Build and run all tests" - @echo " make clean Remove build directory" - @echo "" - @echo "Quality Targets:" - @echo " make check Static analysis (cppcheck)" - @echo " make tidy Static analysis (clang-tidy)" - @echo " make format Format code (clang-format)" - @echo " make sanitize Build/run with ASan + UBSan" - @echo " make valgrind Memory leak check (valgrind)" - @echo "" - @echo "Info:" - @echo " make info Show build configuration" - @echo " make help This message" - @echo "" - @echo "Options:" - @echo " CC=clang Use Clang instead of GCC" - @echo "" - @echo "Compiler Support: GCC 4.6+ (full: 7+), Clang 6+"