From b43901de1adb524bb3bab236756334b2e867fe5a Mon Sep 17 00:00:00 2001 From: whaffman Date: Thu, 9 Oct 2025 23:13:48 +0200 Subject: [PATCH] moved scripts to script folder --- Makefile | 9 +++++++-- check_iwyu.sh => scripts/check_iwyu.sh | 5 +++-- coverage.sh => scripts/coverage.sh | 2 +- fix_iwyu_auto.sh => scripts/fix_iwyu_auto.sh | 6 +++--- format.sh => scripts/format.sh | 9 ++++++--- reorder_includes.sh => scripts/reorder_includes.sh | 3 +++ run_tests.sh => scripts/run_tests.sh | 3 +++ setup.sh => scripts/setup.sh | 3 +++ webserv/router/Router.cpp | 12 +++++------- 9 files changed, 34 insertions(+), 18 deletions(-) rename check_iwyu.sh => scripts/check_iwyu.sh (97%) rename coverage.sh => scripts/coverage.sh (98%) rename fix_iwyu_auto.sh => scripts/fix_iwyu_auto.sh (96%) rename format.sh => scripts/format.sh (70%) rename reorder_includes.sh => scripts/reorder_includes.sh (97%) rename run_tests.sh => scripts/run_tests.sh (97%) rename setup.sh => scripts/setup.sh (94%) diff --git a/Makefile b/Makefile index dc3d30f..ef3ffc7 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ test_build: release # Coverage targets coverage: @echo "Running coverage analysis..." - ./coverage.sh + ./scripts/coverage.sh coverage_clean: @echo "Cleaning coverage data..." @@ -103,5 +103,10 @@ coverage_manual: $(CMAKE_BUILD) build_coverage cd build_coverage && $(CMAKE_BUILD) . --target coverage +# Code formatting target +format: + @echo "Running code formatting..." + ./scripts/format.sh + # Mark targets as phony -.PHONY: all release debug asan run run_release run_debug run_asan clean fclean re test test_verbose test_build coverage coverage_clean coverage_manual +.PHONY: all release debug asan run run_release run_debug run_asan clean fclean re test test_verbose test_build coverage coverage_clean coverage_manual format diff --git a/check_iwyu.sh b/scripts/check_iwyu.sh similarity index 97% rename from check_iwyu.sh rename to scripts/check_iwyu.sh index 1839a70..a885ec4 100755 --- a/check_iwyu.sh +++ b/scripts/check_iwyu.sh @@ -3,7 +3,8 @@ # Don't exit on first error - we want to continue checking all files # set -e -# Use current working directory as project root +# Change to project root directory (parent of scripts directory) +cd "$(dirname "$0")/.." || exit 1 PROJECT_ROOT="$(pwd)" # Find the build directory - check multiple possible locations @@ -87,7 +88,7 @@ if [ ! -f "$BUILD_DIR/compile_commands.json" ]; then fi # Create results directory -RESULTS_DIR="$PROJECT_ROOT/iwyu_results" +RESULTS_DIR="$PROJECT_ROOT/scripts/iwyu_results" mkdir -p "$RESULTS_DIR" # Function to run IWYU on a single file diff --git a/coverage.sh b/scripts/coverage.sh similarity index 98% rename from coverage.sh rename to scripts/coverage.sh index c22d0b8..5576b78 100755 --- a/coverage.sh +++ b/scripts/coverage.sh @@ -6,7 +6,7 @@ set -e # Exit on any error SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -PROJECT_ROOT="$SCRIPT_DIR" +PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" BUILD_DIR="$PROJECT_ROOT/build_coverage" # Colors for output diff --git a/fix_iwyu_auto.sh b/scripts/fix_iwyu_auto.sh similarity index 96% rename from fix_iwyu_auto.sh rename to scripts/fix_iwyu_auto.sh index 935f046..7c2f9dc 100755 --- a/fix_iwyu_auto.sh +++ b/scripts/fix_iwyu_auto.sh @@ -5,9 +5,9 @@ set -e -# Find project root (directory containing this script) -PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -RESULTS_DIR="$PROJECT_ROOT/iwyu_results" +# Find project root (parent directory of scripts) +PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +RESULTS_DIR="$PROJECT_ROOT/scripts/iwyu_results" # Colors for output RED='\033[0;31m' diff --git a/format.sh b/scripts/format.sh similarity index 70% rename from format.sh rename to scripts/format.sh index ac4c33e..05379e6 100755 --- a/format.sh +++ b/scripts/format.sh @@ -1,10 +1,13 @@ #!/bin/bash -./check_iwyu.sh -./fix_iwyu_auto.sh +# Change to project root directory +cd "$(dirname "$0")/.." || exit 1 + +./scripts/check_iwyu.sh +./scripts/fix_iwyu_auto.sh find webserv -name "*.hpp" -o -name "*.cpp" | xargs sed -i -E 's/#include "(.*)"/#include <\1>/g' 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' _ {} \; # Reorder includes to put corresponding header first -./reorder_includes.sh \ No newline at end of file +./scripts/reorder_includes.sh \ No newline at end of file diff --git a/reorder_includes.sh b/scripts/reorder_includes.sh similarity index 97% rename from reorder_includes.sh rename to scripts/reorder_includes.sh index a3c268a..a1584b3 100755 --- a/reorder_includes.sh +++ b/scripts/reorder_includes.sh @@ -4,6 +4,9 @@ # 1. Move the corresponding .hpp include to the top of includes # 2. Add a blank line after it (avoiding multiple blank lines) +# Change to project root directory +cd "$(dirname "$0")/.." || exit 1 + find webserv -name "*.cpp" | while read -r cpp_file; do # Get the base name without extension (e.g., "Client" from "Client.cpp") base_name=$(basename "$cpp_file" .cpp) diff --git a/run_tests.sh b/scripts/run_tests.sh similarity index 97% rename from run_tests.sh rename to scripts/run_tests.sh index 8ca2686..1ac8188 100755 --- a/run_tests.sh +++ b/scripts/run_tests.sh @@ -56,6 +56,9 @@ done echo -e "${BLUE}๐Ÿงช Webserv Test Runner${NC}" echo "========================================" +# Change to project root directory +cd "$(dirname "$0")/.." || exit 1 + # Check if we're in the right directory if [[ ! -f "CMakeLists.txt" || ! -d "tests" ]]; then echo -e "${RED}โŒ Error: Please run this script from the webserv project root${NC}" diff --git a/setup.sh b/scripts/setup.sh similarity index 94% rename from setup.sh rename to scripts/setup.sh index 2d2ffce..e836dfe 100755 --- a/setup.sh +++ b/scripts/setup.sh @@ -5,6 +5,9 @@ set -e # Exit on any error +# Change to project root directory +cd "$(dirname "$0")/.." || exit 1 + echo "๐Ÿš€ Setting up webserv development environment..." # Detect environment diff --git a/webserv/router/Router.cpp b/webserv/router/Router.cpp index 080bd23..3d1197d 100644 --- a/webserv/router/Router.cpp +++ b/webserv/router/Router.cpp @@ -10,13 +10,11 @@ #include // for HttpHeaders #include // for LOCATION, Log -#include // for identity -#include // for unique_ptr -#include // for optional -#include // for __find_fn, find -#include // for basic_string, string, operator== -#include // for move -#include // for vector +#include // for unique_ptr +#include // for optional +#include // for __find_fn, find +#include // for basic_string, string +#include // for vector bool Router::isMethodSupported(const std::string &method, const AConfig &config) {