diff mbox series

[2/3] xen/misra: xen-analysis.py: allow cppcheck version above 2.7

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

Commit Message

Luca Fancellu May 4, 2023, 1:12 p.m. UTC
Allow the use of Cppcheck version above 2.7, exception for 2.8 which
is known and documented do be broken.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
 xen/scripts/xen_analysis/cppcheck_analysis.py | 20 +++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

Comments

Andrew Cooper May 4, 2023, 1:19 p.m. UTC | #1
On 04/05/2023 2:12 pm, Luca Fancellu wrote:
> Allow the use of Cppcheck version above 2.7, exception for 2.8 which
> is known and documented do be broken.
>
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> ---
>  xen/scripts/xen_analysis/cppcheck_analysis.py | 20 +++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xen_analysis/cppcheck_analysis.py
> index 658795bb9f5b..c3783e8df343 100644
> --- a/xen/scripts/xen_analysis/cppcheck_analysis.py
> +++ b/xen/scripts/xen_analysis/cppcheck_analysis.py
> @@ -157,13 +157,25 @@ def generate_cppcheck_deps():
>              "Error occured retrieving cppcheck version:\n{}\n\n{}"
>          )
>  
> -    version_regex = re.search('^Cppcheck (.*)$', invoke_cppcheck, flags=re.M)
> +    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
> -    if (not version_regex) or (not version_regex.group(1).startswith("2.7")):
> +    if (not version_regex) or len(version_regex.groups()) < 2:
>          raise CppcheckDepsPhaseError(
> -                "Can't find cppcheck version or version is not 2.7"
> -              )
> +            "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):
> +        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"
> +        )

Python sorts tuples the helpful way around, so for example

v = (2, 9)

if v < (2, 7) or v == (2, 8):
    # handle error

does what you want, and far more concisely.

~Andrew
Luca Fancellu May 4, 2023, 1:29 p.m. UTC | #2
> On 4 May 2023, at 14:19, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
> 
> On 04/05/2023 2:12 pm, Luca Fancellu wrote:
>> Allow the use of Cppcheck version above 2.7, exception for 2.8 which
>> is known and documented do be broken.
>> 
>> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
>> ---
>> xen/scripts/xen_analysis/cppcheck_analysis.py | 20 +++++++++++++++----
>> 1 file changed, 16 insertions(+), 4 deletions(-)
>> 
>> diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xen_analysis/cppcheck_analysis.py
>> index 658795bb9f5b..c3783e8df343 100644
>> --- a/xen/scripts/xen_analysis/cppcheck_analysis.py
>> +++ b/xen/scripts/xen_analysis/cppcheck_analysis.py
>> @@ -157,13 +157,25 @@ def generate_cppcheck_deps():
>>             "Error occured retrieving cppcheck version:\n{}\n\n{}"
>>         )
>> 
>> -    version_regex = re.search('^Cppcheck (.*)$', invoke_cppcheck, flags=re.M)
>> +    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
>> -    if (not version_regex) or (not version_regex.group(1).startswith("2.7")):
>> +    if (not version_regex) or len(version_regex.groups()) < 2:
>>         raise CppcheckDepsPhaseError(
>> -                "Can't find cppcheck version or version is not 2.7"
>> -              )
>> +            "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):
>> +        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"
>> +        )
> 
> Python sorts tuples the helpful way around, so for example
> 
> v = (2, 9)
> 
> if v < (2, 7) or v == (2, 8):
>     # handle error
> 
> does what you want, and far more concisely.

Hi Andrew,

Thank you, this is very helpful, it’s clear that I’m at my first experiences with Python,
I will change the code to use this more coincise form.

Cheers,
Luca

> 
> ~Andrew
Stefano Stabellini May 17, 2023, 12:39 a.m. UTC | #3
On Thu, 4 May 2023, Luca Fancellu wrote:
> Allow the use of Cppcheck version above 2.7, exception for 2.8 which
> is known and documented do be broken.
> 
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>

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


> ---
>  xen/scripts/xen_analysis/cppcheck_analysis.py | 20 +++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py b/xen/scripts/xen_analysis/cppcheck_analysis.py
> index 658795bb9f5b..c3783e8df343 100644
> --- a/xen/scripts/xen_analysis/cppcheck_analysis.py
> +++ b/xen/scripts/xen_analysis/cppcheck_analysis.py
> @@ -157,13 +157,25 @@ def generate_cppcheck_deps():
>              "Error occured retrieving cppcheck version:\n{}\n\n{}"
>          )
>  
> -    version_regex = re.search('^Cppcheck (.*)$', invoke_cppcheck, flags=re.M)
> +    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
> -    if (not version_regex) or (not version_regex.group(1).startswith("2.7")):
> +    if (not version_regex) or len(version_regex.groups()) < 2:
>          raise CppcheckDepsPhaseError(
> -                "Can't find cppcheck version or version is not 2.7"
> -              )
> +            "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):
> +        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"
> +        )
>  
>      # If misra option is selected, append misra addon and generate cppcheck
>      # files for misra analysis
> -- 
> 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 658795bb9f5b..c3783e8df343 100644
--- a/xen/scripts/xen_analysis/cppcheck_analysis.py
+++ b/xen/scripts/xen_analysis/cppcheck_analysis.py
@@ -157,13 +157,25 @@  def generate_cppcheck_deps():
             "Error occured retrieving cppcheck version:\n{}\n\n{}"
         )
 
-    version_regex = re.search('^Cppcheck (.*)$', invoke_cppcheck, flags=re.M)
+    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
-    if (not version_regex) or (not version_regex.group(1).startswith("2.7")):
+    if (not version_regex) or len(version_regex.groups()) < 2:
         raise CppcheckDepsPhaseError(
-                "Can't find cppcheck version or version is not 2.7"
-              )
+            "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):
+        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"
+        )
 
     # If misra option is selected, append misra addon and generate cppcheck
     # files for misra analysis