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 E7FB145AAC; Fri, 4 Oct 2024 10:05:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D0BF14027F; Fri, 4 Oct 2024 10:05:59 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 5EA4A40268 for ; Fri, 4 Oct 2024 10:05:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728029157; 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=JQZjWplsTHlk9dukcYjrIx3iH+8GRUsSx29D+DCHYac=; b=ikGIQ46EDtLnJzI17kURq4lCEvrxjNSILSpaUjQ1yjAk0trVTufzipJO6k8Sjth2f7OTzZ 8HW+Wb7pDRVKn6C0LX50p1h+/LQGLh7t3XmMmHv+OtfTxLhxgWeUJ2h+BcjSbR5Wz7qxOP HA9Yj/LrRDKQphkAYDlqz8HgS5xXMAU= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563--YGEOfk3Ot-IIBUUDmO7qQ-1; Fri, 04 Oct 2024 04:05:56 -0400 X-MC-Unique: -YGEOfk3Ot-IIBUUDmO7qQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-37ccd7c3080so765143f8f.3 for ; Fri, 04 Oct 2024 01:05:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728029155; x=1728633955; h=in-reply-to:references:user-agent:subject:to:from:cc:message-id :date:content-transfer-encoding:mime-version:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=JQZjWplsTHlk9dukcYjrIx3iH+8GRUsSx29D+DCHYac=; b=t+bs982OLjH9Il9YsBR58075kxGe++yzn0bz1LSJpoegLBO/met6IkZR8XpH1MbC3v mxzNmcCY1+g4GVewCvSmmT0mGqcM4cLLC5a8owdAWIs0jTvZjdG9veCcFdc+pMbresJt i+tsxTRjQdE7utD8wRN/du4IcFxvGOTYAB563wGTa5tYmOjPnIf+PsBTq6qG6A/RSWMb Tl+UwDqr2/VhZYaOLD4700XkKNiuvUGPwdDX9RtihVs9XXtHgqv3q6008nl0bwbW6wAb PAwIuBgiE19YuLdGAWEYGYFdoT6Ja2batgdo53v3iFXa++Y2FxP8QGJyVwt4LMVUfXKy W2cQ== X-Forwarded-Encrypted: i=1; AJvYcCVryNrZuUsxosfsmRB5aTAHF73wXvSDMoW7OoSJsAPiO9Bpi15TLPNOE2ZSEk+ILGSaasg=@dpdk.org X-Gm-Message-State: AOJu0YwevREfF4EPYM0mjb1bdFB3ucIYOUmqWMOcLx11KReBl/qc8hfg 0ty+fVIHH1MFn32l+f275l+HW58psut18Knf1WzzUhFLELqCE+k0QekgN7P5kRfCzDlixuCbyRT BUEXNNHrnlr50G5nth1dqT66Vh37ZVwnftVPp8dm0 X-Received: by 2002:a5d:64e7:0:b0:378:8dea:4bee with SMTP id ffacd0b85a97d-37d0e75d534mr1334940f8f.33.1728029155049; Fri, 04 Oct 2024 01:05:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1TSclZx85oymkdyjQjHY/0MXyPFSWaBmHUngpuVma3Tt/C3X0igkde5yt6y6Z482ah39maw== X-Received: by 2002:a5d:64e7:0:b0:378:8dea:4bee with SMTP id ffacd0b85a97d-37d0e75d534mr1334914f8f.33.1728029154531; Fri, 04 Oct 2024 01:05:54 -0700 (PDT) Received: from localhost (2a01cb00025433006239e1f47a0b2371.ipv6.abo.wanadoo.fr. [2a01:cb00:254:3300:6239:e1f4:7a0b:2371]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d08216564sm2735369f8f.35.2024.10.04.01.05.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Oct 2024 01:05:54 -0700 (PDT) Mime-Version: 1.0 Date: Fri, 04 Oct 2024 10:05:53 +0200 Message-Id: Cc: "Heng Wang" , "Stephen Hemminger" , "Tyler Retzlaff" , =?utf-8?q?Morten_Br=C3=B8rup?= , "Jack Bond-Preston" , "David Marchand" , "Chengwen Feng" 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 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> In-Reply-To: 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 04, 2024 at 09:31: > On 2024-10-03 18:47, Robin Jarry wrote: >>> +def chk_missing(filename): >>> +=C2=A0=C2=A0=C2=A0 header =3D open(filename).read() >>=20 >> with open(filename) as f: >> =C2=A0=C2=A0 header =3D f.read() >>=20 > > What benefit would that construct be to this program? open(filename).read() leaks open file descriptors. This construct=20 ensures the file is closed after reading is complete. I understand that this script isn't mission critical, but let's avoid=20 leaving bad examples in the code that others may follow by accident :) >> I know it is a simple python script but it would be better to add a=20 >> proper main() function and use argparse to handle errors. E.g.: >>=20 >> def main(): >> =C2=A0=C2=A0 parser =3D argparse.ArgumentParser(description=3D__doc__) >> =C2=A0=C2=A0 parser.add_argument("op", choices=3D("missing", "redundant= ")) >> =C2=A0=C2=A0 parser.add_argument("headers", nargs=3D"+") >> =C2=A0=C2=A0 args =3D parser.parse_args() >>=20 >> =C2=A0=C2=A0 for h in args.headers: >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if op =3D=3D "missing": >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 chk_missin= g(h) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 elif op =3D=3D "redundant": >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 chk_redund= ant(h) >>=20 >> if __name__ =3D=3D "__main__": >> =C2=A0=C2=A0 main() >>=20 >>=20 > > I don't think you need to bring in the usual Python boiler plate. This=20 > script is not supposed to be invoked directly by a user - it's just an=20 > extension of the meson build scripts. Same as above, I know it is not a user facing script. But I think it=20 would be much better to write proper python code to have good examples=20 for newcomers to follow. >>> diff --git a/buildtools/chkincs/meson.build b/buildtools/chkincs/=20 >>> meson.build >>> index f2dadcae18..762f85efe5 100644 >>> --- a/buildtools/chkincs/meson.build >>> +++ b/buildtools/chkincs/meson.build >>> @@ -38,13 +38,13 @@ if not add_languages('cpp', required: false) >>> =C2=A0endif >>> >>> =C2=A0# check for extern C in files, since this is not detected as an e= rror=20 >>> by the compiler >>> -grep =3D find_program('grep', required: false) >>> -if grep.found() >>> -=C2=A0=C2=A0=C2=A0 errlist =3D run_command([grep, '--files-without-mat= ch', '^extern=20 >>> "C"', dpdk_chkinc_headers], >>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 che= ck: false, capture: true).stdout().split() >>> -=C2=A0=C2=A0=C2=A0 if errlist !=3D [] >>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error('Files missing C++ \'= extern "C"\' guards:\n- ' + '\n-=20 >>> '.join(errlist)) >>> -=C2=A0=C2=A0=C2=A0 endif >>> +chkextern =3D find_program('chkextern.py') >>> + >>> +missing_extern_headers =3D run_command(chkextern, 'missing',=20 >>> dpdk_chkinc_headers, >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 capture: true, check: true).stdout().sp= lit() >>> + >>> +if missing_extern_headers !=3D [] >>> +=C2=A0=C2=A0=C2=A0 error('Files missing C++ \'extern "C"\' guards:\n- = ' + '\n-=20 >>> '.join(missing_extern_headers)) >>=20 >> Instead of just relying on this script output, it would be better if it= =20 >> exited with a non-zero status when something is wrong. That way you=20 >> would not have to capture stdout at all and you could leave meson do the= =20 >> work. >>=20 > > Sure, but it would be required to invoke the script for every header=20 > file in the tree. Not sure I think that would be a net gain. You can store a global exit status in the script and process all headers=20 before exiting with an error if any. > Thanks for the review. > >>> =C2=A0endif >>> >>> =C2=A0gen_cpp_files =3D generator(gen_c_file_for_header, >>> --=20 >>> 2.43.0 >>=20