All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Thomas Huth" <thuth@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>
Subject: Re: [PATCH v3 1/9] tests: introduce tree-wide code style checking
Date: Thu, 21 Jul 2022 09:54:44 -0500	[thread overview]
Message-ID: <20220721145444.cnh4wbuqiqczqy42@redhat.com> (raw)
In-Reply-To: <20220707163720.1421716-2-berrange@redhat.com>

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



  parent reply	other threads:[~2022-07-21 14:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07 16:37 [PATCH v3 0/9] tests: introduce a tree-wide code style checking facility Daniel P. Berrangé
2022-07-07 16:37 ` [PATCH v3 1/9] tests: introduce tree-wide code style checking Daniel P. Berrangé
2022-07-20 16:25   ` Peter Maydell
2022-07-20 16:31     ` Daniel P. Berrangé
2022-07-20 17:08       ` Eric Blake
2022-07-20 17:38         ` Peter Maydell
2022-07-25 15:25       ` Peter Maydell
2022-07-21 14:54   ` Eric Blake [this message]
2022-07-07 16:37 ` [PATCH v3 2/9] misc: fix mixups of bool constants with int variables Daniel P. Berrangé
2022-07-11 14:18   ` Peter Maydell
2022-07-07 16:37 ` [PATCH v3 3/9] tests/style: check for " Daniel P. Berrangé
2022-07-11 16:24   ` Philippe Mathieu-Daudé via
2022-07-13  8:21     ` Daniel P. Berrangé
2022-07-07 16:37 ` [PATCH v3 4/9] misc: fix commonly doubled up words Daniel P. Berrangé
2022-07-11 14:21   ` Peter Maydell
2022-07-07 16:37 ` [PATCH v3 5/9] tests/style: check for " Daniel P. Berrangé
2022-07-07 16:37 ` [PATCH v3 6/9] misc: ensure qemu/osdep.h is included first in all .c files Daniel P. Berrangé
2022-07-07 16:37 ` [PATCH v3 7/9] tests/style: check qemu/osdep.h is included " Daniel P. Berrangé
2022-07-21 19:13   ` Eric Blake
2022-07-07 16:37 ` [PATCH v3 8/9] misc: remove qemu/osdep.h from headers / included source files Daniel P. Berrangé
2022-07-11 16:20   ` Philippe Mathieu-Daudé via
2022-07-20 17:10   ` Eric Blake
2022-07-07 16:37 ` [PATCH v3 9/9] tests/style: check qemu/osdep.h is NOT included in all .h/.c.inc files Daniel P. Berrangé
2022-07-11 16:21   ` Philippe Mathieu-Daudé via
2022-07-21 19:16   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220721145444.cnh4wbuqiqczqy42@redhat.com \
    --to=eblake@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.