/
run.go
85 lines (78 loc) · 2.51 KB
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2023, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cmd
import (
"fmt"
"path/filepath"
"runtime"
"cogentcore.org/core/base/exec"
"cogentcore.org/core/base/logx"
"cogentcore.org/core/cmd/core/config"
"cogentcore.org/core/cmd/core/mobile"
"cogentcore.org/core/cmd/core/web"
)
// Run builds and runs the config package. It also displays the logs generated
// by the app. It uses the same config info as build.
func Run(c *config.Config) error { //types:add
if len(c.Build.Target) != 1 {
return fmt.Errorf("expected 1 target platform, but got %d (%v)", len(c.Build.Target), c.Build.Target)
}
t := c.Build.Target[0]
if t.Arch == "*" {
if t.OS == "android" || t.OS == "ios" {
t.Arch = "arm64"
} else {
t.Arch = runtime.GOARCH
}
c.Build.Target[0] = t
}
if t.OS == "ios" && !c.Build.Debug {
// TODO: is there a way to launch without running the debugger?
logx.PrintlnWarn("warning: only installing, not running, because there is no effective way to just launch an app on iOS from the terminal without debugging; pass the -d flag to run and debug")
}
if t.OS == "web" {
// needed for changes to show during local development
c.Web.RandomVersion = true
}
err := Build(c)
if err != nil {
return fmt.Errorf("error building app: %w", err)
}
// Build may have added iossimulator, so we get rid of it for
// the running stage (we already confirmed we were passed 1 up above)
if len(c.Build.Target) > 1 {
c.Build.Target = []config.Platform{t}
}
switch t.OS {
case "darwin", "windows", "linux":
return exec.Verbose().SetBuffer(false).Run("." + string(filepath.Separator) + c.Name)
case "android":
err := exec.Run("adb", "install", "-r", filepath.Join("bin", "android", c.Name+".apk"))
if err != nil {
return fmt.Errorf("error installing app: %w", err)
}
// see https://stackoverflow.com/a/4567928
args := []string{"shell", "am", "start", "-n", c.ID + "/org.golang.app.GoNativeActivity"}
// TODO: get adb am debug on Android working
// if c.Build.Debug {
// args = append(args, "-D")
// }
err = exec.Run("adb", args...)
if err != nil {
return fmt.Errorf("error starting app: %w", err)
}
if c.Build.Debug {
return Log(c)
}
return nil
case "ios":
if !c.Build.Debug {
return mobile.Install(c)
}
return exec.Verbose().SetBuffer(false).Run("ios-deploy", "-b", filepath.Join("bin", "ios", c.Name+".app"), "-d")
case "web":
return web.Serve(c)
}
return nil
}