From nobody Tue Dec 16 12:21:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 293C5C4167B for ; Thu, 30 Nov 2023 14:59:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346137AbjK3O7c (ORCPT ); Thu, 30 Nov 2023 09:59:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232258AbjK3O72 (ORCPT ); Thu, 30 Nov 2023 09:59:28 -0500 Received: from mail-m155101.qiye.163.com (mail-m155101.qiye.163.com [101.71.155.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C32810F0 for ; Thu, 30 Nov 2023 06:59:34 -0800 (PST) Received: from localhost.localdomain (unknown [120.208.100.109]) by mail-m121145.qiye.163.com (Hmail) with ESMTPA id 5DF278000BB; Thu, 30 Nov 2023 22:57:59 +0800 (CST) From: Hu Haowen <2023002089@link.tyut.edu.cn> To: 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: Hu Haowen <2023002089@link.tyut.edu.cn>, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] scripts/bpf_doc: add __main__ judgement before main code Date: Thu, 30 Nov 2023 22:57:46 +0800 Message-Id: <20231130145746.23621-1-2023002089@link.tyut.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkZT0wYVk8fGElKTh1PQhgdTlUTARMWGhIXJBQOD1 lXWRgSC1lBWUpJS1VJS0NVSktLVUpLQllXWRYaDxIVHRRZQVlLVUtVS1VLWQY+ X-HM-Tid: 0a8c20bc9835b03akuuu5df278000bb X-HM-MType: 10 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NRw6Sjo6SDw*KBdIMxM9Lg8# HDhPCxxVSlVKTEtKSE5NSUNLTEpNVTMWGhIXVUlLSUhLS0lLQ0I7FxIVEFUPAg4PVR4fDlUYFUVZ V1kSC1lBWUpJS1VJS0NVSktLVUpLQllXWQgBWUFOT05MNwY+ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When doing Python programming it is a nice convention to insert the if statement `if __name__ =3D=3D "__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> --- 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): =20 ##########################################################################= ##### =20 -# 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 pa= rse, -# otherwise the --filename argument will be required from the command line. -script =3D os.path.abspath(sys.argv[0]) -linuxRoot =3D os.path.dirname(os.path.dirname(script)) -bpfh =3D os.path.join(linuxRoot, 'include/uapi/linux/bpf.h') - -printers =3D { - 'helpers': PrinterHelpersRST, - 'syscall': PrinterSyscallRST, -} - -argParser =3D argparse.ArgumentParser(description=3D""" -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=3D'store_true', - help=3D'generate C header file') -if (os.path.isfile(bpfh)): - argParser.add_argument('--filename', help=3D'path to include/uapi/linu= x/bpf.h', - default=3Dbpfh) -else: - argParser.add_argument('--filename', help=3D'path to include/uapi/linu= x/bpf.h') -argParser.add_argument('target', nargs=3D'?', default=3D'helpers', - choices=3Dprinters.keys(), help=3D'eBPF API target') -args =3D argParser.parse_args() - -# Parse file. -headerParser =3D HeaderParser(args.filename) -headerParser.run() - -# Print formatted output to standard output. -if args.header: - if args.target !=3D 'helpers': - raise NotImplementedError('Only helpers header generation is suppo= rted') - printer =3D PrinterHelpers(headerParser) -else: - printer =3D printers[args.target](headerParser) -printer.print_all() +if __name__ =3D=3D "__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 t= o parse, + # otherwise the --filename argument will be required from the command = line. + script =3D os.path.abspath(sys.argv[0]) + linuxRoot =3D os.path.dirname(os.path.dirname(script)) + bpfh =3D os.path.join(linuxRoot, 'include/uapi/linux/bpf.h') + + printers =3D { + 'helpers': PrinterHelpersRST, + 'syscall': PrinterSyscallRST, + } + + argParser =3D argparse.ArgumentParser(description=3D""" + Parse eBPF header file and generate documentation for the eBPF API. + The RST-formatted output produced can be turned into a manual page wit= h the + rst2man utility. + """) + argParser.add_argument('--header', action=3D'store_true', + help=3D'generate C header file') + if (os.path.isfile(bpfh)): + argParser.add_argument('--filename', help=3D'path to include/uapi/= linux/bpf.h', + default=3Dbpfh) + else: + argParser.add_argument('--filename', help=3D'path to include/uapi/= linux/bpf.h') + argParser.add_argument('target', nargs=3D'?', default=3D'helpers', + choices=3Dprinters.keys(), help=3D'eBPF API tar= get') + args =3D argParser.parse_args() + + # Parse file. + headerParser =3D HeaderParser(args.filename) + headerParser.run() + + # Print formatted output to standard output. + if args.header: + if args.target !=3D 'helpers': + raise NotImplementedError('Only helpers header generation is s= upported') + printer =3D PrinterHelpers(headerParser) + else: + printer =3D printers[args.target](headerParser) + printer.print_all() --=20 2.34.1