You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/03/09 02:35:33 UTC

[1/7] incubator-mynewt-newt git commit: Allow multiple targets in delete command.

Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/rename_project_app 9351ecf97 -> f3842f09a


Allow multiple targets in delete command.


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/aef3d397
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/aef3d397
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/aef3d397

Branch: refs/heads/rename_project_app
Commit: aef3d397c82de355fa8a2511af204f9770af523d
Parents: d2d5ef1
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 15:18:15 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:31:54 2016 -0800

----------------------------------------------------------------------
 newt/target/cmds.go | 67 +++++++++++++++++++++++++++---------------------
 1 file changed, 38 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/aef3d397/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index c55fd39..d831063 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -33,12 +33,14 @@ import (
 	"mynewt.apache.org/newt/util"
 )
 
-// Type for sorting an array of target pointers alphabetically by name.
-type ByName []*Target
+func parseTargetName(arg string) (*Target, error) {
+	t := ResolveTargetName(arg)
+	if t == nil {
+		return nil, util.NewNewtError("Unknown target: " + arg)
+	}
 
-func (a ByName) Len() int           { return len(a) }
-func (a ByName) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
-func (a ByName) Less(i, j int) bool { return a[i].Package().Name() < a[j].Package().Name() }
+	return t, nil
+}
 
 func targetShowCmd(cmd *cobra.Command, args []string) {
 	proj := project.GetProject()
@@ -108,12 +110,10 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
 	}
 
 	// Parse target name.
-	tName := args[0]
-	t := ResolveTargetName(tName)
-	if t == nil {
-		cli.NewtUsage(cmd, util.NewNewtError("Unknown target: "+tName))
+	t, err := parseTargetName(args[0])
+	if err != nil {
+		cli.NewtUsage(cmd, err)
 	}
-	tName = t.Name()
 
 	// Parse series of k=v pairs.  If an argument doesn't contain a '='
 	// character, display the valid values for the variable and quit.
@@ -155,10 +155,11 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
 	for _, kv := range vars {
 		if kv[1] == "" {
 			cli.StatusMessage(cli.VERBOSITY_DEFAULT,
-				"Target %s successfully unset %s\n", tName, kv[0])
+				"Target %s successfully unset %s\n", t.Name(), kv[0])
 		} else {
 			cli.StatusMessage(cli.VERBOSITY_DEFAULT,
-				"Target %s successfully set %s to %s\n", tName, kv[0], kv[1])
+				"Target %s successfully set %s to %s\n", t.Name(), kv[0],
+				kv[1])
 		}
 	}
 }
@@ -198,22 +199,13 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
 	}
 }
 
-func targetDelCmd(cmd *cobra.Command, args []string) {
-	if len(args) < 1 {
-		cli.NewtUsage(cmd, util.NewNewtError("Must specify target to delete"))
-	}
-
-	t := ResolveTargetName(args[0])
-	if t == nil {
-		cli.NewtUsage(cmd, util.NewNewtError("Target does not exist"))
-	}
-
+func targetDelOne(t *Target) error {
 	if !cli.Force {
 		// Determine if the target directory contains extra user files.  If it
 		// does, a prompt (or force) is required to delete it.
 		userFiles, err := t.ContainsUserFiles()
 		if err != nil {
-			cli.NewtUsage(cmd, err)
+			return err
 		}
 
 		if userFiles {
@@ -222,20 +214,37 @@ func targetDelCmd(cmd *cobra.Command, args []string) {
 				"delete anyway? (y/N): ", t.basePkg.Name())
 			rc := scanner.Scan()
 			if !rc || strings.ToLower(scanner.Text()) != "y" {
-				return
+				return nil
 			}
 		}
 	}
 
-	// Clean target prior to deletion; ignore errors during clean.
-	//t.BuildClean(false)
-
 	if err := t.Delete(); err != nil {
-		cli.NewtUsage(cmd, err)
+		return err
 	}
 
 	cli.StatusMessage(cli.VERBOSITY_DEFAULT,
-		"Target %s successfully removed\n", args[0])
+		"Target %s successfully removed\n", t.Name())
+
+	return nil
+}
+
+func targetDelCmd(cmd *cobra.Command, args []string) {
+	if len(args) < 1 {
+		cli.NewtUsage(cmd, util.NewNewtError("Must specify at least one "+
+			"target to delete"))
+	}
+
+	targets, err := ResolveTargetNames(args...)
+	if err != nil {
+		cli.NewtUsage(cmd, err)
+	}
+
+	for _, t := range targets {
+		if err := targetDelOne(t); err != nil {
+			cli.NewtUsage(cmd, err)
+		}
+	}
 }
 
 func AddCommands(cmd *cobra.Command) {


[6/7] incubator-mynewt-newt git commit: Add silent/quiet/verbose options.

Posted by cc...@apache.org.
Add silent/quiet/verbose options.


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/dc1e9475
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/dc1e9475
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/dc1e9475

Branch: refs/heads/rename_project_app
Commit: dc1e947524dce7b9b5f5bff27cb75245ae874171
Parents: 65b5bb3
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 16:09:37 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:35:02 2016 -0800

----------------------------------------------------------------------
 newt/cli/util.go | 13 ++-----------
 newt/newt.go     | 21 ++++++++++++++++++++-
 2 files changed, 22 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dc1e9475/newt/cli/util.go
----------------------------------------------------------------------
diff --git a/newt/cli/util.go b/newt/cli/util.go
index fde67f3..a48de90 100644
--- a/newt/cli/util.go
+++ b/newt/cli/util.go
@@ -88,7 +88,7 @@ func FormatHelp(text string) string {
 }
 
 // Initialize the CLI module
-func Init(level string, silent bool, quiet bool, verbose bool) {
+func Init(level string, verbosity int) {
 	if level == "" {
 		level = "WARN"
 	}
@@ -101,16 +101,7 @@ func Init(level string, silent bool, quiet bool, verbose bool) {
 	}
 
 	log.SetOutput(filter)
-
-	if silent {
-		Verbosity = VERBOSITY_SILENT
-	} else if quiet {
-		Verbosity = VERBOSITY_QUIET
-	} else if verbose {
-		Verbosity = VERBOSITY_VERBOSE
-	} else {
-		Verbosity = VERBOSITY_DEFAULT
-	}
+	Verbosity = verbosity
 }
 
 func CheckBoolMap(mapVar map[string]bool, item string) bool {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dc1e9475/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index 5e279c0..a18d507 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -35,6 +35,9 @@ import (
 
 var NewtVersion string = "0.8.0"
 var NewtLogLevel string = ""
+var newtSilent bool
+var newtQuiet bool
+var newtVerbose bool
 
 func newtCmd() *cobra.Command {
 	newtHelpText := cli.FormatHelp(`Newt allows you to create your own embedded 
@@ -59,13 +62,29 @@ func newtCmd() *cobra.Command {
 		Example: newtHelpEx,
 		PersistentPreRun: func(cmd *cobra.Command, args []string) {
 			NewtLogLevel = strings.ToUpper(NewtLogLevel)
-			cli.Init(NewtLogLevel, false, false, false)
+
+			verbosity := cli.VERBOSITY_DEFAULT
+			if newtSilent {
+				verbosity = cli.VERBOSITY_SILENT
+			} else if newtQuiet {
+				verbosity = cli.VERBOSITY_QUIET
+			} else if newtVerbose {
+				verbosity = cli.VERBOSITY_VERBOSE
+			}
+
+			cli.Init(NewtLogLevel, verbosity)
 		},
 		Run: func(cmd *cobra.Command, args []string) {
 			cmd.Help()
 		},
 	}
 
+	newtCmd.PersistentFlags().BoolVarP(&newtVerbose, "verbose", "v", false,
+		"Enable verbose output when executing commands.")
+	newtCmd.PersistentFlags().BoolVarP(&newtQuiet, "quiet", "q", false,
+		"Be quiet; only display error output.")
+	newtCmd.PersistentFlags().BoolVarP(&newtSilent, "silent", "s", false,
+		"Be silent; don't output anything.")
 	newtCmd.PersistentFlags().StringVarP(&NewtLogLevel, "loglevel", "l",
 		"WARN", "Log level, defaults to WARN.")
 


[4/7] incubator-mynewt-newt git commit: Remove compiler fields from target.

Posted by cc...@apache.org.
Remove compiler fields from target.

Now they are in the bsp.


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/4920e1e4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/4920e1e4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/4920e1e4

Branch: refs/heads/rename_project_app
Commit: 4920e1e47b368a3aadcd5d30d315f7c9c07aec72
Parents: a54695c
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 15:28:13 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:32:48 2016 -0800

----------------------------------------------------------------------
 newt/target/target.go | 4 ----
 1 file changed, 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4920e1e4/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 2a4f781..6a520c3 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -47,7 +47,6 @@ type Target struct {
 	// XXX: Probably don't need the below four fields; they can just be
 	// retrieved from the viper object.  Keep them here for now for easy
 	// initializiation of dummy targets.
-	CompilerName string
 	BspName      string
 	AppName      string
 	Arch         string
@@ -90,14 +89,11 @@ func (target *Target) Load(basePkg *pkg.LocalPackage) error {
 		target.Vars[k] = v.(string)
 	}
 
-	target.CompilerName = target.Vars["target.compiler"]
 	target.BspName = target.Vars["target.bsp"]
 	target.AppName = target.Vars["target.app"]
 	target.Arch = target.Vars["target.arch"]
 	target.BuildProfile = target.Vars["target.build_profile"]
 
-	// XXX: Verify required fields set?
-
 	return nil
 }
 


[3/7] incubator-mynewt-newt git commit: Remove some debug printf calls.

Posted by cc...@apache.org.
Remove some debug printf calls.


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/a54695c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a54695c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a54695c2

Branch: refs/heads/rename_project_app
Commit: a54695c232e496429591a28b8c6d46b9d56cbfad
Parents: aef3d39
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 15:28:03 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:32:44 2016 -0800

----------------------------------------------------------------------
 newt/target/target.go | 4 ----
 1 file changed, 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a54695c2/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 39714d4..2a4f781 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -20,7 +20,6 @@
 package target
 
 import (
-	"fmt"
 	"io/ioutil"
 	"os"
 	"path/filepath"
@@ -117,14 +116,11 @@ func (target *Target) ShortName() string {
 func (target *Target) App() *pkg.LocalPackage {
 	dep, err := pkg.NewDependency(nil, target.AppName)
 	if err != nil {
-		fmt.Println("app name = %s\n", target.AppName)
-		fmt.Println("dep is nil")
 		return nil
 	}
 
 	appPkg := project.GetProject().ResolveDependency(dep)
 	if appPkg == nil {
-		fmt.Printf("app name = %s\n", target.AppName)
 		return nil
 	}
 


[2/7] incubator-mynewt-newt git commit: Allow multiple target vars to be set at once.

Posted by cc...@apache.org.
Allow multiple target vars to be set at once.


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/d2d5ef1e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/d2d5ef1e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/d2d5ef1e

Branch: refs/heads/rename_project_app
Commit: d2d5ef1e9c9a5f32ba6a91e41849ddd82b88ba36
Parents: 9351ecf
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 14:58:44 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:31:54 2016 -0800

----------------------------------------------------------------------
 newt/pkg/localpackage.go |  2 +-
 newt/target/cmds.go      | 58 +++++++++++++++++++++++++++----------------
 newt/target/target.go    |  2 +-
 3 files changed, 38 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2d5ef1e/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 0e1e17f..1738b4c 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -204,7 +204,7 @@ func (pkg *LocalPackage) Save() error {
 	}
 	defer file.Close()
 
-	file.WriteString("### Package: " + pkg.Name() + "\n\n")
+	file.WriteString("### Package: " + pkg.Name() + "\n")
 
 	file.WriteString("pkg.name: " + yaml.EscapeString(pkg.Name()) + "\n")
 	file.WriteString("pkg.type: " +

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2d5ef1e/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index cba4dd7..c55fd39 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -101,12 +101,13 @@ func showValidSettings(varName string) error {
 }
 
 func targetSetCmd(cmd *cobra.Command, args []string) {
-	if len(args) != 2 {
+	if len(args) < 2 {
 		cli.NewtUsage(cmd,
-			util.NewNewtError("Must specify two arguments "+
+			util.NewNewtError("Must specify at least two arguments "+
 				"(target-name & k=v) to set"))
 	}
 
+	// Parse target name.
 	tName := args[0]
 	t := ResolveTargetName(tName)
 	if t == nil {
@@ -114,37 +115,50 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
 	}
 	tName = t.Name()
 
-	ar := strings.SplitN(args[1], "=", 2)
-	if !strings.HasPrefix(ar[0], "target.") {
-		ar[0] = "target." + ar[0]
-	}
+	// Parse series of k=v pairs.  If an argument doesn't contain a '='
+	// character, display the valid values for the variable and quit.
+	vars := [][]string{}
+	for i := 1; i < len(args); i++ {
+		kv := strings.SplitN(args[i], "=", 2)
+		if !strings.HasPrefix(kv[0], "target.") {
+			kv[0] = "target." + kv[0]
+		}
 
-	if len(ar) == 1 {
-		// User entered a variable name without a value.  Display valid values
-		// for the specified variable.
-		err := showValidSettings(ar[0])
-		if err != nil {
-			cli.NewtUsage(cmd, err)
+		if len(kv) == 1 {
+			// User entered a variable name without a value.  Display valid
+			// values for the specified variable.
+			err := showValidSettings(kv[0])
+			if err != nil {
+				cli.NewtUsage(cmd, err)
+			}
+			return
 		}
-	} else {
-		if ar[1] == "" {
+
+		vars = append(vars, kv)
+	}
+
+	// Set each specified variable in the target.
+	for _, kv := range vars {
+		if kv[1] == "" {
 			// User specified empty value; delete variable.
-			delete(t.Vars, ar[0])
+			delete(t.Vars, kv[0])
 		} else {
 			// Assign value to specified variable.
-			t.Vars[ar[0]] = ar[1]
+			t.Vars[kv[0]] = kv[1]
 		}
+	}
 
-		if err := t.Save(); err != nil {
-			cli.NewtUsage(cmd, err)
-		}
+	if err := t.Save(); err != nil {
+		cli.NewtUsage(cmd, err)
+	}
 
-		if ar[1] == "" {
+	for _, kv := range vars {
+		if kv[1] == "" {
 			cli.StatusMessage(cli.VERBOSITY_DEFAULT,
-				"Target %s successfully unset %s\n", tName, ar[0])
+				"Target %s successfully unset %s\n", tName, kv[0])
 		} else {
 			cli.StatusMessage(cli.VERBOSITY_DEFAULT,
-				"Target %s successfully set %s to %s\n", tName, ar[0], ar[1])
+				"Target %s successfully set %s to %s\n", tName, kv[0], kv[1])
 		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d2d5ef1e/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 643035e..39714d4 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -169,7 +169,7 @@ func (t *Target) Save() error {
 	}
 	defer file.Close()
 
-	file.WriteString("### Target: " + t.basePkg.Name() + "\n\n")
+	file.WriteString("### Target: " + t.basePkg.Name() + "\n")
 
 	keys := []string{}
 	for k, _ := range t.Vars {


[5/7] incubator-mynewt-newt git commit: Improve some messages.

Posted by cc...@apache.org.
Improve some messages.


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/65b5bb39
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/65b5bb39
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/65b5bb39

Branch: refs/heads/rename_project_app
Commit: 65b5bb39f61e500b6e1d8f635942862c0932cb30
Parents: 4920e1e
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 16:38:17 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:35:02 2016 -0800

----------------------------------------------------------------------
 newt/builder/build.go | 23 +++++++++++++++++++----
 newt/builder/cmds.go  | 33 ++++++++++++++++++---------------
 newt/cli/util.go      |  2 ++
 newt/target/target.go | 18 ++++++++++--------
 util/util.go          | 11 ++---------
 5 files changed, 51 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/65b5bb39/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 1f149af..7b3a35a 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -270,13 +270,23 @@ func (b *Builder) PrepBuild() error {
 	// Collect the seed packages.
 	bspPkg := b.target.Bsp()
 	if bspPkg == nil {
-		return util.NewNewtError("bsp package not specified")
+		if b.target.BspName == "" {
+			return util.NewNewtError("BSP package not specified by target")
+		} else {
+			return util.NewNewtError("BSP package not found: " +
+				b.target.BspName)
+		}
 	}
 
 	b.Bsp = pkg.NewBspPackage(bspPkg)
 	compilerPkg := b.resolveCompiler()
 	if compilerPkg == nil {
-		return util.NewNewtError("compiler package not specified")
+		if b.Bsp.CompilerName == "" {
+			return util.NewNewtError("Compiler package not specified by BSP")
+		} else {
+			return util.NewNewtError("Compiler package not found: " +
+				b.Bsp.CompilerName)
+		}
 	}
 
 	// An app package is not required (e.g., unit tests).
@@ -362,7 +372,12 @@ func (b *Builder) PrepBuild() error {
 
 func (b *Builder) Build() error {
 	if b.target.App() == nil {
-		return util.NewNewtError("app package not specified")
+		if b.target.AppName == "" {
+			return util.NewNewtError("App package not specified by target")
+		} else {
+			return util.NewNewtError("App package not found: " +
+				b.target.AppName)
+		}
 	}
 
 	// Populate the package and feature sets and calculate the base compiler
@@ -445,7 +460,7 @@ func (b *Builder) Test(p *pkg.LocalPackage) error {
 		cli.StatusMessage(cli.VERBOSITY_DEFAULT, "%s", string(o))
 
 		// Always terminate on test failure since only one test is being run.
-		return util.NewtErrorNoTrace("Test failed: " + testFilename)
+		return util.NewNewtError("Test failed: " + testFilename)
 	}
 
 	cli.StatusMessage(cli.VERBOSITY_VERBOSE, "%s", string(o))

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/65b5bb39/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index 1b52c41..24299a8 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -44,12 +44,15 @@ func buildRunCmd(cmd *cobra.Command, args []string) {
 
 	b, err := NewBuilder(t)
 	if err != nil {
-		fmt.Println(err)
+		cli.NewtUsage(cmd, err)
 	}
 	err = b.Build()
 	if err != nil {
-		fmt.Println(err)
+		cli.NewtUsage(cmd, err)
 	}
+
+	cli.StatusMessage(cli.VERBOSITY_DEFAULT, "App successfully built: %s\n",
+		b.AppElfPath())
 }
 
 func cleanRunCmd(cmd *cobra.Command, args []string) {
@@ -64,11 +67,11 @@ func cleanRunCmd(cmd *cobra.Command, args []string) {
 
 	b, err := NewBuilder(t)
 	if err != nil {
-		fmt.Println(err)
+		cli.NewtUsage(cmd, err)
 	}
 	err = b.Clean()
 	if err != nil {
-		fmt.Println(err)
+		cli.NewtUsage(cmd, err)
 	}
 }
 
@@ -85,7 +88,7 @@ func testRunCmd(cmd *cobra.Command, args []string) {
 
 	b, err := NewBuilder(t)
 	if err != nil {
-		fmt.Println(err)
+		cli.NewtUsage(cmd, err)
 	}
 
 	// Verify and resolve each specified package.
@@ -93,16 +96,16 @@ func testRunCmd(cmd *cobra.Command, args []string) {
 	for _, pkgName := range args {
 		dep, err := pkg.NewDependency(nil, pkgName)
 		if err != nil {
-			cli.NewtUsage(cmd, util.NewtErrorNoTrace(fmt.Sprintf("invalid "+
+			cli.NewtUsage(cmd, util.NewNewtError(fmt.Sprintf("invalid "+
 				"package name: %s (%s)", pkgName, err.Error())))
 		}
 		if dep == nil {
-			cli.NewtUsage(cmd, util.NewtErrorNoTrace("invalid package name: "+
+			cli.NewtUsage(cmd, util.NewNewtError("invalid package name: "+
 				pkgName))
 		}
 		pack := project.GetProject().ResolveDependency(dep)
 		if pack == nil {
-			cli.NewtUsage(cmd, util.NewtErrorNoTrace("unknown package: "+
+			cli.NewtUsage(cmd, util.NewNewtError("unknown package: "+
 				pkgName))
 		}
 
@@ -113,7 +116,7 @@ func testRunCmd(cmd *cobra.Command, args []string) {
 	for _, pack := range packs {
 		err = b.Test(pack)
 		if err != nil {
-			fmt.Println(err)
+			cli.NewtUsage(cmd, err)
 		}
 	}
 }
@@ -130,12 +133,12 @@ func downloadRunCmd(cmd *cobra.Command, args []string) {
 
 	b, err := NewBuilder(t)
 	if err != nil {
-		fmt.Println(err)
+		cli.NewtUsage(cmd, err)
 	}
 
 	err = b.Download()
 	if err != nil {
-		fmt.Println(err)
+		cli.NewtUsage(cmd, err)
 	}
 }
 
@@ -151,12 +154,12 @@ func debugRunCmd(cmd *cobra.Command, args []string) {
 
 	b, err := NewBuilder(t)
 	if err != nil {
-		fmt.Println(err)
+		cli.NewtUsage(cmd, err)
 	}
 
 	err = b.Debug()
 	if err != nil {
-		fmt.Println(err)
+		cli.NewtUsage(cmd, err)
 	}
 }
 
@@ -186,7 +189,7 @@ func AddCommands(cmd *cobra.Command) {
 	buildHelpEx := ""
 	buildCmd := &cobra.Command{
 		Use:     "build",
-		Short:   "Command for building target",
+		Short:   "Builds one or more apps.",
 		Long:    buildHelpText,
 		Example: buildHelpEx,
 		Run:     buildRunCmd,
@@ -198,7 +201,7 @@ func AddCommands(cmd *cobra.Command) {
 	cleanHelpEx := ""
 	cleanCmd := &cobra.Command{
 		Use:     "clean",
-		Short:   "Command for cleaning target",
+		Short:   "Deletes app build artifacts.",
 		Long:    cleanHelpText,
 		Example: cleanHelpEx,
 		Run:     cleanRunCmd,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/65b5bb39/newt/cli/util.go
----------------------------------------------------------------------
diff --git a/newt/cli/util.go b/newt/cli/util.go
index 0794cc1..fde67f3 100644
--- a/newt/cli/util.go
+++ b/newt/cli/util.go
@@ -61,6 +61,8 @@ func NewtUsage(cmd *cobra.Command, err error) {
 	}
 
 	if cmd != nil {
+		fmt.Printf("\n")
+		fmt.Printf("%s - ", cmd.Name())
 		cmd.Help()
 	}
 	os.Exit(1)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/65b5bb39/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 6a520c3..90b7afa 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -109,24 +109,26 @@ func (target *Target) ShortName() string {
 	return filepath.Base(target.Name())
 }
 
-func (target *Target) App() *pkg.LocalPackage {
-	dep, err := pkg.NewDependency(nil, target.AppName)
+func resolvePackageName(name string) *pkg.LocalPackage {
+	dep, err := pkg.NewDependency(nil, name)
 	if err != nil {
 		return nil
 	}
 
-	appPkg := project.GetProject().ResolveDependency(dep)
-	if appPkg == nil {
+	pack, ok := project.GetProject().ResolveDependency(dep).(*pkg.LocalPackage)
+	if !ok {
 		return nil
 	}
 
-	return appPkg.(*pkg.LocalPackage)
+	return pack
+}
+
+func (target *Target) App() *pkg.LocalPackage {
+	return resolvePackageName(target.AppName)
 }
 
 func (target *Target) Bsp() *pkg.LocalPackage {
-	dep, _ := pkg.NewDependency(nil, target.BspName)
-	mypkg := project.GetProject().ResolveDependency(dep).(*pkg.LocalPackage)
-	return mypkg
+	return resolvePackageName(target.BspName)
 }
 
 func (target *Target) BinBasePath() string {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/65b5bb39/util/util.go
----------------------------------------------------------------------
diff --git a/util/util.go b/util/util.go
index 8ac4e60..4ac925d 100644
--- a/util/util.go
+++ b/util/util.go
@@ -20,10 +20,10 @@
 package util
 
 import (
-	"mynewt.apache.org/newt/viper"
-	"github.com/hashicorp/logutils"
 	"fmt"
+	"github.com/hashicorp/logutils"
 	"log"
+	"mynewt.apache.org/newt/viper"
 	"os"
 	"path/filepath"
 	"runtime"
@@ -66,13 +66,6 @@ func NewNewtError(msg string) *NewtError {
 	return err
 }
 
-func NewtErrorNoTrace(msg string) *NewtError {
-	return &NewtError{
-		Text:       msg,
-		StackTrace: nil,
-	}
-}
-
 func Min(x, y int) int {
 	if x < y {
 		return x


[7/7] incubator-mynewt-newt git commit: Fix valid app list for "newt target set <...> app"

Posted by cc...@apache.org.
Fix valid app list for "newt target set <...> app"


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/f3842f09
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/f3842f09
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/f3842f09

Branch: refs/heads/rename_project_app
Commit: f3842f09a9dad8a35f6d837944ccdcf2f6a338dc
Parents: dc1e947
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 16:38:32 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:35:02 2016 -0800

----------------------------------------------------------------------
 newt/interfaces/interfaces.go |  2 ++
 newt/pkg/localpackage.go      |  9 +++++++++
 newt/pkg/package.go           | 16 +++++++++------
 newt/project/project.go       | 15 ++++++++++++++
 newt/repo/repo.go             |  4 ++++
 newt/target/target.go         | 25 +++++++++++-------------
 newt/target/vars.go           | 40 +++++++++++++++++++++++++++-----------
 7 files changed, 80 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/interfaces/interfaces.go
----------------------------------------------------------------------
diff --git a/newt/interfaces/interfaces.go b/newt/interfaces/interfaces.go
index 16cd3c6..56b5cba 100644
--- a/newt/interfaces/interfaces.go
+++ b/newt/interfaces/interfaces.go
@@ -21,6 +21,7 @@ package interfaces
 
 type PackageInterface interface {
 	Name() string
+	FullName() string
 	Repo() RepoInterface
 	Type() PackageType
 }
@@ -29,6 +30,7 @@ type PackageType int
 
 type RepoInterface interface {
 	Name() string
+	IsLocal() bool
 }
 
 type VersionReqInterface interface {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 1738b4c..9f14561 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -80,6 +80,15 @@ func (pkg *LocalPackage) Name() string {
 	return pkg.name
 }
 
+func (pkg *LocalPackage) FullName() string {
+	r := pkg.Repo()
+	if r.IsLocal() {
+		return pkg.Name()
+	} else {
+		return "@" + r.Name() + "/" + pkg.Name()
+	}
+}
+
 func (pkg *LocalPackage) BasePath() string {
 	return pkg.basePath
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/pkg/package.go
----------------------------------------------------------------------
diff --git a/newt/pkg/package.go b/newt/pkg/package.go
index 38be9f4..7b30f69 100644
--- a/newt/pkg/package.go
+++ b/newt/pkg/package.go
@@ -34,17 +34,19 @@ const (
 )
 
 const (
-	PACKAGE_TYPE_LIB interfaces.PackageType = iota
+	PACKAGE_TYPE_APP interfaces.PackageType = iota
 	PACKAGE_TYPE_BSP
+	PACKAGE_TYPE_COMPILER
+	PACKAGE_TYPE_LIB
 	PACKAGE_TYPE_TARGET
-	PACKAGE_TYPE_APP
 )
 
 var PackageTypeNames = map[interfaces.PackageType]string{
-	PACKAGE_TYPE_LIB:    "lib",
-	PACKAGE_TYPE_BSP:    "bsp",
-	PACKAGE_TYPE_APP:    "app",
-	PACKAGE_TYPE_TARGET: "target",
+	PACKAGE_TYPE_APP:      "app",
+	PACKAGE_TYPE_BSP:      "bsp",
+	PACKAGE_TYPE_COMPILER: "compiler",
+	PACKAGE_TYPE_LIB:      "lib",
+	PACKAGE_TYPE_TARGET:   "target",
 }
 
 // An interface, representing information about a Package
@@ -59,6 +61,8 @@ type Package interface {
 	Repo() *repo.Repo
 	// The name of this package
 	Name() string
+	// The full name of this package, including repo
+	FullName() string
 	// The type of package (lib, target, bsp, etc.)
 	Type() interfaces.PackageType
 	// Hash of the contents of the package

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index a53fd06..990ba51 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -382,6 +382,21 @@ func (proj *Project) PackageList() interfaces.PackageList {
 	return proj.packages
 }
 
+func (proj *Project) PackagesOfType(pkgType interfaces.PackageType) []interfaces.PackageInterface {
+	matches := []interfaces.PackageInterface{}
+
+	packs := proj.PackageList()
+	for _, packHash := range packs {
+		for _, pack := range *packHash {
+			if pack.Type() == pkgType {
+				matches = append(matches, pack)
+			}
+		}
+	}
+
+	return matches
+}
+
 func LoadProject(dir string) (*Project, error) {
 	projDir, err := findProjectDir(dir)
 	if err != nil {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 0419e38..93fd31a 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -158,6 +158,10 @@ func (r *Repo) Path() string {
 	return r.localPath
 }
 
+func (r *Repo) IsLocal() bool {
+	return r.name == REPO_NAME_LOCAL
+}
+
 func (r *Repo) VersionRequirements() []interfaces.VersionReqInterface {
 	return r.versreq
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 90b7afa..7b79176 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -211,20 +211,17 @@ func (t *Target) Delete() error {
 func buildTargetMap() error {
 	globalTargetMap = map[string]*Target{}
 
-	packs := project.GetProject().PackageList()
-	for _, packHash := range packs {
-		for name, pack := range *packHash {
-			if pack.Type() == pkg.PACKAGE_TYPE_TARGET {
-				target, err := LoadTarget(pack.(*pkg.LocalPackage))
-				if err != nil {
-					nerr := err.(*util.NewtError)
-					cli.ErrorMessage(cli.VERBOSITY_QUIET,
-						"Warning: failed to load target \"%s\": %s\n", name,
-						nerr.Text)
-				} else {
-					globalTargetMap[name] = target
-				}
-			}
+	packs := project.GetProject().PackagesOfType(pkg.PACKAGE_TYPE_TARGET)
+	for _, packItf := range packs {
+		pack := packItf.(*pkg.LocalPackage)
+		target, err := LoadTarget(pack)
+		if err != nil {
+			nerr := err.(*util.NewtError)
+			cli.ErrorMessage(cli.VERBOSITY_QUIET,
+				"Warning: failed to load target \"%s\": %s\n", pack.Name,
+				nerr.Text)
+		} else {
+			globalTargetMap[pack.Name()] = target
 		}
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f3842f09/newt/target/vars.go
----------------------------------------------------------------------
diff --git a/newt/target/vars.go b/newt/target/vars.go
index fee7bcf..a4b1cac 100644
--- a/newt/target/vars.go
+++ b/newt/target/vars.go
@@ -21,9 +21,12 @@ package target
 
 import (
 	"fmt"
+	"path/filepath"
 	"strings"
 
 	"mynewt.apache.org/newt/newt/cli"
+	. "mynewt.apache.org/newt/newt/interfaces"
+	"mynewt.apache.org/newt/newt/pkg"
 	"mynewt.apache.org/newt/newt/project"
 	"mynewt.apache.org/newt/newt/repo"
 	"mynewt.apache.org/newt/util"
@@ -37,17 +40,20 @@ func varsFromChildDirs(key string, fullPath bool) ([]string, error) {
 	for _, r := range repos {
 		for _, pkgDir := range searchDirs {
 			pkgBaseDir := r.Path() + "/" + pkgDir
-			values, err := cli.DescendantDirsOfParent(pkgBaseDir, key, fullPath)
+			values, err := cli.DescendantDirsOfParent(pkgBaseDir, key,
+				fullPath)
 			if err != nil {
 				return nil, util.NewNewtError(err.Error())
 			}
 
 			for _, value := range values {
 				if fullPath {
-					value = strings.TrimPrefix(value, project.GetProject().Path()+"/")
+					value = strings.TrimPrefix(value,
+						project.GetProject().Path()+"/")
 				}
 				if strings.HasPrefix(value, repo.REPOS_DIR+"/") {
-					value = "$" + strings.TrimPrefix(value, repo.REPOS_DIR+"/")
+					value = "@" +
+						strings.TrimPrefix(value, repo.REPOS_DIR+"/")
 				}
 				valueSlice = append(valueSlice, value)
 			}
@@ -57,21 +63,33 @@ func varsFromChildDirs(key string, fullPath bool) ([]string, error) {
 	return cli.SortFields(valueSlice...), nil
 }
 
+func varsFromPackageType(pt PackageType, fullPath bool) ([]string, error) {
+	values := []string{}
+
+	packs := project.GetProject().PackagesOfType(pt)
+	for _, pack := range packs {
+		value := pack.FullName()
+		if !fullPath {
+			value = filepath.Base(value)
+		}
+
+		values = append(values, value)
+	}
+
+	return values, nil
+}
+
 var varsMap = map[string]func() ([]string, error){
-	"arch": func() ([]string, error) {
+	"target.arch": func() ([]string, error) {
 		return varsFromChildDirs("arch", false)
 	},
 
-	"bsp": func() ([]string, error) {
+	"target.bsp": func() ([]string, error) {
 		return varsFromChildDirs("bsp", true)
 	},
 
-	"compiler": func() ([]string, error) {
-		return varsFromChildDirs("compiler", true)
-	},
-
-	"project": func() ([]string, error) {
-		return varsFromChildDirs("project", true)
+	"target.app": func() ([]string, error) {
+		return varsFromPackageType(pkg.PACKAGE_TYPE_APP, true)
 	},
 }