diff options
| author | Elias Naur <mail@eliasnaur.com> | 2019-02-24 15:18:02 +0100 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2019-02-26 18:00:48 +0000 |
| commit | e3d99a3f8608e308eedc201b83eeb2f0e0d9dc81 (patch) | |
| tree | 17530050f0fcf0b10a80ec80199ffea97cde4404 /misc/android/go_android_exec.go | |
| parent | 3ef7e3d44f3dfaceab83b779c8bcd1cebe834de2 (diff) | |
| download | go-e3d99a3f8608e308eedc201b83eeb2f0e0d9dc81.tar.xz | |
misc/android,cmd/dist: move $GOROOT copying to the exec wrapper
To run the standard library tests on Android, the androidtest.bash
script copies GOROOT to the device. Move that logic to the android
exec wrapper, thereby making androidtest.bash obsolete.
Apart from making Android less special, the sharded builder
infrastructure should now be able to run (emulated) Android builders
and trybots without special treatment.
Updates #23824
Change-Id: I41591fea9a15b38c6dcf84046ea57f1e9165eaa5
Reviewed-on: https://go-review.googlesource.com/c/163619
Run-TryBot: Elias Naur <mail@eliasnaur.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'misc/android/go_android_exec.go')
| -rw-r--r-- | misc/android/go_android_exec.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/misc/android/go_android_exec.go b/misc/android/go_android_exec.go index e36edacc76..1a8ae7070e 100644 --- a/misc/android/go_android_exec.go +++ b/misc/android/go_android_exec.go @@ -13,6 +13,7 @@ import ( "fmt" "go/build" "io" + "io/ioutil" "log" "os" "os/exec" @@ -78,6 +79,8 @@ func main() { deviceCwd := filepath.Join(deviceGoroot, subdir) if !inGoRoot { deviceCwd = filepath.Join(deviceGopath, subdir) + } else { + adbSyncGoroot() } // Binary names can conflict. @@ -164,3 +167,46 @@ func subdir() (pkgpath string, underGoRoot bool) { cwd, runtime.GOROOT(), build.Default.GOPATH) return "", false } + +// adbSyncGoroot ensures that files necessary for testing the Go standard +// packages are present on the attached device. +func adbSyncGoroot() { + // Also known by cmd/dist. The bootstrap command deletes the file. + statPath := filepath.Join(os.TempDir(), "go_android_exec-adb-sync-status") + stat, err := os.OpenFile(statPath, os.O_CREATE|os.O_RDWR, 0666) + if err != nil { + log.Fatal(err) + } + defer stat.Close() + // Serialize check and syncing. + if err := syscall.Flock(int(stat.Fd()), syscall.LOCK_EX); err != nil { + log.Fatal(err) + } + s, err := ioutil.ReadAll(stat) + if err != nil { + log.Fatal(err) + } + if string(s) == "done" { + return + } + devRoot := "/data/local/tmp/goroot" + run("shell", "rm", "-rf", devRoot) + run("shell", "mkdir", "-p", devRoot+"/pkg") + goroot := runtime.GOROOT() + goCmd := filepath.Join(goroot, "bin", "go") + runtimea, err := exec.Command(goCmd, "list", "-f", "{{.Target}}", "runtime").Output() + if err != nil { + log.Fatal(err) + } + pkgdir := filepath.Dir(string(runtimea)) + if pkgdir == "" { + log.Fatal("could not find android pkg dir") + } + for _, dir := range []string{"src", "test", "lib"} { + run("push", filepath.Join(goroot, dir), filepath.Join(devRoot)) + } + run("push", filepath.Join(pkgdir), filepath.Join(devRoot, "pkg/")) + if _, err := stat.Write([]byte("done")); err != nil { + log.Fatal(err) + } +} |
