From patchwork Thu Nov 9 10:33:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Zhijian Li (Fujitsu)\" via" X-Patchwork-Id: 13450918 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1DB26C4332F for ; Thu, 9 Nov 2023 10:34:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r12Lx-0007mf-9p; Thu, 09 Nov 2023 05:33:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r12Lr-0007mU-L5 for qemu-devel@nongnu.org; Thu, 09 Nov 2023 05:33:31 -0500 Received: from smtp-fw-52005.amazon.com ([52.119.213.156]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r12Lo-0000Hw-GA for qemu-devel@nongnu.org; Thu, 09 Nov 2023 05:33:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazon201209; t=1699526008; x=1731062008; h=from:to:cc:subject:date:message-id; bh=tcDArW6GaT5bPuyW9wNKJRfaOZKtro4EH2xj4rr/DEk=; b=IVsd9SFQ+cvKZMIc8GviGM070f3OF0w79EswDAzhRs0jqlsLueAYccXy 1nFUXavHPerGi1Neg3eMhqKRLNTHXw3r1ZXZCTKrctcSoXOFq3rXvMjr+ GmvkElmRtWtxtPLM7hedpZkPimjYEDscpp9EBi1fhY1TOiLVnOW7Cj5ox Q=; X-Amazon-filename: smime.p7s X-IronPort-AV: E=Sophos;i="6.03,289,1694736000"; d="p7s'?scan'208";a="615105358" MIME-Version: 1.0 Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-b5bd57cf.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-52005.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2023 10:33:23 +0000 Received: from smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1a-m6i4x-b5bd57cf.us-east-1.amazon.com (Postfix) with ESMTPS id 60FA848F30; Thu, 9 Nov 2023 10:33:23 +0000 (UTC) Received: from EX19MTAUEC001.ant.amazon.com [10.0.0.204:64094] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.5.237:2525] with esmtp (Farcaster) id 9b4a943d-222a-4a8c-860b-0232d51336ab; Thu, 9 Nov 2023 10:33:22 +0000 (UTC) X-Farcaster-Flow-ID: 9b4a943d-222a-4a8c-860b-0232d51336ab Received: from EX19D008UEC001.ant.amazon.com (10.252.135.232) by EX19MTAUEC001.ant.amazon.com (10.252.135.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Thu, 9 Nov 2023 10:33:22 +0000 Received: from EX19D008UEC001.ant.amazon.com (10.252.135.232) by EX19D008UEC001.ant.amazon.com (10.252.135.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.39; Thu, 9 Nov 2023 10:33:22 +0000 Received: from EX19D008UEC001.ant.amazon.com ([fe80::4702:5d1a:c556:797]) by EX19D008UEC001.ant.amazon.com ([fe80::4702:5d1a:c556:797%3]) with mapi id 15.02.1118.039; Thu, 9 Nov 2023 10:33:22 +0000 To: "peter.maydell@linaro.org" CC: "qemu-devel@nongnu.org" Subject: [PATCH] doc/sphinx/hxtool.py: add optional label argument to SRST directive Thread-Topic: [PATCH] doc/sphinx/hxtool.py: add optional label argument to SRST directive Thread-Index: AQHaEvgp4m9M2sagZ0+ecgeFrzq7mQ== Date: Thu, 9 Nov 2023 10:33:22 +0000 Message-ID: <7a25bd4ee1f8b06c7a51d20486aaa8bc8e1282ea.camel@amazon.co.uk> Accept-Language: en-GB, en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-originating-ip: [10.106.82.23] MIME-Version: 1.0 Precedence: Bulk Received-SPF: pass client-ip=52.119.213.156; envelope-from=prvs=670a93ad5=dwmw@amazon.co.uk; helo=smtp-fw-52005.amazon.com X-Spam_score_int: -118 X-Spam_score: -11.9 X-Spam_bar: ----------- X-Spam_report: (-11.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: "Woodhouse, David" X-Patchwork-Original-From: "Woodhouse, David" via From: "Zhijian Li (Fujitsu)\" via" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We can't just embed labels directly into files like qemu-options.hx which are included from multiple top-level RST files, because Sphinx sees the labels as duplicate: https://github.com/sphinx-doc/sphinx/issues/9707 So add an 'emitrefs' option to the Sphinx hxtool-doc directive, which is set only in invocation.rst and not from the HTML rendition of the man page. Along with an argument to the SRST directive which causes a label of the form '.. _LABEL-reference-label:' to be emitted when the emitrefs option is set. Now where the Xen PV documentation refers to the documentation for the -initrd command line option, it can emit a link directly to it. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- https://qemu-project.gitlab.io/qemu/system/i386/xen.html tells the user to "see the command line documentation for the -initrd option". It'd be a whole lot nicer if we could *link* to it. It actually worked on my test box, but only because I'm using an older version of Sphinx which didn't complain about the duplicate refs, and just picked *one* to link to.  docs/sphinx/hxtool.py      | 18 +++++++++++++++++-  docs/system/i386/xen.rst   |  2 +-  docs/system/invocation.rst |  1 +  qemu-options.hx            |  2 +-  4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/sphinx/hxtool.py b/docs/sphinx/hxtool.py index 9f6b9d87dc..bfb0929573 100644 --- a/docs/sphinx/hxtool.py +++ b/docs/sphinx/hxtool.py @@ -78,18 +78,28 @@ def parse_archheading(file, lnum, line):          serror(file, lnum, "Invalid ARCHHEADING line")      return match.group(1)   +def parse_srst(file, lnum, line): +    """Handle an SRST directive""" +    # The input should be "SRST(label)". +    match = re.match(r'SRST\((.*?)\)', line) +    if match is None: +        serror(file, lnum, "Invalid SRST line") +    return match.group(1) +  class HxtoolDocDirective(Directive):      """Extract rST fragments from the specified .hx file"""      required_argument = 1      optional_arguments = 1      option_spec = { -        'hxfile': directives.unchanged_required +        'hxfile': directives.unchanged_required, +        'emitrefs': directives.flag      }      has_content = False        def run(self):          env = self.state.document.settings.env          hxfile = env.config.hxtool_srctree + '/' + self.arguments[0] +        emitrefs = "emitrefs" in self.options            # Tell sphinx of the dependency          env.note_dependency(os.path.abspath(hxfile)) @@ -113,6 +123,12 @@ def run(self):                          serror(hxfile, lnum, 'expected ERST, found SRST')                      else:                          state = HxState.RST +                        if emitrefs and line != "SRST": +                            label = parse_srst(hxfile, lnum, line) +                            if label != "": +                                rstlist.append("", hxfile, lnum - 1) +                                refline = ".. _" + label + "-reference-label:" +                                rstlist.append(refline, hxfile, lnum - 1)                  elif directive == 'ERST':                      if state == HxState.CTEXT:                          serror(hxfile, lnum, 'expected SRST, found ERST') diff --git a/docs/system/i386/xen.rst b/docs/system/i386/xen.rst index 81898768ba..536dd6a2f9 100644 --- a/docs/system/i386/xen.rst +++ b/docs/system/i386/xen.rst @@ -132,7 +132,7 @@ The example above provides the guest kernel command line after a separator  (" ``--`` ") on the Xen command line, and does not provide the guest kernel  with an actual initramfs, which would need to listed as a second multiboot  module. For more complicated alternatives, see the command line -documentation for the ``-initrd`` option. +:ref:`documentation ` for the ``-initrd`` option.    Host OS requirements  -------------------- diff --git a/docs/system/invocation.rst b/docs/system/invocation.rst index 4ba38fc23d..ef75dad2e2 100644 --- a/docs/system/invocation.rst +++ b/docs/system/invocation.rst @@ -11,6 +11,7 @@ disk_image is a raw hard disk image for IDE hard disk 0. Some targets do  not need a disk image.    .. hxtool-doc:: qemu-options.hx +    :emitrefs:    Device URL Syntax  ~~~~~~~~~~~~~~~~~ diff --git a/qemu-options.hx b/qemu-options.hx index 42fd09e4de..464e7257b0 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3987,7 +3987,7 @@ ERST    DEF("initrd", HAS_ARG, QEMU_OPTION_initrd, \             "-initrd file    use 'file' as initial ram disk\n", QEMU_ARCH_ALL) -SRST +SRST(initrd)    ``-initrd file``      Use file as initial ram disk.