diff mbox series

[1/3] xen/misra: xen-analysis.py: Improve the cppcheck version check

Message ID 20230519093019.2131896-2-luca.fancellu@arm.com (mailing list archive)
State Accepted
Headers show
Series Fix and improvements to xen-analysis.py - Pt.2 | expand

Commit Message

Luca Fancellu May 19, 2023, 9:30 a.m. UTC
Use tuple comparison to check the cppcheck version.

Take the occasion to harden the regex, escaping the dots so that we
check for them instead of generic characters.

Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
 xen/scripts/xen_analysis/cppcheck_analysis.py | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

Comments

Stefano Stabellini May 25, 2023, 12:37 a.m. UTC | #1
On Fri, 19 May 2023, Luca Fancellu wrote:
> Use tuple comparison to check the cppcheck version.
> 
> Take the occasion to harden the regex, escaping the dots so that we
> check for them instead of generic characters.
> 
> Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>

Acked-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
>  xen/scripts/xen_analysis/cppcheck_analysis.py | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xen_analysis/cppcheck_analysis.py
> index c8abbe0fca79..8dc45e653b79 100644
> --- a/xen/scripts/xen_analysis/cppcheck_analysis.py
> +++ b/xen/scripts/xen_analysis/cppcheck_analysis.py
> @@ -157,7 +157,7 @@ def generate_cppcheck_deps():
>              "Error occured retrieving cppcheck version:\n{}\n\n{}"
>          )
>  
> -    version_regex = re.search('^Cppcheck (\d+).(\d+)(?:.\d+)?$',
> +    version_regex = re.search('^Cppcheck (\d+)\.(\d+)(?:\.\d+)?$',
>                                invoke_cppcheck, flags=re.M)
>      # Currently, only cppcheck version >= 2.7 is supported, but version 2.8 is
>      # known to be broken, please refer to docs/misra/cppcheck.txt
> @@ -166,15 +166,10 @@ def generate_cppcheck_deps():
>              "Can't find cppcheck version or version not identified: "
>              "{}".format(invoke_cppcheck)
>          )
> -    major = int(version_regex.group(1))
> -    minor = int(version_regex.group(2))
> -    if major < 2 or (major == 2 and minor < 7):
> +    version = (int(version_regex.group(1)), int(version_regex.group(2)))
> +    if version < (2, 7) or version == (2, 8):
>          raise CppcheckDepsPhaseError(
> -            "Cppcheck version < 2.7 is not supported"
> -        )
> -    if major == 2 and minor == 8:
> -        raise CppcheckDepsPhaseError(
> -            "Cppcheck version 2.8 is known to be broken, see the documentation"
> +            "Cppcheck version < 2.7 or 2.8 are not supported"
>          )
>  
>      # If misra option is selected, append misra addon and generate cppcheck
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xen_analysis/cppcheck_analysis.py
index c8abbe0fca79..8dc45e653b79 100644
--- a/xen/scripts/xen_analysis/cppcheck_analysis.py
+++ b/xen/scripts/xen_analysis/cppcheck_analysis.py
@@ -157,7 +157,7 @@  def generate_cppcheck_deps():
             "Error occured retrieving cppcheck version:\n{}\n\n{}"
         )
 
-    version_regex = re.search('^Cppcheck (\d+).(\d+)(?:.\d+)?$',
+    version_regex = re.search('^Cppcheck (\d+)\.(\d+)(?:\.\d+)?$',
                               invoke_cppcheck, flags=re.M)
     # Currently, only cppcheck version >= 2.7 is supported, but version 2.8 is
     # known to be broken, please refer to docs/misra/cppcheck.txt
@@ -166,15 +166,10 @@  def generate_cppcheck_deps():
             "Can't find cppcheck version or version not identified: "
             "{}".format(invoke_cppcheck)
         )
-    major = int(version_regex.group(1))
-    minor = int(version_regex.group(2))
-    if major < 2 or (major == 2 and minor < 7):
+    version = (int(version_regex.group(1)), int(version_regex.group(2)))
+    if version < (2, 7) or version == (2, 8):
         raise CppcheckDepsPhaseError(
-            "Cppcheck version < 2.7 is not supported"
-        )
-    if major == 2 and minor == 8:
-        raise CppcheckDepsPhaseError(
-            "Cppcheck version 2.8 is known to be broken, see the documentation"
+            "Cppcheck version < 2.7 or 2.8 are not supported"
         )
 
     # If misra option is selected, append misra addon and generate cppcheck