https://github.com/chelcassanova updated https://github.com/llvm/llvm-project/pull/148736
>From e473fa9d67517d18ed106c900d665b4bda2f1aff Mon Sep 17 00:00:00 2001 From: Chelsea Cassanova <chelsea_cassan...@apple.com> Date: Mon, 14 Jul 2025 16:58:23 -0500 Subject: [PATCH] [lldb][framework] Glob headers from source for framework When gathering the headers to fix up and place in LLDB.framework, we were previously globbing the header files from a location in the build directory. This commit changes this to glob from the source directory instead, as we were globbing from the build directory without ensuring that the necessary files were actually in that location before globbing.f --- lldb/cmake/modules/LLDBFramework.cmake | 43 -------------------------- lldb/scripts/version-header-fix.py | 4 +++ lldb/source/API/CMakeLists.txt | 25 +++++++++++++-- 3 files changed, 27 insertions(+), 45 deletions(-) diff --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake index bbd717a982cf3..c6f00ed05cfc2 100644 --- a/lldb/cmake/modules/LLDBFramework.cmake +++ b/lldb/cmake/modules/LLDBFramework.cmake @@ -70,33 +70,6 @@ endif() find_program(unifdef_EXECUTABLE unifdef) -# All necessary header files will be staged in the include directory in the build directory, -# so just copy the files from there into the framework's staging directory. -set(lldb_build_dir_header_staging "${CMAKE_BINARY_DIR}/include/lldb") -set(lldb_framework_header_staging "${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders") -file(GLOB lldb_build_dir_header_staging_list ${lldb_build_dir_header_staging}/*) -foreach(header ${lldb_build_dir_header_staging_list}) - - get_filename_component(basename ${header} NAME) - set(staged_header ${lldb_framework_header_staging}/${basename}) - - if(unifdef_EXECUTABLE) - # unifdef returns 0 when the file is unchanged and 1 if something was changed. - # That means if we successfully remove SWIG code, the build system believes - # that the command has failed and stops. This is undesirable. - set(copy_command ${unifdef_EXECUTABLE} -USWIG -o ${staged_header} ${header} || (exit 0)) - else() - set(copy_command ${CMAKE_COMMAND} -E copy ${header} ${staged_header}) - endif() - - add_custom_command( - DEPENDS ${header} OUTPUT ${staged_header} - COMMAND ${copy_command} - COMMENT "LLDB.framework: collect framework header and remove SWIG macros") - - list(APPEND lldb_staged_headers ${staged_header}) -endforeach() - # Wrap output in a target, so lldb-framework can depend on it. add_custom_target(liblldb-resource-headers DEPENDS lldb-sbapi-dwarf-enums ${lldb_staged_headers}) set_target_properties(liblldb-resource-headers PROPERTIES FOLDER "LLDB/Resources") @@ -105,22 +78,6 @@ set_target_properties(liblldb-resource-headers PROPERTIES FOLDER "LLDB/Resources add_dependencies(liblldb-resource-headers liblldb-header-staging) add_dependencies(liblldb liblldb-resource-headers) -# Take the headers from the staging directory and fix up their includes for the framework. -# Then write them to the output directory. -# Also, run unifdef to remove any specified guards from the header files. -file(GLOB lldb_framework_header_staging_list ${lldb_framework_header_staging}/*) -foreach(header ${lldb_framework_header_staging_list}) - - set(input_header ${header}) - get_filename_component(header_basename ${input_header} NAME) - set(output_header $<TARGET_FILE_DIR:liblldb>/Headers/${header_basename}) - - add_custom_command(TARGET liblldb POST_BUILD - COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.py -f lldb_main -i ${input_header} -o ${output_header} -p ${unifdef_EXECUTABLE} USWIG - COMMENT "LLDB.framework: Fix up and copy framework headers" - ) -endforeach() - # Copy vendor-specific headers from clang (without staging). if(NOT APPLE_EMBEDDED) if (TARGET clang-resource-headers) diff --git a/lldb/scripts/version-header-fix.py b/lldb/scripts/version-header-fix.py index 98457e6f5b3cd..0caf7c62bc91f 100755 --- a/lldb/scripts/version-header-fix.py +++ b/lldb/scripts/version-header-fix.py @@ -29,6 +29,10 @@ def main(): input_path = str(args.input_path) output_path = str(args.output_path) + # Create the output dir if it doesn't already exist + if not os.path.exists(os.path.dirname(output_path)): + os.makedirs(os.path.dirname(output_path)) + with open(input_path, "r") as input_file: lines = input_file.readlines() file_buffer = "".join(lines) diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt index 4751ed319b259..103e8d6d42deb 100644 --- a/lldb/source/API/CMakeLists.txt +++ b/lldb/source/API/CMakeLists.txt @@ -295,12 +295,21 @@ endif() # Stage all headers in the include directory in the build dir. file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h) set(lldb_header_staging_dir ${CMAKE_BINARY_DIR}/include/lldb) +set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/API/SBLanguages.h) file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h) file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h) list(REMOVE_ITEM root_public_headers ${root_private_headers}) find_program(unifdef_EXECUTABLE unifdef) +add_custom_target(liblldb-header-staging DEPENDS ${lldb_staged_headers} ${lldb_header_staging_dir}/lldb-defines.h) + +if (LLDB_BUILD_FRAMEWORK) + add_custom_target(lldb-framework-fixup-all-headers) + add_dependencies(lldb-framework-fixup-all-headers liblldb-header-staging) + add_dependencies(liblldb lldb-framework-fixup-all-headers) +endif() + foreach(header ${public_headers} ${generated_public_headers} @@ -323,12 +332,24 @@ foreach(header COMMENT "LLDB headers: stage LLDB headers in include directory") list(APPEND lldb_staged_headers ${staged_header}) + + if (LLDB_BUILD_FRAMEWORK) + set(input_header ${staged_header}) + set(output_header $<TARGET_FILE_DIR:liblldb>/Headers/${basename}) + + add_custom_target(lldb-framework-fixup-header-${basename} DEPENDS ${input_header}) + add_dependencies(lldb-framework-fixup-all-headers lldb-framework-fixup-header-${basename}) + + add_custom_command(TARGET lldb-framework-fixup-header-${basename} POST_BUILD + COMMAND "${Python3_EXECUTABLE}" ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.py -f lldb_main -i ${input_header} -o ${output_header} -p ${unifdef_EXECUTABLE} USWIG + COMMENT "LLDB.framework: Fix up and copy framework headers" + ) + endif() endforeach() -add_custom_command(TARGET liblldb POST_BUILD +add_custom_command(TARGET liblldb-header-staging POST_BUILD COMMAND "${Python3_EXECUTABLE}" ${LLDB_SOURCE_DIR}/scripts/version-header-fix.py -i ${LLDB_SOURCE_DIR}/include/lldb/lldb-defines.h -o ${lldb_header_staging_dir}/lldb-defines.h -m ${LLDB_VERSION_MAJOR} -n ${LLDB_VERSION_MINOR} -p ${LLDB_VERSION_PATCH} ) -add_custom_target(liblldb-header-staging DEPENDS ${lldb_staged_headers}) add_dependencies(liblldb liblldb-header-staging) if(LLDB_BUILD_FRAMEWORK) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits