wikiheaders: Bridge README files in the docs directory to wiki. Fixes #6026. (cherry picked from commit 2506676f34dc9d3e64ab7bbd9c947b8c13364913)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
diff --git a/.wikiheaders-options b/.wikiheaders-options
index 85f4f30..634840e 100644
--- a/.wikiheaders-options
+++ b/.wikiheaders-options
@@ -2,6 +2,7 @@ projectfullname = SDL2
projectshortname = SDL2
incsubdir = include
wikisubdir = SDL2
+readmesubdir = docs
apiprefixregex = (SDL_|SDLK_|KMOD_|AUDIO_)
mainincludefname = SDL.h
versionfname = include/SDL_version.h
diff --git a/build-scripts/wikiheaders.pl b/build-scripts/wikiheaders.pl
index 5288547..29d62b0 100755
--- a/build-scripts/wikiheaders.pl
+++ b/build-scripts/wikiheaders.pl
@@ -3,6 +3,7 @@
use warnings;
use strict;
use Text::Wrap;
+use File::Copy;
$Text::Wrap::huge = 'overflow';
@@ -10,6 +11,7 @@ my $projectfullname = 'Simple Directmedia Layer';
my $projectshortname = 'SDL';
my $wikisubdir = '';
my $incsubdir = 'include';
+my $readmesubdir = undef;
my $apiprefixregex = undef;
my $versionfname = 'include/SDL_version.h';
my $versionmajorregex = '\A\#define\s+SDL_MAJOR_VERSION\s+(\d+)\Z';
@@ -22,6 +24,7 @@ my $wikiurl = 'https://wiki.libsdl.org';
my $bugreporturl = 'https://github.com/libsdl-org/sdlwiki/issues/new';
my $srcpath = undef;
my $wikipath = undef;
+my $wikireadmesubdir = 'README';
my $warn_about_missing = 0;
my $copy_direction = 0;
my $optionsfname = undef;
@@ -71,6 +74,7 @@ if (defined $optionsfname) {
$projectshortname = $val, next if $key eq 'projectshortname';
$wikisubdir = $val, next if $key eq 'wikisubdir';
$incsubdir = $val, next if $key eq 'incsubdir';
+ $readmesubdir = $val, next if $key eq 'readmesubdir';
$versionmajorregex = $val, next if $key eq 'versionmajorregex';
$versionminorregex = $val, next if $key eq 'versionminorregex';
$versionpatchregex = $val, next if $key eq 'versionpatchregex';
@@ -493,6 +497,12 @@ my %headerfuncshasdoxygen = (); # $headerfuncschunk{"SDL_OpenAudio"} -> 1 if t
my $incpath = "$srcpath";
$incpath .= "/$incsubdir" if $incsubdir ne '';
+my $wikireadmepath = "$wikipath/$wikireadmesubdir";
+my $readmepath = undef;
+if (defined $readmesubdir) {
+ $readmepath = "$srcpath/$readmesubdir";
+}
+
opendir(DH, $incpath) or die("Can't opendir '$incpath': $!\n");
while (readdir(DH)) {
my $dent = $_;
@@ -1004,6 +1014,19 @@ if ($copy_direction == 1) { # --copy-to-headers
rename($path, "$incpath/$header") or die("Can't rename '$path' to '$incpath/$header': $!\n");
}
+ if (defined $readmepath) {
+ if ( -d $wikireadmepath ) {
+ mkdir($readmepath); # just in case
+ opendir(DH, $wikireadmepath) or die("Can't opendir '$wikireadmepath': $!\n");
+ while (readdir(DH)) {
+ my $dent = $_;
+ if ($dent =~ /\A(.*?)\.md\Z/) { # we only bridge Markdown files here.
+ copy("$wikireadmepath/$dent", "$readmepath/README-$dent") or die("failed to copy '$wikireadmepath/$dent' to '$readmepath/README-$dent': $!\n");
+ }
+ }
+ closedir(DH);
+ }
+ }
} elsif ($copy_direction == -1) { # --copy-to-wiki
if (defined $changeformat) {
@@ -1333,6 +1356,35 @@ if ($copy_direction == 1) { # --copy-to-headers
rename($path, "$wikipath/$_.${wikitype}") or die("Can't rename '$path' to '$wikipath/$_.${wikitype}': $!\n");
}
+ if (defined $readmepath) {
+ if ( -d $readmepath ) {
+ mkdir($wikireadmepath); # just in case
+ opendir(DH, $readmepath) or die("Can't opendir '$readmepath': $!\n");
+ while (readdir(DH)) {
+ my $dent = $_;
+ if ($dent =~ /\AREADME\-(.*?\.md)\Z/) { # we only bridge Markdown files here.
+ my $wikifname = $1;
+ copy("$readmepath/$dent", "$wikireadmepath/$wikifname") or die("failed to copy '$readmepath/$dent' to '$wikireadmepath/$wikifname': $!\n");
+ }
+ }
+ closedir(DH);
+
+ open(FH, '>', "$wikireadmepath/FrontPage.md") or die("Can't open '$wikireadmepath/FrontPage.md': $!\n");
+ print FH "# All READMEs available here\n\n";
+
+ opendir(DH, $wikireadmepath) or die("Can't opendir '$wikireadmepath': $!\n");
+ while (readdir(DH)) {
+ my $dent = $_;
+ if ($dent =~ /\A(.*?)\.(mediawiki|md)\Z/) {
+ my $wikiname = $1;
+ print FH "- [$wikiname]($wikiname)\n";
+ }
+ }
+ closedir(DH);
+ close(FH);
+ }
+ }
+
} elsif ($copy_direction == -2) { # --copy-to-manpages
# This only takes from the wiki data, since it has sections we omit from the headers, like code examples.