Skip to content

Commit c3811c8

Browse files
[lldb][scripts] Use named args in versioning script (#145993)
Using named args means that you don't need to keep track of 5 positional args.
1 parent f93df5e commit c3811c8

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

lldb/scripts/version-header-fix.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python3
22
"""
3-
Usage: <path/to/input-header.h> <path/to/output-header.h> LLDB_MAJOR_VERSION LLDB_MINOR_VERSION LLDB_PATCH_VERSION
3+
Usage: -i <path/to/input-header.h> -o <path/to/output-header.h> -m LLDB_MAJOR_VERSION -n LLDB_MINOR_VERSION -p LLDB_PATCH_VERSION
44
5-
This script uncomments and populates the versioning information in lldb-defines.h
5+
This script uncomments and populates the versioning information in lldb-defines.h. Note that the LLDB version numbering looks like MAJOR.MINOR.PATCH
66
"""
77

88
import argparse
@@ -15,18 +15,19 @@
1515

1616

1717
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")
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.")
2428
args = parser.parse_args()
2529
input_path = str(args.input_path)
2630
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
3031

3132
with open(input_path, "r") as input_file:
3233
lines = input_file.readlines()
@@ -38,19 +39,19 @@ def main():
3839
# e.g. //#define LLDB_VERSION -> #define LLDB_VERSION <LLDB_MAJOR_VERSION>
3940
file_buffer = re.sub(
4041
LLDB_VERSION_REGEX,
41-
r"#define LLDB_VERSION " + lldb_version_major,
42+
r"#define LLDB_VERSION " + args.major,
4243
file_buffer,
4344
)
4445

4546
file_buffer = re.sub(
4647
LLDB_REVISION_REGEX,
47-
r"#define LLDB_REVISION " + lldb_version_patch,
48+
r"#define LLDB_REVISION " + args.patch,
4849
file_buffer,
4950
)
5051
file_buffer = re.sub(
5152
LLDB_VERSION_STRING_REGEX,
5253
r'#define LLDB_VERSION_STRING "{0}.{1}.{2}"'.format(
53-
lldb_version_major, lldb_version_minor, lldb_version_patch
54+
args.major, args.minor, args.patch
5455
),
5556
file_buffer,
5657
)

lldb/source/API/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ foreach(header
326326
endforeach()
327327

328328
add_custom_command(TARGET liblldb POST_BUILD
329-
COMMAND "${Python3_EXECUTABLE}" ${LLDB_SOURCE_DIR}/scripts/version-header-fix.py ${LLDB_SOURCE_DIR}/include/lldb/lldb-defines.h ${lldb_header_staging_dir}/lldb-defines.h ${LLDB_VERSION_MAJOR} ${LLDB_VERSION_MINOR} ${LLDB_VERSION_PATCH}
329+
COMMAND "${Python3_EXECUTABLE}" ${LLDB_SOURCE_DIR}/scripts/version-header-fix.py -i ${LLDB_SOURCE_DIR}/include/lldb/lldb-defines.h -o ${lldb_header_staging_dir}/lldb-defines.h -m ${LLDB_VERSION_MAJOR} -n ${LLDB_VERSION_MINOR} -p ${LLDB_VERSION_PATCH}
330330
)
331331
add_custom_target(liblldb-header-staging DEPENDS ${lldb_staged_headers})
332332
add_dependencies(liblldb liblldb-header-staging)

lldb/test/Shell/Scripts/TestVersionFixScript.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Create a temp dir for output and run the version fix script on the truncated version of lldb-defines.h in the inputs dir.
22
RUN: mkdir -p %t/Outputs
3-
RUN: %python %p/../../../scripts/version-header-fix.py %p/Inputs/lldb-defines.h %t/Outputs/lldb-defines.h 21 0 12
3+
RUN: %python %p/../../../scripts/version-header-fix.py --input_path %p/Inputs/lldb-defines.h --output_path %t/Outputs/lldb-defines.h --major 21 --minor 0 --patch 12
44

55
# Check the output
66
RUN: cat %t/Outputs/lldb-defines.h | FileCheck %s

0 commit comments

Comments
 (0)