diff mbox series

[v3,4/7] binman: bintool: parametrize args to pass to binary for returning version

Message ID 20220901155143.1868735-4-foss+uboot@0leil.net
State Accepted
Commit e440843448d27f2cc5a6446decd1bcbaae3b1533
Delegated to: Simon Glass
Headers show
Series [v3,1/7] binman: bintool: move version check implementation into bintool class | expand

Commit Message

Quentin Schulz Sept. 1, 2022, 3:51 p.m. UTC
From: Quentin Schulz <quentin.schulz@theobroma-systems.com>

The code to check the version is very similar between binaries, the most
likely only needed variables are the regex to find the version (already
supported) and the args to pass to the binary so that it prints this
version (e.g. --version, -V or similar).

Let's make it a parameter of Bintool so that code duplication can be
avoided for simple changes.

Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
---

v3:
 - rename version_parameters into version_args,


added in v2

 tools/binman/bintool.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Simon Glass Sept. 1, 2022, 6:44 p.m. UTC | #1
On Thu, 1 Sept 2022 at 09:52, Quentin Schulz <foss+uboot@0leil.net> wrote:
>
> From: Quentin Schulz <quentin.schulz@theobroma-systems.com>
>
> The code to check the version is very similar between binaries, the most
> likely only needed variables are the regex to find the version (already
> supported) and the args to pass to the binary so that it prints this
> version (e.g. --version, -V or similar).
>
> Let's make it a parameter of Bintool so that code duplication can be
> avoided for simple changes.
>
> Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> ---
>
> v3:
>  - rename version_parameters into version_args,
>
>
> added in v2
>
>  tools/binman/bintool.py | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass Sept. 7, 2022, 12:30 p.m. UTC | #2
On Thu, 1 Sept 2022 at 09:52, Quentin Schulz <foss+uboot@0leil.net> wrote:
>
> From: Quentin Schulz <quentin.schulz@theobroma-systems.com>
>
> The code to check the version is very similar between binaries, the most
> likely only needed variables are the regex to find the version (already
> supported) and the args to pass to the binary so that it prints this
> version (e.g. --version, -V or similar).
>
> Let's make it a parameter of Bintool so that code duplication can be
> avoided for simple changes.
>
> Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> ---
>
> v3:
>  - rename version_parameters into version_args,
>
>
> added in v2
>
>  tools/binman/bintool.py | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/tools/binman/bintool.py b/tools/binman/bintool.py
index ef2bdeb696..032179a99d 100644
--- a/tools/binman/bintool.py
+++ b/tools/binman/bintool.py
@@ -53,10 +53,11 @@  class Bintool:
     # List of bintools to regard as missing
     missing_list = []
 
-    def __init__(self, name, desc, version_regex=None):
+    def __init__(self, name, desc, version_regex=None, version_args='-V'):
         self.name = name
         self.desc = desc
         self.version_regex = version_regex
+        self.version_args = version_args
 
     @staticmethod
     def find_bintool_class(btype):
@@ -476,7 +477,7 @@  binaries. It is fairly easy to create new bintools. Just add a new file to the
 
         import re
 
-        result = self.run_cmd_result('-V')
+        result = self.run_cmd_result(self.version_args)
         out = result.stdout.strip()
         if not out:
             out = result.stderr.strip()
@@ -507,9 +508,9 @@  class BintoolPacker(Bintool):
     """
     def __init__(self, name, compression=None, compress_args=None,
                  decompress_args=None, fetch_package=None,
-                 version_regex=r'(v[0-9.]+)'):
+                 version_regex=r'(v[0-9.]+)', version_args='-V'):
         desc = '%s compression' % (compression if compression else name)
-        super().__init__(name, desc, version_regex)
+        super().__init__(name, desc, version_regex, version_args)
         if compress_args is None:
             compress_args = ['--compress']
         self.compress_args = compress_args