diff --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt --- a/clang/lib/Tooling/CMakeLists.txt +++ b/clang/lib/Tooling/CMakeLists.txt @@ -30,46 +30,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 { - -bool NodeIntrospection::hasIntrospectionSupport() { return false; } - -NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations(clang::Decl const *) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations( - clang::CXXCtorInitializer const *) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations( - clang::NestedNameSpecifierLoc const&) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations( - clang::TemplateArgumentLoc const&) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations( - clang::CXXBaseSpecifier const*) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations( - clang::TypeLoc 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() @@ -115,11 +79,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 diff --git a/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py b/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py --- a/clang/lib/Tooling/DumpTool/generate_cxx_src_locs.py +++ b/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): @@ -326,13 +327,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)): @@ -346,47 +350,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 { - -bool NodeIntrospection::hasIntrospectionSupport() { return false; } - -NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations(clang::Decl const *) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations( - clang::CXXCtorInitializer const *) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations( - clang::NestedNameSpecifierLoc const&) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations( - clang::TemplateArgumentLoc const&) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations( - clang::CXXBaseSpecifier const*) { - return {}; -} -NodeLocationAccessors NodeIntrospection::GetLocations( - clang::TypeLoc 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) templateClasses = [] diff --git a/clang/lib/Tooling/EmptyNodeIntrospection.inc.in b/clang/lib/Tooling/EmptyNodeIntrospection.inc.in new file mode 100644 --- /dev/null +++ b/clang/lib/Tooling/EmptyNodeIntrospection.inc.in @@ -0,0 +1,44 @@ +//===- 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 { +bool NodeIntrospection::hasIntrospectionSupport() { return false; } + +NodeLocationAccessors NodeIntrospection::GetLocations(clang::Stmt const *) { + return {}; +} +NodeLocationAccessors NodeIntrospection::GetLocations(clang::Decl const *) { + return {}; +} +NodeLocationAccessors NodeIntrospection::GetLocations( + clang::CXXCtorInitializer const *) { + return {}; +} +NodeLocationAccessors NodeIntrospection::GetLocations( + clang::NestedNameSpecifierLoc const&) { + return {}; +} +NodeLocationAccessors NodeIntrospection::GetLocations( + clang::TemplateArgumentLoc const&) { + return {}; +} +NodeLocationAccessors NodeIntrospection::GetLocations( + clang::CXXBaseSpecifier const*) { + return {}; +} +NodeLocationAccessors NodeIntrospection::GetLocations( + clang::TypeLoc const&) { + return {}; +} +NodeLocationAccessors +NodeIntrospection::GetLocations(clang::DynTypedNode const &) { + return {}; +} +} // namespace tooling +} // namespace clang