Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp365608rdb; Thu, 30 Nov 2023 06:59:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMnLa7B18ZdSJMZfy7kv9GeZUKw+uQSYzGLKA3CwuPNKmE71vCVzX0ce4RjNRaoslvpEGN X-Received: by 2002:a05:6a21:788e:b0:18a:fbd1:8e6d with SMTP id bf14-20020a056a21788e00b0018afbd18e6dmr23344038pzc.27.1701356389692; Thu, 30 Nov 2023 06:59:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701356389; cv=none; d=google.com; s=arc-20160816; b=bdWtHOZCzV/zvgNCPdXeD/kvA6Hk5KLHA4kKM5zq8/mE1oeZoNBucN4MoGs6CHPKvD zsSCbUNdvsomD9ZJDRw3+2p7CHw9Mgy+ifAXOmqF2tlJ5c7OaDzY0DCGWA4MIXhY9/Q8 IwPB2zTrBga3TRn9iHh8fbjLDUaXCNpJ2hDm2pHJ0WLV/REqXc2/16WWpcOK2+sLHS78 363YObsPBMZ4xiguUDQMIJcWGDeTLUE6Eurr3V6COdQ9GKEG/61kO6q4LK82CkyOr6Mo 3Qho07toxSSIwy0XJECz3YvURzpj9DFvBGFPazy6P5CubPen9isbhWh5OKpU2cdP/x/O TuRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=W8xLQxUSGPgwpoAgExVmjkcmKWKGxa7jn4alAsDWuXI=; fh=xQBmpL4YU/mE7N9K9C5M714xB4WQxfTC+wLwCxDOWyI=; b=VdeHPMDWoegZfP0eFZ488jfkv1jQ2rGeBxKJDs71fIDUjiNONPZcxlAflmYdSINEeX JvE4GFaxysKzxvhv0drs0T95BrOYZ8xbw7T2o5C6D7O/+7gE/ILS04AgiP4eh5SIcY9u +JTh4dD1VsrYFfM+9YdRWFf0LXWA2ygT/hol96VgS6BjwaNe/3oYhGMGanFlN7eRmuVH mM6P1yjnjWTo/O2+/rDZoOhFfnglDHerJgum67ZgnSmvgWhGs0QB/lq53j5+UUBEXE4S 29eW5s2CDEu3gDXgu8/E2E5ODcAC1Xse5f/bBLW2nWv4oH6kS3cd+uw0V4R1PtBssVtR dS9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=link.tyut.edu.cn Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s22-20020a056a0008d600b006c6930e7540si1416001pfu.121.2023.11.30.06.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 06:59:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=link.tyut.edu.cn Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 3130B80CBF02; Thu, 30 Nov 2023 06:59:47 -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 S235195AbjK3O7b (ORCPT + 99 others); Thu, 30 Nov 2023 09:59:31 -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: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkZT0wYVk8fGElKTh1PQhgdTlUTARMWGhIXJBQOD1 lXWRgSC1lBWUpJS1VJS0NVSktLVUpLQllXWRYaDxIVHRRZQVlLVUtVS1VLWQY+ X-HM-Tid: 0a8c20bc9835b03akuuu5df278000bb X-HM-MType: 10 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6NRw6Sjo6SDw*KBdIMxM9Lg8# HDhPCxxVSlVKTEtKSE5NSUNLTEpNVTMWGhIXVUlLSUhLS0lLQ0I7FxIVEFUPAg4PVR4fDlUYFUVZ V1kSC1lBWUpJS1VJS0NVSktLVUpLQllXWQgBWUFOT05MNwY+ X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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]); Thu, 30 Nov 2023 06:59:47 -0800 (PST) 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> --- 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() -- 2.34.1