From b6c16068897c370661f03af91e8ba46860408e61 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 8 Jun 2022 16:33:45 -0700 Subject: [PATCH] internal/goarch, internal/goos: update generators for syslist.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update the generator programs for the changes to syslist.go in CL 390274 and the changes to the generated files in CL 344955. Tested by running the programs and verifying that the files did not change. Fixes #53299 Change-Id: I2b2c5769f7e9283aa05c803256d2ea1eb9ad1547 Reviewed-on: https://go-review.googlesource.com/c/go/+/411334 Reviewed-by: Daniel Martí Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Cherry Mui Auto-Submit: Ian Lance Taylor TryBot-Result: Gopher Robot --- src/go/build/syslist.go | 4 ++++ src/internal/goarch/gengoarch.go | 19 +++++++++++-------- src/internal/goos/gengoos.go | 19 +++++++++++-------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/go/build/syslist.go b/src/go/build/syslist.go index ea67662c3e2..35cffce6dca 100644 --- a/src/go/build/syslist.go +++ b/src/go/build/syslist.go @@ -4,6 +4,10 @@ package build +// Note that this file is read by internal/goarch/gengoarch.go and by +// internal/goos/gengoos.go. If you change this file, look at those +// files as well. + // knownOS is the list of past, present, and future known GOOS values. // Do not remove from this list, as it is used for filename matching. // If you add an entry to this list, look at unixOS, below. diff --git a/src/internal/goarch/gengoarch.go b/src/internal/goarch/gengoarch.go index 3c706e04ad0..0b0be5cd157 100644 --- a/src/internal/goarch/gengoarch.go +++ b/src/internal/goarch/gengoarch.go @@ -11,7 +11,6 @@ import ( "fmt" "log" "os" - "strconv" "strings" ) @@ -22,14 +21,18 @@ func main() { if err != nil { log.Fatal(err) } - const goarchPrefix = `const goarchList = ` + const goarchPrefix = `var knownArch = map[string]bool{` + inGOARCH := false for _, line := range strings.Split(string(data), "\n") { if strings.HasPrefix(line, goarchPrefix) { - text, err := strconv.Unquote(strings.TrimPrefix(line, goarchPrefix)) - if err != nil { - log.Fatalf("parsing goarchList: %v", err) - } - goarches = strings.Fields(text) + inGOARCH = true + } else if inGOARCH && strings.HasPrefix(line, "}") { + break + } else if inGOARCH { + goarch := strings.Fields(line)[0] + goarch = strings.TrimPrefix(goarch, `"`) + goarch = strings.TrimSuffix(goarch, `":`) + goarches = append(goarches, goarch) } } @@ -39,7 +42,7 @@ func main() { } var buf bytes.Buffer fmt.Fprintf(&buf, "// Code generated by gengoarch.go using 'go generate'. DO NOT EDIT.\n\n") - fmt.Fprintf(&buf, "//go:build %s\n", target) // must explicitly include target for bootstrapping purposes + fmt.Fprintf(&buf, "//go:build %s\n\n", target) // must explicitly include target for bootstrapping purposes fmt.Fprintf(&buf, "package goarch\n\n") fmt.Fprintf(&buf, "const GOARCH = `%s`\n\n", target) for _, goarch := range goarches { diff --git a/src/internal/goos/gengoos.go b/src/internal/goos/gengoos.go index 1b62503fd00..37d9706d1e8 100644 --- a/src/internal/goos/gengoos.go +++ b/src/internal/goos/gengoos.go @@ -11,7 +11,6 @@ import ( "fmt" "log" "os" - "strconv" "strings" ) @@ -22,14 +21,18 @@ func main() { if err != nil { log.Fatal(err) } - const goosPrefix = `const goosList = ` + const goosPrefix = `var knownOS = map[string]bool{` + inGOOS := false for _, line := range strings.Split(string(data), "\n") { if strings.HasPrefix(line, goosPrefix) { - text, err := strconv.Unquote(strings.TrimPrefix(line, goosPrefix)) - if err != nil { - log.Fatalf("parsing goosList: %v", err) - } - gooses = strings.Fields(text) + inGOOS = true + } else if inGOOS && strings.HasPrefix(line, "}") { + break + } else if inGOOS { + goos := strings.Fields(line)[0] + goos = strings.TrimPrefix(goos, `"`) + goos = strings.TrimSuffix(goos, `":`) + gooses = append(gooses, goos) } } @@ -50,7 +53,7 @@ func main() { tags = append(tags, target) // must explicitly include target for bootstrapping purposes var buf bytes.Buffer fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n") - fmt.Fprintf(&buf, "//go:build %s\n", strings.Join(tags, " && ")) + fmt.Fprintf(&buf, "//go:build %s\n\n", strings.Join(tags, " && ")) fmt.Fprintf(&buf, "package goos\n\n") fmt.Fprintf(&buf, "const GOOS = `%s`\n\n", target) for _, goos := range gooses {