-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[lldb][scripts] Use named args in versioning script #145993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb][scripts] Use named args in versioning script #145993
Conversation
@llvm/pr-subscribers-lldb Author: Chelsea Cassanova (chelcassanova) ChangesUsing named args means that you don't need to keep track of 5 positional args. Full diff: https://github.com/llvm/llvm-project/pull/145993.diff 2 Files Affected:
diff --git a/lldb/scripts/version-header-fix.py b/lldb/scripts/version-header-fix.py
index fb26ee1579e66..26e223d969012 100755
--- a/lldb/scripts/version-header-fix.py
+++ b/lldb/scripts/version-header-fix.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python3
"""
-Usage: <path/to/input-header.h> <path/to/output-header.h> LLDB_MAJOR_VERSION LLDB_MINOR_VERSION LLDB_PATCH_VERSION
+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
-This script uncomments and populates the versioning information in lldb-defines.h
+This script uncomments and populates the versioning information in lldb-defines.h. Note that the LLDB version numbering looks like MAJOR.MINOR.PATCH
"""
import argparse
@@ -15,18 +15,18 @@
def main():
- parser = argparse.ArgumentParser()
- parser.add_argument("input_path")
- parser.add_argument("output_path")
- parser.add_argument("lldb_version_major")
- parser.add_argument("lldb_version_minor")
- parser.add_argument("lldb_version_patch")
+ parser = argparse.ArgumentParser(description="This script uncomments and populates the versioning information in lldb-defines.h. Note that the LLDB version numbering looks like MAJOR.MINOR.PATCH")
+ parser.add_argument("-i", "--input_path", help="The filepath for the input header.")
+ parser.add_argument("-o", "--output_path", help="The filepath for the output header.")
+ parser.add_argument("-m", "--major", help="The LLDB version major.")
+ parser.add_argument("-n", "--minor", help="The LLDB version minor.")
+ parser.add_argument("-p", "--patch", help="The LLDB version patch number.")
args = parser.parse_args()
input_path = str(args.input_path)
output_path = str(args.output_path)
- lldb_version_major = args.lldb_version_major
- lldb_version_minor = args.lldb_version_minor
- lldb_version_patch = args.lldb_version_patch
+ major = args.major
+ minor = args.minor
+ patch = args.patch
with open(input_path, "r") as input_file:
lines = input_file.readlines()
@@ -38,19 +38,19 @@ def main():
# e.g. //#define LLDB_VERSION -> #define LLDB_VERSION <LLDB_MAJOR_VERSION>
file_buffer = re.sub(
LLDB_VERSION_REGEX,
- r"#define LLDB_VERSION " + lldb_version_major,
+ r"#define LLDB_VERSION " + major,
file_buffer,
)
file_buffer = re.sub(
LLDB_REVISION_REGEX,
- r"#define LLDB_REVISION " + lldb_version_patch,
+ r"#define LLDB_REVISION " + patch,
file_buffer,
)
file_buffer = re.sub(
LLDB_VERSION_STRING_REGEX,
r'#define LLDB_VERSION_STRING "{0}.{1}.{2}"'.format(
- lldb_version_major, lldb_version_minor, lldb_version_patch
+ major, minor, patch
),
file_buffer,
)
diff --git a/lldb/test/Shell/Scripts/TestVersionFixScript.test b/lldb/test/Shell/Scripts/TestVersionFixScript.test
index 78cc987263075..9467d1655b05c 100644
--- a/lldb/test/Shell/Scripts/TestVersionFixScript.test
+++ b/lldb/test/Shell/Scripts/TestVersionFixScript.test
@@ -1,6 +1,6 @@
# Create a temp dir for output and run the version fix script on the truncated version of lldb-defines.h in the inputs dir.
RUN: mkdir -p %t/Outputs
-RUN: %python %p/../../../scripts/version-header-fix.py %p/Inputs/lldb-defines.h %t/Outputs/lldb-defines.h 21 0 12
+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
# Check the output
RUN: cat %t/Outputs/lldb-defines.h | FileCheck %s
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo opportunity to drop some locals.
lldb/scripts/version-header-fix.py
Outdated
major = args.major | ||
minor = args.minor | ||
patch = args.patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth having these? Why not use args.major
directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force of habit from grabbing other args from arg parse, I'll update to drop these.
✅ With the latest revision this PR passed the Python code formatter. |
b67da50
to
3f25cc8
Compare
From the Linux pre-commit CI, looks to be a fluke? |
Wait no, I forgot to update the usage of the script in the actual CMake files 🤦🏾♀️ |
Using named args means that you don't need to keep track of 5 positional args.
3f25cc8
to
029ee6e
Compare
Using named args means that you don't need to keep track of 5 positional args.
Using named args means that you don't need to keep track of 5 positional args.