fnsince.pl 5.5 KB

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