| 
 | 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 | + | 
 | 4 | +import argparse  | 
 | 5 | +import os  | 
 | 6 | +import re  | 
 | 7 | +import subprocess  | 
 | 8 | + | 
 | 9 | + | 
 | 10 | +def main():  | 
 | 11 | +    parser = argparse.ArgumentParser()  | 
 | 12 | +    parser.add_argument("input")  | 
 | 13 | +    parser.add_argument("output")  | 
 | 14 | +    args = parser.parse_args()  | 
 | 15 | +    input_path = str(args.input)  | 
 | 16 | +    output_path = str(args.output)  | 
 | 17 | +    with open(input_path, "r+") as input_file:  | 
 | 18 | +        lines = input_file.readlines()  | 
 | 19 | + | 
 | 20 | +    with open(output_path, "w+") as output_file:  | 
 | 21 | +        for line in lines:  | 
 | 22 | +            # NOTE: We do not use lldb-forward or lldb-versioning in RPC.  | 
 | 23 | +            if re.match(  | 
 | 24 | +                r'#include "lldb/lldb-forward|#include "lldb/lldb-versioning', line  | 
 | 25 | +            ):  | 
 | 26 | +                continue  | 
 | 27 | +            # For lldb-defines.h  | 
 | 28 | +            elif re.match(r".+LLDB_LLDB_", line):  | 
 | 29 | +                output_file.write(re.sub(r"LLDB_LLDB_", r"LLDB_RPC_", line))  | 
 | 30 | +            # For SBDefines.h  | 
 | 31 | +            elif re.match(r".+LLDB_API_", line):  | 
 | 32 | +                output_file.write(re.sub(r"LLDB_API_", r"LLDB_RPC_API_", line))  | 
 | 33 | +            # For lldb-rpc-version.h and lldb-rpc-defines.h  | 
 | 34 | +            elif re.match(r".+LLDB_VERSION", line):  | 
 | 35 | +                output_file.write(re.sub(r"LLDB_VERSION", r"LLDB_RPC_VERSION", line))  | 
 | 36 | +            elif re.match(r".+LLDB_REVISION", line):  | 
 | 37 | +                output_file.write(re.sub(r"LLDB_REVISION", r"LLDB_RPC_REVISION", line))  | 
 | 38 | +            elif re.match(r".+LLDB_VERSION_STRING", line):  | 
 | 39 | +                output_file.write(  | 
 | 40 | +                    re.sub(r"LLDB_VERSION_STRING", r"LLDB_RPC_VERSION_STRING", line)  | 
 | 41 | +                )  | 
 | 42 | +            # For local #includes  | 
 | 43 | +            elif re.match(r'#include "lldb/lldb-', line):  | 
 | 44 | +                output_file.write(re.sub(r"lldb/lldb-", r"lldb-rpc-", line))  | 
 | 45 | +            # Rename the lldb namespace to lldb-rpc  | 
 | 46 | +            elif re.match(r"namespace lldb", line):  | 
 | 47 | +                output_file.write(re.sub(r"lldb", r"lldb_rpc", line))  | 
 | 48 | +            # Rename namespace references  | 
 | 49 | +            elif re.match(r".+lldb::", line):  | 
 | 50 | +                output_file.write(re.sub(r"lldb::", r"lldb_rpc::", line))  | 
 | 51 | +            else:  | 
 | 52 | +                # Write any line that doesn't need to be converted  | 
 | 53 | +                output_file.write(line)  | 
 | 54 | + | 
 | 55 | + | 
 | 56 | +if __name__ == "__main__":  | 
 | 57 | +    main()  | 
0 commit comments