From patchwork Tue Aug 23 15:53:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 12952434 X-Patchwork-Delegate: bpf@iogearbox.net 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 E96F1C32772 for ; Tue, 23 Aug 2022 17:53:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231608AbiHWRxf (ORCPT ); Tue, 23 Aug 2022 13:53:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233163AbiHWRws (ORCPT ); Tue, 23 Aug 2022 13:52:48 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC7CE6FA3C for ; Tue, 23 Aug 2022 08:54:25 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id v7-20020a1cac07000000b003a6062a4f81so9846321wme.1 for ; Tue, 23 Aug 2022 08:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=bkLmSlSilGFE1QJrhM8SiC5gWbFLHjcrAXY+jH31wms=; b=qxZST4kipaSZftXRzTnaR7laRUKswCCQF3JQ4elcqgtdpHUe0++m5alK0T1PtApuiA Slo+ZzFk3ZUdbA2B0WgbasnuF0xutN24hVG3aCKYBIGdaxxif/Ba3v2dfp+V8lU+DgJR dtDBS44C+xY+tfCaI5lWJMtFvoVqZHKfXndk7OrZyvs408m4GWjjWGTTakQseX2OM4JK mqwbw1GLGdTkgFyLEY0mcLblGLOy7wYoAi+0SObZ7nh9E4iu3mFd3box22xdCc0IXmi8 htCQCA3oDYogTl7uzBVHKqOsce6yRqHUtQrXAIJBfCCTAup4SgXaR7bbOTPqQzCfIFrz TMZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=bkLmSlSilGFE1QJrhM8SiC5gWbFLHjcrAXY+jH31wms=; b=WjXvi0NcVIwI7K9VmpkjfmTKMMRx2bXZ3W2vSDgrPIacnd1qkseqo9OvQsHWinOS23 aJoE2ecNPVzDZkIz2Hyvb/0vDydDcOeIonFftNCqCfmsFtPLEc+HD43FroqMPKPq5Cb/ FunibiG2/0JI4101cu7IUilvQ5cGGgC3Ic0gXL3nOv1Gd7lXQRsYNKMaHjmpICDimqvJ KeInYSzN+080Comu8MAHtO67Wr+JYQWhtcioqT43r9W/fBHz/BuidjLFnHm8rz4lH+1w osj8/CxDKdhH/dEjJpTHI11VrthBv1kLu/x68iOoAaYdB7xUKYyxaYcIpfRCTjgkRzWO g+NQ== X-Gm-Message-State: ACgBeo2jjuMGBLBEwCtGE9ZFYIAVmdFb9ge1xCCLW01np7okd2sIOaqW l/JY0DQNqw9Vu3ZFAYUbpP5Aew== X-Google-Smtp-Source: AA6agR7zgG0FfbmeTqsmhRtDnKN2jHC72LSYtoLOBfAA95BKXTvfIz9D8Zz2rse7og0A9hqNWTGDdw== X-Received: by 2002:a05:600c:1da3:b0:3a5:c1ea:cd98 with SMTP id p35-20020a05600c1da300b003a5c1eacd98mr2634716wms.174.1661270064255; Tue, 23 Aug 2022 08:54:24 -0700 (PDT) Received: from harfang.fritz.box ([51.155.200.13]) by smtp.gmail.com with ESMTPSA id m9-20020a7bce09000000b003a3442f1229sm21064089wmc.29.2022.08.23.08.54.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 08:54:23 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Quentin Monnet , Alejandro Colomar Subject: [PATCH bpf-next v2 1/2] scripts/bpf: Set version attribute for bpf-helpers(7) man page Date: Tue, 23 Aug 2022 16:53:26 +0100 Message-Id: <20220823155327.98888-1-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The bpf-helpers(7) manual page shipped in the man-pages project is generated from the documentation contained in the BPF UAPI header, in the Linux repository, parsed by script/bpf_doc.py and then fed to rst2man. After a recent update of that page [0], Alejandro reported that the linter used to validate the man pages complains about the generated document [1]. The header for the page is supposed to contain some attributes that we do not set correctly with the script. This commit updates the "project and version" field. We discussed the format of those fields in [1] and [2]. Before: $ ./scripts/bpf_doc.py helpers | rst2man | grep '\.TH' .TH BPF-HELPERS 7 "" "" "" After: $ ./scripts/bpf_doc.py helpers | rst2man | grep '\.TH' .TH BPF-HELPERS 7 "" "Linux v5.19-14022-g30d2a4d74e11" "" We get the version from "git describe", but if unavailable, we fall back on "make kernelversion". If none works, for example because neither git nore make are installed, we just set the field to "Linux" and keep generating the page. [0] https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/man7/bpf-helpers.7?id=19c7f78393f2b038e76099f87335ddf43a87f039 [1] https://lore.kernel.org/all/20220823084719.13613-1-quentin@isovalent.com/t/#m58a418a318642c6428e14ce9bb84eba5183b06e8 [2] https://lore.kernel.org/all/20220721110821.8240-1-alx.manpages@gmail.com/t/#m8e689a822e03f6e2530a0d6de9d128401916c5de Cc: Alejandro Colomar Reported-by: Alejandro Colomar Signed-off-by: Quentin Monnet Reviewed-by: Alejandro Colomar --- scripts/bpf_doc.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py index dfb260de17a8..061ad1dc3212 100755 --- a/scripts/bpf_doc.py +++ b/scripts/bpf_doc.py @@ -10,6 +10,8 @@ from __future__ import print_function import argparse import re import sys, os +import subprocess + class NoHelperFound(BaseException): pass @@ -357,6 +359,20 @@ class PrinterRST(Printer): print('') + def get_kernel_version(self): + try: + version = subprocess.run(['git', 'describe'], cwd=linuxRoot, + capture_output=True, check=True) + version = version.stdout.decode().rstrip() + except: + try: + version = subprocess.run(['make', 'kernelversion'], cwd=linuxRoot, + capture_output=True, check=True) + version = version.stdout.decode().rstrip() + except: + return 'Linux' + return 'Linux {version}'.format(version=version) + class PrinterHelpersRST(PrinterRST): """ A printer for dumping collected information about helpers as a ReStructured @@ -378,6 +394,7 @@ list of eBPF helper functions ------------------------------------------------------------------------------- :Manual section: 7 +:Version: {version} DESCRIPTION =========== @@ -410,8 +427,10 @@ kernel at the top). HELPERS ======= ''' + kernelVersion = self.get_kernel_version() + PrinterRST.print_license(self) - print(header) + print(header.format(version=kernelVersion)) def print_footer(self): footer = ''' From patchwork Tue Aug 23 15:53:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 12952435 X-Patchwork-Delegate: bpf@iogearbox.net 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 31554C3F6B0 for ; Tue, 23 Aug 2022 17:53:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231582AbiHWRxh (ORCPT ); Tue, 23 Aug 2022 13:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230461AbiHWRwt (ORCPT ); Tue, 23 Aug 2022 13:52:49 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB9D194ED0 for ; Tue, 23 Aug 2022 08:54:26 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id b5so13254883wrr.5 for ; Tue, 23 Aug 2022 08:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=vh52awskeItZOpUKkVy87rMrn/g3p6/h+Ynuvw85Drc=; b=FGlNFaSP6Q44C1G8G+/fYstGzueHBI4uWSGcULREFvyrlxCN3byNC8D9/V67qonRox tTrZyOvWWE9umOS5VloGOlccd0IxuCSfDnEp3f5Z9z8Ge5Edt49mVUUv2+AJSU9mDK9i AVA7DHlT7KyFlqJho8hWq4ikvSxoNv6nCPVsAsrAx8gj7oOt70sF2OfdatBsWrU5o9YY PCklo68zglCfb4BVB1tyA9BN2ZvjeDPMaOWZw3NYC0TychXgS+8Ia0pFlkptMq88DpH2 WSKYoNM+0TEWXhdG5BhliZ1QwJu7aLlO6abHUSIZ2gZk7lYzrZw3HhGL3dzI9TMoOjo1 9dTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=vh52awskeItZOpUKkVy87rMrn/g3p6/h+Ynuvw85Drc=; b=sARKzChVq8+ZM16tIN8tYt9fos8s34sYhnQk4quXKZ8qMqh6LHEU1DST4FIIM44gt6 TUmNeHz33SzAzSO2YtYJNULaIJcpeIV5RQG3mKJEzafV8a8nWQK+mA/PLmJ1qdspkQQe Zdx0hn1IFr4oyVcUVLERqPWcSR+E40G6DYBin4e/A9H/V9haqg1uV5p5lCA2Cg0a3r3N oMq9XXpIoMezoy1vrf6fKvMkCvx6v8KY0OvCtfr/4xOpI4ijSUXHYxAoK9Mc2Jl3DTrh hguDNpVPEI3aYJRILloRSq8jUY2ikFut35wSY1kJE4m4JnbVPhYWmi3IurQgpkZJkiUm AAlw== X-Gm-Message-State: ACgBeo0HAQKRPCDOxzM9FDvVA7vvUx9rvTYHkfCDnwnePdv2RJtwoYfx sVqWFo9dSvTRFVMgjdc6qhdG5g== X-Google-Smtp-Source: AA6agR4pqHVMP/UeG3qcaTFOE8u2w53BMA1ShU/x1NIWe9PEhl2SZQrMsViIgPZ9eKU0vnN2LkIjUg== X-Received: by 2002:a05:6000:1882:b0:221:b062:e578 with SMTP id a2-20020a056000188200b00221b062e578mr13402255wri.500.1661270065181; Tue, 23 Aug 2022 08:54:25 -0700 (PDT) Received: from harfang.fritz.box ([51.155.200.13]) by smtp.gmail.com with ESMTPSA id m9-20020a7bce09000000b003a3442f1229sm21064089wmc.29.2022.08.23.08.54.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 08:54:24 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Quentin Monnet , Alejandro Colomar Subject: [PATCH bpf-next v2 2/2] scripts/bpf: Set date attribute for bpf-helpers(7) man page Date: Tue, 23 Aug 2022 16:53:27 +0100 Message-Id: <20220823155327.98888-2-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220823155327.98888-1-quentin@isovalent.com> References: <20220823155327.98888-1-quentin@isovalent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The bpf-helpers(7) manual page shipped in the man-pages project is generated from the documentation contained in the BPF UAPI header, in the Linux repository, parsed by script/bpf_doc.py and then fed to rst2man. The man page should contain the date of last modification of the documentation. This commit adds the relevant date when generating the page. Before: $ ./scripts/bpf_doc.py helpers | rst2man | grep '\.TH' .TH BPF-HELPERS 7 "" "Linux v5.19-14022-g30d2a4d74e11" "" After: $ ./scripts/bpf_doc.py helpers | rst2man | grep '\.TH' .TH BPF-HELPERS 7 "2022-08-15" "Linux v5.19-14022-g30d2a4d74e11" "" We get the version by using "git log" to look for the commit date of the latest change to the section of the BPF header containing the documentation. If the command fails, we just skip the date field. and keep generating the page. Cc: Alejandro Colomar Reported-by: Alejandro Colomar Signed-off-by: Quentin Monnet Reviewed-by: Alejandro Colomar --- scripts/bpf_doc.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py index 061ad1dc3212..f4f3e7ec6d44 100755 --- a/scripts/bpf_doc.py +++ b/scripts/bpf_doc.py @@ -12,6 +12,7 @@ import re import sys, os import subprocess +helpersDocStart = 'Start of BPF helper function descriptions:' class NoHelperFound(BaseException): pass @@ -235,7 +236,7 @@ class HeaderParser(object): self.enum_syscalls = re.findall('(BPF\w+)+', bpf_cmd_str) def parse_desc_helpers(self): - self.seek_to('* Start of BPF helper function descriptions:', + self.seek_to(helpersDocStart, 'Could not find start of eBPF helper descriptions list') while True: try: @@ -373,6 +374,17 @@ class PrinterRST(Printer): return 'Linux' return 'Linux {version}'.format(version=version) + def get_last_doc_update(self, delimiter): + try: + cmd = ['git', 'log', '-1', '--pretty=format:%cs', '--no-patch', + '-L', + '/{}/,/\*\//:include/uapi/linux/bpf.h'.format(delimiter)] + date = subprocess.run(cmd, cwd=linuxRoot, + capture_output=True, check=True) + return date.stdout.decode().rstrip() + except: + return '' + class PrinterHelpersRST(PrinterRST): """ A printer for dumping collected information about helpers as a ReStructured @@ -395,6 +407,7 @@ list of eBPF helper functions :Manual section: 7 :Version: {version} +{date_field}{date} DESCRIPTION =========== @@ -428,9 +441,12 @@ HELPERS ======= ''' kernelVersion = self.get_kernel_version() + lastUpdate = self.get_last_doc_update(helpersDocStart) PrinterRST.print_license(self) - print(header.format(version=kernelVersion)) + print(header.format(version=kernelVersion, + date_field = ':Date: ' if lastUpdate else '', + date=lastUpdate)) def print_footer(self): footer = '''