Skip to content

[lldb][framework] Glob headers from source for framework #148736

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 16 additions & 10 deletions lldb/cmake/modules/LLDBFramework.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,21 @@ 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})
# Glob all necessary header files from source and place them into a list.
# These headers will then be collected for the framework and placed in the
# FrameworkHeaders staging directory.
file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h)
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})
set(lldb_framework_header_staging_list ${public_headers} ${generated_public_headers} ${root_public_headers})

set(lldb_framework_header_staging_dir ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders)
foreach(header ${lldb_framework_header_staging_list})

get_filename_component(basename ${header} NAME)
set(staged_header ${lldb_framework_header_staging}/${basename})
set(staged_header ${lldb_framework_header_staging_dir}/${basename})

if(unifdef_EXECUTABLE)
# unifdef returns 0 when the file is unchanged and 1 if something was changed.
Expand Down Expand Up @@ -106,17 +112,17 @@ 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.
# Then write them to the framework itself.
# Also, run unifdef to remove any specified guards from the header files.
file(GLOB lldb_framework_header_staging_list ${lldb_framework_header_staging}/*)
file(GLOB lldb_framework_staged_headers ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders/*.h)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still globbing the build directory, so this patch still has the issue from the description. I imagine you want to do something like this instead:

  1. Glob the source directory and collect all the header paths.
  2. Iterate through all the header paths from the source directory and create a target for each of them to stage it. The target should have a file dependency on the header from the source directory and be a dependency of a top level staging target so you can do ninja lldb-stage-headers or something to verify this works. You probably want to make this target a dependency of liblldb. While doing this, you're going to iterate over the list of headers, so now's a good time to extract the basename and created a list with names of headers.
  3. Iterate through the list of header filenames and create a target for each of them to fix them up for the framework. Make every target depend on its staging counterpart and create a top level target so you can do ninja lldb-fixup-headers or something. You probably want to make this a dependency of liblldb as well.

As I'm writing this, why do you need to do to the staging at all? I thought the staging was to put the headers in <build dir>/include/lldb but this code lives in LLDBFramework so it's for the framework only, and the headers are staged in FrameworkHeaders. Do we need this at all? The framework-header-fix script is already doin the unifdefing so I'm not sure what this is doing in the first place. If that's the case, then the code that globs the source dir and puts the headers in the build dir should take the role of (1).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this at all? The framework-header-fix script is already doin the unifdefing so I'm not sure what this is doing in the first place.

If by this you mean FrameworkHeaders then I would say that I like having a staging directory to work from for the framework headers specifically, though I do agree that since the framework fix script already unifdefs the headers then the unifdefing that we have before we run the script should not be necessary anymore. I think from there then that loop that we have for unifdefing can be used for step (2) as you described while the loop for fixing up can be used for step (3). Any thoughts?

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
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"
)
endforeach()
Expand Down
Loading