Skip to content

[lldb] Add some convenience functionality for updating static bindings #8281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lldb/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,13 @@ endif()
if (LLDB_ENABLE_LUA)
add_subdirectory(lua)
endif()

if(NOT ${LLDB_USE_STATIC_BINDINGS})
set(copy_static_bindings_script "${LLDB_SOURCE_DIR}/scripts/copy-static-bindings.py")
add_custom_target(update-static-bindings
COMMAND ${copy_static_bindings_script} ${CMAKE_BINARY_DIR}
COMMENT "Copying the generated bindings to the static bindings directory in source."
VERBATIM
)
add_dependencies(update-static-bindings swig_wrapper_python)
endif()
32 changes: 27 additions & 5 deletions lldb/scripts/copy-static-bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,26 @@
import sys
import shutil

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

def copy_bindings(build_dir, source_dir, language, extensions=['.cpp']):
binding_build_dir = os.path.join(build_dir, 'bindings', language)
# Failing that, check if it's a unified build (i.e. build with LLVM+Clang)
bindings_build_dir = os.path.join(build_dir, 'tools', 'lldb', 'bindings',
language)
if os.path.exists(bindings_build_dir):
return bindings_build_dir

return None


def copy_bindings(generated_bindings_dir, source_dir, language, extensions=['.cpp']):
binding_source_dir = os.path.join(source_dir, 'bindings', language,
'static-binding')

for root, _, files in os.walk(binding_build_dir):
for root, _, files in os.walk(generated_bindings_dir):
for file in files:
_, extension = os.path.splitext(file)
filepath = os.path.join(root, file)
Expand Down Expand Up @@ -56,8 +69,17 @@ def main():
source_dir))
sys.exit(1)

copy_bindings(build_dir, source_dir, 'python', ['.py', '.cpp'])
copy_bindings(build_dir, source_dir, 'lua', ['.cpp'])
generated_bindings_python_dir = find_generated_bindings(build_dir, 'python')
if generated_bindings_python_dir is None:
print("error: unable to locate the python bindings in the build directory")
else:
copy_bindings(generated_bindings_python_dir, source_dir, 'python', ['.py', '.cpp'])

generated_bindings_lua_dir = find_generated_bindings(build_dir, 'lua')
if generated_bindings_lua_dir is None:
print("error: unable to locate the lua bindings in the build directory")
else:
copy_bindings(generated_bindings_lua_dir, source_dir, 'lua', ['.cpp'])


if __name__ == "__main__":
Expand Down