Skip to content

Commit 809a610

Browse files
committed
fix(build): make --clean actually remove local build directories
- implement clean_local_build_dirs() to remove build-dev, build-ninja, build-release - support target-specific build dirs (e.g. build-dev-<triple>) - ensure stale CMake cache is fully removed before configure - align --clean behavior with user expectation and CLI message This fixes the issue where --clean did not remove old CMakeCache.txt, causing "stale build cache detected" errors despite using --clean.
1 parent b19fe31 commit 809a610

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/commands/BuildCommand.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,43 @@ namespace vix::commands::BuildCommand
647647
return util::file_exists(buildDir / "CMakeCache.txt");
648648
}
649649

650+
static void clean_local_build_dirs(
651+
const fs::path &projectDir,
652+
const std::string &targetTriple,
653+
bool quiet)
654+
{
655+
std::vector<fs::path> dirs = {
656+
projectDir / "build-dev",
657+
projectDir / "build-ninja",
658+
projectDir / "build-release"};
659+
660+
if (!targetTriple.empty())
661+
{
662+
dirs.push_back(projectDir / ("build-dev-" + targetTriple));
663+
dirs.push_back(projectDir / ("build-ninja-" + targetTriple));
664+
dirs.push_back(projectDir / ("build-release-" + targetTriple));
665+
}
666+
667+
for (const auto &dir : dirs)
668+
{
669+
if (!fs::exists(dir))
670+
continue;
671+
672+
std::error_code ec;
673+
fs::remove_all(dir, ec);
674+
675+
if (ec)
676+
{
677+
error("Failed to remove build directory: " + dir.string());
678+
hint(ec.message());
679+
throw std::runtime_error("clean failed");
680+
}
681+
682+
if (!quiet)
683+
step("removed " + dir.string());
684+
}
685+
}
686+
650687
static std::vector<std::pair<std::string, std::string>>
651688
build_cmake_vars(
652689
const process::Preset &p,
@@ -835,6 +872,18 @@ namespace vix::commands::BuildCommand
835872
plan_ = *planOpt;
836873
const fs::path globalPackagesFile = plan_.buildDir / "vix-global-packages.cmake";
837874

875+
if (opt_.clean)
876+
{
877+
try
878+
{
879+
clean_local_build_dirs(plan_.projectDir, opt_.targetTriple, opt_.quiet);
880+
}
881+
catch (const std::exception &)
882+
{
883+
return 1;
884+
}
885+
}
886+
838887
const bool verboseMode = opt_.verbose || opt_.cmakeVerbose;
839888
const bool defer = (!opt_.quiet && verboseMode);
840889
DeferredConsole out(defer);
@@ -1195,7 +1244,7 @@ namespace vix::commands::BuildCommand
11951244
out << " --sysroot <path> Sysroot for cross toolchain (optional)\n";
11961245
out << " --static Request static linking (VIX_LINK_STATIC=ON)\n";
11971246
out << " -j, --jobs <n> Parallel build jobs (default: CPU count, clamped)\n";
1198-
out << " --clean Force reconfigure (ignore cache/signature)\n";
1247+
out << " --clean Remove local build directories and reconfigure from scratch\n";
11991248
out << " --no-cache Disable signature cache shortcut\n";
12001249
out << " --fast Fast loop: if Ninja says up-to-date, exit immediately\n";
12011250
out << " --linker <mode> auto|default|mold|lld (auto prefers mold then lld)\n";

0 commit comments

Comments
 (0)