summaryrefslogtreecommitdiff
path: root/src/go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2014-10-06 14:50:58 -0700
committerRob Pike <r@golang.org>2014-10-06 14:50:58 -0700
commit06dffe0d90136e051ba908bdde851c30ebe865b7 (patch)
treeed306d8b955d8dac2667c13409e4efb7eb9eea27 /src/go
parent68c0db9ea9d37fdbbe96f106514d4793a7b7fdca (diff)
downloadgo-06dffe0d90136e051ba908bdde851c30ebe865b7.tar.gz
go/build: do not consider "android.go" to be android-specific
A file name must have a non-empty underscore-separated prefix before its suffix matches GOOS. This is what the documentation already said but is not what the code did. Fixes issue 8838. This needs to be called out in the release notes. The he single affected file code.google.com/p/go.text/collate/tools/colcmp/darwin.go could use a renaming but works because it has a build tag inside. LGTM=adg, rsc R=golang-codereviews, adg, rsc CC=golang-codereviews https://codereview.appspot.com/147690043
Diffstat (limited to 'src/go')
-rw-r--r--src/go/build/build.go12
-rw-r--r--src/go/build/build_test.go4
2 files changed, 16 insertions, 0 deletions
diff --git a/src/go/build/build.go b/src/go/build/build.go
index 5e11c9b9c..3ac798083 100644
--- a/src/go/build/build.go
+++ b/src/go/build/build.go
@@ -1291,6 +1291,18 @@ func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool {
if dot := strings.Index(name, "."); dot != -1 {
name = name[:dot]
}
+
+ // Before Go 1.4, a file called "linux.go" would be equivalent to having a
+ // build tag "linux" in that file. For Go 1.4 and beyond, we require this
+ // auto-tagging to apply only to files with a non-empty prefix, so
+ // "foo_linux.go" is tagged but "linux.go" is not. This allows new operating
+ // sytems, such as android, to arrive without breaking existing code with
+ // innocuous source code in "android.go". The easiest fix: files without
+ // underscores are always included.
+ if !strings.ContainsRune(name, '_') {
+ return true
+ }
+
l := strings.Split(name, "_")
if n := len(l); n > 0 && l[n-1] == "test" {
l = l[:n-1]
diff --git a/src/go/build/build_test.go b/src/go/build/build_test.go
index 004010113..23ce89b4b 100644
--- a/src/go/build/build_test.go
+++ b/src/go/build/build_test.go
@@ -173,6 +173,10 @@ var matchFileTests = []struct {
{ctxtAndroid, "foo_linux.go", "", true},
{ctxtAndroid, "foo_android.go", "", true},
{ctxtAndroid, "foo_plan9.go", "", false},
+ {ctxtAndroid, "android.go", "", true},
+ {ctxtAndroid, "plan9.go", "", true},
+ {ctxtAndroid, "arm.s", "", true},
+ {ctxtAndroid, "amd64.s", "", true},
}
func TestMatchFile(t *testing.T) {