qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v3 1/9] tests: introduce tree-wide code style checking


From: Eric Blake
Subject: Re: [PATCH v3 1/9] tests: introduce tree-wide code style checking
Date: Thu, 21 Jul 2022 09:54:44 -0500
User-agent: NeoMutt/20220429

On Thu, Jul 07, 2022 at 05:37:12PM +0100, Daniel P. Berrangé wrote:
> Historically QEMU has used the 'scripts/checkpatch.pl' script to
> validate various style rules but there are a number of issues:
> 
>  - Contributors / maintainers are reluctant to add new
>    tests to it, nor fix existint rules, because the Perl

existing

> 
> The 'prohibit' rule is matched line-wise across every .c source
> file. If any violation is found, the contents of that line are
> printed, and 'message' is shown as a error message.

Can we add an exception regex as well: the prohibit rule is ignored on
lines that also match the exception rule, allowing us to write a rule
that would recognize magic comments on lines where we intentionally
break the normal rule?

> +++ b/tests/style.py
> @@ -0,0 +1,218 @@

> +
> +# Expand a regular expression from the config file which
> +# can be in several formats
> +#
> +#  - a plain string - used as-is as a regular expression
> +#  - a list of strings - each element is joined with '|'
> +#  - a dict containing
> +#      - 'terms' - interpreted as a string / list of strings
> +#      - 'prefix' - added to the front of the regular
> +#      - 'prefix' - added to the end of the regular

'suffix'

> +
> +# Evalate the rule against the designated sources
> +#
> +# Returns: 1 if the rule failed against one or more sources, 0 otherwise
> +def evaluate(sources, name, rule, ignored=False):

Rather large, but looks like a nice translation of much of gnulib's
maint.mk rule engine.

> +
> +    if len(proc.stdout) > 0:
> +        print("\033[31;1mFAIL\033[0m ❌ (%0.2f secs)" % delta)
> +        print(proc.stdout.strip())
> +        print("\033[31;1mERROR\033[0m: %s: %s ❌" % (name, rule["message"]))
> +        return 1
> +    else:
> +        print("\033[32;1mPASS\033[0m ✅ (%0.2f secs)" % delta)
> +        return 0

Do we need to make the colorization dependent on whether output is a
terminal or a specific flag is in use?

> +++ b/tests/style.yml
> @@ -0,0 +1,88 @@
> +# Source code style checking rules
> +#
> +# Each top level key defines a new check, that is
> +# exposed as a test case in the meson 'style' test
> +# suite.
> +#
> +# Within each check, the following keys are valid
> +#
> +#  * files
> +#
> +#    A regular expression matching filenames that
> +#    are to be checked. Typically used to filter
> +#    based on file extension. If omitted all files
> +#    managed by git will be checked.
> +#
> +#  * prohibit
> +#
> +#    A regular expression matching content that is
> +#    not allowed to be present in source files. Matches
> +#    against single lines of text, unless 'multiline'
> +#    option overrides. Either this option or 'require'
> +#    must be present
> +#
> +#  * require
> +#
> +#    A regular expression matching content that must
> +#    always be present in source files. Matches against
> +#    single lines of text, unless 'multiline' option
> +#    overrides. Either this option of 'prohibit' must
> +#    be present
> +#
> +#  * multiline
> +#
> +#    A boolean controlling whether 'prohibit' and 'require'
> +#    regular expressions match single lines or the entire
> +#    file contents. Defaults to 'false', matching single
> +#    lines at a time.
> +#
> +#  * ignore
> +#
> +#    A regular expression matching files to exclude from
> +#    the check. This is typically used when certain files
> +#    otherwise checked have known acceptable violations

s/have/that have/

> +#    of the test.
> +#
> +#  * message
> +#
> +#    A string providing a message to emit when the test
> +#    condition fails. Must be present
> +#
> +#  * enabled
> +#
> +#    A boolean providing a way to temporarily disable
> +#    a check. Defaults to 'true' if omitted.
> +#
> +# For all the keys above which accept a regular expression,
> +# one of three syntaxes are permitted
> +#
> +#  * string
> +#
> +#    The full regular expression to match
> +#
> +#  * list of strings
> +#
> +#    Each element of the list will be combined with '|'
> +#    to form the final regular expression. This is typically
> +#    useful to keep line length short when specifying matches
> +#    across many filenames
> +#
> +#  * dict
> +#
> +#    Contains the keys:
> +#
> +#      * terms
> +#
> +#        Either a string or list of strings interpreted as above
> +#
> +#      * prefix
> +#
> +#        A match added to the front of the regex. Useful when
> +#        'terms' is a list of strings and a common prefix is
> +#        desired
> +#
> +#      * suffix
> +#
> +#        A match added to the front of the regex. Useful when

s/front/end/

> +#        'terms' is a list of strings and a common prefix is

s/prefix/suffix/

> +#        desired
> -- 
> 2.36.1
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]