Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
464257ba b9a565b3

+32 -15
-6
Documentation/Makefile
··· 42 42 # User-friendly check for sphinx-build 43 43 HAVE_SPHINX := $(shell if which $(SPHINXBUILD) >/dev/null 2>&1; then echo 1; else echo 0; fi) 44 44 45 - ifneq ($(wildcard $(srctree)/.config),) 46 - ifeq ($(CONFIG_RUST),y) 47 - RUSTDOC=--rustdoc 48 - endif 49 - endif 50 - 51 45 ifeq ($(HAVE_SPHINX),0) 52 46 53 47 .DEFAULT:
+32 -9
tools/docs/sphinx-build-wrapper
··· 119 119 120 120 return path 121 121 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 + 122 145 def get_sphinx_extra_opts(self, n_jobs): 123 146 """ 124 147 Get the number of jobs to be used for docs build passed via command ··· 259 236 260 237 self.get_sphinx_extra_opts(n_jobs) 261 238 239 + self.check_rust() 240 + 262 241 # 263 242 # If venv command line argument is specified, run Sphinx from venv 264 243 # ··· 331 306 332 307 return subprocess.call(cmd, *args, **pwargs) 333 308 334 - def handle_html(self, css, output_dir, rustdoc): 309 + def handle_html(self, css, output_dir): 335 310 """ 336 311 Extra steps for HTML and epub output. 337 312 ··· 352 327 except (OSError, IOError) as e: 353 328 print(f"Warning: Failed to copy CSS: {e}", file=sys.stderr) 354 329 355 - if rustdoc: 330 + if self.rustdoc: 331 + print("Building rust docs") 356 332 if "MAKE" in self.env: 357 333 cmd = [self.env["MAKE"]] 358 334 else: ··· 648 622 shutil.rmtree(self.builddir, ignore_errors=True) 649 623 650 624 def build(self, target, sphinxdirs=None, 651 - theme=None, css=None, paper=None, deny_vf=None, rustdoc=False, 625 + theme=None, css=None, paper=None, deny_vf=None, 652 626 skip_sphinx=False): 653 627 """ 654 628 Build documentation using Sphinx. This is the core function of this ··· 697 671 698 672 args.extend(["-D", f"latex_elements.papersize={paper}paper"]) 699 673 700 - if rustdoc: 674 + if self.rustdoc: 701 675 args.extend(["-t", "rustdoc"]) 702 676 703 677 if not sphinxdirs: ··· 775 749 # Ensure that each html/epub output will have needed static files 776 750 # 777 751 if target in ["htmldocs", "epubdocs"]: 778 - self.handle_html(css, output_dir, rustdoc) 752 + self.handle_html(css, output_dir) 779 753 780 754 # 781 755 # Step 2: Some targets (PDF and info) require an extra step once ··· 830 804 parser.add_argument('--deny-vf', 831 805 help="Configuration to deny variable fonts on pdf builds") 832 806 833 - parser.add_argument('--rustdoc', action="store_true", 834 - help="Enable rustdoc build. Requires CONFIG_RUST") 835 - 836 807 parser.add_argument("-v", "--verbose", action='store_true', 837 808 help="place build in verbose mode") 838 809 ··· 857 834 858 835 builder.build(args.target, sphinxdirs=args.sphinxdirs, 859 836 theme=args.theme, css=args.css, paper=args.paper, 860 - rustdoc=args.rustdoc, deny_vf=args.deny_vf, 837 + deny_vf=args.deny_vf, 861 838 skip_sphinx=args.skip_sphinx_build) 862 839 863 840 if __name__ == "__main__":