mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject [2/2] incubator-mynewt-newt git commit: Allow target features to be set and cleared.
Date Fri, 11 Mar 2016 02:13:27 GMT
Allow target features to be set and cleared.


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

Branch: refs/heads/develop
Commit: 0ed12f3441a16b33394eb937d2d86a61c357fafc
Parents: 4763963
Author: Christopher Collins <ccollins476ad@gmail.com>
Authored: Thu Mar 10 18:12:47 2016 -0800
Committer: Christopher Collins <ccollins476ad@gmail.com>
Committed: Thu Mar 10 18:12:47 2016 -0800

----------------------------------------------------------------------
 newt/cli/target_cmds.go  | 37 ++++++++++++++++++++++++++++++++-----
 newt/pkg/localpackage.go |  5 +++++
 2 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0ed12f34/newt/cli/target_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go
index 9772768..3c3e0a0 100644
--- a/newt/cli/target_cmds.go
+++ b/newt/cli/target_cmds.go
@@ -21,6 +21,7 @@ package cli
 
 import (
 	"bufio"
+	"bytes"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -67,6 +68,18 @@ func targetContainsUserFiles(t *target.Target) (bool, error) {
 	return userFiles, nil
 }
 
+func featuresString(pack *pkg.LocalPackage) string {
+	features := pack.Viper.GetStringSlice("pkg.features")
+	sort.Strings(features)
+
+	var buffer bytes.Buffer
+	for _, f := range features {
+		buffer.WriteString(f)
+		buffer.WriteString(" ")
+	}
+	return buffer.String()
+}
+
 func targetShowCmd(cmd *cobra.Command, args []string) {
 	targetNames := []string{}
 	if len(args) == 0 {
@@ -102,6 +115,8 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
 			util.StatusMessage(util.VERBOSITY_DEFAULT, "    %s=%s\n",
 				varName, value)
 		}
+		util.StatusMessage(util.VERBOSITY_DEFAULT, "    features=%s\n",
+			featuresString(target.Package()))
 	}
 }
 
@@ -164,12 +179,24 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
 
 	// Set each specified variable in the target.
 	for _, kv := range vars {
-		if kv[1] == "" {
-			// User specified empty value; delete variable.
-			delete(t.Vars, kv[0])
+		// "features" is a special case; it goes in the base package and not
+		// the target.
+		if kv[0] == "target.features" {
+			if kv[1] == "" {
+				// User specified empty value; delete variable.
+				t.Package().Viper.Set("pkg.features", nil)
+			} else {
+				features := strings.Fields(kv[1])
+				t.Package().Viper.Set("pkg.features", features)
+			}
 		} else {
-			// Assign value to specified variable.
-			t.Vars[kv[0]] = kv[1]
+			if kv[1] == "" {
+				// User specified empty value; delete variable.
+				delete(t.Vars, kv[0])
+			} else {
+				// Assign value to specified variable.
+				t.Vars[kv[0]] = kv[1]
+			}
 		}
 	}
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0ed12f34/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index d2547af..ab2e4d4 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -248,6 +248,11 @@ func (pkg *LocalPackage) Save() error {
 	file.WriteString("pkg.repository: " +
 		yaml.EscapeString(pkg.Repo().Name()) + "\n")
 
+	file.WriteString("pkg.features:\n")
+	for _, f := range pkg.Viper.GetStringSlice("pkg.features") {
+		file.WriteString("    - " + f + "\n")
+	}
+
 	return nil
 }
 


Mime
View raw message