From 9aa630faa868fde13af74e5b22ddba89a635d837 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 8 Feb 2016 07:08:14 -0500 Subject: [PATCH] cmd/dist: accept "//+build" with no spaces, like go/build 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 --- src/cmd/dist/build.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index 39a88ccab5..7f2f75341f 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -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 } -- 2.48.1