mirror of
https://github.com/golang/go
synced 2024-11-17 21:04:43 -07:00
cmd/go: recognize android suffix when constructing build list
cmd/go/internal/imports.ScanDir extracts a list of imports from a directory. It's used instead of go/build.ImportDir when constructing the build list. GOOS and GOARCH may be used to filter files. With this change, imports.MatchFile understands that when the "android" tag is set, the "linux" tag is implied. Fixes #30888 Change-Id: Ia29bd1590b69c9183ab14a879d5fc1b639f8eaef Reviewed-on: https://go-review.googlesource.com/c/go/+/168378 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
5ee1d5d39f
commit
f07a99e30a
@ -184,13 +184,13 @@ func MatchFile(name string, tags map[string]bool) bool {
|
||||
}
|
||||
n := len(l)
|
||||
if n >= 2 && KnownOS[l[n-2]] && KnownArch[l[n-1]] {
|
||||
return tags[l[n-2]] && tags[l[n-1]]
|
||||
return matchTag(l[n-2], tags, true) && matchTag(l[n-1], tags, true)
|
||||
}
|
||||
if n >= 1 && KnownOS[l[n-1]] {
|
||||
return tags[l[n-1]]
|
||||
return matchTag(l[n-1], tags, true)
|
||||
}
|
||||
if n >= 1 && KnownArch[l[n-1]] {
|
||||
return tags[l[n-1]]
|
||||
return matchTag(l[n-1], tags, true)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -5,10 +5,13 @@
|
||||
package imports
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"internal/testenv"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -51,17 +54,41 @@ func TestScan(t *testing.T) {
|
||||
t.Errorf("json missing test import net/http (%q)", testImports)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScanStar(t *testing.T) {
|
||||
func TestScanDir(t *testing.T) {
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
imports, _, err := ScanDir("testdata/import1", map[string]bool{"*": true})
|
||||
dirs, err := ioutil.ReadDir("testdata")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, dir := range dirs {
|
||||
if !dir.IsDir() || strings.HasPrefix(dir.Name(), ".") {
|
||||
continue
|
||||
}
|
||||
t.Run(dir.Name(), func(t *testing.T) {
|
||||
tagsData, err := ioutil.ReadFile(filepath.Join("testdata", dir.Name(), "tags.txt"))
|
||||
if err != nil {
|
||||
t.Fatalf("error reading tags: %v", err)
|
||||
}
|
||||
tags := make(map[string]bool)
|
||||
for _, t := range strings.Fields(string(tagsData)) {
|
||||
tags[t] = true
|
||||
}
|
||||
|
||||
want := []string{"import1", "import2", "import3", "import4"}
|
||||
if !reflect.DeepEqual(imports, want) {
|
||||
t.Errorf("ScanDir testdata/import1:\nhave %v\nwant %v", imports, want)
|
||||
wantData, err := ioutil.ReadFile(filepath.Join("testdata", dir.Name(), "want.txt"))
|
||||
if err != nil {
|
||||
t.Fatalf("error reading want: %v", err)
|
||||
}
|
||||
want := string(bytes.TrimSpace(wantData))
|
||||
|
||||
imports, _, err := ScanDir(path.Join("testdata", dir.Name()), tags)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := strings.Join(imports, "\n")
|
||||
if got != want {
|
||||
t.Errorf("ScanDir: got imports:\n%s\n\nwant:\n%s", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
3
src/cmd/go/internal/imports/testdata/android/a_android.go
vendored
Normal file
3
src/cmd/go/internal/imports/testdata/android/a_android.go
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
package android
|
||||
|
||||
import _ "a"
|
3
src/cmd/go/internal/imports/testdata/android/b_android_arm64.go
vendored
Normal file
3
src/cmd/go/internal/imports/testdata/android/b_android_arm64.go
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
package android
|
||||
|
||||
import _ "b"
|
3
src/cmd/go/internal/imports/testdata/android/c_linux.go
vendored
Normal file
3
src/cmd/go/internal/imports/testdata/android/c_linux.go
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
package android
|
||||
|
||||
import _ "c"
|
3
src/cmd/go/internal/imports/testdata/android/d_linux_arm64.go
vendored
Normal file
3
src/cmd/go/internal/imports/testdata/android/d_linux_arm64.go
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
package android
|
||||
|
||||
import _ "d"
|
5
src/cmd/go/internal/imports/testdata/android/e.go
vendored
Normal file
5
src/cmd/go/internal/imports/testdata/android/e.go
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
// +build android
|
||||
|
||||
package android
|
||||
|
||||
import _ "e"
|
5
src/cmd/go/internal/imports/testdata/android/f.go
vendored
Normal file
5
src/cmd/go/internal/imports/testdata/android/f.go
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
// +build linux
|
||||
|
||||
package android
|
||||
|
||||
import _ "f"
|
5
src/cmd/go/internal/imports/testdata/android/g.go
vendored
Normal file
5
src/cmd/go/internal/imports/testdata/android/g.go
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
// +build !android
|
||||
|
||||
package android
|
||||
|
||||
import _ "g"
|
1
src/cmd/go/internal/imports/testdata/android/tags.txt
vendored
Normal file
1
src/cmd/go/internal/imports/testdata/android/tags.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
android arm64
|
6
src/cmd/go/internal/imports/testdata/android/want.txt
vendored
Normal file
6
src/cmd/go/internal/imports/testdata/android/want.txt
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
e
|
||||
f
|
1
src/cmd/go/internal/imports/testdata/star/tags.txt
vendored
Normal file
1
src/cmd/go/internal/imports/testdata/star/tags.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
*
|
4
src/cmd/go/internal/imports/testdata/star/want.txt
vendored
Normal file
4
src/cmd/go/internal/imports/testdata/star/want.txt
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import1
|
||||
import2
|
||||
import3
|
||||
import4
|
Loading…
Reference in New Issue
Block a user