You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2015/11/03 23:34:31 UTC
[1/2] incubator-mynewt-newt git commit: Add 'target download' and
'target debug' commands.
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/master eea46ae54 -> 0c3bbfa55
Add 'target download' and 'target debug' commands.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/a0e79e49
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a0e79e49
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a0e79e49
Branch: refs/heads/master
Commit: a0e79e4917af78bac29d15da1073e31f2a9d101a
Parents: eea46ae
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Nov 3 11:38:49 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Nov 3 11:38:49 2015 -0800
----------------------------------------------------------------------
cli/egg.go | 7 +++++
cli/target.go | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
cli/util.go | 40 +++++++++++++++++++++++++
newt.go | 60 +++++++++++++++++++++++++++++++++++++
4 files changed, 194 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a0e79e49/cli/egg.go
----------------------------------------------------------------------
diff --git a/cli/egg.go b/cli/egg.go
index 4a01306..32816a8 100644
--- a/cli/egg.go
+++ b/cli/egg.go
@@ -58,6 +58,11 @@ type Egg struct {
// Type of egg
LinkerScript string
+ // For BSP egg, how to download
+ DownloadScript string
+ // For BSP egg, how to start debugger and attach it to target board
+ DebugScript string
+
// Has the configuration been loaded for this egg
CfgLoaded bool
@@ -522,6 +527,8 @@ func (egg *Egg) LoadConfig(t *Target, force bool) error {
}
egg.LinkerScript = GetStringIdentities(v, t, "egg.linkerscript")
+ egg.DownloadScript = GetStringIdentities(v, t, "egg.downloadscript")
+ egg.DebugScript = GetStringIdentities(v, t, "egg.debugscript")
egg.Cflags += GetStringIdentities(v, t, "egg.cflags")
egg.Lflags += GetStringIdentities(v, t, "egg.lflags")
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a0e79e49/cli/target.go
----------------------------------------------------------------------
diff --git a/cli/target.go b/cli/target.go
index f976a23..034728d 100644
--- a/cli/target.go
+++ b/cli/target.go
@@ -396,6 +396,93 @@ func (t *Target) Remove() error {
return nil
}
+func (t *Target) Download() error {
+ clutch, err := NewClutch(t.Nest)
+ if err != nil {
+ return err
+ }
+
+ egg, err := clutch.ResolveEggName(t.Bsp)
+ if err != nil {
+ return err
+ }
+
+ err = egg.LoadConfig(t, false)
+ if err != nil {
+ return err
+ }
+ if egg.DownloadScript == "" {
+ return NewNewtError(fmt.Sprintf("No egg.downloadscript defined for %s",
+ egg.FullName))
+ }
+ downloadScript := filepath.Join(egg.BasePath, egg.DownloadScript)
+
+ if t.Vars["project"] == "" {
+ return NewNewtError(fmt.Sprintf("No project associated with target %s",
+ t.Name))
+ }
+ p, err := LoadProject(t.Nest, t, t.Vars["project"])
+ if err != nil {
+ return err
+ }
+
+ os.Chdir(t.Nest.BasePath)
+
+ StatusMessage(VERBOSITY_DEFAULT, "Downloading with %s \n", downloadScript)
+
+ rsp, err := ShellCommand(fmt.Sprintf("%s %s", downloadScript,
+ filepath.Join(p.BinPath(), p.Name)))
+ if err != nil {
+ StatusMessage(VERBOSITY_DEFAULT, "%s", rsp);
+ return err
+ }
+
+ return nil
+}
+
+func (t *Target) Debug() error {
+ clutch, err := NewClutch(t.Nest)
+ if err != nil {
+ return err
+ }
+
+ egg, err := clutch.ResolveEggName(t.Bsp)
+ if err != nil {
+ return err
+ }
+
+ err = egg.LoadConfig(t, false)
+ if err != nil {
+ return err
+ }
+ if egg.DebugScript == "" {
+ return NewNewtError(fmt.Sprintf("No egg.debugscript defined for %s",
+ egg.FullName))
+ }
+ debugScript := filepath.Join(egg.BasePath, egg.DebugScript)
+
+ if t.Vars["project"] == "" {
+ return NewNewtError(fmt.Sprintf("No project associated with target %s",
+ t.Name))
+ }
+ p, err := LoadProject(t.Nest, t, t.Vars["project"])
+ if err != nil {
+ return err
+ }
+
+ os.Chdir(t.Nest.BasePath)
+
+ StatusMessage(VERBOSITY_DEFAULT, "Debugging with %s %s\n", debugScript, p.Name)
+
+ err = ShellInteractiveCommand([]string{debugScript,
+ filepath.Join(p.BinPath(), p.Name)})
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
type MemSection struct {
Name string
Offset uint64
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a0e79e49/cli/util.go
----------------------------------------------------------------------
diff --git a/cli/util.go b/cli/util.go
index 71c61d0..0501ef0 100644
--- a/cli/util.go
+++ b/cli/util.go
@@ -25,9 +25,11 @@ import (
"log"
"os"
"os/exec"
+ "os/signal"
"path/filepath"
"runtime"
"strings"
+ "syscall"
"time"
)
@@ -209,6 +211,44 @@ func ShellCommand(cmdStr string) ([]byte, error) {
}
}
+// Run interactive shell command
+func ShellInteractiveCommand(cmdStr []string) error {
+ log.Print("[VERBOSE] " + cmdStr[0])
+
+ //
+ // Block SIGINT, at least.
+ // Otherwise Ctrl-C meant for gdb would kill newt.
+ //
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, os.Interrupt)
+ signal.Notify(c, syscall.SIGTERM)
+ go func(){
+ <-c
+ }()
+
+ // Transfer stdin, stdout, and stderr to the new process
+ // and also set target directory for the shell to start in.
+ pa := os.ProcAttr {
+ Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
+ }
+
+ // Start up a new shell.
+ proc, err := os.StartProcess(cmdStr[0], cmdStr, &pa)
+ if err != nil {
+ signal.Stop(c)
+ return err
+ }
+
+ // Release and exit
+ _, err = proc.Wait()
+ if err != nil {
+ signal.Stop(c)
+ return err
+ }
+ signal.Stop(c)
+ return nil
+}
+
func CopyFile(srcFile string, destFile string) error {
_, err := ShellCommand(fmt.Sprintf("mkdir -p %s", filepath.Dir(destFile)))
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a0e79e49/newt.go
----------------------------------------------------------------------
diff --git a/newt.go b/newt.go
index 4bb499a..9360c96 100644
--- a/newt.go
+++ b/newt.go
@@ -284,6 +284,38 @@ func targetSizeCmd(cmd *cobra.Command, args []string) {
cli.StatusMessage(cli.VERBOSITY_DEFAULT, "%s", txt)
}
+func targetDownloadCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 1 {
+ NewtUsage(cmd, cli.NewNewtError("Must specify target to download"))
+ }
+
+ t, err := cli.LoadTarget(NewtNest, args[0])
+ if err != nil {
+ NewtUsage(nil, err)
+ }
+
+ err = t.Download()
+ if err != nil {
+ NewtUsage(nil, err)
+ }
+}
+
+func targetDebugCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 1 {
+ NewtUsage(cmd, cli.NewNewtError("Must specify target for debug"))
+ }
+
+ t, err := cli.LoadTarget(NewtNest, args[0])
+ if err != nil {
+ NewtUsage(nil, err)
+ }
+
+ err = t.Debug()
+ if err != nil {
+ NewtUsage(nil, err)
+ }
+}
+
func targetExportCmd(cmd *cobra.Command, args []string) {
var targetName string
if ExportAll {
@@ -335,6 +367,8 @@ func targetAddCmds(base *cobra.Command) {
targetHelpEx += " newt target build <target-name> [clean[ all]]\n"
targetHelpEx += " newt target test <target-name> [clean[ all]]\n"
targetHelpEx += " newt target size <target-name>\n"
+ targetHelpEx += " newt target download <target-name>\n"
+ targetHelpEx += " newt target debug <target-name>\n"
targetHelpEx += " newt target export [-a -export-all] [<target-name>]\n"
targetHelpEx += " newt target import [-a -import-all] [<target-name>]"
@@ -483,6 +517,32 @@ func targetAddCmds(base *cobra.Command) {
targetCmd.AddCommand(sizeCmd)
+ downloadHelpText := formatHelp(`Download project image to target for
+ <target-name>.`)
+ downloadHelpEx := " newt target download <target-name>\n"
+
+ downloadCmd := &cobra.Command{
+ Use: "download",
+ Short: "Download project to target",
+ Long: downloadHelpText,
+ Example: downloadHelpEx,
+ Run: targetDownloadCmd,
+ }
+ targetCmd.AddCommand(downloadCmd)
+
+ debugHelpText := formatHelp(`Download project image to target for
+ <target-name>.`)
+ debugHelpEx := " newt target download <target-name>\n"
+
+ debugCmd := &cobra.Command{
+ Use: "debug",
+ Short: "Open debugger session to target",
+ Long: debugHelpText,
+ Example: debugHelpEx,
+ Run: targetDebugCmd,
+ }
+ targetCmd.AddCommand(debugCmd)
+
exportHelpText := formatHelp(`Export build targets from the current nest, and
print them to standard output. If the -a (or -export-all) option is
specified, then all targets will be exported. Otherwise, <target-name>
[2/2] incubator-mynewt-newt git commit: Add target.Identities to
command line args when invoking download/debug.
Posted by ma...@apache.org.
Add target.Identities to command line args when invoking download/debug.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/0c3bbfa5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/0c3bbfa5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/0c3bbfa5
Branch: refs/heads/master
Commit: 0c3bbfa55b112cd399b9845f10d6eae04dbdc4ea
Parents: a0e79e4
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Nov 3 14:33:44 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Nov 3 14:33:44 2015 -0800
----------------------------------------------------------------------
cli/target.go | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0c3bbfa5/cli/target.go
----------------------------------------------------------------------
diff --git a/cli/target.go b/cli/target.go
index 034728d..4a7c64a 100644
--- a/cli/target.go
+++ b/cli/target.go
@@ -428,10 +428,9 @@ func (t *Target) Download() error {
os.Chdir(t.Nest.BasePath)
- StatusMessage(VERBOSITY_DEFAULT, "Downloading with %s \n", downloadScript)
-
- rsp, err := ShellCommand(fmt.Sprintf("%s %s", downloadScript,
- filepath.Join(p.BinPath(), p.Name)))
+ StatusMessage(VERBOSITY_DEFAULT, "Downloading with %s\n", downloadScript)
+ rsp, err := ShellCommand(fmt.Sprintf("%s %s %s", downloadScript,
+ filepath.Join(p.BinPath(), p.Name), strings.Join(t.Identities, " ")))
if err != nil {
StatusMessage(VERBOSITY_DEFAULT, "%s", rsp);
return err
@@ -474,8 +473,9 @@ func (t *Target) Debug() error {
StatusMessage(VERBOSITY_DEFAULT, "Debugging with %s %s\n", debugScript, p.Name)
- err = ShellInteractiveCommand([]string{debugScript,
- filepath.Join(p.BinPath(), p.Name)})
+ cmdLine := []string{debugScript, filepath.Join(p.BinPath(), p.Name)}
+ cmdLine = append(cmdLine, t.Identities...)
+ err = ShellInteractiveCommand(cmdLine)
if err != nil {
return err
}