Skip to content

Commit b977e1b

Browse files
rscgopherbot
authored andcommitted
relnote: simplify invocation
Plain 'relnote' works now. Change-Id: I16e5cd1854bd11154aeb14896e5a50e07c4ce1c4 Reviewed-on: https://go-review.googlesource.com/c/build/+/453097 Auto-Submit: Russ Cox <[email protected]> Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent 28f7994 commit b977e1b

File tree

1 file changed

+45
-39
lines changed

1 file changed

+45
-39
lines changed

cmd/relnote/relnote.go

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import (
1212
"flag"
1313
"fmt"
1414
"html"
15-
"io/ioutil"
1615
"log"
16+
"os"
1717
"path"
18+
"path/filepath"
1819
"regexp"
20+
"runtime"
1921
"sort"
2022
"strconv"
2123
"strings"
@@ -27,11 +29,7 @@ import (
2729
"golang.org/x/build/repos"
2830
)
2931

30-
var (
31-
verbose = flag.Bool("v", false, "print verbose logging")
32-
htmlMode = flag.Bool("html", false, "write HTML output")
33-
exclFile = flag.String("exclude-from", "", "optional path to release notes HTML file. If specified, any 'CL NNNN' occurrence in the content will cause that CL to be excluded from this tool's output.")
34-
)
32+
var verbose = flag.Bool("v", false, "print verbose logging")
3533

3634
// change is a change that was noted via a RELNOTE= comment.
3735
type change struct {
@@ -95,6 +93,22 @@ func main() {
9593
log.SetFlags(0)
9694
flag.Parse()
9795

96+
goroot := runtime.GOROOT()
97+
if goroot == "" {
98+
log.Fatalf("missing GOROOT")
99+
}
100+
101+
// Read internal/goversion to find the next release.
102+
data, err := os.ReadFile(filepath.Join(goroot, "src/internal/goversion/goversion.go"))
103+
if err != nil {
104+
log.Fatal(err)
105+
}
106+
m := regexp.MustCompile(`Version = (\d+)`).FindStringSubmatch(string(data))
107+
if m == nil {
108+
log.Fatalf("cannot find Version in src/internal/goversion/goversion.go")
109+
}
110+
version := m[1]
111+
98112
// Releases are every 6 months. Walk forward by 6 month increments to next release.
99113
cutoff := time.Date(2016, time.August, 1, 00, 00, 00, 0, time.UTC)
100114
now := time.Now()
@@ -114,13 +128,9 @@ func main() {
114128
log.Fatal(err)
115129
}
116130

117-
var existingHTML []byte
118-
if *exclFile != "" {
119-
var err error
120-
existingHTML, err = ioutil.ReadFile(*exclFile)
121-
if err != nil {
122-
log.Fatal(err)
123-
}
131+
existingHTML, err := os.ReadFile(filepath.Join(goroot, "doc/go1."+version+".html"))
132+
if err != nil {
133+
log.Fatal(err)
124134
}
125135

126136
corpus, err := godata.Get(context.Background())
@@ -213,34 +223,30 @@ func main() {
213223
}
214224
sort.Strings(pkgs)
215225

216-
if *htmlMode {
217-
for _, pkg := range pkgs {
218-
if !strings.HasPrefix(pkg, "cmd/") {
219-
continue
220-
}
221-
for _, change := range changes[pkg] {
222-
fmt.Printf("<!-- %s: %s -->\n", change.ID(), change.TextLine())
223-
}
226+
// TODO(rsc): Instead of making people do the mechanical work of
227+
// copy and pasting this TODO HTML into the release notes,
228+
// relnote should edit the release notes directly to insert the TODOs.
229+
// Then it should print to standard output only a summary of the
230+
// changes it made.
231+
for _, pkg := range pkgs {
232+
if !strings.HasPrefix(pkg, "cmd/") {
233+
continue
224234
}
225-
for _, pkg := range pkgs {
226-
if strings.HasPrefix(pkg, "cmd/") {
227-
continue
228-
}
229-
fmt.Printf("\n<dl id=%q><dt><a href=%q>%s</a></dt>\n <dd>",
230-
pkg, "/pkg/"+pkg+"/", pkg)
231-
for _, change := range changes[pkg] {
232-
fmt.Printf("\n <p><!-- %s -->\n TODO: <a href=%q>%s</a>: %s\n </p>\n",
233-
change.ID(), change.URL(), change.URL(), html.EscapeString(change.TextLine()))
234-
}
235-
fmt.Printf(" </dd>\n</dl><!-- %s -->\n", pkg)
235+
for _, change := range changes[pkg] {
236+
fmt.Printf("<!-- %s -->\n<p>\n <!-- %s -->\n</p>\n", change.ID(), change.TextLine())
236237
}
237-
} else {
238-
for _, pkg := range pkgs {
239-
fmt.Printf("%s\n", pkg)
240-
for _, change := range changes[pkg] {
241-
fmt.Printf(" %s: %s\n", change.URL(), change.TextLine())
242-
}
238+
}
239+
for _, pkg := range pkgs {
240+
if strings.HasPrefix(pkg, "cmd/") {
241+
continue
242+
}
243+
fmt.Printf("\n<dl id=%q><dt><a href=%q>%s</a></dt>\n <dd>",
244+
pkg, "/pkg/"+pkg+"/", pkg)
245+
for _, change := range changes[pkg] {
246+
fmt.Printf("\n <p><!-- %s -->\n TODO: <a href=%q>%s</a>: %s\n </p>\n",
247+
change.ID(), change.URL(), change.URL(), html.EscapeString(change.TextLine()))
243248
}
249+
fmt.Printf(" </dd>\n</dl><!-- %s -->\n", pkg)
244250
}
245251
}
246252

@@ -354,7 +360,7 @@ func hasLabel(issue *maintner.GitHubIssue, label string) bool {
354360
return false
355361
}
356362

357-
var numbersRE = regexp.MustCompile(`(?m)(?:^|\s)#([0-9]{3,})`)
363+
var numbersRE = regexp.MustCompile(`(?m)(?:^|\s|golang/go)#([0-9]{3,})`)
358364
var golangGoNumbersRE = regexp.MustCompile(`(?m)golang/go#([0-9]{3,})`)
359365

360366
// issueNumbers returns the golang/go issue numbers referred to by the CL.

0 commit comments

Comments
 (0)