Skip to content

[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

Merged

Conversation

chelcassanova
Copy link
Contributor

Using named args means that you don't need to keep track of 5 positional args.

@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2025

@llvm/pr-subscribers-lldb

Author: Chelsea Cassanova (chelcassanova)

Changes

Using 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:

  • (modified) lldb/scripts/version-header-fix.py (+14-14)
  • (modified) lldb/test/Shell/Scripts/TestVersionFixScript.test (+1-1)
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

Copy link
Member

@JDevlieghere JDevlieghere left a 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.

Comment on lines 27 to 29
major = args.major
minor = args.minor
patch = args.patch
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link

github-actions bot commented Jun 26, 2025

✅ With the latest revision this PR passed the Python code formatter.

@chelcassanova chelcassanova force-pushed the use-named-args-in-versioning-script branch from b67da50 to 3f25cc8 Compare June 26, 2025 23:41
@chelcassanova
Copy link
Contributor Author

cp: cannot stat '/home/gha/actions-runner/_work/llvm-project/llvm-project/build/test-results.*.xml': No such file or directory
+ :
+ shopt -s nullglob
+ python3 /home/gha/actions-runner/_work/llvm-project/llvm-project/.ci/generate_test_report_github.py ':penguin: Linux x64 Test Results' 1

From the Linux pre-commit CI, looks to be a fluke?

@chelcassanova
Copy link
Contributor Author

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.
@chelcassanova chelcassanova force-pushed the use-named-args-in-versioning-script branch from 3f25cc8 to 029ee6e Compare June 26, 2025 23:52
@chelcassanova chelcassanova merged commit c3811c8 into llvm:main Jun 27, 2025
7 checks passed
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
Using named args means that you don't need to keep track of 5 positional
args.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants