fnsince.pl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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\.[01]\.\d+\Z/) { # make everything up to the first SDL3 official release look like 3.2.0.
  79. $release = '3.2.0';
  80. }
  81. open(PIPEFH, '-|', "git show '$blobname'") or die "Failed to read git blob '$blobname': $!\n";
  82. while (<PIPEFH>) {
  83. chomp;
  84. if (/\A\#define\s+(SDL_.*?)\s+SDL_.*?_REAL\Z/) {
  85. my $fn = $1;
  86. $funcs{$fn} = $release if not defined $funcs{$fn};
  87. }
  88. }
  89. close(PIPEFH);
  90. }
  91. if (not defined $wikipath) {
  92. foreach my $release (@releases) {
  93. foreach my $fn (sort keys %funcs) {
  94. print("$fn: $funcs{$fn}\n") if $funcs{$fn} eq $release;
  95. }
  96. }
  97. } else {
  98. if (defined $wikipath) {
  99. chdir($wikipath);
  100. foreach my $fn (keys %funcs) {
  101. 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).
  102. my $revision = $funcs{$fn};
  103. $revision = $next_release if $revision eq 'HEAD';
  104. my $fname = "$fn.md";
  105. if ( ! -f $fname ) {
  106. #print STDERR "No such file: $fname\n";
  107. next;
  108. }
  109. my @lines = ();
  110. open(FH, '<', $fname) or die("Can't open $fname for read: $!\n");
  111. my $added = 0;
  112. while (<FH>) {
  113. chomp;
  114. if ((/\A\-\-\-\-/) && (!$added)) {
  115. push @lines, "## Version";
  116. push @lines, "";
  117. push @lines, "This function is available since SDL $revision.";
  118. push @lines, "";
  119. $added = 1;
  120. }
  121. push @lines, $_;
  122. next if not /\A\#\#\s+Version/;
  123. $added = 1;
  124. push @lines, "";
  125. push @lines, "This function is available since SDL $revision.";
  126. push @lines, "";
  127. while (<FH>) {
  128. chomp;
  129. next if not (/\A\#\#\s+/ || /\A\-\-\-\-/);
  130. push @lines, $_;
  131. last;
  132. }
  133. }
  134. close(FH);
  135. if (!$added) {
  136. push @lines, "## Version";
  137. push @lines, "";
  138. push @lines, "This function is available since SDL $revision.";
  139. push @lines, "";
  140. }
  141. open(FH, '>', $fname) or die("Can't open $fname for write: $!\n");
  142. foreach (@lines) {
  143. print FH "$_\n";
  144. }
  145. close(FH);
  146. }
  147. }
  148. }