Skip to content

Commit d09e811

Browse files
committed
[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
1 parent 90dbb47 commit d09e811

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

clang/test/AST/gen_ast_dump_json_test.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,19 @@ def filter_json(dict_var, filters, out):
5555
for e in v:
5656
if isinstance(e, OrderedDict):
5757
filter_json(e, filters, out)
58-
58+
59+
60+
def default_clang_path():
61+
guessed_clang = os.path.join(os.path.dirname(__file__), "clang")
62+
if os.path.isfile(guessed_clang):
63+
return guessed_clang
64+
return None
65+
66+
5967
def main():
6068
parser = argparse.ArgumentParser()
6169
parser.add_argument("--clang", help="The clang binary (could be a relative or absolute path)",
62-
action="store", required=True)
70+
action="store", default=default_clang_path())
6371
parser.add_argument("--source", help="the source file. Command used to generate the json will be of the format <clang> -cc1 -ast-dump=json <opts> <source>",
6472
action="store", required=True)
6573
parser.add_argument("--filters", help="comma separated list of AST filters. Ex: --filters=TypedefDecl,BuiltinType",

clang/test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ if (CLANG_ENABLE_STATIC_ANALYZER)
136136
endif()
137137
endif()
138138

139+
# Copy gen_ast_dump_json_test.py to the clang build dir. This allows invoking
140+
# it without having to pass the --clang= argument
141+
configure_file(AST/gen_ast_dump_json_test.py ${LLVM_TOOLS_BINARY_DIR}/gen_ast_dump_json_test.py COPYONLY)
142+
139143
add_custom_target(clang-test-depends DEPENDS ${CLANG_TEST_DEPS})
140144
set_target_properties(clang-test-depends PROPERTIES FOLDER "Clang tests")
141145

0 commit comments

Comments
 (0)