
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>
50 lines
1.0 KiB
Perl
Executable File
50 lines
1.0 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
my ($build_dir) = @ARGV;
|
|
my %include = ();
|
|
my %included = ();
|
|
|
|
for my $text (<*.txt>) {
|
|
open I, '<', $text || die "cannot read: $text";
|
|
while (<I>) {
|
|
if (/^include::/) {
|
|
chomp;
|
|
s/^include::\s*//;
|
|
s/\[\]//;
|
|
s/{build_dir}/${build_dir}/;
|
|
$include{$text}{$_} = 1;
|
|
$included{$_} = 1;
|
|
}
|
|
}
|
|
close I;
|
|
}
|
|
|
|
# Do we care about chained includes???
|
|
my $changed = 1;
|
|
while ($changed) {
|
|
$changed = 0;
|
|
while (my ($text, $included) = each %include) {
|
|
for my $i (keys %$included) {
|
|
# $text has include::$i; if $i includes $j
|
|
# $text indirectly includes $j.
|
|
if (exists $include{$i}) {
|
|
for my $j (keys %{$include{$i}}) {
|
|
if (!exists $include{$text}{$j}) {
|
|
$include{$text}{$j} = 1;
|
|
$included{$j} = 1;
|
|
$changed = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach my $text (sort keys %include) {
|
|
my $included = $include{$text};
|
|
if (! exists $included{$text} &&
|
|
(my $base = $text) =~ s/\.txt$//) {
|
|
print "$base.html $base.xml : ", join(" ", sort keys %$included), "\n";
|
|
}
|
|
}
|