2015-02-10 12:44:55 -05:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-07-11 11:55:10 -07:00
|
|
|
"fmt"
|
2015-02-10 12:44:55 -05:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2015-07-11 11:55:10 -07:00
|
|
|
"strings"
|
2015-02-10 12:44:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var cmdInstall = &command{
|
|
|
|
run: runInstall,
|
|
|
|
Name: "install",
|
2015-06-19 12:27:15 -04:00
|
|
|
Usage: "[-target android] [build flags] [package]",
|
2015-07-11 11:55:10 -07:00
|
|
|
Short: "compile android APK and install on device",
|
2015-02-10 12:44:55 -05:00
|
|
|
Long: `
|
|
|
|
Install compiles and installs the app named by the import path on the
|
|
|
|
attached mobile device.
|
|
|
|
|
2015-06-19 12:27:15 -04:00
|
|
|
Only -target android is supported. The 'adb' tool must be on the PATH.
|
2015-02-10 12:44:55 -05:00
|
|
|
|
2015-06-19 12:27:15 -04:00
|
|
|
The build flags -a, -i, -n, -x, and -tags are shared with the build command.
|
|
|
|
For documentation, see 'go help build'.
|
2015-02-10 12:44:55 -05:00
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
|
|
|
func runInstall(cmd *command) error {
|
2015-07-11 11:55:10 -07:00
|
|
|
if buildTarget != "android" {
|
|
|
|
return fmt.Errorf("install is not supported for -target=%s", buildTarget)
|
|
|
|
}
|
2015-02-10 12:44:55 -05:00
|
|
|
if err := runBuild(cmd); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
install := exec.Command(
|
|
|
|
`adb`,
|
|
|
|
`install`,
|
|
|
|
`-r`,
|
|
|
|
filepath.Base(pkg.Dir)+`.apk`,
|
|
|
|
)
|
2015-07-11 11:55:10 -07:00
|
|
|
if buildX {
|
|
|
|
printcmd("%s", strings.Join(install.Args, " "))
|
|
|
|
}
|
2015-02-11 14:51:15 -05:00
|
|
|
if buildV {
|
|
|
|
install.Stdout = os.Stdout
|
|
|
|
install.Stderr = os.Stderr
|
|
|
|
}
|
2015-02-10 12:44:55 -05:00
|
|
|
return install.Run()
|
|
|
|
}
|