]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: accept "//+build" with no spaces, like go/build
authorRuss Cox <rsc@golang.org>
Mon, 8 Feb 2016 12:08:14 +0000 (07:08 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 19 Feb 2016 01:37:51 +0000 (01:37 +0000)
The go/build parser accepts "//+build", with no spaces.
Make the cmd/dist bootstrap parser do the same.
While in theory we should always use the space form,
I copied some code that did not into the standard tree,
and I was very confused that 'go test' had had no problem
but then make.bash died.

(As a reminder, cmd/dist does not use go/build because
cmd/dist must build against earlier versions of Go.)

Change-Id: I90a18014bd878247b8811487e5c1a7589260cbfc
Reviewed-on: https://go-review.googlesource.com/19618
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/dist/build.go

index 39a88ccab591f3cfa2f985550c0d2ba19583900a..7f2f75341fabf7ca87bc7c7f0cfffdb6117f6a02 100644 (file)
@@ -754,7 +754,7 @@ func matchtag(tag string) bool {
                }
                return !matchtag(tag[1:])
        }
-       return tag == goos || tag == goarch || tag == "cmd_go_bootstrap" || tag == "go1.1" || (goos == "android" && tag == "linux")
+       return tag == "gc" || tag == goos || tag == goarch || tag == "cmd_go_bootstrap" || tag == "go1.1" || (goos == "android" && tag == "linux")
 }
 
 // shouldbuild reports whether we should build this file.
@@ -798,10 +798,15 @@ func shouldbuild(file, dir string) bool {
                if p == "" {
                        continue
                }
-               if strings.Contains(p, "package documentation") {
+               code := p
+               i := strings.Index(code, "//")
+               if i > 0 {
+                       code = strings.TrimSpace(code[:i])
+               }
+               if code == "package documentation" {
                        return false
                }
-               if strings.Contains(p, "package main") && dir != "cmd/go" && dir != "cmd/cgo" {
+               if code == "package main" && dir != "cmd/go" && dir != "cmd/cgo" {
                        return false
                }
                if !strings.HasPrefix(p, "//") {
@@ -810,11 +815,11 @@ func shouldbuild(file, dir string) bool {
                if !strings.Contains(p, "+build") {
                        continue
                }
-               fields := splitfields(p)
-               if len(fields) < 2 || fields[1] != "+build" {
+               fields := splitfields(p[2:])
+               if len(fields) < 1 || fields[0] != "+build" {
                        continue
                }
-               for _, p := range fields[2:] {
+               for _, p := range fields[1:] {
                        if matchfield(p) {
                                goto fieldmatch
                        }