67 lines · python
1#!/usr/bin/env python32"""3Usage: -i <path/to/input-header.h> -o <path/to/output-header.h> -m LLDB_MAJOR_VERSION -n LLDB_MINOR_VERSION -p LLDB_PATCH_VERSION4 5This script uncomments and populates the versioning information in lldb-defines.h. Note that the LLDB version numbering looks like MAJOR.MINOR.PATCH6"""7 8import argparse9import os10import re11 12LLDB_VERSION_REGEX = re.compile(r"//\s*#define LLDB_VERSION\s*$", re.M)13LLDB_REVISION_REGEX = re.compile(r"//\s*#define LLDB_REVISION\s*$", re.M)14LLDB_VERSION_STRING_REGEX = re.compile(r"//\s*#define LLDB_VERSION_STRING\s*$", re.M)15 16 17def main():18 parser = argparse.ArgumentParser(19 description="This script uncomments and populates the versioning information in lldb-defines.h. Note that the LLDB version numbering looks like MAJOR.MINOR.PATCH"20 )21 parser.add_argument("-i", "--input_path", help="The filepath for the input header.")22 parser.add_argument(23 "-o", "--output_path", help="The filepath for the output header."24 )25 parser.add_argument("-m", "--major", help="The LLDB version major.")26 parser.add_argument("-n", "--minor", help="The LLDB version minor.")27 parser.add_argument("-p", "--patch", help="The LLDB version patch number.")28 args = parser.parse_args()29 input_path = str(args.input_path)30 output_path = str(args.output_path)31 32 # Create the output dir if it doesn't already exist33 if not os.path.exists(os.path.dirname(output_path)):34 os.makedirs(os.path.dirname(output_path))35 36 with open(input_path, "r") as input_file:37 lines = input_file.readlines()38 file_buffer = "".join(lines)39 40 with open(output_path, "w") as output_file:41 # For the defines in lldb-defines.h that define the major, minor and version string42 # uncomment each define and populate its value using the arguments passed in.43 # e.g. //#define LLDB_VERSION -> #define LLDB_VERSION <LLDB_MAJOR_VERSION>44 file_buffer = re.sub(45 LLDB_VERSION_REGEX,46 r"#define LLDB_VERSION " + args.major,47 file_buffer,48 )49 50 file_buffer = re.sub(51 LLDB_REVISION_REGEX,52 r"#define LLDB_REVISION " + args.patch,53 file_buffer,54 )55 file_buffer = re.sub(56 LLDB_VERSION_STRING_REGEX,57 r'#define LLDB_VERSION_STRING "{0}.{1}.{2}"'.format(58 args.major, args.minor, args.patch59 ),60 file_buffer,61 )62 output_file.write(file_buffer)63 64 65if __name__ == "__main__":66 main()67