mirror of
https://github.com/golang/go
synced 2024-11-22 15:34:53 -07:00
cmd/api: make check pickier about api/*.txt
We don't have a formatter for these files, so check here that they are in the right form to allow 'cat next/*.txt >go1.X.txt' at the end of each cycle. Fix the api files that the check finds. Change-Id: I0c5e4ab11751c7d0afce32503131d487313f41c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/431335 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
be7068fb08
commit
ca8b31920a
@ -126,7 +126,11 @@ func setContexts() {
|
|||||||
|
|
||||||
var internalPkg = regexp.MustCompile(`(^|/)internal($|/)`)
|
var internalPkg = regexp.MustCompile(`(^|/)internal($|/)`)
|
||||||
|
|
||||||
|
var exitCode = 0
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
log.SetPrefix("api: ")
|
||||||
|
log.SetFlags(0)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if build.Default.GOROOT == "" {
|
if build.Default.GOROOT == "" {
|
||||||
@ -199,16 +203,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fail := false
|
bw := bufio.NewWriter(os.Stdout)
|
||||||
defer func() {
|
defer func() {
|
||||||
if fail {
|
bw.Flush()
|
||||||
os.Exit(1)
|
if exitCode != 0 {
|
||||||
|
os.Exit(exitCode)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
bw := bufio.NewWriter(os.Stdout)
|
|
||||||
defer bw.Flush()
|
|
||||||
|
|
||||||
if *checkFiles == "" {
|
if *checkFiles == "" {
|
||||||
sort.Strings(features)
|
sort.Strings(features)
|
||||||
for _, f := range features {
|
for _, f := range features {
|
||||||
@ -228,7 +230,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exception := fileFeatures(*exceptFile)
|
exception := fileFeatures(*exceptFile)
|
||||||
fail = !compareAPI(bw, features, required, optional, exception, *allowNew)
|
if !compareAPI(bw, features, required, optional, exception, *allowNew) {
|
||||||
|
exitCode = 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// export emits the exported package features.
|
// export emits the exported package features.
|
||||||
@ -362,9 +366,26 @@ func fileFeatures(filename string) []string {
|
|||||||
}
|
}
|
||||||
bs, err := os.ReadFile(filename)
|
bs, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error reading file %s: %v", filename, err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
s := string(bs)
|
s := string(bs)
|
||||||
|
|
||||||
|
// Diagnose common mistakes people make,
|
||||||
|
// since there is no apifmt to format these files.
|
||||||
|
// The missing final newline is important for the
|
||||||
|
// final release step of cat next/*.txt >go1.X.txt.
|
||||||
|
// If the files don't end in full lines, the concatenation goes awry.
|
||||||
|
if strings.Contains(s, "\r") {
|
||||||
|
log.Printf("%s: contains CRLFs", filename)
|
||||||
|
exitCode = 1
|
||||||
|
}
|
||||||
|
if s == "" {
|
||||||
|
log.Printf("%s: empty file", filename)
|
||||||
|
exitCode = 1
|
||||||
|
} else if s[len(s)-1] != '\n' {
|
||||||
|
log.Printf("%s: missing final newline", filename)
|
||||||
|
exitCode = 1
|
||||||
|
}
|
||||||
s = aliasReplacer.Replace(s)
|
s = aliasReplacer.Replace(s)
|
||||||
lines := strings.Split(s, "\n")
|
lines := strings.Split(s, "\n")
|
||||||
var nonblank []string
|
var nonblank []string
|
||||||
@ -376,11 +397,13 @@ func fileFeatures(filename string) []string {
|
|||||||
if needApproval {
|
if needApproval {
|
||||||
feature, approval, ok := strings.Cut(line, "#")
|
feature, approval, ok := strings.Cut(line, "#")
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatalf("%s:%d: missing proposal approval\n", filename, i+1)
|
log.Printf("%s:%d: missing proposal approval\n", filename, i+1)
|
||||||
|
exitCode = 1
|
||||||
}
|
}
|
||||||
_, err := strconv.Atoi(approval)
|
_, err := strconv.Atoi(approval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("%s:%d: malformed proposal approval #%s\n", filename, i+1, approval)
|
log.Printf("%s:%d: malformed proposal approval #%s\n", filename, i+1, approval)
|
||||||
|
exitCode = 1
|
||||||
}
|
}
|
||||||
line = strings.TrimSpace(feature)
|
line = strings.TrimSpace(feature)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user