llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: Chelsea Cassanova (chelcassanova) <details> <summary>Changes</summary> As part of upstreaming LLDB RPC, this commit adds python scripts that are used by LLDB RPC to modify the public lldb header files for use with RPC. https://discourse.llvm.org/t/rfc-upstreaming-lldb-rpc/85804 --- Full diff: https://github.com/llvm/llvm-project/pull/138028.diff 3 Files Affected: - (added) lldb/scripts/convert-lldb-header-to-rpc-header.py (+65) - (added) lldb/scripts/framework-header-include-fix.py (+44) - (added) lldb/scripts/framework-header-version-fix.py (+65) ``````````diff diff --git a/lldb/scripts/convert-lldb-header-to-rpc-header.py b/lldb/scripts/convert-lldb-header-to-rpc-header.py new file mode 100755 index 0000000000000..4550837d8e08d --- /dev/null +++ b/lldb/scripts/convert-lldb-header-to-rpc-header.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# Usage: convert-lldb-header-to-rpc-header.py <path/to/input-header.h> <path/to/output-header.h> +# This scripts takes common LLDB headers (such as lldb-defines.h) and replaces references to LLDB +# with those for RPC. This happens for: +# - namespace definitions +# - namespace usage +# - version string macros +# - ifdef/ifndef lines + +import argparse +import os +import re + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("input") + parser.add_argument("output") + args = parser.parse_args() + input_path = str(args.input) + output_path = str(args.output) + with open(input_path, "r") as input_file: + lines = input_file.readlines() + + with open(output_path, "w") as output_file: + for line in lines: + # NOTE: We do not use lldb-forward.h or lldb-versioning.h in RPC, so remove + # all includes that are found for these files. + if re.match( + r'#include "lldb/lldb-forward|#include "lldb/lldb-versioning', line + ): + continue + # For lldb-rpc-defines.h, replace the ifndef LLDB_LLDB_ portion with LLDB_RPC_ as we're not + # using LLDB private definitions in RPC. + elif re.match(r".+LLDB_LLDB_", line): + output_file.write(re.sub(r"LLDB_LLDB_", r"LLDB_RPC_", line)) + # Similarly to lldb-rpc-defines.h, replace the ifndef for LLDB_API in SBDefines.h to LLDB_RPC_API_ for the same reason. + elif re.match(r".+LLDB_API_", line): + output_file.write(re.sub(r"LLDB_API_", r"LLDB_RPC_API_", line)) + # Replace the references for the macros that define the versioning strings in + # lldb-rpc-defines.h. + elif re.match(r".+LLDB_VERSION", line): + output_file.write(re.sub(r"LLDB_VERSION", r"LLDB_RPC_VERSION", line)) + elif re.match(r".+LLDB_REVISION", line): + output_file.write(re.sub(r"LLDB_REVISION", r"LLDB_RPC_REVISION", line)) + elif re.match(r".+LLDB_VERSION_STRING", line): + output_file.write( + re.sub(r"LLDB_VERSION_STRING", r"LLDB_RPC_VERSION_STRING", line) + ) + # For local #includes + elif re.match(r'#include "lldb/lldb-', line): + output_file.write(re.sub(r"lldb/lldb-", r"lldb-rpc-", line)) + # Rename the lldb namespace definition to lldb-rpc. + elif re.match(r"namespace lldb", line): + output_file.write(re.sub(r"lldb", r"lldb_rpc", line)) + # Rename namespace references + elif re.match(r".+lldb::", line): + output_file.write(re.sub(r"lldb::", r"lldb_rpc::", line)) + else: + # Write any line that doesn't need to be converted + output_file.write(line) + + +if __name__ == "__main__": + main() diff --git a/lldb/scripts/framework-header-include-fix.py b/lldb/scripts/framework-header-include-fix.py new file mode 100755 index 0000000000000..e214ce005923f --- /dev/null +++ b/lldb/scripts/framework-header-include-fix.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# Usage: framework-header-include-fix.py <path/to/input-header.h> <path/to/output-header.h> +# This script modifies all #include lines in all lldb-rpc headers +# from either filesystem or local includes to liblldbrpc includes. + +import argparse +import os +import re + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("input") + parser.add_argument("output") + args = parser.parse_args() + input_path = str(args.input) + output_path = str(args.output) + with open(input_path, "r+") as input_file: + lines = input_file.readlines() + + with open(output_path, "w+") as output_file: + for line in lines: + # Replace includes from RPCCommon to liblldbrpc includes. + # e.g. #include <lldb-rpc/common/RPCArgument.h> -> #include <LLDBRPC/RPCArgument.h> + if re.match(r".+<lldb-rpc/common", line): + output_file.write(re.sub(r"<lldb-rpc/common", r"<LLDBRPC", line)) + # Replace all local file includes to liblldbrpc includes. + # e.g. #include "SBFoo.h" -> #include <LLDBRPC/SBFoo.h> + elif re.match(r'#include "(.*)"', line): + include_filename = re.search(r'#include "(.*)"', line).groups()[0] + output_file.write( + re.sub( + r'#include "(.*)"', + r"#include <LLDBRPC/" + include_filename + ">", + line, + ) + ) + else: + # Write any line that doesn't need to be converted + output_file.write(line) + + +if __name__ == "__main__": + main() diff --git a/lldb/scripts/framework-header-version-fix.py b/lldb/scripts/framework-header-version-fix.py new file mode 100755 index 0000000000000..72185f8e820ce --- /dev/null +++ b/lldb/scripts/framework-header-version-fix.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# Usage: framework-header-version-fix.py <path/to/input-header.h> <path/to/output-header.h> MAJOR MINOR PATCH +# This script modifies lldb-rpc-defines.h to uncomment the macro defines used for the LLDB +# major, minor and patch values as well as populating their definitions. + +import argparse +import os +import re + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("input") + parser.add_argument("output") + parser.add_argument("lldb_version_major") + parser.add_argument("lldb_version_minor") + parser.add_argument("lldb_version_patch") + args = parser.parse_args() + input_path = str(args.input) + output_path = str(args.output) + lldb_version_major = args.lldb_version_major + lldb_version_minor = args.lldb_version_minor + lldb_version_patch = args.lldb_version_patch + + with open(input_path, "r") as input_file: + lines = input_file.readlines() + + with open(output_path, "w") as output_file: + for line in lines: + # Uncomment the line that defines the LLDB major version and populate its value. + if re.match(r"//#define LLDB_RPC_VERSION$", line): + output_file.write( + re.sub( + r"//#define LLDB_RPC_VERSION", + r"#define LLDB_RPC_VERSION " + lldb_version_major, + line, + ) + ) + # Uncomment the line that defines the LLDB minor version and populate its value. + elif re.match(r"//#define LLDB_RPC_REVISION$", line): + output_file.write( + re.sub( + r"//#define LLDB_RPC_REVISION", + r"#define LLDB_RPC_REVISION " + lldb_version_minor, + line, + ) + ) + # Uncomment the line that defines the complete LLDB version string and populate its value. + elif re.match(r"//#define LLDB_RPC_VERSION_STRING$", line): + output_file.write( + re.sub( + r"//#define LLDB_RPC_VERSION_STRING", + r'#define LLDB_RPC_VERSION_STRING "{0}.{1}.{2}"'.format( + lldb_version_major, lldb_version_minor, lldb_version_patch + ), + line, + ) + ) + else: + # Write any line that doesn't need to be converted + output_file.write(line) + + +if __name__ == "__main__": + main() `````````` </details> https://github.com/llvm/llvm-project/pull/138028 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits