Documentation: allow sourcing generated includes from separate dir

Our documentation uses "include::" directives to include parts that are either reused across multiple documents or parts that we generate at build time. Unfortunately, top-level includes are only ever resolved relative to the base directory, which is typically the directory of the including document. Most importantly, it is not possible to have either asciidoc or asciidoctor search multiple directories. It follows that both kinds of includes must live in the same directory. This is of course a bummer for out-of-tree builds, because here the dynamically-built includes live in the build directory whereas the static includes live in the source directory. Introduce a `build_dir` attribute and prepend it to all of our includes for dynamically-built files. This attribute gets set to the build directory and thus converts the include path to an absolute path, which asciidoc and asciidoctor know how to resolve. Note that this change also requires us to update "build-docdep.perl", which tries to figure out included files such our Makefile can set up proper build-time dependencies. This script simply scans through the source files for any lines that match "^include::" and treats the remainder of the line as included file path. But given that those may now contain the "{build_dir}" variable we have to teach the script to replace that attribute with the actual build directory. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 6, 2024 at 14:24 UTC 9219325be74c35c493a61ab3107d215cad91cf38
5 files changed +18 -15
Documentation/Makefile
+2 -1
@@ -224,6 +224,7 @@ SHELL_PATH ?= $(SHELL)
224 # Shell quote;
225 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
226
227 +ASCIIDOC_EXTRA += -abuild_dir='$(shell pwd)'
228 ifdef DEFAULT_PAGER
229 DEFAULT_PAGER_SQ = $(subst ','\'',$(DEFAULT_PAGER))
230 ASCIIDOC_EXTRA += -a 'git-default-pager=$(DEFAULT_PAGER_SQ)'
@@ -289,7 +290,7 @@ docdep_prereqs = \
290 cmd-list.made $(cmds_txt)
291
292 doc.dep : $(docdep_prereqs) $(DOC_DEP_TXT) build-docdep.perl
292 - $(QUIET_GEN)$(PERL_PATH) ./build-docdep.perl >$@ $(QUIET_STDERR)
293 + $(QUIET_GEN)$(PERL_PATH) ./build-docdep.perl "$(shell pwd)" >$@ $(QUIET_STDERR)
294
295 ifneq ($(MAKECMDGOALS),clean)
296 -include doc.dep
Documentation/build-docdep.perl
+2
@@ -1,5 +1,6 @@
1 #!/usr/bin/perl
2
3 +my ($build_dir) = @ARGV;
4 my %include = ();
5 my %included = ();
6
@@ -10,6 +11,7 @@ for my $text (<*.txt>) {
11 chomp;
12 s/^include::\s*//;
13 s/\[\]//;
14 + s/{build_dir}/${build_dir}/;
15 $include{$text}{$_} = 1;
16 $included{$_} = 1;
17 }
Documentation/config/diff.txt
+1 -1
@@ -218,7 +218,7 @@ endif::git-diff[]
218 Set this option to `true` to make the diff driver cache the text
219 conversion outputs. See linkgit:gitattributes[5] for details.
220
221 -include::../mergetools-diff.txt[]
221 +include::{build_dir}/mergetools-diff.txt[]
222
223 `diff.indentHeuristic`::
224 Set this option to `false` to disable the default heuristics
Documentation/config/merge.txt
+1 -1
@@ -101,7 +101,7 @@ merge.guitool::
101 Any other value is treated as a custom merge tool and requires that a
102 corresponding mergetool.<guitool>.cmd variable is defined.
103
104 -include::../mergetools-merge.txt[]
104 +include::{build_dir}/mergetools-merge.txt[]
105
106 merge.verbosity::
107 Controls the amount of output shown by the recursive merge
Documentation/git.txt
+12 -12
@@ -245,17 +245,17 @@ ancillary user utilities.
245 Main porcelain commands
246 ~~~~~~~~~~~~~~~~~~~~~~~
247
248 -include::cmds-mainporcelain.txt[]
248 +include::{build_dir}/cmds-mainporcelain.txt[]
249
250 Ancillary Commands
251 ~~~~~~~~~~~~~~~~~~
252 Manipulators:
253
254 -include::cmds-ancillarymanipulators.txt[]
254 +include::{build_dir}/cmds-ancillarymanipulators.txt[]
255
256 Interrogators:
257
258 -include::cmds-ancillaryinterrogators.txt[]
258 +include::{build_dir}/cmds-ancillaryinterrogators.txt[]
259
260
261 Interacting with Others
@@ -264,7 +264,7 @@ Interacting with Others
264 These commands are to interact with foreign SCM and with other
265 people via patch over e-mail.
266
267 -include::cmds-foreignscminterface.txt[]
267 +include::{build_dir}/cmds-foreignscminterface.txt[]
268
269 Reset, restore and revert
270 ~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -313,13 +313,13 @@ repositories.
313 Manipulation commands
314 ~~~~~~~~~~~~~~~~~~~~~
315
316 -include::cmds-plumbingmanipulators.txt[]
316 +include::{build_dir}/cmds-plumbingmanipulators.txt[]
317
318
319 Interrogation commands
320 ~~~~~~~~~~~~~~~~~~~~~~
321
322 -include::cmds-plumbinginterrogators.txt[]
322 +include::{build_dir}/cmds-plumbinginterrogators.txt[]
323
324 In general, the interrogate commands do not touch the files in
325 the working tree.
@@ -328,12 +328,12 @@ the working tree.
328 Syncing repositories
329 ~~~~~~~~~~~~~~~~~~~~
330
331 -include::cmds-synchingrepositories.txt[]
331 +include::{build_dir}/cmds-synchingrepositories.txt[]
332
333 The following are helper commands used by the above; end users
334 typically do not use them directly.
335
336 -include::cmds-synchelpers.txt[]
336 +include::{build_dir}/cmds-synchelpers.txt[]
337
338
339 Internal helper commands
@@ -342,14 +342,14 @@ Internal helper commands
342 These are internal helper commands used by other commands; end
343 users typically do not use them directly.
344
345 -include::cmds-purehelpers.txt[]
345 +include::{build_dir}/cmds-purehelpers.txt[]
346
347 Guides
348 ------
349
350 The following documentation pages are guides about Git concepts.
351
352 -include::cmds-guide.txt[]
352 +include::{build_dir}/cmds-guide.txt[]
353
354 Repository, command and file interfaces
355 ---------------------------------------
@@ -358,7 +358,7 @@ This documentation discusses repository and command interfaces which
358 users are expected to interact with directly. See `--user-formats` in
359 linkgit:git-help[1] for more details on the criteria.
360
361 -include::cmds-userinterfaces.txt[]
361 +include::{build_dir}/cmds-userinterfaces.txt[]
362
363 File formats, protocols and other developer interfaces
364 ------------------------------------------------------
@@ -367,7 +367,7 @@ This documentation discusses file formats, over-the-wire protocols and
367 other git developer interfaces. See `--developer-interfaces` in
368 linkgit:git-help[1].
369
370 -include::cmds-developerinterfaces.txt[]
370 +include::{build_dir}/cmds-developerinterfaces.txt[]
371
372 Configuration Mechanism
373 -----------------------