Skip to content

Revert "[lldb][headers] Create Python script to fix up framework headers" #143941

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

Merged

Conversation

chelcassanova
Copy link
Contributor

Reverts #142051

@llvmbot llvmbot added the lldb label Jun 12, 2025
@chelcassanova chelcassanova merged commit 06dad35 into main Jun 12, 2025
6 of 8 checks passed
@chelcassanova chelcassanova deleted the revert-142051-create-python-framework-fix-script branch June 12, 2025 17:39
@llvmbot
Copy link
Member

llvmbot commented Jun 12, 2025

@llvm/pr-subscribers-lldb

Author: Chelsea Cassanova (chelcassanova)

Changes

Reverts llvm/llvm-project#142051


Full diff: https://github.com/llvm/llvm-project/pull/143941.diff

7 Files Affected:

  • (modified) lldb/cmake/modules/LLDBFramework.cmake (+21-21)
  • (removed) lldb/scripts/framework-header-fix.py (-126)
  • (removed) lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h (-13)
  • (removed) lldb/test/Shell/Scripts/Inputs/RPC/RPCSBAddress.h (-9)
  • (removed) lldb/test/Shell/Scripts/TestFrameworkFixScript.test (-11)
  • (removed) lldb/test/Shell/Scripts/TestFrameworkFixUnifdef.test (-12)
  • (removed) lldb/test/Shell/Scripts/TestRPCFrameworkFixScript.test (-14)
diff --git a/lldb/cmake/modules/LLDBFramework.cmake b/lldb/cmake/modules/LLDBFramework.cmake
index 70010ffbf738c..8961b1afe93ad 100644
--- a/lldb/cmake/modules/LLDBFramework.cmake
+++ b/lldb/cmake/modules/LLDBFramework.cmake
@@ -68,17 +68,24 @@ if(NOT APPLE_EMBEDDED)
   )
 endif()
 
+# At configuration time, collect headers for the framework bundle and copy them
+# into a staging directory. Later we can copy over the entire folder.
+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})
+
 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})
+set(lldb_header_staging ${CMAKE_CURRENT_BINARY_DIR}/FrameworkHeaders)
+foreach(header
+    ${public_headers}
+    ${generated_public_headers}
+    ${root_public_headers})
 
   get_filename_component(basename ${header} NAME)
-  set(staged_header ${lldb_framework_header_staging}/${basename})
+  set(staged_header ${lldb_header_staging}/${basename})
 
   if(unifdef_EXECUTABLE)
     # unifdef returns 0 when the file is unchanged and 1 if something was changed.
@@ -105,20 +112,13 @@ 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})
-  set(output_header $<TARGET_FILE_DIR:liblldb>/Headers/${input_header})
-
-  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()
+# At build time, copy the staged headers into the framework bundle (and do
+# some post-processing in-place).
+add_custom_command(TARGET liblldb POST_BUILD
+  COMMAND ${CMAKE_COMMAND} -E copy_directory ${lldb_header_staging} $<TARGET_FILE_DIR:liblldb>/Headers
+  COMMAND ${LLDB_SOURCE_DIR}/scripts/framework-header-fix.sh $<TARGET_FILE_DIR:liblldb>/Headers ${LLDB_VERSION}
+  COMMENT "LLDB.framework: copy framework headers"
+)
 
 # Copy vendor-specific headers from clang (without staging).
 if(NOT APPLE_EMBEDDED)
diff --git a/lldb/scripts/framework-header-fix.py b/lldb/scripts/framework-header-fix.py
deleted file mode 100755
index 9e4e5f860a2c0..0000000000000
--- a/lldb/scripts/framework-header-fix.py
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/env python3
-
-"""
-Usage: <path/to/input-directory> <path/to/output-directory>
-
-This script is used when building LLDB.framework or LLDBRPC.framework. For each framework, local includes are converted to their respective framework includes.
-
-This script is used in 2 ways:
-1. It is used on header files that are copied into LLDB.framework. For these files, local LLDB includes are converted into framework includes, e.g. #include "lldb/API/SBDefines.h" -> #include <LLDB/SBDefines.h>.
-
-2. It is used on header files for LLDBRPC.framework. For these files, includes of RPC common files will be converted to framework includes, e.g. #include <lldb-rpc/common/RPCCommon.h> -> #include <LLDBRPC/RPCCommon.h>. It will also change local includes to framework includes, e.g. #include "SBAddress.h" -> #include <LLDBRPC/SBAddress.h>
-"""
-
-import argparse
-import os
-import re
-import shutil
-import subprocess
-import sys
-
-# Main header regexes
-INCLUDE_FILENAME_REGEX = re.compile(
-    r'#include "lldb/API/(?P<include_filename>.*){0,1}"'
-)
-
-# RPC header regexes
-RPC_COMMON_REGEX = re.compile(r"#include <lldb-rpc/common/(?P<include_filename>.*)>")
-RPC_INCLUDE_FILENAME_REGEX = re.compile(r'#include "(?P<include_filename>.*)"')
-
-
-def modify_rpc_includes(input_file_path, output_file_path):
-    with open(input_file_path, "r") as input_file:
-        lines = input_file.readlines()
-        file_buffer = "".join(lines)
-        with open(output_file_path, "w") as output_file:
-            # Local includes must be changed to RPC framework level includes.
-            # e.g. #include "SBDefines.h" -> #include <LLDBRPC/SBDefines.h>
-            # Also, RPC common code includes must change to RPC framework level includes.
-            # e.g. #include "lldb-rpc/common/RPCPublic.h" -> #include <LLDBRPC/RPCPublic.h>
-            rpc_common_matches = RPC_COMMON_REGEX.finditer(file_buffer)
-            rpc_include_filename_matches = RPC_INCLUDE_FILENAME_REGEX.finditer(
-                file_buffer
-            )
-            for match in rpc_common_matches:
-                file_buffer = re.sub(
-                    match.group(),
-                    r"#include <LLDBRPC/" + match.group("include_filename") + ">",
-                    file_buffer,
-                )
-            for match in rpc_include_filename_matches:
-                file_buffer = re.sub(
-                    match.group(),
-                    r"#include <LLDBRPC/" + match.group("include_filename") + ">",
-                    file_buffer,
-                )
-            output_file.write(file_buffer)
-
-
-def modify_main_includes(input_file_path, output_file_path):
-    with open(input_file_path, "r") as input_file:
-        lines = input_file.readlines()
-        file_buffer = "".join(lines)
-        with open(output_file_path, "w") as output_file:
-            # Local includes must be changed to framework level includes.
-            # e.g. #include "lldb/API/SBDefines.h" -> #include <LLDB/SBDefines.h>
-            regex_matches = INCLUDE_FILENAME_REGEX.finditer(file_buffer)
-            for match in regex_matches:
-                file_buffer = re.sub(
-                    match.group(),
-                    r"#include <LLDB/" + match.group("include_filename") + ">",
-                    file_buffer,
-                )
-                output_file.write(file_buffer)
-
-
-def remove_guards(output_file_path, unifdef_path, unifdef_guards):
-    # The unifdef path should be passed in from CMake. If it wasn't there in CMake or is incorrect,
-    # find it using shutil. If shutil can't find it, then exit.
-    if not shutil.which(unifdef_path):
-        unifdef_path = shutil.which("unifdef")
-    if not unifdef_path:
-        print(
-            "Unable to find unifdef executable. Guards will not be removed from input files. Exiting..."
-        )
-        sys.exit(1)
-
-    subprocess_command = (
-        [unifdef_path, "-o", output_file_path] + unifdef_guards + [output_file_path]
-    )
-    subprocess.run(subprocess_command)
-
-
-def main():
-    parser = argparse.ArgumentParser()
-    parser.add_argument("-f", "--framework", choices=["lldb_main", "lldb_rpc"])
-    parser.add_argument("-i", "--input_file")
-    parser.add_argument("-o", "--output_file")
-    parser.add_argument("-p", "--unifdef_path")
-    parser.add_argument(
-        "unifdef_guards",
-        nargs="+",
-        type=str,
-        help="Guards to be removed with unifdef. These must be specified in the same way as they would be when passed directly into unifdef.",
-    )
-    args = parser.parse_args()
-    input_file_path = str(args.input_file)
-    output_file_path = str(args.output_file)
-    framework_version = args.framework
-    unifdef_path = str(args.unifdef_path)
-    # Prepend dashes to the list of guards passed in from the command line.
-    # unifdef takes the guards to remove as arguments in their own right (e.g. -USWIG)
-    # but passing them in with dashes for this script causes argparse to think that they're
-    # arguments in and of themself, so they need to passed in without dashes.
-    unifdef_guards = ["-" + guard for guard in args.unifdef_guards]
-
-    if framework_version == "lldb_main":
-        modify_main_includes(input_file_path, output_file_path)
-    if framework_version == "lldb_rpc":
-        modify_rpc_includes(input_file_path, output_file_path)
-    # After the incldues have been modified, run unifdef on the headers to remove any guards
-    # specified at the command line.
-    remove_guards(output_file_path, unifdef_path, unifdef_guards)
-
-
-if __name__ == "__main__":
-    main()
diff --git a/lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h b/lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h
deleted file mode 100644
index fecc69687cd74..0000000000000
--- a/lldb/test/Shell/Scripts/Inputs/Main/SBAddress.h
+++ /dev/null
@@ -1,13 +0,0 @@
-// This is a truncated version of an SB API file
-// used to test framework-header-fix.py to make sure the includes are correctly fixed
-// up for the LLDB.framework.
-
-// Local includes must be changed to framework level includes.
-// e.g. #include "lldb/API/SBDefines.h" -> #include <LLDB/SBDefines.h>
-#include "lldb/API/SBDefines.h"
-#include "lldb/API/SBModule.h"
-
-// Any include guards specified at the command line must be removed.
-#ifndef SWIG
-int a = 10
-#endif
diff --git a/lldb/test/Shell/Scripts/Inputs/RPC/RPCSBAddress.h b/lldb/test/Shell/Scripts/Inputs/RPC/RPCSBAddress.h
deleted file mode 100644
index 556afa38a9225..0000000000000
--- a/lldb/test/Shell/Scripts/Inputs/RPC/RPCSBAddress.h
+++ /dev/null
@@ -1,9 +0,0 @@
-// This is a truncated version of an SB API file generated by lldb-rpc-gen
-// used to test framework-header-fix.py to make sure the includes are correctly fixed
-// up for the LLDBRPC.framework.
-
-// Local includes must be changed to framework level includes.
-// e.g. #include "lldb/API/SBDefines.h" -> #include <LLDB/SBDefines.h>
-#include "LLDBRPC.h"
-#include "SBDefines.h"
-#include <lldb-rpc/common/RPCPublic.h>
diff --git a/lldb/test/Shell/Scripts/TestFrameworkFixScript.test b/lldb/test/Shell/Scripts/TestFrameworkFixScript.test
deleted file mode 100644
index e90c3bdfc5adb..0000000000000
--- a/lldb/test/Shell/Scripts/TestFrameworkFixScript.test
+++ /dev/null
@@ -1,11 +0,0 @@
-# Create a temp dir for output and run the framework fix script on the truncated version of SBAddress.h in the inputs dir.
-RUN: mkdir -p %t/Outputs
-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
-
-# Check the output
-RUN: cat %t/Outputs/SBAddress.h | FileCheck %s
-
-# Local includes must be changed to framework level includes.
-# e.g. #include "lldb/API/SBDefines.h" -> #include <LLDB/SBDefines.h>
-CHECK: #include <LLDB/SBDefines.h>
-CHECK: #include <LLDB/SBModule.h>
diff --git a/lldb/test/Shell/Scripts/TestFrameworkFixUnifdef.test b/lldb/test/Shell/Scripts/TestFrameworkFixUnifdef.test
deleted file mode 100644
index a7e82d2f3640c..0000000000000
--- a/lldb/test/Shell/Scripts/TestFrameworkFixUnifdef.test
+++ /dev/null
@@ -1,12 +0,0 @@
-# REQUIRES: system-darwin
-# Create a temp dir for output and run the framework fix script on the truncated version of SBAddress.h in the inputs dir.
-RUN: mkdir -p %t/Outputs
-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
-
-# Check the output
-RUN: cat %t/Outputs/SBAddress.h | FileCheck %s
-
-# Any include guards specified at the command line must be removed.
-CHECK-NOT: #ifndef SWIG
-CHECK: int a = 10
-CHECK-NOT: #endif
diff --git a/lldb/test/Shell/Scripts/TestRPCFrameworkFixScript.test b/lldb/test/Shell/Scripts/TestRPCFrameworkFixScript.test
deleted file mode 100644
index 8ba03a8c2afa8..0000000000000
--- a/lldb/test/Shell/Scripts/TestRPCFrameworkFixScript.test
+++ /dev/null
@@ -1,14 +0,0 @@
-# Create a temp dir for output and run the framework fix script on the truncated version of SBAddress.h in the inputs dir.
-RUN: mkdir -p %t/Outputs
-RUN: %python %p/../../../scripts/framework-header-fix.py -f lldb_rpc -i %p/Inputs/Main/RPCSBAddress.h -o %t/Outputs/RPCSBAddress.h -p /usr/bin/unifdef USWIG
-
-# Check the output
-RUN: cat %t/Outputs/RPCSBAddress.h | FileCheck %s
-
-# Local includes must be changed to RPC framework level includes.
-# e.g. #include "SBDefines.h" -> #include <LLDBRPC/SBDefines.h>
-# Also, RPC common code includes must change to RPC framework level includes.
-# e.g. #include "lldb-rpc/common/RPCPublic.h" -> #include <LLDBRPC/RPCPublic.h>
-CHECK: #include <LLDBRPC/RPCPublic.h>
-CHECK: #include <LLDBRPC/SBDefines.h>
-CHECK: #include <LLDBRPC/LLDBRPC.h>

chelcassanova added a commit to chelcassanova/llvm-project that referenced this pull request Jun 12, 2025
…ers" (llvm#143941)

Reland the script that converts lldb headers to RPC headers. The RPC
test was failing due to the incorrect input filepath being used.
chelcassanova added a commit to chelcassanova/llvm-project that referenced this pull request Jun 12, 2025
…ers" (llvm#143941)

Reland the script that converts lldb headers to RPC headers. The RPC
test was failing due to the incorrect input filepath being used.
chelcassanova added a commit to chelcassanova/llvm-project that referenced this pull request Jun 12, 2025
…ers" (llvm#143941)

Reland the script that converts lldb headers to RPC headers. The RPC
test was failing due to the incorrect input filepath being used.
chelcassanova added a commit that referenced this pull request Jun 12, 2025
#143945)

…ers" (#143941)

Reland the script that converts lldb headers to RPC headers. The RPC
test was failing due to the incorrect input filepath being used.

Original commit message:
This commit replaces the shell script that fixes up includes for the
LLDB framework with a Python script. This script will also be used when
fixing up includes for the LLDBRPC.framework.
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
llvm#143945)

…ers" (llvm#143941)

Reland the script that converts lldb headers to RPC headers. The RPC
test was failing due to the incorrect input filepath being used.

Original commit message:
This commit replaces the shell script that fixes up includes for the
LLDB framework with a Python script. This script will also be used when
fixing up includes for the LLDBRPC.framework.
chelcassanova added a commit to chelcassanova/llvm-project that referenced this pull request Jun 17, 2025
llvm#143945)

…ers" (llvm#143941)

Reland the script that converts lldb headers to RPC headers. The RPC
test was failing due to the incorrect input filepath being used.

Original commit message:
This commit replaces the shell script that fixes up includes for the
LLDB framework with a Python script. This script will also be used when
fixing up includes for the LLDBRPC.framework.

(cherry picked from commit 8a8ea8f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants