Commit c253ea47 authored by Austin Clements's avatar Austin Clements

cmd/dist: require _ before GOOS and GOARCH when building bootstrap

Currently, dist allows GOOS and GOARCH to appear as *any* substring in
a file name when selecting source files to go into go_bootstrap. This
was necessary prior to Go 1.4, where it needed to match names like
"windows.c", but now it's gratuitously different from go/build. This
led to a bug chase to figure out why "stubs_nonlinux.go" was not being
built on non-Linux OSes.

Change shouldbuild to require an "_" before the GOOS and GOARCH in a
file name. This is still less strict than go/build, but the behavior
is much closer.

Change-Id: I580e9344a3c40d57c0721d345e911e8b4f141f5d
Reviewed-on: https://go-review.googlesource.com/40435
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent 7f32d41e
...@@ -782,9 +782,8 @@ func matchtag(tag string) bool { ...@@ -782,9 +782,8 @@ func matchtag(tag string) bool {
// shouldbuild reports whether we should build this file. // shouldbuild reports whether we should build this file.
// It applies the same rules that are used with context tags // It applies the same rules that are used with context tags
// in package go/build, except that the GOOS and GOARCH // in package go/build, except it's less picky about the order
// can appear anywhere in the file name, not just after _. // of GOOS and GOARCH.
// In particular, they can be the entire file name (like windows.c).
// We also allow the special tag cmd_go_bootstrap. // We also allow the special tag cmd_go_bootstrap.
// See ../go/bootstrap.go and package go/build. // See ../go/bootstrap.go and package go/build.
func shouldbuild(file, dir string) bool { func shouldbuild(file, dir string) bool {
...@@ -796,7 +795,7 @@ func shouldbuild(file, dir string) bool { ...@@ -796,7 +795,7 @@ func shouldbuild(file, dir string) bool {
continue continue
} }
i := strings.Index(name, x) i := strings.Index(name, x)
if i < 0 { if i <= 0 || name[i-1] != '_' {
continue continue
} }
i += len(x) i += len(x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment