]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/api: make check pickier about api/*.txt
authorRuss Cox <rsc@golang.org>
Tue, 13 Sep 2022 13:51:55 +0000 (09:51 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 2 Nov 2022 19:08:10 +0000 (19:08 +0000)
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>

api/next/42537.txt
api/next/43620.txt
api/next/45899.txt
api/next/46746.txt
api/next/50429.txt
api/next/51896.txt
api/next/53482.txt
src/cmd/api/goapi.go

index 4f2446aaf354a15fdb328ddeab6788fcdc95df62..bc83639a1d41b9ed710fb9a9f1b79ab2d1423ba6 100644 (file)
@@ -1,4 +1,4 @@
 pkg bytes, func CutPrefix([]uint8, []uint8) ([]uint8, bool) #42537
 pkg bytes, func CutSuffix([]uint8, []uint8) ([]uint8, bool) #42537
 pkg strings, func CutPrefix(string, string) (string, bool) #42537
-pkg strings, func CutSuffix(string, string) (string, bool) #42537
\ No newline at end of file
+pkg strings, func CutSuffix(string, string) (string, bool) #42537
index 9d272fd0c7153b66b679adb8a672ec07534f5b18..6753f1527fc9b68a1e9a780062ca19b40ea3e81d 100644 (file)
@@ -1 +1 @@
-pkg testing, method (*B) Elapsed() time.Duration #43620
\ No newline at end of file
+pkg testing, method (*B) Elapsed() time.Duration #43620
index a823142b15d49a49ea9bb4b1c9ba7337ac140799..9b06edbb3c4bf123922f5261e1f3b6850e1a0181 100644 (file)
@@ -2,4 +2,4 @@ pkg io, type OffsetWriter struct #45899
 pkg io, func NewOffsetWriter(WriterAt, int64) *OffsetWriter #45899
 pkg io, method (*OffsetWriter) Write([]uint8) (int, error) #45899
 pkg io, method (*OffsetWriter) WriteAt([]uint8, int64) (int, error) #45899
-pkg io, method (*OffsetWriter) Seek(int64, int) (int64, error) #45899
\ No newline at end of file
+pkg io, method (*OffsetWriter) Seek(int64, int) (int64, error) #45899
index ae07682b34b8b5ef9884dde7fe82290cf90430ac..f48771d52243405a1b86385c67d40c93560f682d 100644 (file)
@@ -1,2 +1,2 @@
 pkg reflect, method (Value) Comparable() bool #46746
-pkg reflect, method (Value) Equal(Value) bool #46746
\ No newline at end of file
+pkg reflect, method (Value) Equal(Value) bool #46746
index 558937de1cbed322e06ca353e02a150c208df890..2c51384c68d94bf108039bb771e46acb7a7883a6 100644 (file)
@@ -1 +1 @@
-pkg go/ast, type RangeStmt struct, Range token.Pos #50429
\ No newline at end of file
+pkg go/ast, type RangeStmt struct, Range token.Pos #50429
index d4ef14cfa2b8d221cad82ea10380b21f58d2627a..ca7ecd069b41b6f24ccf661b0ec180d1c36b0c5b 100644 (file)
@@ -1 +1 @@
-pkg unicode/utf16, func AppendRune([]uint16, int32) []uint16 #51896
\ No newline at end of file
+pkg unicode/utf16, func AppendRune([]uint16, int32) []uint16 #51896
index a54894498fc0d7567a1ced19a512d0d0b9124814..d437c8abb2aa12f42c0ccfe402d53550d3cb2d9a 100644 (file)
@@ -1,2 +1,2 @@
-pkg net, const FlagRunning = 32 #53482\r
-pkg net, const FlagRunning Flags #53482\r
+pkg net, const FlagRunning = 32 #53482
+pkg net, const FlagRunning Flags #53482
index e6bf62df1fb5cb29d200dfc2a5a9d0b3288ecbfc..894657c117a47987060a44416b16a94ff23b4089 100644 (file)
@@ -126,7 +126,11 @@ func setContexts() {
 
 var internalPkg = regexp.MustCompile(`(^|/)internal($|/)`)
 
+var exitCode = 0
+
 func main() {
+       log.SetPrefix("api: ")
+       log.SetFlags(0)
        flag.Parse()
 
        if build.Default.GOROOT == "" {
@@ -199,16 +203,14 @@ func main() {
                }
        }
 
-       fail := false
+       bw := bufio.NewWriter(os.Stdout)
        defer func() {
-               if fail {
-                       os.Exit(1)
+               bw.Flush()
+               if exitCode != 0 {
+                       os.Exit(exitCode)
                }
        }()
 
-       bw := bufio.NewWriter(os.Stdout)
-       defer bw.Flush()
-
        if *checkFiles == "" {
                sort.Strings(features)
                for _, f := range features {
@@ -228,7 +230,9 @@ func main() {
                }
        }
        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.
@@ -362,9 +366,26 @@ func fileFeatures(filename string) []string {
        }
        bs, err := os.ReadFile(filename)
        if err != nil {
-               log.Fatalf("Error reading file %s: %v", filename, err)
+               log.Fatal(err)
        }
        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)
        lines := strings.Split(s, "\n")
        var nonblank []string
@@ -376,11 +397,13 @@ func fileFeatures(filename string) []string {
                if needApproval {
                        feature, approval, ok := strings.Cut(line, "#")
                        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)
                        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)
                }