Skip to content

Commit d8709ae

Browse files
committed
[clangd] [C++20 Modules] Add --debug-modules-builder to not remove built module files on exit
In practice I found the option is very helpful for me to understand what happens when clangd's C++20 modules support fails. With '--log=verbose', I can rerun the command by clangd to understand what's going wrong actually. The documentation or adding the option to '--help' list can be done separately.
1 parent c2e8065 commit d8709ae

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@
1414
#include "clang/Serialization/ASTReader.h"
1515
#include "clang/Serialization/ModuleCache.h"
1616
#include "llvm/ADT/ScopeExit.h"
17+
#include "llvm/Support/CommandLine.h"
18+
1719
#include <queue>
1820

1921
namespace clang {
2022
namespace clangd {
2123

2224
namespace {
2325

26+
llvm::cl::opt<bool> DebugModulesBuilder(
27+
"debug-modules-builder",
28+
llvm::cl::desc("Don't remove clangd's built module files for debugging. "
29+
"Remember to remove them later after debugging."),
30+
llvm::cl::init(false));
31+
2432
// Create a path to store module files. Generally it should be:
2533
//
2634
// {TEMP_DIRS}/clangd/module_files/{hashed-file-name}-%%-%%-%%-%%-%%-%%/.
@@ -122,7 +130,7 @@ struct ModuleFile {
122130
}
123131

124132
~ModuleFile() {
125-
if (!ModuleFilePath.empty())
133+
if (!ModuleFilePath.empty() && !DebugModulesBuilder)
126134
llvm::sys::fs::remove(ModuleFilePath);
127135
}
128136

0 commit comments

Comments
 (0)