Skip to content

Commit 3d865b3

Browse files
committed
feat(errors): add dedicated build error detectors for CMake failures
1 parent 1f63c6b commit 3d865b3

6 files changed

Lines changed: 120 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
# debug information files
4141
*.dwo
42-
build/
42+
build-*/
4343
.vscode/
4444
vix.log
4545
cmd.md
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
*
3+
* @file BuildErrorDetectors.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*
13+
*/
14+
#ifndef VIX_BUILD_ERROR_DETECTORS_HPP
15+
#define VIX_BUILD_ERROR_DETECTORS_HPP
16+
17+
#include <string_view>
18+
19+
namespace vix::cli::errors::build
20+
{
21+
bool handleBuildErrors(std::string_view log);
22+
}
23+
24+
#endif
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
*
3+
* @file CMakeBuildErrors.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*
13+
*/
14+
#ifndef VIX_CMAKE_BUILD_ERRORS_HPP
15+
#define VIX_CMAKE_BUILD_ERRORS_HPP
16+
17+
#include <string_view>
18+
19+
namespace vix::cli::errors::build
20+
{
21+
bool handleCMakeBuildError(std::string_view log);
22+
}
23+
24+
#endif

src/ErrorHandler.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
* Vix.cpp
1212
*
1313
*/
14-
#include "vix/cli/ErrorHandler.hpp"
15-
16-
#include "vix/cli/errors/ClangGccParser.hpp"
17-
#include "vix/cli/errors/CompilerError.hpp"
18-
#include "vix/cli/errors/ErrorContext.hpp"
19-
#include "vix/cli/errors/ErrorPipeline.hpp"
20-
#include "vix/cli/errors/RawLogDetectors.hpp"
21-
#include "vix/cli/errors/CodeFrame.hpp"
14+
#include <vix/cli/ErrorHandler.hpp>
15+
16+
#include <vix/cli/errors/ClangGccParser.hpp>
17+
#include <vix/cli/errors/CompilerError.hpp>
18+
#include <vix/cli/errors/ErrorContext.hpp>
19+
#include <vix/cli/errors/ErrorPipeline.hpp>
20+
#include <vix/cli/errors/RawLogDetectors.hpp>
21+
#include <vix/cli/errors/CodeFrame.hpp>
22+
#include <vix/cli/errors/build/BuildErrorDetectors.hpp>
2223
#include <vix/utils/Env.hpp>
24+
2325
#include <iostream>
2426
#include <sstream>
2527
#include <unordered_map>
@@ -218,6 +220,9 @@ namespace vix::cli
218220
if (RawLogDetectors::handleLinkerOrSanitizer(cleanedLog, sourceFile, contextMessage))
219221
return;
220222

223+
if (vix::cli::errors::build::handleBuildErrors(cleanedLog))
224+
return;
225+
221226
error(contextMessage + " (see compiler output below):");
222227
std::cerr << cleanedLog << "\n";
223228
return;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <vix/cli/errors/build/BuildErrorDetectors.hpp>
2+
#include <vix/cli/errors/build/CMakeBuildErrors.hpp>
3+
4+
namespace vix::cli::errors::build
5+
{
6+
bool handleBuildErrors(std::string_view log)
7+
{
8+
if (handleCMakeBuildError(log))
9+
return true;
10+
11+
return false;
12+
}
13+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
*
3+
* @file CMakeBuildErrors.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*
13+
*/
14+
#include <vix/cli/errors/build/CMakeBuildErrors.hpp>
15+
16+
#include <iostream>
17+
#include <string>
18+
19+
#include <vix/cli/Style.hpp>
20+
21+
using namespace vix::cli::style;
22+
23+
namespace vix::cli::errors::build
24+
{
25+
bool handleCMakeBuildError(std::string_view log)
26+
{
27+
const bool cacheDirMismatch =
28+
log.find("The current CMakeCache.txt directory") != std::string_view::npos;
29+
30+
const bool sourceMismatch =
31+
log.find("does not match the source") != std::string_view::npos &&
32+
log.find("used to generate cache") != std::string_view::npos;
33+
34+
if (!cacheDirMismatch && !sourceMismatch)
35+
return false;
36+
37+
error("CMake configure failed: stale build cache detected.");
38+
hint("Your build directory was generated from another project location.");
39+
hint("Remove the old build directory and reconfigure.");
40+
hint("Recommended: vix build --clean");
41+
hint("Manual fix: rm -rf build-ninja build-dev build-release");
42+
43+
return true;
44+
}
45+
}

0 commit comments

Comments
 (0)