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
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
var internalPkg = regexp.MustCompile(`(^|/)internal($|/)`)
+var exitCode = 0
+
func main() {
+ log.SetPrefix("api: ")
+ log.SetFlags(0)
flag.Parse()
if build.Default.GOROOT == "" {
}
}
- 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 {
}
}
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.
}
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
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)
}