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 2016/03/09 21:23:28 UTC

[13/50] incubator-mynewt-newt git commit: Don't require "target/" prefix in arguments.

Don't require "target/" prefix in arguments.


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

Branch: refs/heads/develop
Commit: a3d68ef227c7de4a724df226dd2941973bc116cd
Parents: 77e2a2a
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 13:37:17 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 13:52:51 2016 -0800

----------------------------------------------------------------------
 newt/builder/build.go |  9 +++++++--
 newt/cli/util.go      |  9 ++++++++-
 newt/target/cmds.go   | 46 +++++++++++++++++++++++++++-------------------
 newt/target/target.go | 43 +++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 83 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a3d68ef2/newt/builder/build.go
----------------------------------------------------------------------
diff --git a/newt/builder/build.go b/newt/builder/build.go
index 0ff0bc0..185ec37 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -195,7 +195,7 @@ func (b *Builder) buildPackage(bpkg *BuildPackage) error {
 	}
 
 	c, err := toolchain.NewCompiler(b.compilerPkg.BasePath(),
-		b.pkgBinDir(bpkg.Name()), "default") // XXX Use correct compiler def
+		b.pkgBinDir(bpkg.Name()), b.target.BuildProfile)
 	if err != nil {
 		return err
 	}
@@ -240,7 +240,7 @@ func (b *Builder) buildPackage(bpkg *BuildPackage) error {
 
 func (b *Builder) link(elfName string) error {
 	c, err := toolchain.NewCompiler(b.compilerPkg.BasePath(),
-		b.pkgBinDir(elfName), "default") // XXX
+		b.pkgBinDir(elfName), b.target.BuildProfile)
 	if err != nil {
 		return err
 	}
@@ -325,6 +325,7 @@ func (b *Builder) PrepBuild() error {
 
 	baseCi := toolchain.NewCompilerInfo()
 
+	// App flags.
 	if appBpkg != nil {
 		appCi, err := appBpkg.CompilerInfo(b)
 		if err != nil {
@@ -333,18 +334,22 @@ func (b *Builder) PrepBuild() error {
 		baseCi.AddCompilerInfo(appCi)
 	}
 
+	// Bsp flags.
 	bspCi, err := bspBpkg.CompilerInfo(b)
 	if err != nil {
 		return err
 	}
 	baseCi.AddCompilerInfo(bspCi)
 
+	// Target flags.
 	targetCi, err := targetBpkg.CompilerInfo(b)
 	if err != nil {
 		return err
 	}
 	baseCi.AddCompilerInfo(targetCi)
 
+	// Note: Compiler flags get added when compiler is created.
+
 	// Read the BSP configuration.  These settings are necessary for the link
 	// step.
 	b.Bsp = pkg.NewBspPackage(bspPkg, b.Features())

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a3d68ef2/newt/cli/util.go
----------------------------------------------------------------------
diff --git a/newt/cli/util.go b/newt/cli/util.go
index 0b29f87..0794cc1 100644
--- a/newt/cli/util.go
+++ b/newt/cli/util.go
@@ -320,13 +320,20 @@ func CopyDir(srcDir, destDir string) error {
 	return CopyFile(srcDir, destDir)
 }
 
-// Print Silent, Quiet and Verbose aware status messages
+// Print Silent, Quiet and Verbose aware status messages to stdout.
 func StatusMessage(level int, message string, args ...interface{}) {
 	if Verbosity >= level {
 		fmt.Printf(message, args...)
 	}
 }
 
+// Print Silent, Quiet and Verbose aware status messages to stderr.
+func ErrorMessage(level int, message string, args ...interface{}) {
+	if Verbosity >= level {
+		fmt.Fprintf(os.Stderr, message, args...)
+	}
+}
+
 // Reads each line from the specified text file into an array of strings.  If a
 // line ends with a backslash, it is concatenated with the following line.
 func ReadLines(path string) ([]string, error) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a3d68ef2/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 4102740..018b713 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -42,34 +42,42 @@ func (a ByName) Less(i, j int) bool { return a[i].Package().Name() < a[j].Packag
 
 func targetShowCmd(cmd *cobra.Command, args []string) {
 	proj := project.GetProject()
-	proj.LoadPackageList()
-
-	dispTarget := ""
-	if len(args) == 1 {
-		dispTarget = args[0]
+	err := proj.LoadPackageList()
+	if err != nil {
+		cli.NewtUsage(cmd, err)
 	}
 
 	targetNames := []string{}
-	for name, _ := range GetTargets() {
-		targetNames = append(targetNames, name)
+	if len(args) == 0 {
+		for name, _ := range GetTargets() {
+			targetNames = append(targetNames, name)
+		}
+	} else {
+		targetSlice, err := ResolveTargetNames(args...)
+		if err != nil {
+			cli.NewtUsage(cmd, err)
+		}
+
+		for _, t := range targetSlice {
+			targetNames = append(targetNames, t.Name())
+		}
 	}
+
 	sort.Strings(targetNames)
 
 	for _, name := range targetNames {
-		if dispTarget == "" || dispTarget == name {
-			cli.StatusMessage(cli.VERBOSITY_QUIET, name+"\n")
+		cli.StatusMessage(cli.VERBOSITY_QUIET, name+"\n")
 
-			target := GetTargets()[name]
-			keys := []string{}
-			for k, _ := range target.Vars {
-				keys = append(keys, k)
-			}
+		target := GetTargets()[name]
+		keys := []string{}
+		for k, _ := range target.Vars {
+			keys = append(keys, k)
+		}
 
-			sort.Strings(keys)
-			for _, k := range keys {
-				cli.StatusMessage(cli.VERBOSITY_QUIET,
-					"    %s=%s\n", k, target.Vars[k])
-			}
+		sort.Strings(keys)
+		for _, k := range keys {
+			cli.StatusMessage(cli.VERBOSITY_QUIET, "    %s=%s\n", k,
+				target.Vars[k])
 		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a3d68ef2/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 128ea9b..99c8d1f 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -27,6 +27,7 @@ import (
 	"sort"
 	"strings"
 
+	"mynewt.apache.org/newt/newt/cli"
 	"mynewt.apache.org/newt/newt/pkg"
 	"mynewt.apache.org/newt/newt/project"
 	"mynewt.apache.org/newt/util"
@@ -36,6 +37,10 @@ const TARGET_FILE_NAME string = "target.yml"
 
 var globalTargetMap map[string]*Target
 
+var targetSearchDirs = []string{
+	"targets",
+}
+
 type Target struct {
 	basePkg *pkg.LocalPackage
 
@@ -46,6 +51,7 @@ type Target struct {
 	BspName      string
 	AppName      string
 	Arch         string
+	BuildProfile string
 
 	// target.yml configuration structure
 	Vars map[string]string
@@ -88,6 +94,7 @@ func (target *Target) Load(basePkg *pkg.LocalPackage) error {
 	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?
 
@@ -223,9 +230,13 @@ func buildTargetMap() error {
 			if pack.Type() == pkg.PACKAGE_TYPE_TARGET {
 				target, err := LoadTarget(pack.(*pkg.LocalPackage))
 				if err != nil {
-					return err
+					nerr := err.(*util.NewtError)
+					cli.ErrorMessage(cli.VERBOSITY_QUIET,
+						"Warning: failed to load target \"%s\": %s\n", name,
+						nerr.Text)
+				} else {
+					globalTargetMap[name] = target
 				}
-				globalTargetMap[name] = target
 			}
 		}
 	}
@@ -243,3 +254,31 @@ func GetTargets() map[string]*Target {
 
 	return globalTargetMap
 }
+
+func ResolveTargetName(name string) *Target {
+	targetMap := GetTargets()
+
+	t := targetMap[name]
+	for i := 0; t == nil && i < len(targetSearchDirs); i++ {
+		guess := targetSearchDirs[i] + "/" + name
+		t = targetMap[guess]
+	}
+
+	return t
+}
+
+func ResolveTargetNames(names ...string) ([]*Target, error) {
+	targets := []*Target{}
+
+	for _, name := range names {
+		t := ResolveTargetName(name)
+		if t == nil {
+			return nil, util.NewNewtError("Could not resolve target name: " +
+				name)
+		}
+
+		targets = append(targets, t)
+	}
+
+	return targets, nil
+}