aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/api/goapi.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2012-10-30 13:12:59 +0100
committerBrad Fitzpatrick <bradfitz@golang.org>2012-10-30 13:12:59 +0100
commit71d9e956a00e95f734f633056882475832d534f4 (patch)
tree54343aa287cb16146f94e9ceffc1b48a5f789cbc /src/cmd/api/goapi.go
parente53a2c40b119509356edcffc1655331c9beb6df5 (diff)
downloadgo-71d9e956a00e95f734f633056882475832d534f4.tar.xz
cmd/api: handle contexts re-converging
Fixes #4303 R=golang-dev, adg CC=golang-dev https://golang.org/cl/6816058
Diffstat (limited to 'src/cmd/api/goapi.go')
-rw-r--r--src/cmd/api/goapi.go35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go
index d6ca892103..26b3482409 100644
--- a/src/cmd/api/goapi.go
+++ b/src/cmd/api/goapi.go
@@ -29,6 +29,7 @@ import (
"os/exec"
"path"
"path/filepath"
+ "regexp"
"runtime"
"sort"
"strconv"
@@ -192,17 +193,29 @@ func main() {
fail = !compareAPI(bw, features, required, optional, exception)
}
+func set(items []string) map[string]bool {
+ s := make(map[string]bool)
+ for _, v := range items {
+ s[v] = true
+ }
+ return s
+}
+
+var spaceParensRx = regexp.MustCompile(` \(\S+?\)`)
+
+func featureWithoutContext(f string) string {
+ if !strings.Contains(f, "(") {
+ return f
+ }
+ return spaceParensRx.ReplaceAllString(f, "")
+}
+
func compareAPI(w io.Writer, features, required, optional, exception []string) (ok bool) {
ok = true
- var optionalSet = make(map[string]bool) // feature => true
- var exceptionSet = make(map[string]bool) // exception => true
- for _, f := range optional {
- optionalSet[f] = true
- }
- for _, f := range exception {
- exceptionSet[f] = true
- }
+ optionalSet := set(optional)
+ exceptionSet := set(exception)
+ featureSet := set(features)
sort.Strings(features)
sort.Strings(required)
@@ -215,15 +228,17 @@ func compareAPI(w io.Writer, features, required, optional, exception []string) (
for len(required) > 0 || len(features) > 0 {
switch {
- case len(features) == 0 || required[0] < features[0]:
+ case len(features) == 0 || (len(required) > 0 && required[0] < features[0]):
feature := take(&required)
if exceptionSet[feature] {
fmt.Fprintf(w, "~%s\n", feature)
+ } else if featureSet[featureWithoutContext(feature)] {
+ // okay.
} else {
fmt.Fprintf(w, "-%s\n", feature)
ok = false // broke compatibility
}
- case len(required) == 0 || required[0] > features[0]:
+ case len(required) == 0 || (len(features) > 0 && required[0] > features[0]):
newFeature := take(&features)
if optionalSet[newFeature] {
// Known added feature to the upcoming release.