Skip to content

Commit e27fdb1

Browse files
authored
Merge pull request #8281 from bulbazord/20230725/rdar106648169
[lldb] Add some convenience functionality for updating static bindings
2 parents 1a3436f + 57570c1 commit e27fdb1

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

lldb/bindings/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,13 @@ endif()
5757
if (LLDB_ENABLE_LUA)
5858
add_subdirectory(lua)
5959
endif()
60+
61+
if(NOT ${LLDB_USE_STATIC_BINDINGS})
62+
set(copy_static_bindings_script "${LLDB_SOURCE_DIR}/scripts/copy-static-bindings.py")
63+
add_custom_target(update-static-bindings
64+
COMMAND ${copy_static_bindings_script} ${CMAKE_BINARY_DIR}
65+
COMMENT "Copying the generated bindings to the static bindings directory in source."
66+
VERBATIM
67+
)
68+
add_dependencies(update-static-bindings swig_wrapper_python)
69+
endif()

lldb/scripts/copy-static-bindings.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,26 @@
2222
import sys
2323
import shutil
2424

25+
def find_generated_bindings(build_dir, language):
26+
# First, see if we're in a standalone build of LLDB.
27+
bindings_build_dir = os.path.join(build_dir, 'bindings', language)
28+
if os.path.exists(bindings_build_dir):
29+
return bindings_build_dir
2530

26-
def copy_bindings(build_dir, source_dir, language, extensions=['.cpp']):
27-
binding_build_dir = os.path.join(build_dir, 'bindings', language)
31+
# Failing that, check if it's a unified build (i.e. build with LLVM+Clang)
32+
bindings_build_dir = os.path.join(build_dir, 'tools', 'lldb', 'bindings',
33+
language)
34+
if os.path.exists(bindings_build_dir):
35+
return bindings_build_dir
36+
37+
return None
38+
39+
40+
def copy_bindings(generated_bindings_dir, source_dir, language, extensions=['.cpp']):
2841
binding_source_dir = os.path.join(source_dir, 'bindings', language,
2942
'static-binding')
3043

31-
for root, _, files in os.walk(binding_build_dir):
44+
for root, _, files in os.walk(generated_bindings_dir):
3245
for file in files:
3346
_, extension = os.path.splitext(file)
3447
filepath = os.path.join(root, file)
@@ -56,8 +69,17 @@ def main():
5669
source_dir))
5770
sys.exit(1)
5871

59-
copy_bindings(build_dir, source_dir, 'python', ['.py', '.cpp'])
60-
copy_bindings(build_dir, source_dir, 'lua', ['.cpp'])
72+
generated_bindings_python_dir = find_generated_bindings(build_dir, 'python')
73+
if generated_bindings_python_dir is None:
74+
print("error: unable to locate the python bindings in the build directory")
75+
else:
76+
copy_bindings(generated_bindings_python_dir, source_dir, 'python', ['.py', '.cpp'])
77+
78+
generated_bindings_lua_dir = find_generated_bindings(build_dir, 'lua')
79+
if generated_bindings_lua_dir is None:
80+
print("error: unable to locate the lua bindings in the build directory")
81+
else:
82+
copy_bindings(generated_bindings_lua_dir, source_dir, 'lua', ['.cpp'])
6183

6284

6385
if __name__ == "__main__":

0 commit comments

Comments
 (0)