[PATCH] D100343: [AST][NFC] Remove temporary ASTTU file from Introspection generation.

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 12 14:14:20 PDT 2021


njames93 updated this revision to Diff 336960.
njames93 added a comment.

Add new line at the end of remapped file.


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"),
@@ -86,7 +83,7 @@
                   [](const std::string &IncDir) { return "-I" + IncDir; });
 
   Args.push_back("-fsyntax-only");
-  Args.push_back(AstHeaderFile);
+  Args.push_back("ASTTU.cpp");
 
   std::vector<const char *> Argv(Args.size(), nullptr);
   llvm::transform(Args, Argv.begin(),
@@ -102,9 +99,7 @@
   // 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);
@@ -133,6 +128,9 @@
 
   auto Invocation = std::make_unique<CompilerInvocation>();
   CompilerInvocation::CreateFromArgs(*Invocation, CC1Args, Diagnostics);
+  Invocation->getPreprocessorOpts().addRemappedFile(
+      "ASTTU.cpp",
+      MemoryBuffer::getMemBuffer("#include \"clang/AST/AST.h\"\n").release());
 
   CompilerInstance Compiler(std::make_shared<clang::PCHContainerOperations>());
   Compiler.setInvocation(std::move(Invocation));
Index: clang/lib/Tooling/CMakeLists.txt
===================================================================
--- clang/lib/Tooling/CMakeLists.txt
+++ clang/lib/Tooling/CMakeLists.txt
@@ -62,10 +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})
@@ -75,12 +71,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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100343.336960.patch
Type: text/x-patch
Size: 3541 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210412/5c47e3c4/attachment.bin>


More information about the cfe-commits mailing list