Skip to content

Commit d64802d

Browse files
[lldb][framework] Glob headers from source for framework (#148736)
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.
1 parent b846d8c commit d64802d

File tree

6 files changed

+33
-50
lines changed

6 files changed

+33
-50
lines changed

lldb/cmake/modules/LLDBFramework.cmake

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -70,33 +70,6 @@ endif()
7070

7171
find_program(unifdef_EXECUTABLE unifdef)
7272

73-
# All necessary header files will be staged in the include directory in the build directory,
74-
# so just copy the files from there into the framework's staging directory.
75-
set(lldb_build_dir_header_staging "${CMAKE_BINARY_DIR}/include/lldb")
76-
set(lldb_framework_header_staging "${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders")
77-
file(GLOB lldb_build_dir_header_staging_list ${lldb_build_dir_header_staging}/*)
78-
foreach(header ${lldb_build_dir_header_staging_list})
79-
80-
get_filename_component(basename ${header} NAME)
81-
set(staged_header ${lldb_framework_header_staging}/${basename})
82-
83-
if(unifdef_EXECUTABLE)
84-
# unifdef returns 0 when the file is unchanged and 1 if something was changed.
85-
# That means if we successfully remove SWIG code, the build system believes
86-
# that the command has failed and stops. This is undesirable.
87-
set(copy_command ${unifdef_EXECUTABLE} -USWIG -o ${staged_header} ${header} || (exit 0))
88-
else()
89-
set(copy_command ${CMAKE_COMMAND} -E copy ${header} ${staged_header})
90-
endif()
91-
92-
add_custom_command(
93-
DEPENDS ${header} OUTPUT ${staged_header}
94-
COMMAND ${copy_command}
95-
COMMENT "LLDB.framework: collect framework header and remove SWIG macros")
96-
97-
list(APPEND lldb_staged_headers ${staged_header})
98-
endforeach()
99-
10073
# Wrap output in a target, so lldb-framework can depend on it.
10174
add_custom_target(liblldb-resource-headers DEPENDS lldb-sbapi-dwarf-enums ${lldb_staged_headers})
10275
set_target_properties(liblldb-resource-headers PROPERTIES FOLDER "LLDB/Resources")
@@ -105,22 +78,6 @@ set_target_properties(liblldb-resource-headers PROPERTIES FOLDER "LLDB/Resources
10578
add_dependencies(liblldb-resource-headers liblldb-header-staging)
10679
add_dependencies(liblldb liblldb-resource-headers)
10780

108-
# Take the headers from the staging directory and fix up their includes for the framework.
109-
# Then write them to the output directory.
110-
# Also, run unifdef to remove any specified guards from the header files.
111-
file(GLOB lldb_framework_header_staging_list ${lldb_framework_header_staging}/*)
112-
foreach(header ${lldb_framework_header_staging_list})
113-
114-
set(input_header ${header})
115-
get_filename_component(header_basename ${input_header} NAME)
116-
set(output_header $<TARGET_FILE_DIR:liblldb>/Headers/${header_basename})
117-
118-
add_custom_command(TARGET liblldb POST_BUILD
119-
COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.py -f lldb_main -i ${input_header} -o ${output_header} -p ${unifdef_EXECUTABLE} USWIG
120-
COMMENT "LLDB.framework: Fix up and copy framework headers"
121-
)
122-
endforeach()
123-
12481
# Copy vendor-specific headers from clang (without staging).
12582
if(NOT APPLE_EMBEDDED)
12683
if (TARGET clang-resource-headers)

lldb/scripts/framework-header-fix.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def main():
9797
parser.add_argument("-o", "--output_file")
9898
parser.add_argument("-p", "--unifdef_path")
9999
parser.add_argument(
100-
"unifdef_guards",
100+
"--unifdef_guards",
101101
nargs="+",
102102
type=str,
103103
help="Guards to be removed with unifdef. These must be specified in the same way as they would be when passed directly into unifdef.",
@@ -111,7 +111,8 @@ def main():
111111
# unifdef takes the guards to remove as arguments in their own right (e.g. -USWIG)
112112
# but passing them in with dashes for this script causes argparse to think that they're
113113
# arguments in and of themself, so they need to passed in without dashes.
114-
unifdef_guards = ["-" + guard for guard in args.unifdef_guards]
114+
if args.unifdef_guards:
115+
unifdef_guards = ["-" + guard for guard in args.unifdef_guards]
115116

116117
# Create the framework's header dir if it doesn't already exist
117118
if not os.path.exists(os.path.dirname(output_file_path)):
@@ -123,7 +124,8 @@ def main():
123124
modify_rpc_includes(input_file_path, output_file_path)
124125
# After the incldues have been modified, run unifdef on the headers to remove any guards
125126
# specified at the command line.
126-
remove_guards(output_file_path, unifdef_path, unifdef_guards)
127+
if args.unifdef_guards:
128+
remove_guards(output_file_path, unifdef_path, unifdef_guards)
127129

128130

129131
if __name__ == "__main__":

lldb/scripts/version-header-fix.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def main():
2929
input_path = str(args.input_path)
3030
output_path = str(args.output_path)
3131

32+
# Create the output dir if it doesn't already exist
33+
if not os.path.exists(os.path.dirname(output_path)):
34+
os.makedirs(os.path.dirname(output_path))
35+
3236
with open(input_path, "r") as input_file:
3337
lines = input_file.readlines()
3438
file_buffer = "".join(lines)

lldb/source/API/CMakeLists.txt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,21 @@ endif()
295295
# Stage all headers in the include directory in the build dir.
296296
file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h)
297297
set(lldb_header_staging_dir ${CMAKE_BINARY_DIR}/include/lldb)
298+
set(generated_public_headers ${LLDB_OBJ_DIR}/include/lldb/API/SBLanguages.h)
298299
file(GLOB root_public_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-*.h)
299300
file(GLOB root_private_headers ${LLDB_SOURCE_DIR}/include/lldb/lldb-private*.h)
300301
list(REMOVE_ITEM root_public_headers ${root_private_headers})
301302

302303
find_program(unifdef_EXECUTABLE unifdef)
303304

305+
add_custom_target(liblldb-header-staging DEPENDS ${lldb_staged_headers} ${lldb_header_staging_dir}/lldb-defines.h)
306+
307+
if (LLDB_BUILD_FRAMEWORK)
308+
add_custom_target(lldb-framework-fixup-all-headers)
309+
add_dependencies(lldb-framework-fixup-all-headers liblldb-header-staging)
310+
add_dependencies(liblldb lldb-framework-fixup-all-headers)
311+
endif()
312+
304313
foreach(header
305314
${public_headers}
306315
${generated_public_headers}
@@ -323,12 +332,23 @@ foreach(header
323332
COMMENT "LLDB headers: stage LLDB headers in include directory")
324333

325334
list(APPEND lldb_staged_headers ${staged_header})
335+
336+
if (LLDB_BUILD_FRAMEWORK)
337+
set(output_header $<TARGET_FILE_DIR:liblldb>/Headers/${basename})
338+
339+
add_custom_target(lldb-framework-fixup-header-${basename} DEPENDS ${staged_header})
340+
add_dependencies(lldb-framework-fixup-all-headers lldb-framework-fixup-header-${basename})
341+
342+
add_custom_command(TARGET lldb-framework-fixup-header-${basename} POST_BUILD
343+
COMMAND "${Python3_EXECUTABLE}" ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.py -f lldb_main -i ${staged_header} -o ${output_header}
344+
COMMENT "LLDB.framework: Fix up and copy framework headers"
345+
)
346+
endif()
326347
endforeach()
327348

328-
add_custom_command(TARGET liblldb POST_BUILD
349+
add_custom_command(TARGET liblldb-header-staging POST_BUILD
329350
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}
330351
)
331-
add_custom_target(liblldb-header-staging DEPENDS ${lldb_staged_headers})
332352
add_dependencies(liblldb liblldb-header-staging)
333353

334354
if(LLDB_BUILD_FRAMEWORK)

lldb/test/Shell/Scripts/TestFrameworkFixScript.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Create a temp dir for output and run the framework fix script on the truncated version of SBAddress.h in the inputs dir.
22
RUN: mkdir -p %t/Outputs
3-
RUN: %python %p/../../../scripts/framework-header-fix.py -f lldb_main -i %p/Inputs/Main/SBAddress.h -o %t/Outputs/SBAddress.h -p /usr/bin/unifdef USWIG
3+
RUN: %python %p/../../../scripts/framework-header-fix.py -f lldb_main -i %p/Inputs/Main/SBAddress.h -o %t/Outputs/SBAddress.h -p /usr/bin/unifdef --unifdef_guards USWIG
44

55
# Check the output
66
RUN: cat %t/Outputs/SBAddress.h | FileCheck %s

lldb/test/Shell/Scripts/TestRPCFrameworkFixScript.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Create a temp dir for output and run the framework fix script on the truncated version of SBAddress.h in the inputs dir.
22
RUN: mkdir -p %t/Outputs
3-
RUN: %python %p/../../../scripts/framework-header-fix.py -f lldb_rpc -i %p/Inputs/RPC/RPCSBAddress.h -o %t/Outputs/RPCSBAddress.h -p /usr/bin/unifdef USWIG
3+
RUN: %python %p/../../../scripts/framework-header-fix.py -f lldb_rpc -i %p/Inputs/RPC/RPCSBAddress.h -o %t/Outputs/RPCSBAddress.h -p /usr/bin/unifdef --unifdef_guards USWIG
44

55
# Check the output
66
RUN: cat %t/Outputs/RPCSBAddress.h | FileCheck %s

0 commit comments

Comments
 (0)