diff options
author | Alex Bennée <alex.bennee@linaro.org> | 2025-07-10 11:45:24 +0100 |
---|---|---|
committer | Alex Bennée <alex.bennee@linaro.org> | 2025-07-14 10:39:19 +0100 |
commit | 5ad6432880959ca373d62d715de8f0e2ca507a38 (patch) | |
tree | 61ce52b4547a84ffb4c40d347919b2b03f4dfbf3 | |
parent | 9a4e273ddec3927920c5958d2226c6b38b543336 (diff) | |
download | qemu-5ad6432880959ca373d62d715de8f0e2ca507a38.zip qemu-5ad6432880959ca373d62d715de8f0e2ca507a38.tar.gz qemu-5ad6432880959ca373d62d715de8f0e2ca507a38.tar.bz2 |
gitlab: use argparse in check-units script
Modernise the argument parsing so we can easily add to the script.
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-ID: <20250710104531.3099313-2-alex.bennee@linaro.org>
-rwxr-xr-x | .gitlab-ci.d/check-units.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/.gitlab-ci.d/check-units.py b/.gitlab-ci.d/check-units.py index 268a411..cdc62ae 100755 --- a/.gitlab-ci.d/check-units.py +++ b/.gitlab-ci.d/check-units.py @@ -8,8 +8,10 @@ # SPDX-License-Identifier: GPL-2.0-or-later from os import access, R_OK, path -from sys import argv, exit +from sys import exit import json +import argparse +from pathlib import Path from collections import Counter @@ -51,16 +53,17 @@ def analyse_units(build_units): if __name__ == "__main__": - if len(argv) != 2: - script_name = path.basename(argv[0]) - print(f"Usage: {script_name} <path_to_compile_commands.json>") - exit(1) + parser = argparse.ArgumentParser( + description="analyse number of build units in compile_commands.json") + parser.add_argument("cc_path", type=Path, default=None, + help="Path to compile_commands.json") + + args = parser.parse_args() - cc_path = argv[1] - if path.isfile(cc_path) and access(cc_path, R_OK): - units = extract_build_units(cc_path) + if path.isfile(args.cc_path) and access(args.cc_path, R_OK): + units = extract_build_units(args.cc_path) analyse_units(units) exit(0) else: - print(f"{cc_path} doesn't exist or isn't readable") + print(f"{args.cc_path} doesn't exist or isn't readable") exit(1) |