Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1129938rdb; Fri, 1 Dec 2023 07:47:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFROK1y/HnDmcgg+67HtR/uPg81zwk0HAEQOOcdtUHuWsWlNx5qI6UuxXzehV/4vm53bQiW X-Received: by 2002:a05:6a20:d04d:b0:189:fd93:c969 with SMTP id hv13-20020a056a20d04d00b00189fd93c969mr33444779pzb.26.1701445625324; Fri, 01 Dec 2023 07:47:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701445625; cv=none; d=google.com; s=arc-20160816; b=pl0CBLGQy9AxZwOJl5moCOo/ajG1hHiHw//at0tfPa6NJLerIWxvXh2ct4dBWfzoUX 9d6RRBBE/EckjfqDdYgfWvCJt0UGC5gwGVTp8o8O5yL2xysIi0Sigxk39gvA9seFDkt0 4KGgdhDbBRM2r6ySSClTNjKdn7hPZZwo24PCWzdszLqtUYUqPO3XX0qTQuua0kzwd+qm oALECNDJW9WerHjvJQrM5XcI3UMastjAoJk/ffsTIG7fe8LJMsHmpgymVH4sy6LiYWWw OEcqTAhkhNpAyGaXspKoKQ67PW9170i1soaPHdtmQfwBRaTSGD2cDzdcGRcnd7KpO3Ld 2f2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=Ju0e9bhxfFKrVDGBd6wlWel0hwJujeGJDjh5JGs5sw0=; fh=mkXiQKetL8y8LhgX0UrjBSlYJeioBqZQNMlBaJyL15Y=; b=V2gDDx761uai1B/AzWCnCF3xlnldywxWI/+4RB6kM0zpjuyuVB0pFOL+kQJ+0HS9Wj XEbPpeN5xzb4dyEPetewk7GP2zCvv/2MvaD1zeisrdCb9Ms75NwssxR4LKYyO8fN7V6h pzvSgRv0cf97/9nQ0RdDssTn3CTLDQ/C0USMCna4RS+R7TIAYunMuFxP3bgRvZNwppB+ 9iyhtBUwNxaM4p/4QSkHblY/99ahNNPOcSWBXQ3ZoTUBzLYhfX3suEyU+3gC/tSVXX02 X67pysO50+E8nQohtOdZgrtSKmTF91VYPKrc2gjDAoMXwFwdRr3+UsTEpRUma/ZM2eny HH6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@iogearbox.net header.s=default2302 header.b=LW9AEKQH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=iogearbox.net Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id df9-20020a056a00470900b006cdd595606asi3278094pfb.392.2023.12.01.07.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 07:47:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@iogearbox.net header.s=default2302 header.b=LW9AEKQH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=iogearbox.net Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 70C608184A97; Fri, 1 Dec 2023 07:46:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbjLAPqe (ORCPT + 99 others); Fri, 1 Dec 2023 10:46:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229536AbjLAPqc (ORCPT ); Fri, 1 Dec 2023 10:46:32 -0500 Received: from www62.your-server.de (www62.your-server.de [213.133.104.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1967A194; Fri, 1 Dec 2023 07:46:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=iogearbox.net; s=default2302; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Ju0e9bhxfFKrVDGBd6wlWel0hwJujeGJDjh5JGs5sw0=; b=LW9AEKQHAe6noKePc7zb4PRH5a hEmImOySMLiJX+5dAlYVRQqNcxPuE3qUSVGFsrFvhEr4C8FQb9Lu1U5NhCDpxIOU/O6Z7mwclUjlz qO8PmZ611TeNybfTpbwEM9QCKN9sBoa8oktEhrMKOSzqGuMzAWTl2xl20KBFzVMg4lVwVOnfyiiSE NPndgckNLPpWdCJ2sjdbUkkysi/DoI3msjRE8Hr2/sEAA2TWborII+I8v0PJwsvvrGAjtjaO++wua Iy+aF9g3SDcDx1K7mVKqDvy+eB/S/Y6/JashfGiQ9IZR/oKqUqjjsqr0r2yVVrSkUaCavtTPBRMrx tCqNn3Bw==; Received: from sslproxy06.your-server.de ([78.46.172.3]) by www62.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r95ih-0008Ky-Uc; Fri, 01 Dec 2023 16:46:23 +0100 Received: from [85.1.206.226] (helo=linux.home) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r95ih-000Dhk-58; Fri, 01 Dec 2023 16:46:23 +0100 Subject: Re: [PATCH] scripts/bpf_doc: add __main__ judgement before main code To: Hu Haowen <2023002089@link.tyut.edu.cn>, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, martin.lau@linux.dev Cc: ast@kernel.org, andrii@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org References: <20231130145746.23621-1-2023002089@link.tyut.edu.cn> From: Daniel Borkmann Message-ID: Date: Fri, 1 Dec 2023 16:46:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20231130145746.23621-1-2023002089@link.tyut.edu.cn> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.103.10/27110/Fri Dec 1 09:44:56 2023) X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 01 Dec 2023 07:46:48 -0800 (PST) Hi Hu, On 11/30/23 3:57 PM, Hu Haowen wrote: > When doing Python programming it is a nice convention to insert the if > statement `if __name__ == "__main__":` before any main code that does > actual functionalities to ensure the code will be executed only as a > script rather than as an imported module. Hence attach the missing > judgement to bpf_doc.py. > > Signed-off-by: Hu Haowen <2023002089@link.tyut.edu.cn> Thanks for the patch. What's the concrete value of this one? Do you plan to distribute the bpf_docs.py outside of the kernel tree? If it's not needed feels somewhat too much churn/marginal value. > scripts/bpf_doc.py | 81 +++++++++++++++++++++++----------------------- > 1 file changed, 41 insertions(+), 40 deletions(-) > > diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py > index 61b7dddedc46..af2a87d97832 100755 > --- a/scripts/bpf_doc.py > +++ b/scripts/bpf_doc.py > @@ -851,43 +851,44 @@ class PrinterHelpers(Printer): > > ############################################################################### > > -# If script is launched from scripts/ from kernel tree and can access > -# ../include/uapi/linux/bpf.h, use it as a default name for the file to parse, > -# otherwise the --filename argument will be required from the command line. > -script = os.path.abspath(sys.argv[0]) > -linuxRoot = os.path.dirname(os.path.dirname(script)) > -bpfh = os.path.join(linuxRoot, 'include/uapi/linux/bpf.h') > - > -printers = { > - 'helpers': PrinterHelpersRST, > - 'syscall': PrinterSyscallRST, > -} > - > -argParser = argparse.ArgumentParser(description=""" > -Parse eBPF header file and generate documentation for the eBPF API. > -The RST-formatted output produced can be turned into a manual page with the > -rst2man utility. > -""") > -argParser.add_argument('--header', action='store_true', > - help='generate C header file') > -if (os.path.isfile(bpfh)): > - argParser.add_argument('--filename', help='path to include/uapi/linux/bpf.h', > - default=bpfh) > -else: > - argParser.add_argument('--filename', help='path to include/uapi/linux/bpf.h') > -argParser.add_argument('target', nargs='?', default='helpers', > - choices=printers.keys(), help='eBPF API target') > -args = argParser.parse_args() > - > -# Parse file. > -headerParser = HeaderParser(args.filename) > -headerParser.run() > - > -# Print formatted output to standard output. > -if args.header: > - if args.target != 'helpers': > - raise NotImplementedError('Only helpers header generation is supported') > - printer = PrinterHelpers(headerParser) > -else: > - printer = printers[args.target](headerParser) > -printer.print_all() > +if __name__ == "__main__": > + # If script is launched from scripts/ from kernel tree and can access > + # ../include/uapi/linux/bpf.h, use it as a default name for the file to parse, > + # otherwise the --filename argument will be required from the command line. > + script = os.path.abspath(sys.argv[0]) > + linuxRoot = os.path.dirname(os.path.dirname(script)) > + bpfh = os.path.join(linuxRoot, 'include/uapi/linux/bpf.h') > + > + printers = { > + 'helpers': PrinterHelpersRST, > + 'syscall': PrinterSyscallRST, > + } > + > + argParser = argparse.ArgumentParser(description=""" > + Parse eBPF header file and generate documentation for the eBPF API. > + The RST-formatted output produced can be turned into a manual page with the > + rst2man utility. > + """) > + argParser.add_argument('--header', action='store_true', > + help='generate C header file') > + if (os.path.isfile(bpfh)): > + argParser.add_argument('--filename', help='path to include/uapi/linux/bpf.h', > + default=bpfh) > + else: > + argParser.add_argument('--filename', help='path to include/uapi/linux/bpf.h') > + argParser.add_argument('target', nargs='?', default='helpers', > + choices=printers.keys(), help='eBPF API target') > + args = argParser.parse_args() > + > + # Parse file. > + headerParser = HeaderParser(args.filename) > + headerParser.run() > + > + # Print formatted output to standard output. > + if args.header: > + if args.target != 'helpers': > + raise NotImplementedError('Only helpers header generation is supported') > + printer = PrinterHelpers(headerParser) > + else: > + printer = printers[args.target](headerParser) > + printer.print_all() >