|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Usage: convert-lldb-header-to-rpc-header.py <path/to/input-header.h> <path/to/output-header.h> |
| 3 | +# This scripts takes common LLDB headers (such as lldb-defines.h) and replaces references to LLDB |
| 4 | +# with those for RPC. This happens for: |
| 5 | +# - namespace definitions |
| 6 | +# - namespace usage |
| 7 | +# - version string macros |
| 8 | +# - ifdef/ifndef lines |
| 9 | + |
| 10 | +import argparse |
| 11 | +import os |
| 12 | +import re |
| 13 | + |
| 14 | + |
| 15 | +def main(): |
| 16 | + parser = argparse.ArgumentParser() |
| 17 | + parser.add_argument("input") |
| 18 | + parser.add_argument("output") |
| 19 | + args = parser.parse_args() |
| 20 | + input_path = str(args.input) |
| 21 | + output_path = str(args.output) |
| 22 | + with open(input_path, "r") as input_file: |
| 23 | + lines = input_file.readlines() |
| 24 | + |
| 25 | + with open(output_path, "w") as output_file: |
| 26 | + for line in lines: |
| 27 | + # NOTE: We do not use lldb-forward.h or lldb-versioning.h in RPC, so remove |
| 28 | + # all includes that are found for these files. |
| 29 | + if re.match( |
| 30 | + r'#include "lldb/lldb-forward|#include "lldb/lldb-versioning', line |
| 31 | + ): |
| 32 | + continue |
| 33 | + # For lldb-rpc-defines.h, replace the ifndef LLDB_LLDB_ portion with LLDB_RPC_ as we're not |
| 34 | + # using LLDB private definitions in RPC. |
| 35 | + elif re.match(r".+LLDB_LLDB_", line): |
| 36 | + output_file.write(re.sub(r"LLDB_LLDB_", r"LLDB_RPC_", line)) |
| 37 | + # Similarly to lldb-rpc-defines.h, replace the ifndef for LLDB_API in SBDefines.h to LLDB_RPC_API_ for the same reason. |
| 38 | + elif re.match(r".+LLDB_API_", line): |
| 39 | + output_file.write(re.sub(r"LLDB_API_", r"LLDB_RPC_API_", line)) |
| 40 | + # Replace the references for the macros that define the versioning strings in |
| 41 | + # lldb-rpc-defines.h. |
| 42 | + elif re.match(r".+LLDB_VERSION", line): |
| 43 | + output_file.write(re.sub(r"LLDB_VERSION", r"LLDB_RPC_VERSION", line)) |
| 44 | + elif re.match(r".+LLDB_REVISION", line): |
| 45 | + output_file.write(re.sub(r"LLDB_REVISION", r"LLDB_RPC_REVISION", line)) |
| 46 | + elif re.match(r".+LLDB_VERSION_STRING", line): |
| 47 | + output_file.write( |
| 48 | + re.sub(r"LLDB_VERSION_STRING", r"LLDB_RPC_VERSION_STRING", line) |
| 49 | + ) |
| 50 | + # For local #includes |
| 51 | + elif re.match(r'#include "lldb/lldb-', line): |
| 52 | + output_file.write(re.sub(r"lldb/lldb-", r"lldb-rpc-", line)) |
| 53 | + # Rename the lldb namespace definition to lldb-rpc. |
| 54 | + elif re.match(r"namespace lldb", line): |
| 55 | + output_file.write(re.sub(r"lldb", r"lldb_rpc", line)) |
| 56 | + # Rename namespace references |
| 57 | + elif re.match(r".+lldb::", line): |
| 58 | + output_file.write(re.sub(r"lldb::", r"lldb_rpc::", line)) |
| 59 | + else: |
| 60 | + # Write any line that doesn't need to be converted |
| 61 | + output_file.write(line) |
| 62 | + |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + main() |
0 commit comments