#!/bin/bash #============================================================================== # Static analysis for Automotive RTOS #============================================================================== set -e # Script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" # Color codes RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Analysis directory ANALYSIS_DIR="${PROJECT_ROOT}/build/analysis" mkdir -p "${ANALYSIS_DIR}" # Print banner echo -e "${BLUE}========================================${NC}" echo -e "${BLUE} Static Analysis${NC}" echo -e "${BLUE}========================================${NC}" echo "" # Check for cppcheck if command -v cppcheck >/dev/null 2>&1; then echo -e "${YELLOW}Running Cppcheck...${NC}" cppcheck \ --enable=all \ --inconclusive \ --std=c11 \ -I"${PROJECT_ROOT}/kernel/include" \ -I"${PROJECT_ROOT}/drivers/include" \ -I"${PROJECT_ROOT}/middleware" \ -I"${PROJECT_ROOT}/config" \ --suppress=missingInclude \ --suppress=missingIncludeSystem \ "${PROJECT_ROOT}/kernel" \ "${PROJECT_ROOT}/drivers" \ "${PROJECT_ROOT}/middleware" \ 2>&1 | tee "${ANALYSIS_DIR}/cppcheck.log" || true echo -e "${GREEN}✓ Cppcheck complete${NC}" else echo -e "${YELLOW}Cppcheck not found. Skipping.${NC}" fi # Check for compiler warnings echo -e "${YELLOW}Checking compiler warnings...${NC}" if command -v arm-none-eabi-gcc >/dev/null 2>&1; then find "${PROJECT_ROOT}/kernel" "${PROJECT_ROOT}/drivers" "${PROJECT_ROOT}/middleware" \ -name "*.c" -exec \ arm-none-eabi-gcc \ -Wall -Wextra \ -fsyntax-only \ -I"${PROJECT_ROOT}/kernel/include" \ -I"${PROJECT_ROOT}/drivers/include" \ -I"${PROJECT_ROOT}/middleware" \ -I"${PROJECT_ROOT}/config" \ {} \; 2>&1 | tee "${ANALYSIS_DIR}/compiler_warnings.log" || true echo -e "${GREEN}✓ Compiler warning check complete${NC}" else echo -e "${YELLOW}ARM toolchain not found. Skipping compiler check.${NC}" fi echo "" echo -e "${GREEN}========================================${NC}" echo -e "${GREEN} Static Analysis Complete${NC}" echo -e "${GREEN}========================================${NC}" echo -e "Reports saved to: ${ANALYSIS_DIR}"