Merge remote-tracking branch 'origin/willem'

This commit is contained in:
Quinten Mennen 2025-09-24 15:54:57 +02:00
commit 93079cd8bd
5 changed files with 28 additions and 252 deletions

View File

@ -3,14 +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 \
# Standard clang tools (this will install the default version)
clang \
clang-format \
clang-tidy \
# Clang 12 toolchain
clang-12 \
clang++-12 \
clang-format-12 \
clang-tidy-12 \
clangd \
lldb \
# Build tools
@ -20,7 +21,6 @@ RUN apt-get update && apt-get install -y \
pkg-config \
# Version control and utilities
git \
wget \
curl \
unzip \
# Development utilities
@ -33,10 +33,18 @@ 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 a non-root user for development
# 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 non-root user
RUN groupadd --gid 1000 vscode \
&& useradd --uid 1000 --gid vscode --shell /bin/bash --create-home vscode \
&& apt-get update \
@ -45,9 +53,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 environment variables
ENV CC=clang-12
ENV CXX=clang++-12
# Set working directory
WORKDIR /workspace

View File

@ -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.'"
}

View File

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

2
format.sh Executable file
View File

@ -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' _ {} \;

View File

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