[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Thu, 4 May 2023 13:29:12 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3ioYc2i7kK+BhRWyxLCx2x30+Dx/K6ksmcXzJy71rcM=; b=HZt6A48AL0Y14l5trIvBleqIK1bP2aYPuYbYpuWrLW2bKmvW3VXBabIY7pEObqdBeC6JqavoHmoiQAhS34pN+7tpOou5fYOfjHFKZMVaZgzKTSW8IWqd0Kccw1WIrw66kyJXPX5HMrB6ixBgn5yLOo/IVDRlWG7GeUm+uOscAKxJeGwM7XS7USeCFw2cspw7YfKGA9boMepWEuEqRQ5rzVBdZidQ0q4olfRG8Zq0XvBjN8lby5BNIQI2nEu5Tc6VuJvasIKhCdJ5qH6sfgrg2RfYOJVlQ0Szcs20N6MpJGXSLCg8Mhgk8DNPH6mEv4Mm591WIapWnu8gg0kjTVdX2A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B7RgcxXW/soawQ5XTGABrJh8CU985W/sUO8XR21NzCtAvH36uKy07ECEyoI5TLZHkqI8Ey2jMAKGnWYINLuVD05vF9qMN9BEOPOh0+fR4j6otT5QvBDe5Nh/ehOXjmFQTAHysSBMsySQo7FInjqRiWTYwq459gUUWiOZh1ri5RDxjSapu7aQiEG2NskWF18xXtq0G2lafb2qnPsMoGI6HDJokarQBULOdLu9/zff0ko6hxrP41cxGqnUdfzhsdMj4T8vFOEHn2q2WvnNwSMHENjBMctskEQxCaB1ImmWAAoh8Pb0I1kzMus1S1qhYfZsSuk1Xd8DGI8OryH4Gh3mFw==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Thu, 04 May 2023 13:29:43 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHZfooyZwW8K0Ij5Ua0WLJyhged2K9KGRcAgAACm4A=
  • Thread-topic: [PATCH 2/3] xen/misra: xen-analysis.py: allow cppcheck version above 2.7


> On 4 May 2023, at 14:19, Andrew Cooper <andrew.cooper3@xxxxxxxxxx> 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@xxxxxxx>
>> ---
>> 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



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.