mirror of
https://github.com/golang/go
synced 2024-11-18 07:04:52 -07:00
cmd/dist: fix build tag parser
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>
This commit is contained in:
parent
c345f7ff95
commit
85069e9e9b
24
src/cmd/dist/build.go
vendored
24
src/cmd/dist/build.go
vendored
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user