From d09e811cb4da3fab554f8a189a79f9ac74cb8d0d Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Tue, 12 Nov 2019 11:47:54 +0000 Subject: [PATCH] [gen_ast_dump_json_test.py] Copy to binary directory to omit --clang argument The script will now check if a clang binary exists in the same directory and default to that instead of requiring a --clang argument. The script is copied to the clang build directory using CMake configure_file() with COPYONLY. This ensures that the version in the build directory is updated any time the source version changes. See https://reviews.llvm.org/D70119 --- clang/test/AST/gen_ast_dump_json_test.py | 12 ++++++++++-- clang/test/CMakeLists.txt | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clang/test/AST/gen_ast_dump_json_test.py b/clang/test/AST/gen_ast_dump_json_test.py index f32b69afb039..699aaf04a5ba 100644 --- a/clang/test/AST/gen_ast_dump_json_test.py +++ b/clang/test/AST/gen_ast_dump_json_test.py @@ -55,11 +55,19 @@ def filter_json(dict_var, filters, out): for e in v: if isinstance(e, OrderedDict): filter_json(e, filters, out) - + + +def default_clang_path(): + guessed_clang = os.path.join(os.path.dirname(__file__), "clang") + if os.path.isfile(guessed_clang): + return guessed_clang + return None + + def main(): parser = argparse.ArgumentParser() parser.add_argument("--clang", help="The clang binary (could be a relative or absolute path)", - action="store", required=True) + action="store", default=default_clang_path()) parser.add_argument("--source", help="the source file. Command used to generate the json will be of the format -cc1 -ast-dump=json ", action="store", required=True) parser.add_argument("--filters", help="comma separated list of AST filters. Ex: --filters=TypedefDecl,BuiltinType", diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt index 5bdbcd9415ab..1e545ef0ea98 100644 --- a/clang/test/CMakeLists.txt +++ b/clang/test/CMakeLists.txt @@ -136,6 +136,10 @@ if (CLANG_ENABLE_STATIC_ANALYZER) endif() endif() +# Copy gen_ast_dump_json_test.py to the clang build dir. This allows invoking +# it without having to pass the --clang= argument +configure_file(AST/gen_ast_dump_json_test.py ${LLVM_TOOLS_BINARY_DIR}/gen_ast_dump_json_test.py COPYONLY) + add_custom_target(clang-test-depends DEPENDS ${CLANG_TEST_DEPS}) set_target_properties(clang-test-depends PROPERTIES FOLDER "Clang tests")