2021-10-26 16:12:52 +00:00
#!/usr/bin/perl -w
use warnings ;
use strict ;
use File::Basename ;
2021-10-26 23:00:06 +00:00
use Cwd qw( abs_path ) ;
my $ wikipath = undef ;
foreach ( @ ARGV ) {
$ wikipath = abs_path ( $ _ ) , next if not defined $ wikipath ;
}
2021-10-26 16:12:52 +00:00
chdir ( dirname ( __FILE__ ) ) ;
chdir ( '..' ) ;
2024-10-10 16:41:46 +00:00
my % fulltags = ( ) ;
2021-10-26 16:12:52 +00:00
my @ unsorted_releases = ( ) ;
open ( PIPEFH , '-|' , 'git tag -l' ) or die "Failed to read git release tags: $!\n" ;
while ( <PIPEFH> ) {
chomp ;
2024-10-10 16:41:46 +00:00
my $ fulltag = $ _ ;
if ( $ fulltag =~ /\A(prerelease|preview|release)\-(\d+)\.(\d+)\.(\d+)\Z/ ) {
2022-11-22 22:39:38 +00:00
# Ignore anything that isn't a x.y.0 release.
2024-10-10 16:41:46 +00:00
# Make sure new APIs are assigned to the next minor version and ignore the patch versions, but we'll make an except for the prereleases.
my $ release_type = $ 1 ;
my $ major = int ( $ 2 ) ;
my $ minor = int ( $ 3 ) ;
my $ patch = int ( $ 4 ) ;
next if ( $ major != 3 ) ; # Ignore anything that isn't an SDL3 release.
next if ( $ patch != 0 ) && ( $ minor >= 2 ) ; # Ignore anything that is a patch release (unless it was between the preview release and the official release).
2022-10-25 18:03:32 +00:00
# Consider this release version.
2024-10-10 16:41:46 +00:00
my $ ver = "${major}.${minor}.${patch}" ;
2022-10-25 18:03:32 +00:00
push @ unsorted_releases , $ ver ;
2024-10-10 16:41:46 +00:00
$ fulltags { $ ver } = $ fulltag ;
2021-10-26 16:12:52 +00:00
}
}
close ( PIPEFH ) ;
#print("\n\nUNSORTED\n");
#foreach (@unsorted_releases) {
# print "$_\n";
#}
my @ releases = sort {
my @ asplit = split /\./ , $ a ;
my @ bsplit = split /\./ , $ b ;
my $ rc ;
for ( my $ i = 0 ; $ i < scalar ( @ asplit ) ; $ i + + ) {
return 1 if ( scalar ( @ bsplit ) <= $ i ) ; # a is "2.0.1" and b is "2.0", or whatever.
my $ aseg = $ asplit [ $ i ] ;
my $ bseg = $ bsplit [ $ i ] ;
$ rc = int ( $ aseg ) <=> int ( $ bseg ) ;
return $ rc if ( $ rc != 0 ) ; # found the difference.
}
return 0 ; # still here? They matched completely?!
} @ unsorted_releases ;
2024-10-10 16:41:46 +00:00
my $ current_release = $ releases [ - 1 ] ;
my $ next_release ;
2022-11-22 22:39:38 +00:00
if ( scalar ( @ releases ) > 0 ) {
# this happens to work for how SDL versions things at the moment.
$ current_release = $ releases [ - 1 ] ;
2022-05-16 03:50:08 +00:00
my @ current_release_segments = split /\./ , $ current_release ;
2024-10-23 16:19:38 +00:00
# if we're still in the 3.1.x prereleases, call the "next release" 3.2.0 even if we do more prereleases.
2024-10-10 16:41:46 +00:00
if ( ( $ current_release_segments [ 0 ] == '3' ) && ( $ current_release_segments [ 1 ] == '1' ) ) {
2024-10-23 16:19:38 +00:00
$ next_release = '3.2.0' ;
2024-10-10 16:41:46 +00:00
} else {
@ current_release_segments [ 1 ] = '' . ( int ( $ current_release_segments [ 1 ] ) + 2 ) ;
2024-10-23 16:19:38 +00:00
$ next_release = join ( '.' , @ current_release_segments ) ;
2024-10-10 16:41:46 +00:00
}
2022-05-16 03:50:08 +00:00
}
2021-11-10 20:40:27 +00:00
2021-10-26 16:12:52 +00:00
#print("\n\nSORTED\n");
#foreach (@releases) {
# print "$_\n";
#}
2021-11-10 20:40:27 +00:00
#print("\nCURRENT RELEASE: $current_release\n");
#print("NEXT RELEASE: $next_release\n\n");
2021-10-26 16:12:52 +00:00
push @ releases , 'HEAD' ;
2024-10-10 16:41:46 +00:00
$ fulltags { 'HEAD' } = 'HEAD' ;
2021-10-26 16:12:52 +00:00
my % funcs = ( ) ;
foreach my $ release ( @ releases ) {
#print("Checking $release...\n");
2024-10-10 16:41:46 +00:00
my $ tag = $ fulltags { $ release } ;
2021-10-26 16:12:52 +00:00
my $ blobname = "$tag:src/dynapi/SDL_dynapi_overrides.h" ;
2024-10-10 16:41:46 +00:00
2024-11-28 04:18:38 +00:00
if ( $ release =~ /\A3\.(0\.\d+|1\.[0123])/ ) { # make everything up to the first SDL3 prerelease look like 3.1.3 (ABI lock version).
2024-10-23 16:19:38 +00:00
$ release = '3.1.3' ;
}
2024-11-28 04:18:38 +00:00
# !!! FIXME: REMOVE ME WHEN 3.2.0 SHIPS!
elsif ( not $ release =~ /\A3\.1\.\d+/ ) { # a couple of releases after the initial 3.1.3, let them through.
$ release = '3.2.0' ;
}
# !!! FIXME: REMOVE ME WHEN 3.2.0 SHIPS!
2024-10-10 16:41:46 +00:00
2021-10-26 16:12:52 +00:00
open ( PIPEFH , '-|' , "git show '$blobname'" ) or die "Failed to read git blob '$blobname': $!\n" ;
while ( <PIPEFH> ) {
chomp ;
if ( /\A\#define\s+(SDL_.*?)\s+SDL_.*?_REAL\Z/ ) {
my $ fn = $ 1 ;
2022-11-22 22:39:38 +00:00
$ funcs { $ fn } = $ release if not defined $ funcs { $ fn } ;
2021-10-26 16:12:52 +00:00
}
}
close ( PIPEFH ) ;
}
2021-10-27 01:01:05 +00:00
if ( not defined $ wikipath ) {
foreach my $ release ( @ releases ) {
foreach my $ fn ( sort keys % funcs ) {
print ( "$fn: $funcs{$fn}\n" ) if $ funcs { $ fn } eq $ release ;
}
2021-10-26 16:12:52 +00:00
}
2021-10-27 01:01:05 +00:00
} else {
if ( defined $ wikipath ) {
chdir ( $ wikipath ) ;
foreach my $ fn ( keys % funcs ) {
2024-10-10 16:41:46 +00:00
next if $ fn eq 'SDL_ThreadID' ; # this was a function early on (it's now called SDL_GetThreadID), but now it's a datatype (which originally had a different capitalization).
2021-10-27 01:01:05 +00:00
my $ revision = $ funcs { $ fn } ;
2021-11-10 20:40:27 +00:00
$ revision = $ next_release if $ revision eq 'HEAD' ;
2024-04-11 17:21:30 +00:00
my $ fname = "$fn.md" ;
2021-10-27 01:01:05 +00:00
if ( ! - f $ fname ) {
#print STDERR "No such file: $fname\n";
next ;
}
2021-10-26 16:12:52 +00:00
2021-10-27 01:01:05 +00:00
my @ lines = ( ) ;
open ( FH , '<' , $ fname ) or die ( "Can't open $fname for read: $!\n" ) ;
my $ added = 0 ;
while ( <FH> ) {
chomp ;
if ( ( /\A\-\-\-\-/ ) && ( ! $ added ) ) {
2024-04-11 17:21:30 +00:00
push @ lines , "## Version" ;
2021-10-27 01:01:05 +00:00
push @ lines , "" ;
push @ lines , "This function is available since SDL $revision." ;
push @ lines , "" ;
$ added = 1 ;
}
push @ lines , $ _ ;
2024-04-11 17:21:30 +00:00
next if not /\A\#\#\s+Version/ ;
2021-10-27 01:01:05 +00:00
$ added = 1 ;
push @ lines , "" ;
push @ lines , "This function is available since SDL $revision." ;
push @ lines , "" ;
while ( <FH> ) {
chomp ;
2024-04-11 17:21:30 +00:00
next if not ( /\A\#\#\s+/ || /\A\-\-\-\-/ ) ;
2021-10-27 01:01:05 +00:00
push @ lines , $ _ ;
last ;
}
}
close ( FH ) ;
2021-10-26 23:00:06 +00:00
2021-10-27 01:01:05 +00:00
if ( ! $ added ) {
2024-04-11 17:21:30 +00:00
push @ lines , "## Version" ;
2021-10-26 23:00:06 +00:00
push @ lines , "" ;
push @ lines , "This function is available since SDL $revision." ;
push @ lines , "" ;
}
2021-10-27 01:01:05 +00:00
open ( FH , '>' , $ fname ) or die ( "Can't open $fname for write: $!\n" ) ;
foreach ( @ lines ) {
print FH "$_\n" ;
}
close ( FH ) ;
2021-10-26 23:00:06 +00:00
}
}
}