Skip to content

Commit 464257b

Browse files
mchehabJonathan Corbet
authored andcommitted
docs: makefile: move rustdoc check to the build wrapper
The makefile logic to detect if rust is enabled is not working the way it was expected: instead of using the current setup for CONFIG_RUST, it uses a cached version from a previous build. The root cause is that the current logic inside docs/Makefile uses a cached version of CONFIG_RUST, from the last time a non documentation target was executed. That's perfectly fine for Sphinx build, as it doesn't need to read or depend on any CONFIG_*. So, instead of relying at the cache, move the logic to the wrapper script and let it check the current content of .config, to verify if CONFIG_RUST was selected. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Message-ID: <c06b1834ef02099735c13ee1109fa2a2b9e47795.1763722971.git.mchehab+huawei@kernel.org>
1 parent b9a565b commit 464257b

2 files changed

Lines changed: 32 additions & 15 deletions

File tree

Documentation/Makefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ FONTS_CONF_DENY_VF ?= $(HOME)/deny-vf
4242
# User-friendly check for sphinx-build
4343
HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi)
4444

45-
ifneq ($(wildcard $(srctree)/.config),)
46-
ifeq ($(CONFIG_RUST),y)
47-
RUSTDOC=--rustdoc
48-
endif
49-
endif
50-
5145
ifeq ($(HAVE_SPHINX),0)
5246

5347
.DEFAULT:

tools/docs/sphinx-build-wrapper

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,29 @@ class SphinxBuilder:
119119

120120
return path
121121

122+
def check_rust(self):
123+
"""
124+
Checks if Rust is enabled
125+
"""
126+
self.rustdoc = False
127+
128+
config = os.path.join(self.srctree, ".config")
129+
130+
if not os.path.isfile(config):
131+
return
132+
133+
re_rust = re.compile(r"CONFIG_RUST=(m|y)")
134+
135+
try:
136+
with open(config, "r", encoding="utf-8") as fp:
137+
for line in fp:
138+
if re_rust.match(line):
139+
self.rustdoc = True
140+
return
141+
142+
except OSError as e:
143+
print(f"Failed to open {config}", file=sys.stderr)
144+
122145
def get_sphinx_extra_opts(self, n_jobs):
123146
"""
124147
Get the number of jobs to be used for docs build passed via command
@@ -236,6 +259,8 @@ class SphinxBuilder:
236259

237260
self.get_sphinx_extra_opts(n_jobs)
238261

262+
self.check_rust()
263+
239264
#
240265
# If venv command line argument is specified, run Sphinx from venv
241266
#
@@ -306,7 +331,7 @@ class SphinxBuilder:
306331

307332
return subprocess.call(cmd, *args, **pwargs)
308333

309-
def handle_html(self, css, output_dir, rustdoc):
334+
def handle_html(self, css, output_dir):
310335
"""
311336
Extra steps for HTML and epub output.
312337
@@ -327,7 +352,8 @@ class SphinxBuilder:
327352
except (OSError, IOError) as e:
328353
print(f"Warning: Failed to copy CSS: {e}", file=sys.stderr)
329354

330-
if rustdoc:
355+
if self.rustdoc:
356+
print("Building rust docs")
331357
if "MAKE" in self.env:
332358
cmd = [self.env["MAKE"]]
333359
else:
@@ -622,7 +648,7 @@ class SphinxBuilder:
622648
shutil.rmtree(self.builddir, ignore_errors=True)
623649

624650
def build(self, target, sphinxdirs=None,
625-
theme=None, css=None, paper=None, deny_vf=None, rustdoc=False,
651+
theme=None, css=None, paper=None, deny_vf=None,
626652
skip_sphinx=False):
627653
"""
628654
Build documentation using Sphinx. This is the core function of this
@@ -671,7 +697,7 @@ class SphinxBuilder:
671697

672698
args.extend(["-D", f"latex_elements.papersize={paper}paper"])
673699

674-
if rustdoc:
700+
if self.rustdoc:
675701
args.extend(["-t", "rustdoc"])
676702

677703
if not sphinxdirs:
@@ -749,7 +775,7 @@ class SphinxBuilder:
749775
# Ensure that each html/epub output will have needed static files
750776
#
751777
if target in ["htmldocs", "epubdocs"]:
752-
self.handle_html(css, output_dir, rustdoc)
778+
self.handle_html(css, output_dir)
753779

754780
#
755781
# Step 2: Some targets (PDF and info) require an extra step once
@@ -804,9 +830,6 @@ def main():
804830
parser.add_argument('--deny-vf',
805831
help="Configuration to deny variable fonts on pdf builds")
806832

807-
parser.add_argument('--rustdoc', action="store_true",
808-
help="Enable rustdoc build. Requires CONFIG_RUST")
809-
810833
parser.add_argument("-v", "--verbose", action='store_true',
811834
help="place build in verbose mode")
812835

@@ -834,7 +857,7 @@ def main():
834857

835858
builder.build(args.target, sphinxdirs=args.sphinxdirs,
836859
theme=args.theme, css=args.css, paper=args.paper,
837-
rustdoc=args.rustdoc, deny_vf=args.deny_vf,
860+
deny_vf=args.deny_vf,
838861
skip_sphinx=args.skip_sphinx_build)
839862

840863
if __name__ == "__main__":

0 commit comments

Comments
 (0)