Commit 6e63b155 authored by Elias Naur's avatar Elias Naur

misc/android: copy go.mod and go.sum files

Fixes TestFindStdlib in x/tools on android.

Change-Id: I2da7c702164e23488c7f9574f636ac36f63ab421
Reviewed-on: https://go-review.googlesource.com/c/go/+/167799
Run-TryBot: Elias Naur <mail@eliasnaur.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 65357913
...@@ -116,7 +116,7 @@ func runMain() (int, error) { ...@@ -116,7 +116,7 @@ func runMain() (int, error) {
if _, err := run("exec-out", "mkdir", "-p", deviceCwd); err != nil { if _, err := run("exec-out", "mkdir", "-p", deviceCwd); err != nil {
return 0, err return 0, err
} }
if err := adbCopyTestdata(deviceCwd, subdir); err != nil { if err := adbCopyTree(deviceCwd, subdir); err != nil {
return 0, err return 0, err
} }
...@@ -217,21 +217,24 @@ func subdir() (pkgpath string, underGoRoot bool, err error) { ...@@ -217,21 +217,24 @@ func subdir() (pkgpath string, underGoRoot bool, err error) {
cwd, runtime.GOROOT(), build.Default.GOPATH) cwd, runtime.GOROOT(), build.Default.GOPATH)
} }
// adbCopyTestdata copies testdata directories from subdir to deviceCwd // adbCopyTree copies testdata, go.mod, go.sum files from subdir
// on the device. // and from parent directories all the way up to the root of subdir.
// It is common for tests to reach out into testdata from parent // go.mod and go.sum files are needed for the go tool modules queries,
// packages, so copy testdata directories all the way up to the root // and the testdata directories for tests. It is common for tests to
// of subdir. // reach out into testdata from parent packages.
func adbCopyTestdata(deviceCwd, subdir string) error { func adbCopyTree(deviceCwd, subdir string) error {
dir := "" dir := ""
for { for {
testdata := filepath.Join(dir, "testdata") for _, path := range []string{"testdata", "go.mod", "go.sum"} {
if _, err := os.Stat(testdata); err == nil { path := filepath.Join(dir, path)
if _, err := os.Stat(path); err != nil {
continue
}
devicePath := filepath.Join(deviceCwd, dir) devicePath := filepath.Join(deviceCwd, dir)
if _, err := run("exec-out", "mkdir", "-p", devicePath); err != nil { if _, err := run("exec-out", "mkdir", "-p", devicePath); err != nil {
return err return err
} }
if _, err := run("push", testdata, devicePath); err != nil { if _, err := run("push", path, devicePath); err != nil {
return err return err
} }
} }
......
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