steveire updated this revision to Diff 331300.
steveire added a comment.

Update


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98774/new/

https://reviews.llvm.org/D98774

Files:
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
  clang/lib/Tooling/EmptyNodeIntrospection.inc.in

Index: clang/lib/Tooling/EmptyNodeIntrospection.inc.in
===================================================================
--- /dev/null
+++ clang/lib/Tooling/EmptyNodeIntrospection.inc.in
@@ -0,0 +1,20 @@
+//===- EmptyNodeIntrospection.inc.in --------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+namespace clang {
+namespace tooling {
+
+NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) {
+  return {};
+}
+NodeLocationAccessors
+NodeIntrospection::GetLocations(clang::DynTypedNode const &) {
+  return {};
+}
+} // namespace tooling
+} // namespace clang
Index: clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
===================================================================
--- clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
+++ clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py
@@ -4,7 +4,8 @@
 import os
 import sys
 import json
-
+import filecmp
+import shutil
 import argparse
 
 class Generator(object):
@@ -148,13 +149,16 @@
                       help='Read API description from FILE', metavar='FILE')
     parser.add_argument('--output-file', help='Generate output in FILEPATH',
                       metavar='FILEPATH')
-    parser.add_argument('--empty-implementation',
+    parser.add_argument('--use-empty-implementation',
                       help='Generate empty implementation',
                       action="store", type=int)
+    parser.add_argument('--empty-implementation',
+                      help='Copy empty implementation from FILEPATH',
+                      action="store", metavar='FILEPATH')
 
     options = parser.parse_args()
 
-    use_empty_implementation = options.empty_implementation
+    use_empty_implementation = options.use_empty_implementation
 
     if (not use_empty_implementation
             and not os.path.exists(options.json_input_path)):
@@ -168,22 +172,9 @@
             use_empty_implementation = True
 
     if use_empty_implementation:
-        with open(os.path.join(os.getcwd(),
-                  options.output_file), 'w') as f:
-            f.write("""
-namespace clang {
-namespace tooling {
-
-NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) {
-  return {};
-}
-NodeLocationAccessors
-NodeIntrospection::GetLocations(clang::DynTypedNode const &) {
-  return {};
-}
-} // namespace tooling
-} // namespace clang
-    """)
+        if not os.path.exists(options.output_file) or \
+                not filecmp.cmp(options.empty_implementation, options.output_file):
+            shutil.copyfile(options.empty_implementation, options.output_file)
         sys.exit(0)
 
     g = Generator()
Index: clang/lib/Tooling/CMakeLists.txt
===================================================================
--- clang/lib/Tooling/CMakeLists.txt
+++ clang/lib/Tooling/CMakeLists.txt
@@ -32,21 +32,10 @@
     OR NOT LLVM_NATIVE_ARCH IN_LIST LLVM_TARGETS_TO_BUILD
     OR NOT X86 IN_LIST LLVM_TARGETS_TO_BUILD
     )
-  file(GENERATE OUTPUT ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
-    CONTENT "
-namespace clang {
-namespace tooling {
-
-NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) {
-  return {};
-}
-NodeLocationAccessors
-NodeIntrospection::GetLocations(clang::DynTypedNode const &) {
-  return {};
-}
-} // namespace tooling
-} // namespace clang
-"
+    configure_file(
+      EmptyNodeIntrospection.inc.in
+      ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
+      COPYONLY
     )
     set(CLANG_TOOLING_BUILD_AST_INTROSPECTION "OFF" CACHE BOOL "")
 else()
@@ -98,11 +87,14 @@
       OUTPUT ${BINARY_INCLUDE_DIR}/NodeIntrospection.inc
       DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
         ${CMAKE_CURRENT_SOURCE_DIR}/DumpTool/generate_cxx_src_locs.py
+        ${CMAKE_CURRENT_SOURCE_DIR}/EmptyNodeIntrospection.inc.in
       COMMAND
       ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/DumpTool/generate_cxx_src_locs.py
         --json-input-path ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
         --output-file NodeIntrospection.inc
-        --empty-implementation ${skip_expensive_processing}
+        --use-empty-implementation ${skip_expensive_processing}
+        --empty-implementation
+          "${CMAKE_CURRENT_SOURCE_DIR}/EmptyNodeIntrospection.inc.in"
       COMMAND
       ${CMAKE_COMMAND} -E copy_if_different
         ${CMAKE_CURRENT_BINARY_DIR}/NodeIntrospection.inc
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to