diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt --- a/lldb/CMakeLists.txt +++ b/lldb/CMakeLists.txt @@ -79,14 +79,14 @@ add_subdirectory(tools) add_subdirectory(docs) -if (LLDB_ENABLE_PYTHON OR LLDB_ENABLE_LUA) +if (LLDB_ENABLE_PYTHON) if(LLDB_BUILD_FRAMEWORK) set(lldb_python_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb") else() set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb") endif() - get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR) - finish_swig("finish_swig" "${lldb_bindings_dir}" "${lldb_python_target_dir}") + get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR) + finish_swig_python("finish_swig_python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}") endif() option(LLDB_INCLUDE_TESTS "Generate build targets for the LLDB unit tests." ${LLVM_INCLUDE_TESTS}) diff --git a/lldb/bindings/CMakeLists.txt b/lldb/bindings/CMakeLists.txt --- a/lldb/bindings/CMakeLists.txt +++ b/lldb/bindings/CMakeLists.txt @@ -29,217 +29,12 @@ -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS ${DARWIN_EXTRAS} - -outdir ${CMAKE_CURRENT_BINARY_DIR} ) if (LLDB_ENABLE_PYTHON) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lldb.py - DEPENDS ${SWIG_SOURCES} - DEPENDS ${SWIG_INTERFACES} - DEPENDS ${SWIG_HEADERS} - COMMAND ${SWIG_EXECUTABLE} - ${SWIG_COMMON_FLAGS} - -c++ - -shadow - -python - -threads - -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp - ${LLDB_SOURCE_DIR}/bindings/python.swig - VERBATIM - COMMENT "Building LLDB Python wrapper") - - add_custom_target(swig_wrapper ALL DEPENDS - ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp - ${CMAKE_CURRENT_BINARY_DIR}/lldb.py - ) + add_subdirectory(python) endif() if (LLDB_ENABLE_LUA) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp - DEPENDS ${SWIG_SOURCES} - DEPENDS ${SWIG_INTERFACES} - DEPENDS ${SWIG_HEADERS} - COMMAND ${SWIG_EXECUTABLE} - ${SWIG_COMMON_FLAGS} - -lua - -w503 - -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp - ${LLDB_SOURCE_DIR}/bindings/lua.swig - VERBATIM - COMMENT "Building LLDB Lua wrapper") - - add_custom_target(swig_wrapper_lua ALL DEPENDS - ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp - ) + add_subdirectory(lua) endif() - -function(create_python_package swig_target working_dir pkg_dir) - cmake_parse_arguments(ARG "NOINIT" "" "FILES" ${ARGN}) - if(ARG_FILES) - set(copy_cmd COMMAND ${CMAKE_COMMAND} -E copy ${ARG_FILES} ${pkg_dir}) - endif() - if(NOT ARG_NOINIT) - set(init_cmd COMMAND ${PYTHON_EXECUTABLE} - "${LLDB_SOURCE_DIR}/bindings/python/createPythonInit.py" - "${pkg_dir}" ${ARG_FILES}) - endif() - add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM - COMMAND ${CMAKE_COMMAND} -E make_directory ${pkg_dir} - ${copy_cmd} - ${init_cmd} - WORKING_DIRECTORY ${working_dir}) -endfunction() - -function(create_relative_symlink swig_target dest_file output_dir output_name) - get_filename_component(dest_file ${dest_file} ABSOLUTE) - get_filename_component(output_dir ${output_dir} ABSOLUTE) - file(RELATIVE_PATH rel_dest_file ${output_dir} ${dest_file}) - if(CMAKE_HOST_UNIX) - set(LLVM_LINK_OR_COPY create_symlink) - else() - set(LLVM_LINK_OR_COPY copy) - endif() - add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM - COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} ${output_name} - WORKING_DIRECTORY ${output_dir}) -endfunction() - -function(finish_swig swig_target lldb_bindings_dir lldb_python_target_dir) - # Add a Post-Build Event to copy over Python files and create the symlink to - # liblldb.so for the Python API(hardlink on Windows). - add_custom_target(${swig_target} ALL VERBATIM - COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_target_dir} - DEPENDS ${lldb_bindings_dir}/lldb.py - COMMENT "Python script sym-linking LLDB Python API") - - if(NOT LLDB_USE_SYSTEM_SIX) - add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM - COMMAND ${CMAKE_COMMAND} -E copy - "${LLDB_SOURCE_DIR}/third_party/Python/module/six/six.py" - "${lldb_python_target_dir}/../six.py") - endif() - - add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM - COMMAND ${CMAKE_COMMAND} -E copy - "${lldb_bindings_dir}/lldb.py" - "${lldb_python_target_dir}/__init__.py") - - add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM - COMMAND ${CMAKE_COMMAND} -E copy - "${LLDB_SOURCE_DIR}/source/Interpreter/embedded_interpreter.py" - "${lldb_python_target_dir}") - - # Distribute the examples as python packages. - create_python_package( - ${swig_target} - ${lldb_python_target_dir} - "formatters/cpp" - FILES "${LLDB_SOURCE_DIR}/examples/synthetic/gnu_libstdcpp.py" - "${LLDB_SOURCE_DIR}/examples/synthetic/libcxx.py") - - create_python_package( - ${swig_target} - ${lldb_python_target_dir} - "formatters" - FILES "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/cache.py" - "${LLDB_SOURCE_DIR}/examples/summaries/synth.py" - "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/metrics.py" - "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/attrib_fromdict.py" - "${LLDB_SOURCE_DIR}/examples/summaries/cocoa/Logger.py") - - create_python_package( - ${swig_target} - ${lldb_python_target_dir} - "utils" - FILES "${LLDB_SOURCE_DIR}/examples/python/in_call_stack.py" - "${LLDB_SOURCE_DIR}/examples/python/symbolication.py") - - if(APPLE) - create_python_package( - ${swig_target} - ${lldb_python_target_dir} "macosx" - FILES "${LLDB_SOURCE_DIR}/examples/python/crashlog.py" - "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap.py") - - create_python_package( - ${swig_target} - ${lldb_python_target_dir} "macosx/heap" - FILES "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/heap_find.cpp" - "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/Makefile" - NOINIT) - - create_python_package( - ${swig_target} - ${lldb_python_target_dir} "diagnose" - FILES "${LLDB_SOURCE_DIR}/examples/python/diagnose_unwind.py" - "${LLDB_SOURCE_DIR}/examples/python/diagnose_nsstring.py") - endif() - - if(LLDB_BUILD_FRAMEWORK) - set(LIBLLDB_SYMLINK_DEST "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/LLDB") - else() - set(LIBLLDB_SYMLINK_DEST "${LLVM_SHLIB_OUTPUT_INTDIR}/liblldb${CMAKE_SHARED_LIBRARY_SUFFIX}") - endif() - if(WIN32) - if(CMAKE_BUILD_TYPE STREQUAL Debug) - set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb_d.pyd") - else() - set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.pyd") - endif() - else() - set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.so") - endif() - create_relative_symlink(${swig_target} ${LIBLLDB_SYMLINK_DEST} - ${lldb_python_target_dir} ${LIBLLDB_SYMLINK_OUTPUT_FILE}) - - if(NOT LLDB_BUILD_FRAMEWORK) - set(LLDB_ARGDUMPER_FILENAME "lldb-argdumper${CMAKE_EXECUTABLE_SUFFIX}") - create_relative_symlink(${swig_target} "${LLVM_RUNTIME_OUTPUT_INTDIR}/${LLDB_ARGDUMPER_FILENAME}" - ${lldb_python_target_dir} ${LLDB_ARGDUMPER_FILENAME}) - endif() - - add_dependencies(${swig_target} swig_wrapper liblldb lldb-argdumper) - set_target_properties(${swig_target} swig_wrapper PROPERTIES FOLDER "lldb misc") - - # Ensure we do the python post-build step when building lldb. - add_dependencies(lldb ${swig_target}) - - # Install the LLDB python module - if(LLDB_BUILD_FRAMEWORK) - set(LLDB_PYTHON_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Resources/Python) - else() - set(LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_RELATIVE_PATH}) - endif() - if (NOT CMAKE_CFG_INTDIR STREQUAL ".") - string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH}) - string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" lldb_python_target_dir ${lldb_python_target_dir}) - endif() - set(swig_scripts_target "${swig_target}_scripts") - set(swig_scripts_install_target "${swig_target}_scripts_install") - add_custom_target(${swig_scripts_target}) - add_dependencies(${swig_scripts_target} ${swig_target}) - install(DIRECTORY ${lldb_python_target_dir}/../ - DESTINATION ${LLDB_PYTHON_INSTALL_PATH} - COMPONENT ${swig_scripts_target}) - if (NOT LLVM_ENABLE_IDE) - add_llvm_install_targets(${swig_scripts_install_target} - COMPONENT ${swig_scripts_target} - DEPENDS ${swig_scripts_target}) - endif() - - # Add a Post-Build Event to copy the custom Python DLL to the lldb binaries dir so that Windows can find it when launching - # lldb.exe or any other executables that were linked with liblldb. - if (WIN32 AND NOT "${PYTHON_DLL}" STREQUAL "") - # When using the Visual Studio CMake generator the lldb binaries end up in Release/bin, Debug/bin etc. - file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin" LLDB_BIN_DIR) - file(TO_NATIVE_PATH "${PYTHON_DLL}" PYTHON_DLL_NATIVE_PATH) - add_custom_command( - TARGET ${swig_target} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_DLL_NATIVE_PATH} ${LLDB_BIN_DIR} VERBATIM - COMMENT "Copying Python DLL to LLDB binaries directory.") - endif() -endfunction() diff --git a/lldb/bindings/lua/CMakeLists.txt b/lldb/bindings/lua/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/lldb/bindings/lua/CMakeLists.txt @@ -0,0 +1,18 @@ +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp + DEPENDS ${SWIG_SOURCES} + DEPENDS ${SWIG_INTERFACES} + DEPENDS ${SWIG_HEADERS} + COMMAND ${SWIG_EXECUTABLE} + ${SWIG_COMMON_FLAGS} + -lua + -w503 + -outdir ${CMAKE_CURRENT_BINARY_DIR} + -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/lua.swig + VERBATIM + COMMENT "Building LLDB Lua wrapper") + +add_custom_target(swig_wrapper_lua ALL DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp +) diff --git a/lldb/bindings/lua.swig b/lldb/bindings/lua/lua.swig rename from lldb/bindings/lua.swig rename to lldb/bindings/lua/lua.swig diff --git a/lldb/bindings/CMakeLists.txt b/lldb/bindings/python/CMakeLists.txt copy from lldb/bindings/CMakeLists.txt copy to lldb/bindings/python/CMakeLists.txt --- a/lldb/bindings/CMakeLists.txt +++ b/lldb/bindings/python/CMakeLists.txt @@ -1,80 +1,25 @@ -file(GLOB SWIG_INTERFACES interface/*.i) -file(GLOB_RECURSE SWIG_SOURCES *.swig) -file(GLOB SWIG_HEADERS - ${LLDB_SOURCE_DIR}/include/lldb/API/*.h - ${LLDB_SOURCE_DIR}/include/lldb/*.h +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lldb.py + DEPENDS ${SWIG_SOURCES} + DEPENDS ${SWIG_INTERFACES} + DEPENDS ${SWIG_HEADERS} + COMMAND ${SWIG_EXECUTABLE} + ${SWIG_COMMON_FLAGS} + -c++ + -shadow + -python + -threads + -outdir ${CMAKE_CURRENT_BINARY_DIR} + -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/python.swig + VERBATIM + COMMENT "Building LLDB Python wrapper") + +add_custom_target(swig_wrapper_python ALL DEPENDS + ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp + ${CMAKE_CURRENT_BINARY_DIR}/lldb.py ) -file(GLOB SWIG_PRIVATE_HEADERS - ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h -) -foreach(private_header ${SWIG_PRIVATE_HEADERS}) - list(REMOVE_ITEM SWIG_HEADERS ${private_header}) -endforeach() - -if(LLDB_BUILD_FRAMEWORK) - set(framework_arg --framework --target-platform Darwin) -endif() - -if(APPLE) - set(DARWIN_EXTRAS "-D__APPLE__") -else() - set(DARWIN_EXTRAS "") -endif() - -set(SWIG_COMMON_FLAGS - -c++ - -features autodoc - -I${LLDB_SOURCE_DIR}/include - -I${CMAKE_CURRENT_SOURCE_DIR} - -D__STDC_LIMIT_MACROS - -D__STDC_CONSTANT_MACROS - ${DARWIN_EXTRAS} - -outdir ${CMAKE_CURRENT_BINARY_DIR} -) - -if (LLDB_ENABLE_PYTHON) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lldb.py - DEPENDS ${SWIG_SOURCES} - DEPENDS ${SWIG_INTERFACES} - DEPENDS ${SWIG_HEADERS} - COMMAND ${SWIG_EXECUTABLE} - ${SWIG_COMMON_FLAGS} - -c++ - -shadow - -python - -threads - -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp - ${LLDB_SOURCE_DIR}/bindings/python.swig - VERBATIM - COMMENT "Building LLDB Python wrapper") - - add_custom_target(swig_wrapper ALL DEPENDS - ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp - ${CMAKE_CURRENT_BINARY_DIR}/lldb.py - ) -endif() - -if (LLDB_ENABLE_LUA) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp - DEPENDS ${SWIG_SOURCES} - DEPENDS ${SWIG_INTERFACES} - DEPENDS ${SWIG_HEADERS} - COMMAND ${SWIG_EXECUTABLE} - ${SWIG_COMMON_FLAGS} - -lua - -w503 - -o ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp - ${LLDB_SOURCE_DIR}/bindings/lua.swig - VERBATIM - COMMENT "Building LLDB Lua wrapper") - - add_custom_target(swig_wrapper_lua ALL DEPENDS - ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapLua.cpp - ) -endif() function(create_python_package swig_target working_dir pkg_dir) cmake_parse_arguments(ARG "NOINIT" "" "FILES" ${ARGN}) @@ -107,12 +52,12 @@ WORKING_DIRECTORY ${output_dir}) endfunction() -function(finish_swig swig_target lldb_bindings_dir lldb_python_target_dir) +function(finish_swig_python swig_target lldb_python_bindings_dir lldb_python_target_dir) # Add a Post-Build Event to copy over Python files and create the symlink to # liblldb.so for the Python API(hardlink on Windows). add_custom_target(${swig_target} ALL VERBATIM COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_target_dir} - DEPENDS ${lldb_bindings_dir}/lldb.py + DEPENDS ${lldb_python_bindings_dir}/lldb.py COMMENT "Python script sym-linking LLDB Python API") if(NOT LLDB_USE_SYSTEM_SIX) @@ -124,7 +69,7 @@ add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM COMMAND ${CMAKE_COMMAND} -E copy - "${lldb_bindings_dir}/lldb.py" + "${lldb_python_bindings_dir}/lldb.py" "${lldb_python_target_dir}/__init__.py") add_custom_command(TARGET ${swig_target} POST_BUILD VERBATIM @@ -201,8 +146,8 @@ ${lldb_python_target_dir} ${LLDB_ARGDUMPER_FILENAME}) endif() - add_dependencies(${swig_target} swig_wrapper liblldb lldb-argdumper) - set_target_properties(${swig_target} swig_wrapper PROPERTIES FOLDER "lldb misc") + add_dependencies(${swig_target} swig_wrapper_python liblldb lldb-argdumper) + set_target_properties(${swig_target} swig_wrapper_python PROPERTIES FOLDER "lldb misc") # Ensure we do the python post-build step when building lldb. add_dependencies(lldb ${swig_target}) diff --git a/lldb/bindings/python.swig b/lldb/bindings/python/python.swig rename from lldb/bindings/python.swig rename to lldb/bindings/python/python.swig diff --git a/lldb/docs/CMakeLists.txt b/lldb/docs/CMakeLists.txt --- a/lldb/docs/CMakeLists.txt +++ b/lldb/docs/CMakeLists.txt @@ -30,11 +30,11 @@ # Because we don't build liblldb, epydoc will complain that the import of # _lldb.so failed, but that doesn't prevent it from generating the docs. file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lldb) - get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR) + get_target_property(lldb_bindings_dir swig_wrapper_python BINARY_DIR) add_custom_target(lldb-python-doc-package COMMAND "${CMAKE_COMMAND}" -E copy "${lldb_bindings_dir}/lldb.py" "${CMAKE_CURRENT_BINARY_DIR}/lldb/__init__.py" COMMENT "Copying lldb.py to pretend package.") - add_dependencies(lldb-python-doc-package swig_wrapper) + add_dependencies(lldb-python-doc-package swig_wrapper_python) set(DOC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/doc") file(MAKE_DIRECTORY "${DOC_DIR}") @@ -49,7 +49,7 @@ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating LLDB Python API reference with epydoc" VERBATIM ) - add_dependencies(lldb-python-doc swig_wrapper lldb-python-doc-package) + add_dependencies(lldb-python-doc swig_wrapper_python lldb-python-doc-package) else() message(STATUS "Could NOT find epydoc") endif() diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -4,19 +4,19 @@ get_property(LLDB_ALL_PLUGINS GLOBAL PROPERTY LLDB_PLUGINS) -if(LLDB_ENABLE_PYTHON) - get_target_property(lldb_bindings_dir swig_wrapper BINARY_DIR) - set(lldb_python_wrapper ${lldb_bindings_dir}/LLDBWrapPython.cpp) +if(LLDB_BUILD_FRAMEWORK) + set(option_install_prefix INSTALL_PREFIX ${LLDB_FRAMEWORK_INSTALL_DIR}) + set(option_framework FRAMEWORK) endif() -if(LLDB_ENABLE_LUA) - get_target_property(lldb_bindings_dir swig_wrapper_lua BINARY_DIR) - set(lldb_lua_wrapper ${lldb_bindings_dir}/LLDBWrapLua.cpp) +if(LLDB_ENABLE_PYTHON) + get_target_property(python_bindings_dir swig_wrapper_python BINARY_DIR) + set(lldb_python_wrapper ${python_bindings_dir}/LLDBWrapPython.cpp) endif() -if(LLDB_BUILD_FRAMEWORK) - set(option_install_prefix INSTALL_PREFIX ${LLDB_FRAMEWORK_INSTALL_DIR}) - set(option_framework FRAMEWORK) +if(LLDB_ENABLE_LUA) + get_target_property(lua_bindings_dir swig_wrapper_lua BINARY_DIR) + set(lldb_lua_wrapper ${lua_bindings_dir}/LLDBWrapLua.cpp) endif() add_lldb_library(liblldb SHARED ${option_framework} @@ -127,8 +127,8 @@ endif() -if(lldb_python_wrapper) - add_dependencies(liblldb swig_wrapper) +if(LLDB_ENABLE_PYTHON) + add_dependencies(liblldb swig_wrapper_python) if (MSVC) set_property(SOURCE ${lldb_python_wrapper} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0") @@ -148,7 +148,7 @@ endif () endif() -if(lldb_lua_wrapper) +if(LLDB_ENABLE_LUA) add_dependencies(liblldb swig_wrapper_lua) target_include_directories(liblldb PRIVATE ${LUA_INCLUDE_DIR})