|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Usage: <path/to/input-header.h> <path/to/output-header.h> LLDB_MAJOR_VERSION LLDB_MINOR_VERSION LLDB_PATCH_VERSION |
| 4 | +
|
| 5 | +This script uncomments and populates the versioning information in lldb-defines.h |
| 6 | +""" |
| 7 | + |
| 8 | +import argparse |
| 9 | +import os |
| 10 | +import re |
| 11 | + |
| 12 | +LLDB_VERSION_REGEX = re.compile(r"//\s*#define LLDB_VERSION\s*$", re.M) |
| 13 | +LLDB_REVISION_REGEX = re.compile(r"//\s*#define LLDB_REVISION\s*$", re.M) |
| 14 | +LLDB_VERSION_STRING_REGEX = re.compile(r"//\s*#define LLDB_VERSION_STRING\s*$", re.M) |
| 15 | + |
| 16 | + |
| 17 | +def main(): |
| 18 | + parser = argparse.ArgumentParser() |
| 19 | + parser.add_argument("input_path") |
| 20 | + parser.add_argument("output_path") |
| 21 | + parser.add_argument("lldb_version_major") |
| 22 | + parser.add_argument("lldb_version_minor") |
| 23 | + parser.add_argument("lldb_version_patch") |
| 24 | + args = parser.parse_args() |
| 25 | + input_path = str(args.input_path) |
| 26 | + output_path = str(args.output_path) |
| 27 | + lldb_version_major = args.lldb_version_major |
| 28 | + lldb_version_minor = args.lldb_version_minor |
| 29 | + lldb_version_patch = args.lldb_version_patch |
| 30 | + |
| 31 | + with open(input_path, "r") as input_file: |
| 32 | + lines = input_file.readlines() |
| 33 | + file_buffer = "".join(lines) |
| 34 | + |
| 35 | + with open(output_path, "w") as output_file: |
| 36 | + # For the defines in lldb-defines.h that define the major, minor and version string |
| 37 | + # uncomment each define and populate its value using the arguments passed in. |
| 38 | + # e.g. //#define LLDB_VERSION -> #define LLDB_VERSION <LLDB_MAJOR_VERSION> |
| 39 | + file_buffer = re.sub( |
| 40 | + LLDB_VERSION_REGEX, |
| 41 | + r"#define LLDB_VERSION " + lldb_version_major, |
| 42 | + file_buffer, |
| 43 | + ) |
| 44 | + |
| 45 | + file_buffer = re.sub( |
| 46 | + LLDB_REVISION_REGEX, |
| 47 | + r"#define LLDB_REVISION " + lldb_version_patch, |
| 48 | + file_buffer, |
| 49 | + ) |
| 50 | + file_buffer = re.sub( |
| 51 | + LLDB_VERSION_STRING_REGEX, |
| 52 | + r'#define LLDB_VERSION_STRING "{0}.{1}.{2}"'.format( |
| 53 | + lldb_version_major, lldb_version_minor, lldb_version_patch |
| 54 | + ), |
| 55 | + file_buffer, |
| 56 | + ) |
| 57 | + output_file.write(file_buffer) |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + main() |
0 commit comments