fnsince.pl 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 %fulltags = ();
  13. my @unsorted_releases = ();
  14. open(PIPEFH, '-|', 'git tag -l') or die "Failed to read git release tags: $!\n";
  15. while (<PIPEFH>) {
  16. chomp;
  17. my $fulltag = $_;
  18. if ($fulltag =~ /\A(prerelease|preview|release)\-(\d+)\.(\d+)\.(\d+)\Z/) {
  19. # Ignore anything that isn't a x.y.0 release.
  20. # 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.
  21. my $release_type = $1;
  22. my $major = int($2);
  23. my $minor = int($3);
  24. my $patch = int($4);
  25. next if ($major != 3); # Ignore anything that isn't an SDL3 release.
  26. next if ($patch != 0) && ($minor >= 2); # Ignore anything that is a patch release (unless it was between the preview release and the official release).
  27. # Consider this release version.
  28. my $ver = "${major}.${minor}.${patch}";
  29. push @unsorted_releases, $ver;
  30. $fulltags{$ver} = $fulltag;
  31. }
  32. }
  33. close(PIPEFH);
  34. #print("\n\nUNSORTED\n");
  35. #foreach (@unsorted_releases) {
  36. # print "$_\n";
  37. #}
  38. my @releases = sort {
  39. my @asplit = split /\./, $a;
  40. my @bsplit = split /\./, $b;
  41. my $rc;
  42. for (my $i = 0; $i < scalar(@asplit); $i++) {
  43. return 1 if (scalar(@bsplit) <= $i); # a is "2.0.1" and b is "2.0", or whatever.
  44. my $aseg = $asplit[$i];
  45. my $bseg = $bsplit[$i];
  46. $rc = int($aseg) <=> int($bseg);
  47. return $rc if ($rc != 0); # found the difference.
  48. }
  49. return 0; # still here? They matched completely?!
  50. } @unsorted_releases;
  51. my $current_release = $releases[-1];
  52. my $next_release;
  53. if (scalar(@releases) > 0) {
  54. # this happens to work for how SDL versions things at the moment.
  55. $current_release = $releases[-1];
  56. my @current_release_segments = split /\./, $current_release;
  57. # if we're still in the 3.1.x prereleases, call the "next release" 3.2.0 even if we do more prereleases.
  58. if (($current_release_segments[0] == '3') && ($current_release_segments[1] == '1')) {
  59. $next_release = '3.2.0';
  60. } else {
  61. @current_release_segments[1] = '' . (int($current_release_segments[1]) + 2);
  62. $next_release = join('.', @current_release_segments);
  63. }
  64. }
  65. #print("\n\nSORTED\n");
  66. #foreach (@releases) {
  67. # print "$_\n";
  68. #}
  69. #print("\nCURRENT RELEASE: $current_release\n");
  70. #print("NEXT RELEASE: $next_release\n\n");
  71. push @releases, 'HEAD';
  72. $fulltags{'HEAD'} = 'HEAD';
  73. my %funcs = ();
  74. foreach my $release (@releases) {
  75. #print("Checking $release...\n");
  76. my $tag = $fulltags{$release};
  77. my $blobname = "$tag:src/dynapi/SDL_dynapi_overrides.h";
  78. if ($release =~ /\A3\.(0\.\d+|1\.[0123])/) { # make everything up to the first SDL3 prerelease look like 3.1.3 (ABI lock version).
  79. $release = '3.1.3';
  80. }
  81. # !!! FIXME: REMOVE ME WHEN 3.2.0 SHIPS!
  82. elsif (not $release =~ /\A3\.1\.\d+/) { # a couple of releases after the initial 3.1.3, let them through.
  83. $release = '3.2.0';
  84. }
  85. # !!! FIXME: REMOVE ME WHEN 3.2.0 SHIPS!
  86. open(PIPEFH, '-|', "git show '$blobname'") or die "Failed to read git blob '$blobname': $!\n";
  87. while (<PIPEFH>) {
  88. chomp;
  89. if (/\A\#define\s+(SDL_.*?)\s+SDL_.*?_REAL\Z/) {
  90. my $fn = $1;
  91. $funcs{$fn} = $release if not defined $funcs{$fn};
  92. }
  93. }
  94. close(PIPEFH);
  95. }
  96. if (not defined $wikipath) {
  97. foreach my $release (@releases) {
  98. foreach my $fn (sort keys %funcs) {
  99. print("$fn: $funcs{$fn}\n") if $funcs{$fn} eq $release;
  100. }
  101. }
  102. } else {
  103. if (defined $wikipath) {
  104. chdir($wikipath);
  105. foreach my $fn (keys %funcs) {
  106. 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).
  107. my $revision = $funcs{$fn};
  108. $revision = $next_release if $revision eq 'HEAD';
  109. my $fname = "$fn.md";
  110. if ( ! -f $fname ) {
  111. #print STDERR "No such file: $fname\n";
  112. next;
  113. }
  114. my @lines = ();
  115. open(FH, '<', $fname) or die("Can't open $fname for read: $!\n");
  116. my $added = 0;
  117. while (<FH>) {
  118. chomp;
  119. if ((/\A\-\-\-\-/) && (!$added)) {
  120. push @lines, "## Version";
  121. push @lines, "";
  122. push @lines, "This function is available since SDL $revision.";
  123. push @lines, "";
  124. $added = 1;
  125. }
  126. push @lines, $_;
  127. next if not /\A\#\#\s+Version/;
  128. $added = 1;
  129. push @lines, "";
  130. push @lines, "This function is available since SDL $revision.";
  131. push @lines, "";
  132. while (<FH>) {
  133. chomp;
  134. next if not (/\A\#\#\s+/ || /\A\-\-\-\-/);
  135. push @lines, $_;
  136. last;
  137. }
  138. }
  139. close(FH);
  140. if (!$added) {
  141. push @lines, "## Version";
  142. push @lines, "";
  143. push @lines, "This function is available since SDL $revision.";
  144. push @lines, "";
  145. }
  146. open(FH, '>', $fname) or die("Can't open $fname for write: $!\n");
  147. foreach (@lines) {
  148. print FH "$_\n";
  149. }
  150. close(FH);
  151. }
  152. }
  153. }