DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Mattias Rönnblom" <hofors@lysator.liu.se>
To: "Robin Jarry" <rjarry@redhat.com>,
	"Mattias Rönnblom" <mattias.ronnblom@ericsson.com>,
	dev@dpdk.org
Cc: "Heng Wang" <heng.wang@ericsson.com>,
	"Stephen Hemminger" <stephen@networkplumber.org>,
	"Tyler Retzlaff" <roretzla@linux.microsoft.com>,
	"Morten Brørup" <mb@smartsharesystems.com>,
	"Jack Bond-Preston" <jack.bond-preston@foss.arm.com>,
	"David Marchand" <david.marchand@redhat.com>,
	"Chengwen Feng" <fengchengwen@huawei.com>,
	"Richardson, Bruce" <bruce.richardson@intel.com>
Subject: Re: [PATCH v12 1/7] buildtools/chkincs: relax C linkage requirement
Date: Thu, 10 Oct 2024 12:24:25 +0200	[thread overview]
Message-ID: <0f81b9f3-8724-4bfb-bcd4-8d5c7c035d15@lysator.liu.se> (raw)
In-Reply-To: <D4OUI8LRL27R.3SO694JXZMR0J@redhat.com>

On 2024-10-06 17:58, Robin Jarry wrote:
> Mattias Rönnblom, Oct 06, 2024 at 16:17:
>>> I think you need to change run_command() to custom_target(). I was 
>>> thinking of this patch to be much simpler as follows:
>>
>> I started off with a shell script, but I switched to Python when I 
>> wanted to strip off comments. (Not that that can't be done in bourne 
>> shell.)
>>
>> The below script doesn't strip off comments, and provides no usage 
>> information. Earlier I got the impression you wanted to improve 
>> command-line usage.
>>
>> I think we need to decide if this thing is an integral part of the 
>> build system, custom-made for its needs, or if its something that 
>> should also be friendly to a command-line human user.
>>
>> I could go either way on that.
> 
> We don't have to choose. Being part of the build system does not mean 

If it's an integral part of the build system, and the only user is 
another program (e.g., meson.build), the script can be made simpler. For 
example, you need not bother with usage information, since a computer 
program will not have any use of it.

It would be helpful if Bruce could comment on this. How should we think 
about small tools like this? That are more-or-less just an artifact of 
the lack of expressiveness in meson.

I'm leaning toward having them as proper human-usable CLI tools, 
provided it doesn't cause too much fuzz on the meson.build side of things.

> the script cannot use the standard python tools to parse arguments. Here 
> is what I came up with. It is shorter, strips comments and deals with 
> arguments in a simpler way. We don't need to pass the "missing" or 
> "redundant" operation to the script, it can figure out what to do on its 
> own (see inline comment in main()):

Sure, you could check for both issues at the same time. The primary 
reason for doing otherwise was that the code base wouldn't survive the 
"redundant" check at the time of the script's introduction (in the patch 
set).

> 
> diff --git a/buildtools/chkincs/check_extern_c.py b/buildtools/chkincs/ 
> check_extern_c.py
> new file mode 100755
> index 000000000000..3e61719a5ea5
> --- /dev/null
> +++ b/buildtools/chkincs/check_extern_c.py
> @@ -0,0 +1,72 @@
> +#!/usr/bin/env python3
> +# SPDX-License-Identifier: BSD-3-Clause
> +
> +"""
> +Detect missing or redundant `extern "C"` statements in headers.
> +"""
> +
> +import argparse
> +import re
> +import sys
> +
> +
> +# regular expressions
> +EXTERN_C_RE = re.compile(r'^extern\s+"C"', re.MULTILINE)
> +CPP_LINE_COMMENT_RE = re.compile(r"//.*$", re.MULTILINE)
> +C_BLOCK_COMMENT_RE = re.compile(r"/\*.+?\*/", re.DOTALL)
> +C_SYMBOL_RE = [
> +    # external variable definitions
> +    re.compile(r"^extern\s+[a-z0-9_]+\s", re.MULTILINE),
> +    # exported functions
> +    re.compile(r"\brte_[a-z0-9_]+\("),
> +    re.compile(r"\bcmdline_[a-z0-9_]+\("),
> +    re.compile(r"\bvt100_[a-z0-9_]+\("),
> +    re.compile(r"\brdline_[a-z0-9_]+\("),
> +    re.compile(r"\bcirbuf_[a-z0-9_]+\("),
> +    # windows compatibility
> +    re.compile(r"\bpthread_[a-z0-9_]+\("),
> +    re.compile(r"\bregcomp\("),
> +    re.compile(r"\bcount_cpu\("),
> +]
> +
> +
> +def strip_comments(buf: str) -> str:
> +    buf = CPP_LINE_COMMENT_RE.sub("", buf, re.MULTILINE)
> +    return C_BLOCK_COMMENT_RE.sub("", buf, re.DOTALL)
> +
> +
> +def has_c_symbols(buf: str) -> bool:
> +    for expr in C_SYMBOL_RE:
> +        if expr.search(buf, re.MULTILINE):
> +            return True
> +    return False
> +
> +
> +def main() -> int:
> +    parser = argparse.ArgumentParser(description=__doc__)
> +    parser.add_argument("headers", nargs="+")
> +    args = parser.parse_args()
> +
> +    ret = 0
> +
> +    for h in args.headers:
> +        with open(h) as f:
> +            buf = f.read()
> +
> +        buf = strip_comments(buf)
> +
> +        if has_c_symbols(buf):
> +            if not EXTERN_C_RE.search(buf):
> +                print('error: missing extern "C" in', h)
> +                ret = 1
> +        # Uncomment next block once all extraneous extern "C" have been 
> removed
> +        #else:
> +        #    if EXTERN_C_RE.search(buf):
> +        #        print('error: extraneous extern "C" in', h)
> +        #        ret = 1
> +
> +    return ret
> +
> +
> +if __name__ == "__main__":
> +    sys.exit(main())
> diff --git a/buildtools/chkincs/meson.build b/buildtools/chkincs/ 
> meson.build
> index f2dadcae18ef..a551b2df9268 100644
> --- a/buildtools/chkincs/meson.build
> +++ b/buildtools/chkincs/meson.build
> @@ -38,14 +38,11 @@ if not add_languages('cpp', required: false)
> endif
> 
> # check for extern C in files, since this is not detected as an error by 
> the compiler
> -grep = find_program('grep', required: false)
> -if grep.found()
> -    errlist = run_command([grep, '--files-without-match', '^extern 
> "C"', dpdk_chkinc_headers],
> -            check: false, capture: true).stdout().split()
> -    if errlist != []
> -        error('Files missing C++ \'extern "C"\' guards:\n- ' + '\n- 
> '.join(errlist))
> -    endif
> -endif
> +custom_target('check-extern-c',
> +        command: files('check_extern_c.py') + ['@INPUT@'],
> +        input: dpdk_chkinc_headers,
> +        output: 'check-extern-c',
> +        build_by_default: true)
> 
> gen_cpp_files = generator(gen_c_file_for_header,
>          output: '@BASENAME@.cpp',
> 

I won't review this in detail, but you can always submit a new patch 
against what's on main. What is there now is somewhat half-way between 
"proper CLI tool" and "meson.build delegate".


  reply	other threads:[~2024-10-10 10:24 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-31 13:13 [RFC v3] eal: add bitset type Mattias Rönnblom
2024-01-31 16:02 ` Stephen Hemminger
2024-01-31 16:28   ` Mattias Rönnblom
2024-01-31 16:06 ` Stephen Hemminger
2024-01-31 18:45   ` Mattias Rönnblom
2024-02-01  8:04     ` Morten Brørup
2024-02-02 10:19       ` Mattias Rönnblom
2024-02-02 12:42         ` Morten Brørup
2024-02-16 10:23 ` [RFC v4 1/4] " Mattias Rönnblom
2024-02-16 10:23   ` [RFC v4 2/4] eal: add bitset test suite Mattias Rönnblom
2024-02-16 10:23   ` [RFC v4 3/4] service: use multi-word bitset to represent service flags Mattias Rönnblom
2024-02-16 10:23   ` [RFC v4 4/4] event/dsw: optimize serving port logic Mattias Rönnblom
2024-05-05  7:33   ` [RFC v5 1/6] eal: add bitset type Mattias Rönnblom
2024-05-05  7:33     ` [RFC v5 2/6] eal: add bitset test suite Mattias Rönnblom
2024-05-05  7:33     ` [RFC v5 3/6] eal: add atomic bitset functions Mattias Rönnblom
2024-05-05  7:33     ` [RFC v5 4/6] eal: add unit tests for atomic bitset operations Mattias Rönnblom
2024-05-05  7:33     ` [RFC v5 5/6] service: use multi-word bitset to represent service flags Mattias Rönnblom
2024-05-05  7:33     ` [RFC v5 6/6] event/dsw: optimize serving port logic Mattias Rönnblom
2024-08-09 20:14     ` [PATCH 1/6] eal: add bitset type Mattias Rönnblom
2024-08-09 20:14       ` [PATCH 2/6] eal: add bitset test suite Mattias Rönnblom
2024-09-12  4:51         ` Tyler Retzlaff
2024-08-09 20:14       ` [PATCH 3/6] eal: add atomic bitset functions Mattias Rönnblom
2024-09-12  4:51         ` Tyler Retzlaff
2024-08-09 20:14       ` [PATCH 4/6] eal: add unit tests for atomic bitset operations Mattias Rönnblom
2024-09-12  4:52         ` Tyler Retzlaff
2024-10-09 20:29           ` Morten Brørup
2024-08-09 20:14       ` [PATCH 5/6] service: use multi-word bitset to represent service flags Mattias Rönnblom
2024-09-12  4:52         ` Tyler Retzlaff
2024-08-09 20:14       ` [PATCH 6/6] event/dsw: add support for larger port count Mattias Rönnblom
2024-09-12  4:53         ` Tyler Retzlaff
2024-08-20 17:09       ` [PATCH 1/6] eal: add bitset type Mattias Rönnblom
2024-09-02 13:55       ` Morten Brørup
2024-09-02 14:46         ` Mattias Rönnblom
2024-09-02 14:49         ` Mattias Rönnblom
2024-09-12  4:51       ` Tyler Retzlaff
2024-09-17  9:36       ` [PATCH v7 0/6] Improve EAL bit operations API Mattias Rönnblom
2024-09-17  9:36         ` [PATCH v7 1/6] dpdk: do not force C linkage on include file dependencies Mattias Rönnblom
2024-09-17 10:48           ` [PATCH v8 0/6] Improve EAL bit operations API Mattias Rönnblom
2024-09-17 10:48             ` [PATCH v8 1/6] dpdk: do not force C linkage on include file dependencies Mattias Rönnblom
2024-09-18  9:04               ` [PATCH v9 0/6] Improve EAL bit operations API Mattias Rönnblom
2024-09-18  9:04                 ` [PATCH v9 1/6] dpdk: do not force C linkage on include file dependencies Mattias Rönnblom
2024-09-19 19:31                   ` [PATCH v10 0/7] Improve EAL bit operations API Mattias Rönnblom
2024-09-19 19:31                     ` [PATCH v10 1/7] buildtools/chkincs: relax C linkage requirement Mattias Rönnblom
2024-09-20  6:24                       ` [PATCH v11 0/7] Improve EAL bit operations API Mattias Rönnblom
2024-09-20  6:24                         ` [PATCH v11 1/7] buildtools/chkincs: relax C linkage requirement Mattias Rönnblom
2024-09-20 10:47                           ` [PATCH v12 0/7] Improve EAL bit operations API Mattias Rönnblom
2024-09-20 10:47                             ` [PATCH v12 1/7] buildtools/chkincs: relax C linkage requirement Mattias Rönnblom
2024-10-03 16:47                               ` Robin Jarry
2024-10-04  7:31                                 ` Mattias Rönnblom
2024-10-04  8:05                                   ` Robin Jarry
2024-10-04  8:40                                     ` Mattias Rönnblom
2024-10-04 11:51                                       ` Robin Jarry
2024-10-04 12:19                                         ` Thomas Monjalon
2024-10-06  8:55                                         ` Mattias Rönnblom
2024-10-06  9:47                                           ` Mattias Rönnblom
2024-10-06 12:25                                             ` Robin Jarry
2024-10-06 13:09                                               ` Robin Jarry
2024-10-06 14:17                                               ` Mattias Rönnblom
2024-10-06 15:58                                                 ` Robin Jarry
2024-10-10 10:24                                                   ` Mattias Rönnblom [this message]
2024-10-10 10:39                                                     ` Bruce Richardson
2024-09-20 10:47                             ` [PATCH v12 2/7] dpdk: use C linkage only where appropriate Mattias Rönnblom
2024-09-20 10:47                             ` [PATCH v12 3/7] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-20 10:47                             ` [PATCH v12 4/7] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-20 10:47                             ` [PATCH v12 5/7] eal: add atomic " Mattias Rönnblom
2024-09-20 10:47                             ` [PATCH v12 6/7] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-10-10 10:45                               ` David Marchand
2024-10-10 11:55                                 ` Mattias Rönnblom
2024-10-10 12:14                                   ` David Marchand
2024-10-10 12:35                                     ` Mattias Rönnblom
2024-10-10 13:07                                       ` Thomas Monjalon
2024-10-11  8:35                                   ` David Marchand
2024-10-11 15:06                                 ` Morten Brørup
2024-10-11 15:11                                   ` David Marchand
2024-10-11 15:15                                     ` Morten Brørup
2024-10-11 15:18                                       ` David Marchand
2024-09-20 10:47                             ` [PATCH v12 7/7] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-10-09 20:18                             ` [PATCH v12 0/7] Improve EAL bit operations API David Marchand
2024-09-20  6:24                         ` [PATCH v11 2/7] dpdk: use C linkage only where appropriate Mattias Rönnblom
2024-09-20  6:24                         ` [PATCH v11 3/7] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-20  6:24                         ` [PATCH v11 4/7] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-20  6:24                         ` [PATCH v11 5/7] eal: add atomic " Mattias Rönnblom
2024-09-20  6:24                         ` [PATCH v11 6/7] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-20  6:24                         ` [PATCH v11 7/7] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-19 19:31                     ` [PATCH v10 2/7] dpdk: use C linkage only where appropriate Mattias Rönnblom
2024-09-19 19:31                     ` [PATCH v10 3/7] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-19 19:31                     ` [PATCH v10 4/7] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-19 19:31                     ` [PATCH v10 5/7] eal: add atomic " Mattias Rönnblom
2024-09-19 19:31                     ` [PATCH v10 6/7] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-19 19:31                     ` [PATCH v10 7/7] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-18  9:04                 ` [PATCH v9 2/6] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-18  9:04                 ` [PATCH v9 3/6] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-18  9:04                 ` [PATCH v9 4/6] eal: add atomic " Mattias Rönnblom
2024-09-18  9:04                 ` [PATCH v9 5/6] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-18  9:04                 ` [PATCH v9 6/6] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-17 10:48             ` [PATCH v8 2/6] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-17 10:48             ` [PATCH v8 3/6] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-17 10:48             ` [PATCH v8 4/6] eal: add atomic " Mattias Rönnblom
2024-09-17 10:48             ` [PATCH v8 5/6] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-17 10:48             ` [PATCH v8 6/6] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-09-17  9:36         ` [PATCH v7 2/6] eal: extend bit manipulation functionality Mattias Rönnblom
2024-09-17  9:36         ` [PATCH v7 3/6] eal: add unit tests for bit operations Mattias Rönnblom
2024-09-17  9:36         ` [PATCH v7 4/6] eal: add atomic " Mattias Rönnblom
2024-09-17  9:36         ` [PATCH v7 5/6] eal: add unit tests for atomic bit access functions Mattias Rönnblom
2024-09-17  9:36         ` [PATCH v7 6/6] eal: extend bitops to handle volatile pointers Mattias Rönnblom
2024-10-10  8:30       ` [PATCH v2 0/4] Add bitset type David Marchand
2024-10-10  8:30         ` [PATCH v2 1/4] eal: add " David Marchand
2024-10-11  9:35           ` Mattias Rönnblom
2024-10-16 11:30           ` David Marchand
2024-10-16 13:37             ` Mattias Rönnblom
2024-10-10  8:30         ` [PATCH v2 2/4] bitset: add atomic functions David Marchand
2024-10-10  8:30         ` [PATCH v2 3/4] service: use multi-word bitset to represent service flags David Marchand
2024-10-10  8:30         ` [PATCH v2 4/4] event/dsw: add support for larger port count David Marchand
2024-10-14 15:08         ` [PATCH v2 0/4] Add bitset type David Marchand

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=0f81b9f3-8724-4bfb-bcd4-8d5c7c035d15@lysator.liu.se \
    --to=hofors@lysator.liu.se \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=fengchengwen@huawei.com \
    --cc=heng.wang@ericsson.com \
    --cc=jack.bond-preston@foss.arm.com \
    --cc=mattias.ronnblom@ericsson.com \
    --cc=mb@smartsharesystems.com \
    --cc=rjarry@redhat.com \
    --cc=roretzla@linux.microsoft.com \
    --cc=stephen@networkplumber.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).