tools/docs: sphinx-build-wrapper: avoid spurious rust docs generation
Subsystems (2)
cover tools/docs: sphinx-build-wrapper: avoid spurious rust docs generation
Currently the rust docs are generated for each entry of SPHINXDIRS, even those not mentioning the rust directory.
Only generate the rust docs only once and only when requested.
---
Thomas Weißschuh (4):
tools/docs: sphinx-build-wrapper: generate rust docs only once tools/docs: sphinx-build-wrapper: make 'rustdoc' a local variable tools/docs: sphinx-build-wrapper: compute sphinxdirs_list earlier tools/docs: sphinx-build-wrapper: only generate rust docs when requested
tools/docs/sphinx-build-wrapper | 80 +++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 39 deletions(-)
---
base-commit: e1a8301cd941b8029893500e6857d7978873483f
change-id: 20260117-docs-spurious-rust-8ffa2748925c
Best regards,
Signature · 1 line
Thomas Weißschuh <[email protected]>
PATCH 1/4 tools/docs: sphinx-build-wrapper: generate rust docs only once
Currently the rust docs are generated for each entry in SPHINXDIRS. This is unnecessary as they will be the same for each one.
Move the generation, so it is executed only once.
--- tools/docs/sphinx-build-wrapper | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
tools/docs/sphinx-build-wrapper +17 -17
@@ -352,23 +352,6 @@ class SphinxBuilder: except (OSError, IOError) as e: print(f"Warning: Failed to copy CSS: {e}", file=sys.stderr) - if self.rustdoc: - print("Building rust docs") - if "MAKE" in self.env: - cmd = [self.env["MAKE"]] - else: - cmd = ["make", "LLVM=1"] - - cmd += [ "rustdoc"] - if self.verbose: - print(" ".join(cmd)) - - try: - subprocess.run(cmd, check=True) - except subprocess.CalledProcessError as e: - print(f"Ignored errors when building rustdoc: {e}. Is RUST enabled?", - file=sys.stderr) - def build_pdf_file(self, latex_cmd, from_dir, path): """Builds a single pdf file using latex_cmd""" try:
@@ -786,6 +769,23 @@ class SphinxBuilder: elif target == "infodocs": self.handle_info(output_dirs) + if self.rustdoc and target in ["htmldocs", "epubdocs"]: + print("Building rust docs") + if "MAKE" in self.env: + cmd = [self.env["MAKE"]] + else: + cmd = ["make", "LLVM=1"] + + cmd += [ "rustdoc"] + if self.verbose: + print(" ".join(cmd)) + + try: + subprocess.run(cmd, check=True) + except subprocess.CalledProcessError as e: + print(f"Ignored errors when building rustdoc: {e}. Is RUST enabled?", + file=sys.stderr) + def jobs_type(value): """ Handle valid values for -j. Accepts Sphinx "-jauto", plus a number
Signature · 1 line
2.52.0
PATCH 2/4 tools/docs: sphinx-build-wrapper: make 'rustdoc' a local variable
In reply to Thomas WeißschuhAll users of this variable are now in the same method.
Demote the instance variable to a local one.
--- tools/docs/sphinx-build-wrapper | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
tools/docs/sphinx-build-wrapper +8 -9
@@ -123,12 +123,10 @@ class SphinxBuilder: """ Checks if Rust is enabled """ - self.rustdoc = False - config = os.path.join(self.srctree, ".config") if not os.path.isfile(config): - return + return False re_rust = re.compile(r"CONFIG_RUST=(m|y)")
@@ -136,11 +134,13 @@ class SphinxBuilder: with open(config, "r", encoding="utf-8") as fp: for line in fp: if re_rust.match(line): - self.rustdoc = True - return + return True except OSError as e: print(f"Failed to open {config}", file=sys.stderr) + return False + + return False def get_sphinx_extra_opts(self, n_jobs): """
@@ -259,8 +259,6 @@ class SphinxBuilder: self.get_sphinx_extra_opts(n_jobs) - self.check_rust() - # # If venv command line argument is specified, run Sphinx from venv #
@@ -680,7 +678,8 @@ class SphinxBuilder: args.extend(["-D", f"latex_elements.papersize={paper}paper"]) - if self.rustdoc: + rustdoc = self.check_rust() + if rustdoc: args.extend(["-t", "rustdoc"]) if not sphinxdirs:
@@ -769,7 +768,7 @@ class SphinxBuilder: elif target == "infodocs": self.handle_info(output_dirs) - if self.rustdoc and target in ["htmldocs", "epubdocs"]: + if rustdoc and target in ["htmldocs", "epubdocs"]: print("Building rust docs") if "MAKE" in self.env: cmd = [self.env["MAKE"]]
Signature · 1 line
2.52.0
PATCH 3/4 tools/docs: sphinx-build-wrapper: compute sphinxdirs_list earlier
In reply to Thomas WeißschuhAn upcoming patch will require sphinxdirs_list to be available before the call to check_rust().
Move it up in the function.
--- tools/docs/sphinx-build-wrapper | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
tools/docs/sphinx-build-wrapper +13 -13
@@ -670,6 +670,19 @@ class SphinxBuilder: if kerneldoc.startswith(self.srctree): kerneldoc = os.path.relpath(kerneldoc, self.srctree) + if not sphinxdirs: + sphinxdirs = os.environ.get("SPHINXDIRS", ".") + + # + # sphinxdirs can be a list or a whitespace-separated string + # + sphinxdirs_list = [] + for sphinxdir in sphinxdirs: + if isinstance(sphinxdir, list): + sphinxdirs_list += sphinxdir + else: + sphinxdirs_list += sphinxdir.split() + args = [ "-b", builder, "-c", docs_dir ] if builder == "latex":
@@ -682,9 +695,6 @@ class SphinxBuilder: if rustdoc: args.extend(["-t", "rustdoc"]) - if not sphinxdirs: - sphinxdirs = os.environ.get("SPHINXDIRS", ".") - # # The sphinx-build tool has a bug: internally, it tries to set # locale with locale.setlocale(locale.LC_ALL, ''). This causes a
@@ -695,16 +705,6 @@ class SphinxBuilder: except locale.Error: self.env["LC_ALL"] = "C" - # - # sphinxdirs can be a list or a whitespace-separated string - # - sphinxdirs_list = [] - for sphinxdir in sphinxdirs: - if isinstance(sphinxdir, list): - sphinxdirs_list += sphinxdir - else: - sphinxdirs_list += sphinxdir.split() - # # Step 1: Build each directory in separate. #
Signature · 1 line
2.52.0
PATCH 4/4 tools/docs: sphinx-build-wrapper: only generate rust docs when requested
In reply to Thomas WeißschuhWhen the user explicitly specifies SPHINXDIRS to build a specific subdirectory it is unexpected that the rust docs are also generated. Especially as their generation may dominate the execution time.
Only generate the rust docs when they are part of the SPHINXDIRS requested by the user. 'rust/rustdocs' is not considered, as it is not a valid SPHINXDIRS anyways.
--- tools/docs/sphinx-build-wrapper | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/docs/sphinx-build-wrapper +5 -2
@@ -119,12 +119,15 @@ class SphinxBuilder: return path - def check_rust(self): + def check_rust(self, sphinxdirs): """ Checks if Rust is enabled """ config = os.path.join(self.srctree, ".config") + if not {'.', 'rust'}.intersection(sphinxdirs): + return False + if not os.path.isfile(config): return False
@@ -691,7 +694,7 @@ class SphinxBuilder: args.extend(["-D", f"latex_elements.papersize={paper}paper"]) - rustdoc = self.check_rust() + rustdoc = self.check_rust(sphinxdirs_list) if rustdoc: args.extend(["-t", "rustdoc"])
Signature · 1 line
2.52.0
Quoted 13 lines · On Sun, 18 Jan 2026 00:26:20 +0100 Thomas Weißschuh <[email protected]>…
Currently the rust docs are generated for each entry of SPHINXDIRS, even those not mentioning the rust directory.
Only generate the rust docs only once and only when requested.
Signed-off-by Thomas Weißschuh <[email protected]>---
Thomas Weißschuh (4):
tools/docs: sphinx-build-wrapper: generate rust docs only oncetools/docs: sphinx-build-wrapper: make 'rustdoc' a local variabletools/docs: sphinx-build-wrapper: computesphinxdirs_listearliertools/docs: sphinx-build-wrapper: only generate rust docs when requested
Quoted 2 lines
tools/docs/sphinx-build-wrapper | 80 +++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 39 deletions(-)
Patches in this series look ok. Code reviewed and I also did some tests, and all LGTM.
So, for this series:
[mchehab: tested building with and without config RUST, doing
a full build and also passing --sphinxdirs rust peci and just --sphinxdirs rust]
Thanks,
Mauro
Quoted 13 lines · Thomas Weißschuh
Currently the rust docs are generated for each entry of SPHINXDIRS, even those not mentioning the rust directory.
Only generate the rust docs only once and only when requested.
Signed-off-by Thomas Weißschuh <[email protected]>---
Thomas Weißschuh (4):
tools/docs: sphinx-build-wrapper: generate rust docs only oncetools/docs: sphinx-build-wrapper: make 'rustdoc' a local variabletools/docs: sphinx-build-wrapper: computesphinxdirs_listearliertools/docs: sphinx-build-wrapper: only generate rust docs when requested
Quoted 2 lines
tools/docs/sphinx-build-wrapper | 80 +++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 39 deletions(-)
Applied, thanks.
jon