aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/api/api.go
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitshur@golang.org>2023-04-26 16:41:41 -0400
committerGopher Robot <gobot@golang.org>2023-04-27 14:07:10 +0000
commite8c8b79f000515e086012df632f01fc0ec21076b (patch)
tree58fb99c578134ab813f8e85e28e2c9ca6c402076 /src/cmd/api/api.go
parent0972096c5c2facec2d5c6db08a2df32684f41caa (diff)
downloadgo-e8c8b79f000515e086012df632f01fc0ec21076b.tar.xz
cmd/api: remove unused functionality
We no longer use the optional parameter to compareAPI. We now always set allowAdd to false. (Except in tests, making them less useful than they could be.) Flags and parsing their value are no more. Remove all the unused functionality and update test cases so they're closer to what the API checker does when it runs for real. Order the features, required, exception variables and fields more consistently. For #43956. Change-Id: Iaa4656a89a3fca3129742165a448d385e55e4a98 Reviewed-on: https://go-review.googlesource.com/c/go/+/489436 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/api/api.go')
-rw-r--r--src/cmd/api/api.go65
1 files changed, 10 insertions, 55 deletions
diff --git a/src/cmd/api/api.go b/src/cmd/api/api.go
index 4dd33b13a5..376dc53fdc 100644
--- a/src/cmd/api/api.go
+++ b/src/cmd/api/api.go
@@ -10,7 +10,6 @@ import (
"bufio"
"bytes"
"encoding/json"
- "flag"
"fmt"
"go/ast"
"go/build"
@@ -46,8 +45,7 @@ func goCmd() string {
return "go"
}
-// contexts are the default contexts which are scanned, unless
-// overridden by the -contexts flag.
+// contexts are the default contexts which are scanned.
var contexts = []*build.Context{
{GOOS: "linux", GOARCH: "386", CgoEnabled: true},
{GOOS: "linux", GOARCH: "386"},
@@ -96,25 +94,6 @@ func contextName(c *build.Context) string {
return s
}
-func parseContext(c string) *build.Context {
- parts := strings.Split(c, "-")
- if len(parts) < 2 {
- log.Fatalf("bad context: %q", c)
- }
- bc := &build.Context{
- GOOS: parts[0],
- GOARCH: parts[1],
- }
- if len(parts) == 3 {
- if parts[2] == "cgo" {
- bc.CgoEnabled = true
- } else {
- log.Fatalf("bad context: %q", c)
- }
- }
- return bc
-}
-
var internalPkg = regexp.MustCompile(`(^|/)internal($|/)`)
var exitCode = 0
@@ -152,12 +131,7 @@ func Check(t *testing.T) {
var featureCtx = make(map[string]map[string]bool) // feature -> context name -> true
for _, w := range walkers {
- pkgNames := w.stdPackages
- if flag.NArg() > 0 {
- pkgNames = flag.Args()
- }
-
- for _, name := range pkgNames {
+ for _, name := range w.stdPackages {
pkg, err := w.import_(name)
if _, nogo := err.(*build.NoGoError); nogo {
continue
@@ -193,7 +167,7 @@ func Check(t *testing.T) {
bw := bufio.NewWriter(os.Stdout)
defer bw.Flush()
- var required, optional []string
+ var required []string
for _, file := range checkFiles {
required = append(required, fileFeatures(file, needApproval(file))...)
}
@@ -205,7 +179,7 @@ func Check(t *testing.T) {
if exitCode == 1 {
t.Errorf("API database problems found")
}
- if !compareAPI(bw, features, required, optional, exception, false) {
+ if !compareAPI(bw, features, required, exception) {
t.Errorf("API differences found")
}
}
@@ -251,12 +225,11 @@ func portRemoved(feature string) bool {
strings.Contains(feature, "(darwin-386-cgo)")
}
-func compareAPI(w io.Writer, features, required, optional, exception []string, allowAdd bool) (ok bool) {
+func compareAPI(w io.Writer, features, required, exception []string) (ok bool) {
ok = true
- optionalSet := set(optional)
- exceptionSet := set(exception)
featureSet := set(features)
+ exceptionSet := set(exception)
sort.Strings(features)
sort.Strings(required)
@@ -267,7 +240,7 @@ func compareAPI(w io.Writer, features, required, optional, exception []string, a
return s
}
- for len(required) > 0 || len(features) > 0 {
+ for len(features) > 0 || len(required) > 0 {
switch {
case len(features) == 0 || (len(required) > 0 && required[0] < features[0]):
feature := take(&required)
@@ -288,33 +261,15 @@ func compareAPI(w io.Writer, features, required, optional, exception []string, a
}
case len(required) == 0 || (len(features) > 0 && required[0] > features[0]):
newFeature := take(&features)
- if optionalSet[newFeature] {
- // Known added feature to the upcoming release.
- // Delete it from the map so we can detect any upcoming features
- // which were never seen. (so we can clean up the nextFile)
- delete(optionalSet, newFeature)
- } else {
- fmt.Fprintf(w, "+%s\n", newFeature)
- if !allowAdd {
- ok = false // we're in lock-down mode for next release
- }
- }
+ fmt.Fprintf(w, "+%s\n", newFeature)
+ ok = false // feature not in api/next/*
default:
take(&required)
take(&features)
}
}
- // In next file, but not in API.
- var missing []string
- for feature := range optionalSet {
- missing = append(missing, feature)
- }
- sort.Strings(missing)
- for _, feature := range missing {
- fmt.Fprintf(w, "±%s\n", feature)
- }
- return
+ return ok
}
// aliasReplacer applies type aliases to earlier API files,