summaryrefslogtreecommitdiffstats
path: root/js/src/devtools/release/release-notes
blob: 48cc53ac9ea6d8415f9b7131a4a9a6b278ffc5d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/perl

# How to use:
#
# Step 1: run release-notes diff old-jsapi.h new-jsapi.h > diff.txt
#
# Step 2: edit diff.txt
#  - when a function has been renamed, get the - and + lines adjacent and mark the - line with [renamed] at the end
#  - when a function has been replaced, do the same (replacements behave differently)
#  - for anything that isn't a simple addition, deletion, rename, or replace, tag with [other]
#    (things tagged [other] will be put in a separate section for manual fixup)
#
# Step 3: run release-notes < diff.txt > changes.txt
#  - this will group changes into sections and annotate them with bug numbers
#  - the bugs chosen are just the bug that last touched each line, and are unlikely to be entirely accurate
#
# Step 4: run release-notes mdn < changes.txt > final.txt
#  - this will add an MDN link to every list item, first checking whether such a link is valid
#
# Step 5: paste into the MDN page, eg https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/45

# Upcoming: basing everything off of jsapi.h is probably not going to work for
# much longer, given that more stuff is moving into js/public. Scan
# js/public/*.h too and record where everything comes from (to automate header
# changes in the notes)?
#
# This is only looking at C style APIs. Dump out all methods too?
#
# The enbuggification should be split out into a separate phase because it is
# wrong a fair amount of the time (whitespace changes, parameter changes,
# etc.), and should have a way of running repeatedly so you can incrementally
# fix stuff up.
#
# It would be very nice to have an example program that links against mozjs,
# tested in CI, so we can diff that for release notes.

use strict;
use warnings;

if (@ARGV && $ARGV[0] eq 'diff') {
    my ($orig_file, $new_file) = @ARGV[1..2];
    my $orig_api = grab_api($orig_file);
    my $new_api = grab_api($new_file);
    diff_apis($orig_api, $new_api);
    exit 0;
}

my $path = "/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_Reference";
my $url_prefix = "https://developer.mozilla.org$path";

if (@ARGV && $ARGV[0] eq 'mdn') {
    shift(@ARGV);
    while(<>) {
        if (/<li>([\w:]+)/) {
            print STDERR "Checking $1...\n";
            system("wget", "-q", "$url_prefix/$1");
            if ($? == 0) {
                s!<li>([\w:]+)!<li><a href="$path/$1">$1</a>!;
            }
        }
        print;
    }
    exit 0;
}

sub grab_api {
    my ($file) = @_;
    open(my $fh, "<", $file) or die "open $file: $!";
    my $grabbing;
    my @api;
    while(<$fh>) {
        if ($grabbing && /^(\w+)/) {
            push @api, $1;
        }
        $grabbing = /JS_PUBLIC_API/;
    }
    return \@api;
}

sub diff_apis {
    my ($old, $new) = @_;
    my %old;
    @old{@$old} = ();
    my %new;
    @new{@$new} = ();

    open(my $ofh, ">", "/tmp/r-c.diff.1");
    print $ofh "$_\n" foreach (@$old);
    close $ofh;
    open(my $nfh, ">", "/tmp/r-c.diff.2");
    print $nfh "$_\n" foreach (@$new);
    close $nfh;
    open(my $diff, "diff -u /tmp/r-c.diff.1 /tmp/r-c.diff.2 |");
    while(<$diff>) {
        if (/^-(\w+)/) {
            next if exists $new{$1}; # Still exists, so skip it
        } elsif (/^\+(\w+)/) {
            next if exists $old{$1}; # It was already there, skip it
        }
        print;
    }
}

my @added;
my @renamed;
my @replaced;
my @deleted;
my @other;

my %N;

my $renaming;
my $replacing;
while (<>) {
    my $name;
    if (/^[ +-](\w+)/) {
        $name = $1;
        $N{$name} = $name =~ /^JS_/ ? $name : "JS::$name";
    }

    if (/^-/) {
        die if ! $name;
        if (/\[rename\]/) {
            $renaming = $name;
        } elsif (/\[replace\]/) {
            $replacing = $name;
        } elsif (/\[other\]/) {
            push @other, $name;
        } else {
            push @deleted, $name;
        }
    } elsif (/^\+/) {
        die if ! $name;
        if ($renaming) {
            push @renamed, [ $renaming, $name ];
            undef $renaming;
        } elsif ($replacing) {
            push @replaced, [ $replacing, $name ];
            undef $replacing;
        } elsif (/\[other\]/) {
            push @other, $name;
        } else {
            push @added, $name;
        }
    }
}

open(my $fh, "<", "jsapi.blame") or die "open jsapi.blame: $!";
my $grabbing;
my %changerev;
my %revs;
while(<$fh>) {
    if ($grabbing && /^\s*(\d+): (\w+)/ ) {
        $changerev{$2} = $1;
        $revs{$1} = 1;
    }
    $grabbing = /JS_PUBLIC_API/;
}

my %bug;
for my $rev (keys %revs) {
    open(my $fh, "hg log -r $rev -T '{desc}' |");
    while(<$fh>) {
        if (/[bB]ug (\d+)/) {
            $bug{$rev} = $1;
        }
    }
}

sub get_bug_suffix {
    my ($api) = @_;
    $DB::single = 1 if ! $changerev{$api};
    my $bug = $bug{$changerev{$api}};
    return $bug ? " {{{bug($bug)}}}" : "";
}

print "(new apis)\n";
print "<ul>\n";
print "  <li>$N{$_}" . get_bug_suffix($_) . "</li>\n" foreach @added;
print "  <li>$N{$_->[0]} renamed to $N{$_->[1]}" . get_bug_suffix($_->[1]) . "</li>\n" foreach @renamed;
print "  <li>$N{$_->[0]} replaced with $N{$_->[1]}" . get_bug_suffix($_->[1]) . "</li>\n" foreach @replaced;
print "</ul>\n";
print "\n";

print qq(<h2 id="Deleted_APIs">Deleted APIs</h2>\n);
print "<ul>\n";
print "  <li>$N{$_}</li>\n" foreach @deleted;
print "</ul>\n";
print "\n";

print qq(<h2 id="Changed_APIs">Changed APIs</h2>\n);
print "<ul>\n";
print "  <li>$N{$_}" . get_bug_suffix($_) . "</li>\n" foreach @other;
print "</ul>\n";
print "\n";