]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: fix build tag parser
authorRuss Cox <rsc@golang.org>
Mon, 20 Apr 2015 03:55:47 +0000 (23:55 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 3 Jun 2015 20:35:04 +0000 (20:35 +0000)
It was mishandling conjunctions containing negations.

Change-Id: Ife571b28416870ba2ceadbdac5ecb4670432bba1
Reviewed-on: https://go-review.googlesource.com/9151
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/dist/build.go

index 0cdb7d69f77ba69032a605a7212528b97681ff35..2262a736de2a3ae23acc16beff1bfcde45c69120 100644 (file)
@@ -714,17 +714,31 @@ func install(dir string) {
        run("", CheckExit|ShowOutput, link...)
 }
 
-// matchfield reports whether the field matches this build.
+// matchfield reports whether the field (x,y,z) matches this build.
+// all the elements in the field must be satisfied.
 func matchfield(f string) bool {
        for _, tag := range strings.Split(f, ",") {
-               if tag == goos || tag == goarch || tag == "cmd_go_bootstrap" || tag == "go1.1" || (goos == "android" && tag == "linux") {
-                       continue
+               if !matchtag(tag) {
+                       return false
                }
-               return false
        }
        return true
 }
 
+// matchtag reports whether the tag (x or !x) matches this build.
+func matchtag(tag string) bool {
+       if tag == "" {
+               return false
+       }
+       if tag[0] == '!' {
+               if len(tag) == 1 || tag[1] == '!' {
+                       return false
+               }
+               return !matchtag(tag[1:])
+       }
+       return tag == goos || tag == goarch || tag == "cmd_go_bootstrap" || tag == "go1.1" || (goos == "android" && tag == "linux")
+}
+
 // shouldbuild reports whether we should build this file.
 // It applies the same rules that are used with context tags
 // in package go/build, except that the GOOS and GOARCH
@@ -783,7 +797,7 @@ func shouldbuild(file, dir string) bool {
                        continue
                }
                for _, p := range fields[2:] {
-                       if (p[0] == '!' && !matchfield(p[1:])) || matchfield(p) {
+                       if matchfield(p) {
                                goto fieldmatch
                        }
                }