diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt --- a/lldb/CMakeLists.txt +++ b/lldb/CMakeLists.txt @@ -103,77 +103,105 @@ # 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(finish_swig ALL VERBATIM - COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_build_path} - DEPENDS ${lldb_scripts_dir}/lldb.py - COMMENT "Python script sym-linking LLDB Python API") + add_custom_target(finish_swig ALL + COMMENT "Copy over Python files and create symlinks for LLDB Python API.") + set_target_properties(finish_swig PROPERTIES FOLDER "lldb misc") + + function(add_copy_file_target Name) + cmake_parse_arguments(ARG "" "DEST_DIR;DEST_FILE_NAME" "FILES" ${ARGN}) + add_custom_command(OUTPUT ${ARG_DEST_DIR} VERBATIM + COMMAND ${CMAKE_COMMAND} -E make_directory ${ARG_DEST_DIR}) + foreach(src_file ${ARG_FILES}) + if(ARG_DEST_FILE_NAME) + set(file_name ${ARG_DEST_FILE_NAME}) + else() + get_filename_component(file_name ${src_file} NAME) + endif() + set(dest_file ${ARG_DEST_DIR}/${file_name}) + list(APPEND DEST_FILES ${dest_file}) + add_custom_command(OUTPUT ${dest_file} VERBATIM + COMMAND ${CMAKE_COMMAND} -E copy ${src_file} ${dest_file} + DEPENDS ${ARG_DEST_DIR} ${src_file}) + endforeach() + add_custom_target(${Name} DEPENDS ${DEST_FILES} ${ARG_DEST_DIR}) + endfunction() if(NOT LLDB_USE_SYSTEM_SIX) - add_custom_command(TARGET finish_swig POST_BUILD VERBATIM - COMMAND ${CMAKE_COMMAND} -E copy - "${LLDB_SOURCE_DIR}/third_party/Python/module/six/six.py" - "${lldb_python_build_path}/../six.py") + add_copy_file_target(lldb_python_six + FILES "${LLDB_SOURCE_DIR}/third_party/Python/module/six/six.py" + DEST_DIR "${lldb_python_build_path}/..") + add_dependencies(finish_swig lldb_python_six) endif() - add_custom_command(TARGET finish_swig POST_BUILD VERBATIM - COMMAND ${CMAKE_COMMAND} -E copy - "${lldb_scripts_dir}/lldb.py" - "${lldb_python_build_path}/__init__.py") + add_copy_file_target(lldb_python_init + FILES "${lldb_scripts_dir}/lldb.py" + DEST_DIR "${lldb_python_build_path}" + DEST_FILE_NAME "__init__.py") + add_dependencies(finish_swig lldb_python_init) if(APPLE) - SET(lldb_python_heap_dir "${lldb_python_build_path}/macosx/heap") - add_custom_command(TARGET finish_swig POST_BUILD VERBATIM - COMMAND ${CMAKE_COMMAND} -E make_directory ${lldb_python_heap_dir} - COMMAND ${CMAKE_COMMAND} -E copy - "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/heap_find.cpp" - "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/Makefile" - ${lldb_python_heap_dir}) + add_copy_file_target(lldb_python_heap + FILES "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/heap_find.cpp" + "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap/Makefile" + DEST_DIR "${lldb_python_build_path}/macosx/heap") + add_dependencies(finish_swig lldb_python_heap) endif() - function(create_python_package target pkg_dir) + add_copy_file_target(lldb_python_embeded_interpreter + FILES "${LLDB_SOURCE_DIR}/source/Interpreter/embedded_interpreter.py" + DEST_DIR "${lldb_python_build_path}") + add_dependencies(finish_swig lldb_python_embeded_interpreter) + + function(add_lldb_python_package_target Name PKG_DIR) cmake_parse_arguments(ARG "" "" "FILES" ${ARGN}) - if(ARG_FILES) - set(copy_cmd COMMAND ${CMAKE_COMMAND} -E copy ${ARG_FILES} ${pkg_dir}) - endif() - add_custom_command(TARGET ${target} POST_BUILD VERBATIM - COMMAND ${CMAKE_COMMAND} -E make_directory ${pkg_dir} - ${copy_cmd} + set(ABS_PKG_DIR "${lldb_python_build_path}/${PKG_DIR}") + add_copy_file_target("${Name}_srcs" FILES ${ARG_FILES} DEST_DIR ${ABS_PKG_DIR}) + add_custom_command(OUTPUT "${ABS_PKG_DIR}/__init__.py" VERBATIM COMMAND ${PYTHON_EXECUTABLE} "${LLDB_SOURCE_DIR}/scripts/Python/createPythonInit.py" - ${pkg_dir} ${ARG_FILES} - WORKING_DIRECTORY ${lldb_python_build_path}) + ${PKG_DIR} ${ARG_FILES} + WORKING_DIRECTORY ${lldb_python_build_path} + DEPENDS "${Name}_srcs") + add_custom_target(${Name} DEPENDS "${ABS_PKG_DIR}/__init__.py" "${Name}_srcs") endfunction() - add_custom_command(TARGET finish_swig POST_BUILD VERBATIM - COMMAND ${CMAKE_COMMAND} -E copy - "${LLDB_SOURCE_DIR}/source/Interpreter/embedded_interpreter.py" ${lldb_python_build_path}) - - create_python_package(finish_swig "formatters/cpp" + add_lldb_python_package_target(lldb_python_formatters_cpp "formatters/cpp" FILES "${LLDB_SOURCE_DIR}/examples/synthetic/gnu_libstdcpp.py" "${LLDB_SOURCE_DIR}/examples/synthetic/libcxx.py") + add_dependencies(finish_swig lldb_python_formatters_cpp) + # Make an empty __init__.py in lldb/runtime as this is required for # Python to recognize lldb.runtime as a valid package (and hence, # lldb.runtime.objc as a valid contained package) - create_python_package(finish_swig "runtime") + add_lldb_python_package_target(lldb_python_runtime "runtime") + add_dependencies(finish_swig lldb_python_runtime) + # Having these files copied here ensure that lldb/formatters is a # valid package itself - create_python_package(finish_swig "formatters" + add_lldb_python_package_target(lldb_python_formatters "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(finish_swig "utils" + add_dependencies(finish_swig lldb_python_formatters) + + add_lldb_python_package_target(lldb_python_utils "utils" FILES "${LLDB_SOURCE_DIR}/examples/python/symbolication.py") + add_dependencies(finish_swig lldb_python_utils) + if(APPLE) - create_python_package(finish_swig "macosx" + add_lldb_python_package_target(lldb_python_macosx "macosx" FILES "${LLDB_SOURCE_DIR}/examples/python/crashlog.py" "${LLDB_SOURCE_DIR}/examples/darwin/heap_find/heap.py") - create_python_package(finish_swig "diagnose" + add_dependencies(finish_swig lldb_python_macosx) + + add_lldb_python_package_target(lldb_python_diagnose "diagnose" FILES "${LLDB_SOURCE_DIR}/examples/python/diagnose_unwind.py" "${LLDB_SOURCE_DIR}/examples/python/diagnose_nsstring.py") + add_dependencies(finish_swig lldb_python_diagnose) endif() - function(create_relative_symlink target dest_file output_dir output_name) + function(add_relative_symlink_target name 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}) @@ -182,9 +210,10 @@ else() set(LLVM_LINK_OR_COPY copy) endif() - add_custom_command(TARGET ${target} POST_BUILD VERBATIM + add_custom_command(OUTPUT ${output_dir}/${output_name} DEPENDS ${output_dir}/${rel_dest_file} COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} ${rel_dest_file} ${output_name} - WORKING_DIRECTORY ${output_dir}) + WORKING_DIRECTORY ${output_dir} VERBATIM) + add_custom_target(${name} DEPENDS ${output_dir}/${output_name}) endfunction() if(LLDB_BUILD_FRAMEWORK) @@ -201,18 +230,18 @@ else() set(LIBLLDB_SYMLINK_OUTPUT_FILE "_lldb.so") endif() - create_relative_symlink(finish_swig ${LIBLLDB_SYMLINK_DEST} - ${lldb_python_build_path} ${LIBLLDB_SYMLINK_OUTPUT_FILE}) + add_relative_symlink_target(lldb_python_liblldb ${LIBLLDB_SYMLINK_DEST} + ${lldb_python_build_path} ${LIBLLDB_SYMLINK_OUTPUT_FILE}) + add_dependencies(finish_swig lldb_python_liblldb) if(NOT LLDB_BUILD_FRAMEWORK) set(LLDB_ARGDUMPER_FILENAME "lldb-argdumper${CMAKE_EXECUTABLE_SUFFIX}") - create_relative_symlink(finish_swig "${LLVM_RUNTIME_OUTPUT_INTDIR}/${LLDB_ARGDUMPER_FILENAME}" - ${lldb_python_build_path} ${LLDB_ARGDUMPER_FILENAME}) + add_relative_symlink_target(lldb_python_argdumper + "${LLVM_RUNTIME_OUTPUT_INTDIR}/${LLDB_ARGDUMPER_FILENAME}" + ${lldb_python_build_path} ${LLDB_ARGDUMPER_FILENAME}) + add_dependencies(finish_swig lldb_python_argdumper) endif() - add_dependencies(finish_swig swig_wrapper liblldb lldb-argdumper) - set_target_properties(finish_swig swig_wrapper PROPERTIES FOLDER "lldb misc") - # Ensure we do the python post-build step when building lldb. add_dependencies(lldb finish_swig) diff --git a/lldb/scripts/CMakeLists.txt b/lldb/scripts/CMakeLists.txt --- a/lldb/scripts/CMakeLists.txt +++ b/lldb/scripts/CMakeLists.txt @@ -54,4 +54,5 @@ ${CMAKE_CURRENT_BINARY_DIR}/LLDBWrapPython.cpp ${CMAKE_CURRENT_BINARY_DIR}/lldb.py ) +set_target_properties(swig_wrapper PROPERTIES FOLDER "lldb misc")