njames93 updated this revision to Diff 337249.
njames93 added a comment.
Use InMemoryFileSystem instead of Remapped files, turns out they don't work if
the file doesn't exist on disk.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100343/new/
https://reviews.llvm.org/D100343
Files:
clang/lib/Tooling/CMakeLists.txt
clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
Index: clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
===================================================================
--- clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
+++ clang/lib/Tooling/DumpTool/ClangSrcLocDump.cpp
@@ -14,6 +14,7 @@
#include "clang/Driver/Tool.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/CommandLine.h"
@@ -30,10 +31,6 @@
"I", cl::desc("Include directories to use while compiling"),
cl::value_desc("directory"), cl::Required, cl::OneOrMore, cl::Prefix);
-static cl::opt<std::string>
- AstHeaderFile("astheader", cl::desc("AST header to parse API from"),
- cl::Required, cl::value_desc("AST header file"));
-
static cl::opt<bool>
SkipProcessing("skip-processing",
cl::desc("Avoid processing the AST header file"),
@@ -66,6 +63,8 @@
ASTSrcLocProcessor Processor;
};
+static const char Filename[] = "ASTTU.cpp";
+
int main(int argc, const char **argv) {
cl::ParseCommandLineOptions(argc, argv);
@@ -86,7 +85,7 @@
[](const std::string &IncDir) { return "-I" + IncDir; });
Args.push_back("-fsyntax-only");
- Args.push_back(AstHeaderFile);
+ Args.push_back(Filename);
std::vector<const char *> Argv(Args.size(), nullptr);
llvm::transform(Args, Argv.begin(),
@@ -102,18 +101,23 @@
// Don't output diagnostics, because common scenarios such as
// cross-compiling fail with diagnostics. This is not fatal, but
// just causes attempts to use the introspection API to return no data.
- std::string Str;
- llvm::raw_string_ostream OS(Str);
- TextDiagnosticPrinter DiagnosticPrinter(OS, &*DiagOpts);
+ TextDiagnosticPrinter DiagnosticPrinter(llvm::nulls(), &*DiagOpts);
DiagnosticsEngine Diagnostics(
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts,
&DiagnosticPrinter, false);
- FileManager Files(FileSystemOptions(), vfs::getRealFileSystem());
+ auto *OFS = new llvm::vfs::OverlayFileSystem(vfs::getRealFileSystem());
+
+ auto *MemFS = new llvm::vfs::InMemoryFileSystem();
+ OFS->pushOverlay(MemFS);
+ MemFS->addFile(Filename, 0,
+ MemoryBuffer::getMemBuffer("#include \"clang/AST/AST.h\"\n"));
+
+ auto Files = llvm::makeIntrusiveRefCnt<FileManager>(FileSystemOptions(), OFS);
auto Driver = std::make_unique<driver::Driver>(
"clang", llvm::sys::getDefaultTargetTriple(), Diagnostics,
- "ast-api-dump-tool", &Files.getVirtualFileSystem());
+ "ast-api-dump-tool", OFS);
std::unique_ptr<clang::driver::Compilation> Comp(
Driver->BuildCompilation(llvm::makeArrayRef(Argv)));
@@ -143,12 +147,13 @@
// Suppress "2 errors generated" or similar messages
Compiler.getDiagnosticOpts().ShowCarets = false;
- Compiler.createSourceManager(Files);
+ Compiler.createSourceManager(*Files);
+ Compiler.setFileManager(Files.get());
ASTSrcLocGenerationAction ScopedToolAction;
Compiler.ExecuteAction(ScopedToolAction);
- Files.clearStatCache();
+ Files->clearStatCache();
return 0;
}
Index: clang/lib/Tooling/CMakeLists.txt
===================================================================
--- clang/lib/Tooling/CMakeLists.txt
+++ clang/lib/Tooling/CMakeLists.txt
@@ -62,11 +62,6 @@
set(skip_expensive_processing $<OR:$<CONFIG:Debug>,$<NOT:$<BOOL:${CLANG_TOOLING_BUILD_AST_INTROSPECTION}>>>)
- file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTTU.cpp
- CONTENT "
-#include <clang/AST/AST.h>
-")
-
set(implicitDirs)
foreach(implicitDir ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
list(APPEND implicitDirs -I ${implicitDir})
@@ -75,12 +70,11 @@
add_custom_command(
COMMENT Generate ASTNodeAPI.json
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
- DEPENDS clang-ast-dump clang-resource-headers ${CMAKE_CURRENT_BINARY_DIR}/ASTTU.cpp
+ DEPENDS clang-ast-dump clang-resource-headers
COMMAND
$<TARGET_FILE:clang-ast-dump>
# Skip this in debug mode because parsing AST.h is too slow
--skip-processing=${skip_expensive_processing}
- --astheader=${CMAKE_CURRENT_BINARY_DIR}/ASTTU.cpp
-I ${CMAKE_BINARY_DIR}/lib/clang/${CLANG_VERSION}/include
-I ${CMAKE_SOURCE_DIR}/../clang/include
-I ${CMAKE_BINARY_DIR}/tools/clang/include
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits