wikiheaders: Bridge README files in the docs directory to wiki.

Fixes #6026.
This commit is contained in:
Ryan C. Gordon 2023-02-28 11:37:46 -05:00
parent da134a3039
commit 2506676f34
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
2 changed files with 53 additions and 0 deletions

View File

@ -2,6 +2,7 @@ projectfullname = SDL
projectshortname = SDL projectshortname = SDL
incsubdir = include/SDL3 incsubdir = include/SDL3
wikisubdir = wikisubdir =
readmesubdir = docs
apiprefixregex = (SDL_|SDLK_|KMOD_|AUDIO_) apiprefixregex = (SDL_|SDLK_|KMOD_|AUDIO_)
mainincludefname = SDL.h mainincludefname = SDL.h
versionfname = include/SDL3/SDL_version.h versionfname = include/SDL3/SDL_version.h

View File

@ -3,6 +3,7 @@
use warnings; use warnings;
use strict; use strict;
use Text::Wrap; use Text::Wrap;
use File::Copy;
$Text::Wrap::huge = 'overflow'; $Text::Wrap::huge = 'overflow';
@ -10,6 +11,7 @@ my $projectfullname = 'Simple Directmedia Layer';
my $projectshortname = 'SDL'; my $projectshortname = 'SDL';
my $wikisubdir = ''; my $wikisubdir = '';
my $incsubdir = 'include'; my $incsubdir = 'include';
my $readmesubdir = undef;
my $apiprefixregex = undef; my $apiprefixregex = undef;
my $versionfname = 'include/SDL_version.h'; my $versionfname = 'include/SDL_version.h';
my $versionmajorregex = '\A\#define\s+SDL_MAJOR_VERSION\s+(\d+)\Z'; 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 $bugreporturl = 'https://github.com/libsdl-org/sdlwiki/issues/new';
my $srcpath = undef; my $srcpath = undef;
my $wikipath = undef; my $wikipath = undef;
my $wikireadmesubdir = 'README';
my $warn_about_missing = 0; my $warn_about_missing = 0;
my $copy_direction = 0; my $copy_direction = 0;
my $optionsfname = undef; my $optionsfname = undef;
@ -71,6 +74,7 @@ if (defined $optionsfname) {
$projectshortname = $val, next if $key eq 'projectshortname'; $projectshortname = $val, next if $key eq 'projectshortname';
$wikisubdir = $val, next if $key eq 'wikisubdir'; $wikisubdir = $val, next if $key eq 'wikisubdir';
$incsubdir = $val, next if $key eq 'incsubdir'; $incsubdir = $val, next if $key eq 'incsubdir';
$readmesubdir = $val, next if $key eq 'readmesubdir';
$versionmajorregex = $val, next if $key eq 'versionmajorregex'; $versionmajorregex = $val, next if $key eq 'versionmajorregex';
$versionminorregex = $val, next if $key eq 'versionminorregex'; $versionminorregex = $val, next if $key eq 'versionminorregex';
$versionpatchregex = $val, next if $key eq 'versionpatchregex'; $versionpatchregex = $val, next if $key eq 'versionpatchregex';
@ -493,6 +497,12 @@ my %headerfuncshasdoxygen = (); # $headerfuncschunk{"SDL_OpenAudio"} -> 1 if t
my $incpath = "$srcpath"; my $incpath = "$srcpath";
$incpath .= "/$incsubdir" if $incsubdir ne ''; $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"); opendir(DH, $incpath) or die("Can't opendir '$incpath': $!\n");
while (readdir(DH)) { while (readdir(DH)) {
my $dent = $_; 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"); 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 } elsif ($copy_direction == -1) { # --copy-to-wiki
if (defined $changeformat) { 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"); 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 } 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. # This only takes from the wiki data, since it has sections we omit from the headers, like code examples.