From 94085917ab9566dbae71aecb98f8bf090013ed2e Mon Sep 17 00:00:00 2001 From: whaffman Date: Wed, 24 Sep 2025 12:55:40 +0200 Subject: [PATCH 1/4] feat(format): add script for formatting and checking header files --- format.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 format.sh diff --git a/format.sh b/format.sh new file mode 100755 index 0000000..a2a5571 --- /dev/null +++ b/format.sh @@ -0,0 +1,2 @@ +find webserv -name "*.cpp" -o -name "*.hpp" | xargs clang-format -i +find webserv -name "*.hpp" -exec sh -c 'if ! grep -q "#pragma once" "$1"; then echo "Missing #pragma once in $1"; fi' _ {} \; \ No newline at end of file From 878fe4790ac4cc4ab7b0902c93420a6268cba131 Mon Sep 17 00:00:00 2001 From: whaffman Date: Wed, 24 Sep 2025 11:12:50 +0000 Subject: [PATCH 2/4] feat(docker): update Dockerfile to install Clang 12 and set it as default --- .devcontainer/Dockerfile | 42 ++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 7d69b20..1819cad 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -7,10 +7,29 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y \ # Build essentials build-essential \ - # Standard clang tools (this will install the default version) - clang \ - clang-format \ - clang-tidy \ + # Add LLVM repository for specific Clang versions + wget \ + lsb-release \ + software-properties-common \ + gnupg \ + && rm -rf /var/lib/apt/lists/* + +# Install development tools - Ubuntu 22.04 approach +RUN apt-get update && apt-get install -y \ + # Build essentials + build-essential \ + # Check what Clang versions are available and install Clang 12 if possible + software-properties-common \ + wget \ + gnupg \ + && apt-get update && \ + # Install available Clang tools (Ubuntu 22.04 has clang-12 available) + apt-get install -y \ + clang-12 \ + clang++-12 \ + clang-format-12 \ + clang-tidy-12 \ + # clangd and lldb may have different versioning clangd \ lldb \ # Build tools @@ -20,7 +39,6 @@ RUN apt-get update && apt-get install -y \ pkg-config \ # Version control and utilities git \ - wget \ curl \ unzip \ # Development utilities @@ -33,9 +51,17 @@ RUN apt-get update && apt-get install -y \ # Text processing vim \ nano \ + # Include What You Use + iwyu \ # Clean up && rm -rf /var/lib/apt/lists/* +# Create symbolic links to make clang-12 the default +RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 100 \ + && update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 100 \ + && update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-12 100 \ + && update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-12 100 + # Create a non-root user for development RUN groupadd --gid 1000 vscode \ && useradd --uid 1000 --gid vscode --shell /bin/bash --create-home vscode \ @@ -45,9 +71,9 @@ RUN groupadd --gid 1000 vscode \ && chmod 0440 /etc/sudoers.d/vscode \ && rm -rf /var/lib/apt/lists/* -# Set clang as the default compiler -ENV CC=clang -ENV CXX=clang++ +# Set clang-12 as the default compiler +ENV CC=clang-12 +ENV CXX=clang++-12 # Set working directory WORKDIR /workspace From 15d749eae94378df477cc63cd0d614db9db2b33d Mon Sep 17 00:00:00 2001 From: whaffman Date: Wed, 24 Sep 2025 13:15:24 +0000 Subject: [PATCH 3/4] refactor(devcontainer): streamline Dockerfile and update VS Code settings for Clang 12 --- .devcontainer/Dockerfile | 28 +++++---------------------- .devcontainer/devcontainer.json | 34 ++++++++------------------------- 2 files changed, 13 insertions(+), 49 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 1819cad..f10b33d 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,33 +3,15 @@ FROM ubuntu:22.04 # Set environment variables for non-interactive installation ENV DEBIAN_FRONTEND=noninteractive -# Install essential development tools +# Install development tools in one layer RUN apt-get update && apt-get install -y \ # Build essentials build-essential \ - # Add LLVM repository for specific Clang versions - wget \ - lsb-release \ - software-properties-common \ - gnupg \ - && rm -rf /var/lib/apt/lists/* - -# Install development tools - Ubuntu 22.04 approach -RUN apt-get update && apt-get install -y \ - # Build essentials - build-essential \ - # Check what Clang versions are available and install Clang 12 if possible - software-properties-common \ - wget \ - gnupg \ - && apt-get update && \ - # Install available Clang tools (Ubuntu 22.04 has clang-12 available) - apt-get install -y \ + # Clang 12 toolchain clang-12 \ clang++-12 \ clang-format-12 \ clang-tidy-12 \ - # clangd and lldb may have different versioning clangd \ lldb \ # Build tools @@ -56,13 +38,13 @@ RUN apt-get update && apt-get install -y \ # Clean up && rm -rf /var/lib/apt/lists/* -# Create symbolic links to make clang-12 the default +# Set up Clang 12 alternatives RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 100 \ && update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 100 \ && update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-12 100 \ && update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-12 100 -# Create a non-root user for development +# Create non-root user RUN groupadd --gid 1000 vscode \ && useradd --uid 1000 --gid vscode --shell /bin/bash --create-home vscode \ && apt-get update \ @@ -71,7 +53,7 @@ RUN groupadd --gid 1000 vscode \ && chmod 0440 /etc/sudoers.d/vscode \ && rm -rf /var/lib/apt/lists/* -# Set clang-12 as the default compiler +# Set environment variables ENV CC=clang-12 ENV CXX=clang++-12 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 844480e..a277f19 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,12 +20,12 @@ // Container-specific VS Code settings "settings": { - "C_Cpp.default.compilerPath": "/usr/bin/clang++", + "C_Cpp.default.compilerPath": "/usr/bin/clang++-12", "C_Cpp.default.cStandard": "c17", "C_Cpp.default.cppStandard": "c++20", "C_Cpp.default.intelliSenseMode": "linux-clang-x64", "cmake.configureOnOpen": false, - "clang-format.executable": "/usr/bin/clang-format", + "clang-format.executable": "/usr/bin/clang-format-12", "editor.formatOnSave": true, "[cpp]": { "editor.defaultFormatter": "xaver.clang-format" @@ -36,27 +36,15 @@ "files.associations": { "*.hpp": "cpp", "*.tpp": "cpp" - }, - "vscode" : { - "settings" : { - "remote.SSH.forwardAgent": true - } } - } } }, // Container configuration - "workspaceFolder": "/workspace", - "workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached", - - // Development user setup + // "workspaceFolder": "/workspace", "remoteUser": "vscode", - // Container lifecycle hooks - "postCreateCommand": "echo 'Container ready for C++ development!'", - // Port forwarding for web server testing "forwardPorts": [8080, 3000], "portsAttributes": { @@ -70,18 +58,12 @@ } }, - // Container features + // Additional dev container features (SSH agent removed) "features": { "ghcr.io/devcontainers/features/git:1": {}, - "ghcr.io/devcontainers/features/github-cli:1": {}, - "ghcr.io/devcontainers/features/sshd:1": { - "version": "latest", - "forwardPorts": [22] - } + "ghcr.io/devcontainers/features/github-cli:1": {} }, - - // Mount points for better performance - "mounts": [ - "source=webserv-node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume" - ] + + // Simple post-create setup + "postCreateCommand": "echo 'Dev container ready! Use GitHub CLI (gh auth login) or configure Git with HTTPS for GitHub access.'" } \ No newline at end of file From 89e8dcd34da3993da66a4dc5296b4b2add3c29f7 Mon Sep 17 00:00:00 2001 From: whaffman Date: Wed, 24 Sep 2025 13:26:12 +0000 Subject: [PATCH 4/4] refactor(iwyu): remove deprecated IWYU scripts for improved maintenance --- fix_iwyu.sh | 78 --------------------------- safe_iwyu_fix.sh | 138 ----------------------------------------------- 2 files changed, 216 deletions(-) delete mode 100644 fix_iwyu.sh delete mode 100644 safe_iwyu_fix.sh diff --git a/fix_iwyu.sh b/fix_iwyu.sh deleted file mode 100644 index eb9ff5e..0000000 --- a/fix_iwyu.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash - -set -e - -PROJECT_ROOT="/workspace" -RESULTS_DIR="$PROJECT_ROOT/iwyu_results" - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -echo -e "${BLUE}🔧 Reviewing IWYU fixes...${NC}" - -if [ ! -d "$RESULTS_DIR" ]; then - echo -e "${RED}❌ No IWYU results found. Run './check_iwyu.sh' first.${NC}" - exit 1 -fi - -# Check if there are any result files -result_files=("$RESULTS_DIR"/*.iwyu) -if [ ! -f "${result_files[0]}" ]; then - echo -e "${YELLOW}⚠️ No IWYU result files found.${NC}" - exit 1 -fi - -echo -e "${BLUE}💡 IWYU Analysis Results - Manual Review Required${NC}" -echo -e "${YELLOW}Note: Automatic fixing requires careful review before applying changes.${NC}\n" - -files_with_issues=0 - -for result_file in "$RESULTS_DIR"/*.iwyu; do - if [ -f "$result_file" ]; then - filename=$(basename "$result_file" .iwyu) - - # Check if this file has suggestions - if grep -q "should add these lines:\|should remove these lines:" "$result_file"; then - ((files_with_issues++)) - - echo -e "${BLUE}=== $filename.cpp ===${NC}" - - # Show additions - if grep -q "should add these lines:" "$result_file"; then - echo -e "${GREEN}📥 Suggested additions:${NC}" - sed -n '/should add these lines:/,/^$/p' "$result_file" | grep -v "should add these lines:" | head -20 - echo "" - fi - - # Show removals - if grep -q "should remove these lines:" "$result_file"; then - echo -e "${RED}📤 Suggested removals:${NC}" - sed -n '/should remove these lines:/,/^$/p' "$result_file" | grep -v "should remove these lines:" | head -20 - echo "" - fi - - # Show full analysis (first 30 lines for context) - echo -e "${BLUE}📋 Full analysis:${NC}" - head -30 "$result_file" - echo -e "${YELLOW}... (see $result_file for complete output)${NC}" - echo -e "${BLUE}${'='*60}${NC}\n" - fi - fi -done - -if [ $files_with_issues -eq 0 ]; then - echo -e "${GREEN}🎉 No issues found in any analyzed files!${NC}" -else - echo -e "${YELLOW}📊 Summary: $files_with_issues files have suggested changes${NC}" - echo -e "${BLUE}💡 Tips for applying fixes:${NC}" - echo -e " • Review each suggestion carefully" - echo -e " • Test compilation after each change" - echo -e " • Some suggestions might be false positives" - echo -e " • Consider project-specific header policies" - echo "" - echo -e "${BLUE}🗂️ Detailed results available in: $RESULTS_DIR${NC}" -fi \ No newline at end of file diff --git a/safe_iwyu_fix.sh b/safe_iwyu_fix.sh deleted file mode 100644 index 4428e7b..0000000 --- a/safe_iwyu_fix.sh +++ /dev/null @@ -1,138 +0,0 @@ -#!/bin/bash - -# Safe automatic IWYU fix with build system validation -# This version applies fixes and validates using your actual build system - -# Detect project root -if [ -d "/workspace" ]; then - PROJECT_ROOT="/workspace" -else - PROJECT_ROOT="$(pwd)" -fi - -RESULTS_DIR="$PROJECT_ROOT/iwyu_results" - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -echo -e "${BLUE}🔧 Safe IWYU Auto-Fix with Build Validation${NC}" -echo -e "${YELLOW}⚠️ This will apply fixes one file at a time and validate with your build system${NC}" - -if [ ! -d "$RESULTS_DIR" ]; then - echo -e "${RED}❌ No IWYU results found. Run './check_iwyu.sh' first.${NC}" - exit 1 -fi - -# Make sure we can build first -echo -e "${BLUE}🔍 Testing initial build...${NC}" -if ! make -j$(nproc) release >/dev/null 2>&1; then - echo -e "${RED}❌ Project doesn't build currently. Fix build issues first.${NC}" - exit 1 -fi -echo -e "${GREEN}✅ Initial build successful${NC}" - -files_fixed=0 -files_processed=0 - -# Process each .iwyu result file -for result_file in "$RESULTS_DIR"/*.iwyu; do - [ ! -f "$result_file" ] && continue - - # Get the corresponding source file - base_name=$(basename "$result_file" .iwyu) - source_file="" - - # Find the actual source file - while IFS= read -r -d '' file; do - if [[ "$(basename "$file" .cpp)" == "$base_name" ]]; then - source_file="$file" - break - fi - done < <(find "$PROJECT_ROOT/webserv" -name "*.cpp" -print0) - - if [ -z "$source_file" ]; then - continue - fi - - ((files_processed++)) - relative_path="${source_file#$PROJECT_ROOT/}" - - echo -e "\n${BLUE}[$files_processed] Processing: $relative_path${NC}" - - # Check if there are actual suggestions - if ! grep -q "should add these lines:" "$result_file"; then - echo -e "${GREEN} ✅ No additions needed${NC}" - continue - fi - - # Create backup - backup_file="${source_file}.backup" - cp "$source_file" "$backup_file" - - # Extract and apply only the additions (safer than removals) - additions_made=false - - # Get the lines to add and store in temp file to avoid subshell issues - temp_includes=$(mktemp) - awk '/should add these lines:/{flag=1; next} /should remove these lines:|^$/{flag=0} flag && /^#include/{print}' "$result_file" > "$temp_includes" - - # Process each include line - while IFS= read -r include_line; do - [ -z "$include_line" ] && continue - - # Clean up the line (remove any trailing whitespace/comments after //) - clean_include=$(echo "$include_line" | sed 's|//.*$||' | sed 's/[[:space:]]*$//') - - # Check if this exact include is already present (be more strict) - if grep -F "$clean_include" "$source_file" >/dev/null; then - echo -e "${YELLOW} ~ Already present: $clean_include${NC}" - continue - fi - - # Add the include after the first existing #include - if sed -i "1,/^#include/ { /^#include/ a\\ -$include_line -}" "$source_file"; then - echo -e "${GREEN} + Added: $include_line${NC}" - additions_made=true - fi - done < "$temp_includes" - - rm -f "$temp_includes" - - if [ "$additions_made" = true ]; then - # Test build with changes - echo -e "${BLUE} 🔨 Testing build...${NC}" - if make -j$(nproc) release >/dev/null 2>&1; then - echo -e "${GREEN} ✅ Build successful with changes${NC}" - rm "$backup_file" - ((files_fixed++)) - else - echo -e "${RED} ❌ Build failed, reverting changes${NC}" - mv "$backup_file" "$source_file" - fi - else - echo -e "${GREEN} ✅ No new includes to add${NC}" - rm "$backup_file" - fi -done - -echo -e "\n${BLUE}📊 Safe Auto-fix Summary:${NC}" -echo -e "Files processed: $files_processed" -echo -e "Files successfully modified: $files_fixed" - -if [ $files_fixed -gt 0 ]; then - echo -e "${GREEN}🎉 Applied $files_fixed successful fixes!${NC}" - echo -e "${BLUE}💡 Next steps:${NC}" - echo -e " • Review changes: ${BLUE}git diff${NC}" - echo -e " • Run full test: ${BLUE}make clean && make all${NC}" - echo -e " • Commit: ${BLUE}git add -A && git commit -m 'fix: add missing includes (IWYU)'${NC}" -else - echo -e "${GREEN}🎉 No fixes needed - all includes are already optimal!${NC}" -fi - -exit 0 \ No newline at end of file