Skip to content

ci_compile.cpp - #5

Open
AlexGoodmen wants to merge 1 commit into
mainfrom
AlexGoodmen-patch-7
Open

ci_compile.cpp#5
AlexGoodmen wants to merge 1 commit into
mainfrom
AlexGoodmen-patch-7

Conversation

@AlexGoodmen

Copy link
Copy Markdown
Owner

This C++ utility runs locally. and performs three main operations:

  1. Detect Compiler
std::string compiler = "clang++";
if (runCommand("which clang++ > /dev/null 2>&1") != 0) {
    compiler = "g++";
}
  • Tries to find clang++.
  • If not available, falls back to g++. This ensures the script works on systems without Clang.
  1. Compile DebugDisplay.cpp with Strict Checks**
std::string compileCmd = compiler +
    " -std=c++20 "
    "-I\"" + SRC + "\" "
    "-Wall -Wextra -Werror -Wpedantic -Wconversion -Wshadow "
    "-Wdouble-promotion -Wold-style-cast -Woverloaded-virtual -Wnon-virtual-dtor "
    "-Wnull-dereference -Wformat=2 -Wimplicit-fallthrough=5 -Wundef -Wredundant-decls "
    "-fno-omit-frame-pointer "
    "-O0 -g3 "
    "-c \"" + TU + "\" -o /tmp/DebugDisplay.o";

Purpose: Compile only GeneralsMD/Code/GameEngine/Source/GameClient/System/DebugDisplay.cpp into an object file without linking the entire project.

Flags Explained

  • -Wall -Wextra: Enable common and extra warnings.
  • -Werror: Treat warnings as errors.
  • -Wpedantic -Wconversion -Wshadow: Catch risky patterns and implicit type conversions.
  • -O0 -g3: No optimization, full debug info.
  • -c: Compile only (no linking).
  • -I"$SRC": Adds include path for headers.
  • -std=c++20: Enforces modern standard compliance.

If compilation fails, the program exits early so you know exactly which errors are in that translation unit.


3. Static Analysis with clang-tidy

std::string tidyCmd =
    "clang-tidy \"" + TU + "\" "
    "--warnings-as-errors='*' "
    "--extra-arg=-std=c++20 "
    "--extra-arg=-I\"" + SRC + "\" "
    "--checks='clang-analyzer-*,bugprone-*,readability-*,modernize-*,performance-*,cppcoreguidelines-*,-cppcoreguidelines-avoid-magic-numbers' "
    "--header-filter='GeneralsMD/Code/GameEngine/Source/.*' "
    "--format-style=file || true";
  • Purpose: Run static analysis and style checks on the same file using clang-tidy.

  • Checks Applied:

    • clang-analyzer-*: Finds undefined behavior, memory leaks.
    • bugprone-*: Detects common mistakes.
    • modernize-*: Suggests C++ modernizations.
    • performance-*: Flags inefficient code.
    • cppcoreguidelines-*: Enforces core safety rules.
  • WarningsAsErrors='*': Treat all findings as errors in CI context.

  • HeaderFilterRegex: Limits analysis to headers under your GeneralsMD source tree.

If clang-tidy is not installed, it skips this step.

Execution Flow

  1. Print which compiler is used.
  2. Show compiler version.
  3. Compile DebugDisplay.cpp with strict warnings-as-errors.
  4. Run clang-tidy to check for logical errors and style issues.
  5. Exit with success if everything passes.

Goal

  • Detect syntax and header-related issues before full build.
  • Fail fast on warnings.
  • Provide static analysis early.
  • Reduce debugging time by isolating this translation unit.

This C++ utility runs locally. and performs three main operations:

1. Detect Compiler

```cpp
std::string compiler = "clang++";
if (runCommand("which clang++ > /dev/null 2>&1") != 0) {
    compiler = "g++";
}
```

* Tries to find `clang++`.
* If not available, falls back to `g++`.
  This ensures the script works on systems without Clang.

2. Compile `DebugDisplay.cpp` with Strict Checks**

```cpp
std::string compileCmd = compiler +
    " -std=c++20 "
    "-I\"" + SRC + "\" "
    "-Wall -Wextra -Werror -Wpedantic -Wconversion -Wshadow "
    "-Wdouble-promotion -Wold-style-cast -Woverloaded-virtual -Wnon-virtual-dtor "
    "-Wnull-dereference -Wformat=2 -Wimplicit-fallthrough=5 -Wundef -Wredundant-decls "
    "-fno-omit-frame-pointer "
    "-O0 -g3 "
    "-c \"" + TU + "\" -o /tmp/DebugDisplay.o";
```

Purpose: Compile only `GeneralsMD/Code/GameEngine/Source/GameClient/System/DebugDisplay.cpp` into an object file without linking the entire project.

Flags Explained

  * `-Wall -Wextra`: Enable common and extra warnings.
  * `-Werror`: Treat warnings as errors.
  * `-Wpedantic -Wconversion -Wshadow`: Catch risky patterns and implicit type conversions.
  * `-O0 -g3`: No optimization, full debug info.
  * `-c`: Compile only (no linking).
  * `-I"$SRC"`: Adds include path for headers.
  * `-std=c++20`: Enforces modern standard compliance.

If compilation fails, the program exits early so you know exactly which errors are in that translation unit.

---

### **3. Static Analysis with `clang-tidy`**

```cpp
std::string tidyCmd =
    "clang-tidy \"" + TU + "\" "
    "--warnings-as-errors='*' "
    "--extra-arg=-std=c++20 "
    "--extra-arg=-I\"" + SRC + "\" "
    "--checks='clang-analyzer-*,bugprone-*,readability-*,modernize-*,performance-*,cppcoreguidelines-*,-cppcoreguidelines-avoid-magic-numbers' "
    "--header-filter='GeneralsMD/Code/GameEngine/Source/.*' "
    "--format-style=file || true";
```

* **Purpose**: Run static analysis and style checks on the same file using `clang-tidy`.
* **Checks Applied**:

  * `clang-analyzer-*`: Finds undefined behavior, memory leaks.
  * `bugprone-*`: Detects common mistakes.
  * `modernize-*`: Suggests C++ modernizations.
  * `performance-*`: Flags inefficient code.
  * `cppcoreguidelines-*`: Enforces core safety rules.
* `WarningsAsErrors='*'`: Treat all findings as errors in CI context.
* `HeaderFilterRegex`: Limits analysis to headers under your `GeneralsMD` source tree.

If `clang-tidy` is not installed, it skips this step.


Execution Flow

1. Print which compiler is used.
2. Show compiler version.
3. Compile `DebugDisplay.cpp` with strict warnings-as-errors.
4. Run `clang-tidy` to check for logical errors and style issues.
5. Exit with success if everything passes.

---

Goal

* Detect syntax and header-related issues **before full build**.
* Fail fast on warnings.
* Provide static analysis early.
* Reduce debugging time by isolating this translation unit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant