From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 585E345AC8; Sun, 6 Oct 2024 17:58:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1FCC1402C3; Sun, 6 Oct 2024 17:58:12 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id BFF114025D for ; Sun, 6 Oct 2024 17:58:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728230290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=96E7Z/FgR4HEaDw3SCQPO/e+N7R/1b5RT9mn+aDlfZ0=; b=Z+Vb8lavWnx1w1YaxnY8T6zrgqp6qHYSb217pI774cxhylKcsGBz7ZjxVN7Su3fSmj0zhH HvN05eJzDbVsfttsFIqlyQEGkVlG5V6T7HsdPXx77XM6LhFqlVjd5GHC4hi/ny5jgSzJua 3RC024vDNlOoczVF79BDis9/fivznHc= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-284-iLMMYGC3P7yt1VvAiqJnNA-1; Sun, 06 Oct 2024 11:58:09 -0400 X-MC-Unique: iLMMYGC3P7yt1VvAiqJnNA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-42cb89fbb8bso22220855e9.3 for ; Sun, 06 Oct 2024 08:58:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728230288; x=1728835088; h=in-reply-to:references:user-agent:cc:subject:to:from:message-id :date:content-transfer-encoding:mime-version:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=96E7Z/FgR4HEaDw3SCQPO/e+N7R/1b5RT9mn+aDlfZ0=; b=tLdoybSfIPDOrxw1VIbkkY/eklpSH21OU9qN0fpyF9Z/bUS5G/9p6snOYxzmGhGgXt N6JsIGUspQdEvp3FFH8MOy6ReL8r0z2N3Q8B4pgr++8dtAeUs/TWH69wFcFr27Cbr6C+ dsi7MNgHe2b9yKf9UGbeBw7mILecq6MKmbCRfQOULfC2EDXh2CC4QYLOI954PL8+Hd8c dS8tblj9xebuxgpz/+s8okbvq01RY6tCt53YQ/9jCQ69CZEIlcpKmb8OzsZ5v6hmzDCQ wMerqxmfeYgaVFIIsTtTXX6d5WQ3PSjEJv0Kl+zYi3Wf2XYuVSqESzx01O8vRPesTekV Oukg== X-Forwarded-Encrypted: i=1; AJvYcCVN5mtUyYVwNG2/d3wA0DMXMGHETAE15E/CAaWzaPFhoDrfq63gLYLGZC+x7ZDpPrLO2r0=@dpdk.org X-Gm-Message-State: AOJu0YwHeKbjQbIn0mgUY/4pWQcnycFxPtUfEvhzvCF2bTJscZcgPzCb G6mizxpynuuBuMC9Aowj4X09EEB21xiKY83Qr49RZBsGa8IR2aGSSo0MahyirlZNZMTx+D973yv WayNT9wrEc+HhPHN+h1NFlSeHT7Asj6u69PslUPyJ X-Received: by 2002:a5d:5492:0:b0:374:c8d1:70be with SMTP id ffacd0b85a97d-37d0eafa40cmr3695811f8f.38.1728230287764; Sun, 06 Oct 2024 08:58:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnN834te+7opylkh8sH2Xy95TqOKqi5aRhznUD3fLrit8KK5IsZizE3wjg4dILZO9k2eC7QQ== X-Received: by 2002:a5d:5492:0:b0:374:c8d1:70be with SMTP id ffacd0b85a97d-37d0eafa40cmr3695805f8f.38.1728230287328; Sun, 06 Oct 2024 08:58:07 -0700 (PDT) Received: from localhost (2a01cb00025433001b9f807167cdbf20.ipv6.abo.wanadoo.fr. [2a01:cb00:254:3300:1b9f:8071:67cd:bf20]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42f86b4abadsm67560515e9.46.2024.10.06.08.58.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Oct 2024 08:58:06 -0700 (PDT) Mime-Version: 1.0 Date: Sun, 06 Oct 2024 17:58:05 +0200 Message-Id: From: "Robin Jarry" To: =?utf-8?q?Mattias_R=C3=B6nnblom?= , =?utf-8?q?Mattias_R=C3=B6nnblom?= , Subject: Re: [PATCH v12 1/7] buildtools/chkincs: relax C linkage requirement Cc: "Heng Wang" , "Stephen Hemminger" , "Tyler Retzlaff" , =?utf-8?q?Morten_Br=C3=B8rup?= , "Jack Bond-Preston" , "David Marchand" , "Chengwen Feng" User-Agent: aerc/0.18.2-74-g7e4ac1a5f54c References: <20240920062437.738706-2-mattias.ronnblom@ericsson.com> <20240920104754.739033-1-mattias.ronnblom@ericsson.com> <20240920104754.739033-2-mattias.ronnblom@ericsson.com> <74e86a66-4341-465d-bcba-d76db66035cd@lysator.liu.se> <722ddf9d-29ed-4d3b-bc54-ac2aafefd2bb@lysator.liu.se> <6fd9040d-d923-42e2-8eab-b7ad5e48e28c@lysator.liu.se> <2ee279b5-910f-4428-84e0-6a14dd4dfd5c@lysator.liu.se> In-Reply-To: <2ee279b5-910f-4428-84e0-6a14dd4dfd5c@lysator.liu.se> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8; format=Flowed X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Mattias R=C3=B6nnblom, Oct 06, 2024 at 16:17: >> I think you need to change run_command() to custom_target(). I was=20 >> thinking of this patch to be much simpler as follows: > > I started off with a shell script, but I switched to Python when I=20 > wanted to strip off comments. (Not that that can't be done in bourne shel= l.) > > The below script doesn't strip off comments, and provides no usage=20 > information. Earlier I got the impression you wanted to improve=20 > command-line usage. > > I think we need to decide if this thing is an integral part of the build= =20 > system, custom-made for its needs, or if its something that should also= =20 > 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=20 the script cannot use the standard python tools to parse arguments. Here=20 is what I came up with. It is shorter, strips comments and deals with=20 arguments in a simpler way. We don't need to pass the "missing" or=20 "redundant" operation to the script, it can figure out what to do on its=20 own (see inline comment in main()): diff --git a/buildtools/chkincs/check_extern_c.py b/buildtools/chkincs/chec= k_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 =3D re.compile(r'^extern\s+"C"', re.MULTILINE) +CPP_LINE_COMMENT_RE =3D re.compile(r"//.*$", re.MULTILINE) +C_BLOCK_COMMENT_RE =3D re.compile(r"/\*.+?\*/", re.DOTALL) +C_SYMBOL_RE =3D [ + # 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 =3D 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 =3D argparse.ArgumentParser(description=3D__doc__) + parser.add_argument("headers", nargs=3D"+") + args =3D parser.parse_args() + + ret =3D 0 + + for h in args.headers: + with open(h) as f: + buf =3D f.read() + + buf =3D strip_comments(buf) + + if has_c_symbols(buf): + if not EXTERN_C_RE.search(buf): + print('error: missing extern "C" in', h) + ret =3D 1 + # Uncomment next block once all extraneous extern "C" have been re= moved + #else: + # if EXTERN_C_RE.search(buf): + # print('error: extraneous extern "C" in', h) + # ret =3D 1 + + return ret + + +if __name__ =3D=3D "__main__": + sys.exit(main()) diff --git a/buildtools/chkincs/meson.build b/buildtools/chkincs/meson.buil= d 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 =20 # check for extern C in files, since this is not detected as an error by t= he compiler -grep =3D find_program('grep', required: false) -if grep.found() - errlist =3D run_command([grep, '--files-without-match', '^extern "C"',= dpdk_chkinc_headers], - check: false, capture: true).stdout().split() - if errlist !=3D [] - 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) =20 gen_cpp_files =3D generator(gen_c_file_for_header, output: '@BASENAME@.cpp',