fnsince.pl 4.5 KB

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