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:51 UTC

[36/50] incubator-mynewt-newt git commit: Handle targets from non-local repos.

Handle targets from non-local repos.


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

Branch: refs/heads/develop
Commit: 5c7d6ff4a8210eec06d52a54dbd0eeffd3b2f95c
Parents: 8815613
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 18:34:53 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 19:39:09 2016 -0800

----------------------------------------------------------------------
 newt/builder/cmds.go  |  2 +-
 newt/target/cmds.go   | 12 +++++++-----
 newt/target/target.go | 44 ++++++++++++++++++++++++++++++--------------
 3 files changed, 38 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5c7d6ff4/newt/builder/cmds.go
----------------------------------------------------------------------
diff --git a/newt/builder/cmds.go b/newt/builder/cmds.go
index aaf4836..2744127 100644
--- a/newt/builder/cmds.go
+++ b/newt/builder/cmds.go
@@ -57,7 +57,7 @@ func buildRunCmd(cmd *cobra.Command, args []string) {
 
 func cleanRunCmd(cmd *cobra.Command, args []string) {
 	if len(args) < 1 {
-		cli.NewtUsage(cmd, nil)
+		cli.NewtUsage(cmd, util.NewNewtError("Must specify target"))
 	}
 
 	t := target.ResolveTargetName(args[0])

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5c7d6ff4/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index 1cfe18a..7480c0f 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -61,7 +61,7 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
 		}
 
 		for _, t := range targetSlice {
-			targetNames = append(targetNames, t.Name())
+			targetNames = append(targetNames, t.FullName())
 		}
 	}
 
@@ -155,10 +155,10 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
 	for _, kv := range vars {
 		if kv[1] == "" {
 			util.StatusMessage(util.VERBOSITY_DEFAULT,
-				"Target %s successfully unset %s\n", t.Name(), kv[0])
+				"Target %s successfully unset %s\n", t.FullName(), kv[0])
 		} else {
 			util.StatusMessage(util.VERBOSITY_DEFAULT,
-				"Target %s successfully set %s to %s\n", t.Name(), kv[0],
+				"Target %s successfully set %s to %s\n", t.FullName(), kv[0],
 				kv[1])
 		}
 	}
@@ -176,6 +176,8 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
 		tName = "targets/" + tName
 	}
 
+	// XXX: Deal with repo name at start of target string.
+
 	util.StatusMessage(util.VERBOSITY_DEFAULT, "Creating target "+tName+"\n")
 
 	t := ResolveTargetName(tName)
@@ -211,7 +213,7 @@ func targetDelOne(t *Target) error {
 		if userFiles {
 			scanner := bufio.NewScanner(os.Stdin)
 			fmt.Printf("Target directory %s contains some extra content; "+
-				"delete anyway? (y/N): ", t.basePkg.Name())
+				"delete anyway? (y/N): ", t.basePkg.BasePath())
 			rc := scanner.Scan()
 			if !rc || strings.ToLower(scanner.Text()) != "y" {
 				return nil
@@ -224,7 +226,7 @@ func targetDelOne(t *Target) error {
 	}
 
 	util.StatusMessage(util.VERBOSITY_DEFAULT,
-		"Target %s successfully removed\n", t.Name())
+		"Target %s successfully removed\n", t.FullName())
 
 	return nil
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/5c7d6ff4/newt/target/target.go
----------------------------------------------------------------------
diff --git a/newt/target/target.go b/newt/target/target.go
index 72e1e1d..661df43 100644
--- a/newt/target/target.go
+++ b/newt/target/target.go
@@ -32,14 +32,11 @@ import (
 	"mynewt.apache.org/newt/yaml"
 )
 
-const TARGET_FILE_NAME string = "target.yml"
+const TARGET_FILENAME string = "target.yml"
+const TARGET_DEFAULT_DIR string = "targets"
 
 var globalTargetMap map[string]*Target
 
-var targetSearchDirs = []string{
-	"targets",
-}
-
 type Target struct {
 	basePkg *pkg.LocalPackage
 
@@ -76,7 +73,7 @@ func (target *Target) Init(basePkg *pkg.LocalPackage) {
 
 func (target *Target) Load(basePkg *pkg.LocalPackage) error {
 	v, err := util.ReadConfig(basePkg.BasePath(),
-		strings.TrimSuffix(TARGET_FILE_NAME, ".yml"))
+		strings.TrimSuffix(TARGET_FILENAME, ".yml"))
 	if err != nil {
 		return err
 	}
@@ -104,6 +101,10 @@ func (target *Target) Name() string {
 	return target.basePkg.Name()
 }
 
+func (target *Target) FullName() string {
+	return target.basePkg.FullName()
+}
+
 func (target *Target) ShortName() string {
 	return filepath.Base(target.Name())
 }
@@ -155,7 +156,7 @@ func (t *Target) Save() error {
 	}
 
 	dirpath := t.basePkg.BasePath()
-	filepath := dirpath + "/" + TARGET_FILE_NAME
+	filepath := dirpath + "/" + TARGET_FILENAME
 	file, err := os.Create(filepath)
 	if err != nil {
 		return util.NewNewtError(err.Error())
@@ -189,7 +190,7 @@ func (t *Target) ContainsUserFiles() (bool, error) {
 	for _, node := range contents {
 		name := node.Name()
 		if name != "." && name != ".." &&
-			name != pkg.PACKAGE_FILE_NAME && name != TARGET_FILE_NAME {
+			name != pkg.PACKAGE_FILE_NAME && name != TARGET_FILENAME {
 
 			userFiles = true
 			break
@@ -220,7 +221,7 @@ func buildTargetMap() error {
 				"Warning: failed to load target \"%s\": %s\n", pack.Name,
 				nerr.Text)
 		} else {
-			globalTargetMap[pack.Name()] = target
+			globalTargetMap[pack.FullName()] = target
 		}
 	}
 
@@ -241,13 +242,28 @@ func GetTargets() map[string]*Target {
 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]
+	// Check for fully-qualified name.
+	if t := targetMap[name]; t != nil {
+		return t
+	}
+
+	// Check the local "targets" directory.
+	if t := targetMap[TARGET_DEFAULT_DIR+"/"+name]; t != nil {
+		return t
 	}
 
-	return t
+	// Check each repo alphabetically.
+	fullNames := []string{}
+	for fullName, _ := range targetMap {
+		fullNames = append(fullNames, fullName)
+	}
+	for _, fullName := range util.SortFields(fullNames...) {
+		if name == filepath.Base(fullName) {
+			return targetMap[fullName]
+		}
+	}
+
+	return nil
 }
 
 func ResolveTargetNames(names ...string) ([]*Target, error) {