Skip to content

Commit bd9f7b2

Browse files
committed
feat(check): add smart sanitizer mode with --full override
- Introduce automatic smart sanitizer mode for large projects - Avoid install/export/configure issues during sanitizer checks - Add --full flag to force complete project sanitizer validation - Align behavior across Linux and Windows - Improve check reliability on umbrella CMake projects - Update help to document smart vs full sanitizer modes
1 parent 0c13c54 commit bd9f7b2

File tree

4 files changed

+97
-12
lines changed

4 files changed

+97
-12
lines changed

include/vix/cli/commands/check/CheckDetail.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ namespace vix::commands::CheckCommand::detail
113113
/// Runtime timeout in seconds. 0 means no explicit timeout override.
114114
int runTimeoutSec = 0;
115115

116+
bool full = false;
117+
116118
/** @} */
117119
};
118120

src/commands/CheckCommand.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,18 @@ namespace vix::commands::CheckCommand
129129
out << " vix check [path|file.cpp] [options]\n\n";
130130

131131
print_help_section_header(out, "Description");
132-
out << " Validate a Vix/CMake project or a single-file C++ script.\n\n";
132+
out << " Validate a Vix/CMake project or a single C++ file.\n";
133+
out << " Vix can check build health, test health, runtime health, and sanitizer safety.\n\n";
133134

134135
print_help_section_header(out, "Project mode");
135-
out << " - Configure the project\n";
136-
out << " - Build the project\n";
137-
out << " - Optional: run tests with CTest\n";
138-
out << " - Optional: run the built executable\n";
139-
out << " - With --san / --ubsan, use an isolated check profile\n\n";
136+
out << " - Detect and configure the project\n";
137+
out << " - Build the selected check profile\n";
138+
out << " - Optionally run tests with CTest\n";
139+
out << " - Optionally run the built executable\n";
140+
out << " - With sanitizers, use an isolated build profile\n\n";
140141

141142
print_help_section_header(out, "Script mode");
142-
out << " - Create a temporary CMake project\n";
143+
out << " - Create a temporary CMake project around the file\n";
143144
out << " - Compile the file\n";
144145
out << " - With sanitizers enabled, also run the binary for runtime validation\n\n";
145146

@@ -159,25 +160,38 @@ namespace vix::commands::CheckCommand
159160

160161
print_help_section_header(out, "Sanitizers");
161162
out << " --san Enable AddressSanitizer + UBSan\n";
162-
out << " --ubsan Enable UBSan only\n\n";
163+
out << " --ubsan Enable UBSan only\n";
164+
out << " --full Force the complete sanitizer check, including full project configure\n\n";
165+
166+
print_help_section_header(out, "Sanitizer modes");
167+
out << " Default sanitizer mode is smart.\n";
168+
out << " - Small projects: Vix checks the full project normally.\n";
169+
out << " - Large or umbrella projects: Vix may switch to a reduced sanitizer\n";
170+
out << " configure to avoid unrelated packaging/export/install failures.\n";
171+
out << " - Use --full to force the complete sanitizer configure.\n";
172+
out << " This is useful when you want to detect real CMake/export issues.\n\n";
163173

164174
print_help_section_header(out, "Notes");
165175
out << " - Project checks use isolated build directories per profile.\n";
166176
out << " Example: build-ninja, build-ninja-san, build-ninja-ubsan.\n";
167177
out << " - If a dedicated sanitizer preset does not exist, Vix falls back to\n";
168178
out << " manual configure/build for that check profile.\n";
169-
out << " - In project mode, --san and --ubsan also trigger runtime validation.\n";
179+
out << " - In project mode, --san and --ubsan also enable runtime validation.\n";
170180
out << " - In script mode, sanitizers validate both build and runtime.\n";
171-
out << " - Global packages installed by Vix are integrated into project checks.\n\n";
181+
out << " - Global packages installed by Vix are integrated into project checks.\n";
182+
out << " - --san is the recommended mode for day-to-day validation.\n";
183+
out << " - --san --full is stricter and can reveal real project-level CMake issues.\n\n";
172184

173185
print_help_section_header(out, "Examples");
174186
out << " vix check\n";
175187
out << " vix check --tests\n";
176188
out << " vix check --run\n";
177189
out << " vix check --tests --run\n";
178190
out << " vix check --san\n";
191+
out << " vix check --san --full\n";
179192
out << " vix check --san --tests\n";
180193
out << " vix check --san --tests --run-timeout 20\n";
194+
out << " vix check --ubsan\n";
181195
out << " vix check --dir ./examples/api\n";
182196
out << " vix check main.cpp\n";
183197
out << " vix check main.cpp --san\n";

src/commands/check/CheckFlow.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ namespace vix::commands::CheckCommand::detail
141141
{
142142
o.verbose = true;
143143
}
144+
else if (a == "--full")
145+
{
146+
o.full = true;
147+
}
144148
else if (a == "--log-level" || a == "--loglevel")
145149
{
146150
if (i + 1 < args.size())

src/commands/check/CheckProject.cpp

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,31 @@ namespace vix::commands::CheckCommand::detail
677677

678678
ui::one_line_spacer(std::cout);
679679
}
680+
681+
static bool should_use_smart_sanitizer_mode(
682+
const Options &opt,
683+
const fs::path &projectDir)
684+
{
685+
if (opt.full)
686+
return false;
687+
688+
if (!(opt.enableSanitizers || opt.enableUbsanOnly))
689+
return false;
690+
691+
if (fs::exists(projectDir / ".gitmodules"))
692+
return true;
693+
694+
if (fs::exists(projectDir / "examples"))
695+
return true;
696+
697+
if (fs::exists(projectDir / "modules"))
698+
return true;
699+
700+
if (fs::exists(projectDir / "tests"))
701+
return true;
702+
703+
return false;
704+
}
680705
} // namespace
681706

682707
int check_project(const Options &opt, const fs::path &projectDir)
@@ -690,6 +715,9 @@ namespace vix::commands::CheckCommand::detail
690715
const bool shouldRunRuntime =
691716
opt.runAfterBuild || opt.enableSanitizers || opt.enableUbsanOnly;
692717

718+
const bool smartSanitizerMode =
719+
should_use_smart_sanitizer_mode(opt, projectDir);
720+
693721
if (has_presets(projectDir))
694722
{
695723
const bool wantsSan = opt.enableSanitizers;
@@ -747,8 +775,18 @@ namespace vix::commands::CheckCommand::detail
747775
<< " -DCMAKE_BUILD_TYPE=Debug"
748776
<< " -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=" << quote(globalPackagesFile->string())
749777
<< " -DVIX_ENABLE_SANITIZERS=ON"
750-
<< " -DVIX_SANITIZER_MODE=" << quote(summary.ubsanOnly ? "ubsan" : "asan-ubsan")
751-
<< "\"";
778+
<< " -DVIX_SANITIZER_MODE=" << quote(summary.ubsanOnly ? "ubsan" : "asan-ubsan");
779+
780+
if (smartSanitizerMode)
781+
{
782+
conf << " -DBUILD_TESTING=OFF"
783+
<< " -DVIX_BUILD_TESTS=OFF"
784+
<< " -DVIX_BUILD_EXAMPLES=OFF"
785+
<< " -DCMAKE_SKIP_INSTALL_RULES=ON"
786+
<< " -DVIX_INSTALL=OFF";
787+
}
788+
789+
conf << "\"";
752790
}
753791
else
754792
{
@@ -780,6 +818,15 @@ namespace vix::commands::CheckCommand::detail
780818
<< " -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=" << quote(globalPackagesFile->string())
781819
<< " -DVIX_ENABLE_SANITIZERS=ON"
782820
<< " -DVIX_SANITIZER_MODE=" << quote(summary.ubsanOnly ? "ubsan" : "asan-ubsan");
821+
822+
if (smartSanitizerMode)
823+
{
824+
conf << " -DBUILD_TESTING=OFF"
825+
<< " -DVIX_BUILD_TESTS=OFF"
826+
<< " -DVIX_BUILD_EXAMPLES=OFF"
827+
<< " -DCMAKE_SKIP_INSTALL_RULES=ON"
828+
<< " -DVIX_INSTALL=OFF";
829+
}
783830
}
784831
else
785832
{
@@ -982,6 +1029,15 @@ namespace vix::commands::CheckCommand::detail
9821029
conf << " -DVIX_ENABLE_SANITIZERS=ON"
9831030
<< " -DVIX_SANITIZER_MODE="
9841031
<< quote(summary.ubsanOnly ? "ubsan" : "asan-ubsan");
1032+
1033+
if (smartSanitizerMode)
1034+
{
1035+
conf << " -DBUILD_TESTING=OFF"
1036+
<< " -DVIX_BUILD_TESTS=OFF"
1037+
<< " -DVIX_BUILD_EXAMPLES=OFF"
1038+
<< " -DCMAKE_SKIP_INSTALL_RULES=ON"
1039+
<< " -DVIX_INSTALL=OFF";
1040+
}
9851041
}
9861042

9871043
conf << "\"";
@@ -1007,6 +1063,15 @@ namespace vix::commands::CheckCommand::detail
10071063
conf << " -DVIX_ENABLE_SANITIZERS=ON"
10081064
<< " -DVIX_SANITIZER_MODE="
10091065
<< quote(summary.ubsanOnly ? "ubsan" : "asan-ubsan");
1066+
1067+
if (smartSanitizerMode)
1068+
{
1069+
conf << " -DBUILD_TESTING=OFF"
1070+
<< " -DVIX_BUILD_TESTS=OFF"
1071+
<< " -DVIX_BUILD_EXAMPLES=OFF"
1072+
<< " -DCMAKE_SKIP_INSTALL_RULES=ON"
1073+
<< " -DVIX_INSTALL=OFF";
1074+
}
10101075
}
10111076

10121077
const int code = run_cmd_live_filtered(conf.str(), "Configuring (fallback)");

0 commit comments

Comments
 (0)