fnsince.pl 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/usr/bin/perl -w
  2. use warnings;
  3. use strict;
  4. use File::Basename;
  5. use Cwd qw(abs_path);
  6. my $wikipath = undef;
  7. foreach (@ARGV) {
  8. $wikipath = abs_path($_), next if not defined $wikipath;
  9. }
  10. chdir(dirname(__FILE__));
  11. chdir('..');
  12. my @unsorted_releases = ();
  13. open(PIPEFH, '-|', 'git tag -l') or die "Failed to read git release tags: $!\n";
  14. while (<PIPEFH>) {
  15. chomp;
  16. if (/\Arelease\-(.*?)\Z/) {
  17. # Ignore anything that isn't a x.y.0 release.
  18. # Make sure new APIs are assigned to the next minor version and ignore the patch versions.
  19. my $ver = $1;
  20. my @versplit = split /\./, $ver;
  21. next if (scalar(@versplit) < 1) || ($versplit[0] != 3); # Ignore anything that isn't an SDL3 release.
  22. next if (scalar(@versplit) < 3) || ($versplit[2] != 0);
  23. # Consider this release version.
  24. push @unsorted_releases, $ver;
  25. }
  26. }
  27. close(PIPEFH);
  28. #print("\n\nUNSORTED\n");
  29. #foreach (@unsorted_releases) {
  30. # print "$_\n";
  31. #}
  32. my @releases = sort {
  33. my @asplit = split /\./, $a;
  34. my @bsplit = split /\./, $b;
  35. my $rc;
  36. for (my $i = 0; $i < scalar(@asplit); $i++) {
  37. return 1 if (scalar(@bsplit) <= $i); # a is "2.0.1" and b is "2.0", or whatever.
  38. my $aseg = $asplit[$i];
  39. my $bseg = $bsplit[$i];
  40. $rc = int($aseg) <=> int($bseg);
  41. return $rc if ($rc != 0); # found the difference.
  42. }
  43. return 0; # still here? They matched completely?!
  44. } @unsorted_releases;
  45. my $current_release = 'in-development';
  46. my $next_release = '3.0.0'; # valid until we actually ship something. :)
  47. if (scalar(@releases) > 0) {
  48. # this happens to work for how SDL versions things at the moment.
  49. $current_release = $releases[-1];
  50. my @current_release_segments = split /\./, $current_release;
  51. @current_release_segments[1] = '' . ($current_release_segments[1] + 2);
  52. $next_release = join('.', @current_release_segments);
  53. }
  54. #print("\n\nSORTED\n");
  55. #foreach (@releases) {
  56. # print "$_\n";
  57. #}
  58. #print("\nCURRENT RELEASE: $current_release\n");
  59. #print("NEXT RELEASE: $next_release\n\n");
  60. push @releases, 'HEAD';
  61. my %funcs = ();
  62. foreach my $release (@releases) {
  63. #print("Checking $release...\n");
  64. my $tag = ($release eq 'HEAD') ? $release : "release-$release";
  65. my $blobname = "$tag:src/dynapi/SDL_dynapi_overrides.h";
  66. open(PIPEFH, '-|', "git show '$blobname'") or die "Failed to read git blob '$blobname': $!\n";
  67. while (<PIPEFH>) {
  68. chomp;
  69. if (/\A\#define\s+(SDL_.*?)\s+SDL_.*?_REAL\Z/) {
  70. my $fn = $1;
  71. $funcs{$fn} = $release if not defined $funcs{$fn};
  72. }
  73. }
  74. close(PIPEFH);
  75. }
  76. # these are incorrect in the dynapi header, because we forgot to add them
  77. # until a later release, but are available in the older release.
  78. $funcs{'SDL_WinRTGetFSPathUNICODE'} = '2.0.3';
  79. $funcs{'SDL_WinRTGetFSPathUTF8'} = '2.0.3';
  80. if (not defined $wikipath) {
  81. foreach my $release (@releases) {
  82. foreach my $fn (sort keys %funcs) {
  83. print("$fn: $funcs{$fn}\n") if $funcs{$fn} eq $release;
  84. }
  85. }
  86. } else {
  87. if (defined $wikipath) {
  88. chdir($wikipath);
  89. foreach my $fn (keys %funcs) {
  90. my $revision = $funcs{$fn};
  91. $revision = $next_release if $revision eq 'HEAD';
  92. my $fname = "$fn.mediawiki";
  93. if ( ! -f $fname ) {
  94. #print STDERR "No such file: $fname\n";
  95. next;
  96. }
  97. my @lines = ();
  98. open(FH, '<', $fname) or die("Can't open $fname for read: $!\n");
  99. my $added = 0;
  100. while (<FH>) {
  101. chomp;
  102. if ((/\A\-\-\-\-/) && (!$added)) {
  103. push @lines, "== Version ==";
  104. push @lines, "";
  105. push @lines, "This function is available since SDL $revision.";
  106. push @lines, "";
  107. $added = 1;
  108. }
  109. push @lines, $_;
  110. next if not /\A\=\=\s+Version\s+\=\=/;
  111. $added = 1;
  112. push @lines, "";
  113. push @lines, "This function is available since SDL $revision.";
  114. push @lines, "";
  115. while (<FH>) {
  116. chomp;
  117. next if not (/\A\=\=\s+/ || /\A\-\-\-\-/);
  118. push @lines, $_;
  119. last;
  120. }
  121. }
  122. close(FH);
  123. if (!$added) {
  124. push @lines, "== Version ==";
  125. push @lines, "";
  126. push @lines, "This function is available since SDL $revision.";
  127. push @lines, "";
  128. }
  129. open(FH, '>', $fname) or die("Can't open $fname for write: $!\n");
  130. foreach (@lines) {
  131. print FH "$_\n";
  132. }
  133. close(FH);
  134. }
  135. }
  136. }