]> Cypherpunks repositories - gostls13.git/commitdiff
cmd: consolidate "known" os/arch tables into separate package
authorThan McIntosh <thanm@google.com>
Mon, 22 Jul 2024 15:48:31 +0000 (15:48 +0000)
committerThan McIntosh <thanm@google.com>
Mon, 29 Jul 2024 15:38:20 +0000 (15:38 +0000)
Common up the the "known OS/Arch" tables from { cmd/go/internal/imports,
cmd/go/internal/modindex, go/build } and relocate them to a new
package, internal/syslist. No change in functionality.

Updates #68606.

Change-Id: I6414a05c96b8fddbdbd9678d322cb49d9b1b0af3
Reviewed-on: https://go-review.googlesource.com/c/go/+/601357
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/go/internal/imports/build.go
src/cmd/go/internal/modindex/build.go
src/cmd/go/internal/modindex/syslist.go [deleted file]
src/cmd/go/internal/script/conds.go
src/go/build/build.go
src/go/build/deps_test.go
src/internal/goarch/gengoarch.go
src/internal/goos/gengoos.go
src/internal/syslist/syslist.go [moved from src/go/build/syslist.go with 78% similarity]

index 3a4a66b8699c7cc075248064670829e9a0cde529..6a8b7a84cd41531d11a61febc6ee74f54c872625 100644 (file)
@@ -24,6 +24,7 @@ import (
        "errors"
        "fmt"
        "go/build/constraint"
+       "internal/syslist"
        "strings"
        "unicode"
 )
@@ -213,7 +214,7 @@ func matchTag(name string, tags map[string]bool, prefer bool) bool {
        case "darwin":
                return tags["ios"]
        case "unix":
-               return unixOS[cfg.BuildContext.GOOS]
+               return syslist.UnixOS[cfg.BuildContext.GOOS]
        default:
                return false
        }
@@ -295,80 +296,14 @@ func MatchFile(name string, tags map[string]bool) bool {
                l = l[:n-1]
        }
        n := len(l)
-       if n >= 2 && KnownOS[l[n-2]] && KnownArch[l[n-1]] {
+       if n >= 2 && syslist.KnownOS[l[n-2]] && syslist.KnownArch[l[n-1]] {
                return matchTag(l[n-2], tags, true) && matchTag(l[n-1], tags, true)
        }
-       if n >= 1 && KnownOS[l[n-1]] {
+       if n >= 1 && syslist.KnownOS[l[n-1]] {
                return matchTag(l[n-1], tags, true)
        }
-       if n >= 1 && KnownArch[l[n-1]] {
+       if n >= 1 && syslist.KnownArch[l[n-1]] {
                return matchTag(l[n-1], tags, true)
        }
        return true
 }
-
-var KnownOS = map[string]bool{
-       "aix":       true,
-       "android":   true,
-       "darwin":    true,
-       "dragonfly": true,
-       "freebsd":   true,
-       "hurd":      true,
-       "illumos":   true,
-       "ios":       true,
-       "js":        true,
-       "linux":     true,
-       "nacl":      true, // legacy; don't remove
-       "netbsd":    true,
-       "openbsd":   true,
-       "plan9":     true,
-       "solaris":   true,
-       "wasip1":    true,
-       "windows":   true,
-       "zos":       true,
-}
-
-// unixOS is the set of GOOS values matched by the "unix" build tag.
-// This is not used for filename matching.
-// This is the same list as in go/build/syslist.go and cmd/dist/build.go.
-var unixOS = map[string]bool{
-       "aix":       true,
-       "android":   true,
-       "darwin":    true,
-       "dragonfly": true,
-       "freebsd":   true,
-       "hurd":      true,
-       "illumos":   true,
-       "ios":       true,
-       "linux":     true,
-       "netbsd":    true,
-       "openbsd":   true,
-       "solaris":   true,
-}
-
-var KnownArch = map[string]bool{
-       "386":         true,
-       "amd64":       true,
-       "amd64p32":    true, // legacy; don't remove
-       "arm":         true,
-       "armbe":       true,
-       "arm64":       true,
-       "arm64be":     true,
-       "ppc64":       true,
-       "ppc64le":     true,
-       "mips":        true,
-       "mipsle":      true,
-       "mips64":      true,
-       "mips64le":    true,
-       "mips64p32":   true,
-       "mips64p32le": true,
-       "loong64":     true,
-       "ppc":         true,
-       "riscv":       true,
-       "riscv64":     true,
-       "s390":        true,
-       "s390x":       true,
-       "sparc":       true,
-       "sparc64":     true,
-       "wasm":        true,
-}
index 0b06373984190a53f1b2dc1f30e5f96662e0d404..b4dacb0f523a8d4516a5c4419c07a1d4b7f91dc6 100644 (file)
@@ -17,6 +17,7 @@ import (
        "go/build"
        "go/build/constraint"
        "go/token"
+       "internal/syslist"
        "io"
        "io/fs"
        "path/filepath"
@@ -878,7 +879,7 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
        if ctxt.GOOS == "ios" && name == "darwin" {
                return true
        }
-       if name == "unix" && unixOS[ctxt.GOOS] {
+       if name == "unix" && syslist.UnixOS[ctxt.GOOS] {
                return true
        }
        if name == "boringcrypto" {
@@ -941,14 +942,14 @@ func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool {
                l = l[:n-1]
        }
        n := len(l)
-       if n >= 2 && knownOS[l[n-2]] && knownArch[l[n-1]] {
+       if n >= 2 && syslist.KnownOS[l[n-2]] && syslist.KnownArch[l[n-1]] {
                if allTags != nil {
                        // In case we short-circuit on l[n-1].
                        allTags[l[n-2]] = true
                }
                return ctxt.matchTag(l[n-1], allTags) && ctxt.matchTag(l[n-2], allTags)
        }
-       if n >= 1 && (knownOS[l[n-1]] || knownArch[l[n-1]]) {
+       if n >= 1 && (syslist.KnownOS[l[n-1]] || syslist.KnownArch[l[n-1]]) {
                return ctxt.matchTag(l[n-1], allTags)
        }
        return true
diff --git a/src/cmd/go/internal/modindex/syslist.go b/src/cmd/go/internal/modindex/syslist.go
deleted file mode 100644 (file)
index 41adcc5..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2011 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file is a lightly modified copy go/build/syslist_test.go.
-
-package modindex
-
-// 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.
-var knownOS = map[string]bool{
-       "aix":       true,
-       "android":   true,
-       "darwin":    true,
-       "dragonfly": true,
-       "freebsd":   true,
-       "hurd":      true,
-       "illumos":   true,
-       "ios":       true,
-       "js":        true,
-       "linux":     true,
-       "nacl":      true,
-       "netbsd":    true,
-       "openbsd":   true,
-       "plan9":     true,
-       "solaris":   true,
-       "wasip1":    true,
-       "windows":   true,
-       "zos":       true,
-}
-
-// unixOS is the set of GOOS values matched by the "unix" build tag.
-// This is not used for filename matching.
-// This list also appears in cmd/dist/build.go.
-var unixOS = map[string]bool{
-       "aix":       true,
-       "android":   true,
-       "darwin":    true,
-       "dragonfly": true,
-       "freebsd":   true,
-       "hurd":      true,
-       "illumos":   true,
-       "ios":       true,
-       "linux":     true,
-       "netbsd":    true,
-       "openbsd":   true,
-       "solaris":   true,
-}
-
-// knownArch is the list of past, present, and future known GOARCH values.
-// Do not remove from this list, as it is used for filename matching.
-var knownArch = map[string]bool{
-       "386":         true,
-       "amd64":       true,
-       "amd64p32":    true,
-       "arm":         true,
-       "armbe":       true,
-       "arm64":       true,
-       "arm64be":     true,
-       "loong64":     true,
-       "mips":        true,
-       "mipsle":      true,
-       "mips64":      true,
-       "mips64le":    true,
-       "mips64p32":   true,
-       "mips64p32le": true,
-       "ppc":         true,
-       "ppc64":       true,
-       "ppc64le":     true,
-       "riscv":       true,
-       "riscv64":     true,
-       "s390":        true,
-       "s390x":       true,
-       "sparc":       true,
-       "sparc64":     true,
-       "wasm":        true,
-}
index d70f274efc2261a50ce96022bcf44a021b0b1a1d..25dd6e17ea3bde4f90646e1c839d6d5b94198722 100644 (file)
@@ -5,8 +5,8 @@
 package script
 
 import (
-       "cmd/go/internal/imports"
        "fmt"
+       "internal/syslist"
        "os"
        "runtime"
        "sync"
@@ -25,7 +25,7 @@ func DefaultConds() map[string]Cond {
                        if suffix == runtime.GOOS {
                                return true, nil
                        }
-                       if _, ok := imports.KnownOS[suffix]; !ok {
+                       if _, ok := syslist.KnownOS[suffix]; !ok {
                                return false, fmt.Errorf("unrecognized GOOS %q", suffix)
                        }
                        return false, nil
@@ -37,7 +37,7 @@ func DefaultConds() map[string]Cond {
                        if suffix == runtime.GOARCH {
                                return true, nil
                        }
-                       if _, ok := imports.KnownArch[suffix]; !ok {
+                       if _, ok := syslist.KnownArch[suffix]; !ok {
                                return false, fmt.Errorf("unrecognized GOOS %q", suffix)
                        }
                        return false, nil
index 000db9fb652e957e6c29e1eb0fc7443bb4adf83e..9ffffda08a99b12f29ba94d845b489004a1b5e78 100644 (file)
@@ -17,6 +17,7 @@ import (
        "internal/goroot"
        "internal/goversion"
        "internal/platform"
+       "internal/syslist"
        "io"
        "io/fs"
        "os"
@@ -1976,7 +1977,7 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
        if ctxt.GOOS == "ios" && name == "darwin" {
                return true
        }
-       if name == "unix" && unixOS[ctxt.GOOS] {
+       if name == "unix" && syslist.UnixOS[ctxt.GOOS] {
                return true
        }
        if name == "boringcrypto" {
@@ -2039,14 +2040,14 @@ func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool {
                l = l[:n-1]
        }
        n := len(l)
-       if n >= 2 && knownOS[l[n-2]] && knownArch[l[n-1]] {
+       if n >= 2 && syslist.KnownOS[l[n-2]] && syslist.KnownArch[l[n-1]] {
                if allTags != nil {
                        // In case we short-circuit on l[n-1].
                        allTags[l[n-2]] = true
                }
                return ctxt.matchTag(l[n-1], allTags) && ctxt.matchTag(l[n-2], allTags)
        }
-       if n >= 1 && (knownOS[l[n-1]] || knownArch[l[n-1]]) {
+       if n >= 1 && (syslist.KnownOS[l[n-1]] || syslist.KnownArch[l[n-1]]) {
                return ctxt.matchTag(l[n-1], allTags)
        }
        return true
index a0bcb4f27a0be0a2b740cdb7a203eb010e9cd8c2..441cf8d051c934c4a181fdc564394b015ad0a7ad 100644 (file)
@@ -58,6 +58,7 @@ var depsRules = `
          internal/nettrace,
          internal/platform,
          internal/profilerecord,
+         internal/syslist,
          internal/trace/traceviewer/format,
          log/internal,
          math/bits,
@@ -337,7 +338,7 @@ var depsRules = `
        go/doc/comment, go/parser, internal/lazyregexp, text/template
        < go/doc;
 
-       go/build/constraint, go/doc, go/parser, internal/buildcfg, internal/goroot, internal/goversion, internal/platform
+       go/build/constraint, go/doc, go/parser, internal/buildcfg, internal/goroot, internal/goversion, internal/platform, internal/syslist
        < go/build;
 
        # databases
index 0b0be5cd157da4a8ab4b230a051a410d6a67c374..a52936efb60aaac96edaa8d90483567f32c3cab2 100644 (file)
@@ -17,11 +17,11 @@ import (
 var goarches []string
 
 func main() {
-       data, err := os.ReadFile("../../go/build/syslist.go")
+       data, err := os.ReadFile("../../internal/syslist/syslist.go")
        if err != nil {
                log.Fatal(err)
        }
-       const goarchPrefix = `var knownArch = map[string]bool{`
+       const goarchPrefix = `var KnownArch = map[string]bool{`
        inGOARCH := false
        for _, line := range strings.Split(string(data), "\n") {
                if strings.HasPrefix(line, goarchPrefix) {
index 37d9706d1e877cb98f53626628b4600f4c875032..aba0d3c3356f4fbcf3246021014ffac1be2eabe5 100644 (file)
@@ -17,11 +17,11 @@ import (
 var gooses []string
 
 func main() {
-       data, err := os.ReadFile("../../go/build/syslist.go")
+       data, err := os.ReadFile("../../internal/syslist/syslist..go")
        if err != nil {
                log.Fatal(err)
        }
-       const goosPrefix = `var knownOS = map[string]bool{`
+       const goosPrefix = `var KnownOS = map[string]bool{`
        inGOOS := false
        for _, line := range strings.Split(string(data), "\n") {
                if strings.HasPrefix(line, goosPrefix) {
similarity index 78%
rename from src/go/build/syslist.go
rename to src/internal/syslist/syslist.go
index 783bbe697a32d7bc4e884e62a56f5e23c2db7a93..7d1a2b3c3d6e496883a650fd027e8324d34ccad0 100644 (file)
@@ -2,16 +2,19 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package build
+// Package syslist stores tables of OS and ARCH names that are
+// (or at one point were) acceptable build targets.
+
+package syslist
 
 // 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.
+// 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.
-var knownOS = map[string]bool{
+// If you add an entry to this list, look at UnixOS, below.
+var KnownOS = map[string]bool{
        "aix":       true,
        "android":   true,
        "darwin":    true,
@@ -32,11 +35,11 @@ var knownOS = map[string]bool{
        "zos":       true,
 }
 
-// unixOS is the set of GOOS values matched by the "unix" build tag.
+// UnixOS is the set of GOOS values matched by the "unix" build tag.
 // This is not used for filename matching.
 // This list also appears in cmd/dist/build.go and
 // cmd/go/internal/imports/build.go.
-var unixOS = map[string]bool{
+var UnixOS = map[string]bool{
        "aix":       true,
        "android":   true,
        "darwin":    true,
@@ -51,9 +54,9 @@ var unixOS = map[string]bool{
        "solaris":   true,
 }
 
-// knownArch is the list of past, present, and future known GOARCH values.
+// KnownArch is the list of past, present, and future known GOARCH values.
 // Do not remove from this list, as it is used for filename matching.
-var knownArch = map[string]bool{
+var KnownArch = map[string]bool{
        "386":         true,
        "amd64":       true,
        "amd64p32":    true,