fnsince.pl 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. $funcs{'SDL_WinRTRunApp'} = '2.0.3';
  81. if (not defined $wikipath) {
  82. foreach my $release (@releases) {
  83. foreach my $fn (sort keys %funcs) {
  84. print("$fn: $funcs{$fn}\n") if $funcs{$fn} eq $release;
  85. }
  86. }
  87. } else {
  88. if (defined $wikipath) {
  89. chdir($wikipath);
  90. foreach my $fn (keys %funcs) {
  91. my $revision = $funcs{$fn};
  92. $revision = $next_release if $revision eq 'HEAD';
  93. my $fname = "$fn.mediawiki";
  94. if ( ! -f $fname ) {
  95. #print STDERR "No such file: $fname\n";
  96. next;
  97. }
  98. my @lines = ();
  99. open(FH, '<', $fname) or die("Can't open $fname for read: $!\n");
  100. my $added = 0;
  101. while (<FH>) {
  102. chomp;
  103. if ((/\A\-\-\-\-/) && (!$added)) {
  104. push @lines, "== Version ==";
  105. push @lines, "";
  106. push @lines, "This function is available since SDL $revision.";
  107. push @lines, "";
  108. $added = 1;
  109. }
  110. push @lines, $_;
  111. next if not /\A\=\=\s+Version\s+\=\=/;
  112. $added = 1;
  113. push @lines, "";
  114. push @lines, "This function is available since SDL $revision.";
  115. push @lines, "";
  116. while (<FH>) {
  117. chomp;
  118. next if not (/\A\=\=\s+/ || /\A\-\-\-\-/);
  119. push @lines, $_;
  120. last;
  121. }
  122. }
  123. close(FH);
  124. if (!$added) {
  125. push @lines, "== Version ==";
  126. push @lines, "";
  127. push @lines, "This function is available since SDL $revision.";
  128. push @lines, "";
  129. }
  130. open(FH, '>', $fname) or die("Can't open $fname for write: $!\n");
  131. foreach (@lines) {
  132. print FH "$_\n";
  133. }
  134. close(FH);
  135. }
  136. }
  137. }