================
@@ -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))
----------------
chelcassanova wrote:
I looked at running only the `sub` and I think I'll actually keep it as is
here. The reason for that is because the general pattern here if "if we need to
change the line then change it, otherwise just write whatever was in the
original input file". Running only the `sub` without if clauses makes it harder
to know when we need to just use the original input file line. I'd have
preferred for this to be a `switch` statement (or `case` in Python's case) but
IIUC the current version of Python that we support hasn't caught up to using
that statement yet.
https://github.com/llvm/llvm-project/pull/138028
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits