ci_compile.cpp - #5
Open
AlexGoodmen wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This C++ utility runs locally. and performs three main operations:
clang++.g++. This ensures the script works on systems without Clang.DebugDisplay.cppwith 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.cppinto 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-tidystd::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 yourGeneralsMDsource tree.If
clang-tidyis not installed, it skips this step.Execution Flow
DebugDisplay.cppwith strict warnings-as-errors.clang-tidyto check for logical errors and style issues.Goal