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 2017/04/07 19:36:02 UTC

[01/23] incubator-mynewt-newt git commit: MYNEWT-495: updates to sync command

Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/master 4e940c181 -> a895dc5cb


MYNEWT-495: updates to sync command

- When repo is already cloned, try to update from remote
- If -f is passed, create a modifications diff, and try harder
  to update current local (stash, clean, checkout, pull)


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

Branch: refs/heads/master
Commit: 0196ba5338aa5efdd8110eb1012e17104e435616
Parents: 7ecee8b
Author: Fabio Utzig <ut...@utzig.org>
Authored: Fri Mar 3 09:49:52 2017 -0300
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Mon Mar 6 09:42:46 2017 -0300

----------------------------------------------------------------------
 newt/cli/project_cmds.go                        |  23 ++-
 newt/downloader/downloader.go                   | 110 ++++++++++---
 newt/repo/repo.go                               | 157 +++++++++++++++++--
 newt/vendor/mynewt.apache.org/newt/util/util.go |   1 -
 4 files changed, 247 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0196ba53/newt/cli/project_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/project_cmds.go b/newt/cli/project_cmds.go
index a8d93b2..89a6eae 100644
--- a/newt/cli/project_cmds.go
+++ b/newt/cli/project_cmds.go
@@ -20,6 +20,7 @@
 package cli
 
 import (
+	"fmt"
 	"os"
 	"sort"
 	"strings"
@@ -156,26 +157,32 @@ func syncRunCmd(cmd *cobra.Command, args []string) {
 		NewtUsage(nil, err)
 	}
 
+	var failedRepos []string
 	for _, repo := range repos {
 		var exists bool
+		var updated bool
 		if repo.IsLocal() {
 			continue
 		}
 		vers := ps.GetInstalledVersion(repo.Name())
 		if vers == nil {
 			util.StatusMessage(util.VERBOSITY_DEFAULT,
-				"No installed version of %s found, skipping\n",
+				"No installed version of %s found, skipping\n\n",
 				repo.Name())
 		}
-		if err, exists = repo.Sync(vers, newtutil.NewtForce); err != nil {
-			NewtUsage(nil, err)
+		exists, updated, err = repo.Sync(vers, newtutil.NewtForce)
+		if exists && !updated {
+			failedRepos = append(failedRepos, repo.Name())
 		}
-
-		if exists && !newtutil.NewtForce {
-			util.StatusMessage(util.VERBOSITY_DEFAULT,
-				"Skipping resync of %s because directory exists.  To "+
-					"force resync, add the -f (force) option.\n", repo.Name())
+	}
+	if len(failedRepos) > 0 {
+		var forceMsg string
+		if !newtutil.NewtForce {
+			forceMsg = " To force resync, add the -f (force) option."
 		}
+		err = util.NewNewtError(fmt.Sprintf("Failed for repos: %v."+
+			forceMsg, failedRepos))
+		NewtUsage(nil, err)
 	}
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0196ba53/newt/downloader/downloader.go
----------------------------------------------------------------------
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index 0ab201e..e57ecfa 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -27,6 +27,7 @@ import (
 	"os"
 	"os/exec"
 	"path/filepath"
+	"strings"
 
 	log "github.com/Sirupsen/logrus"
 
@@ -39,6 +40,10 @@ type Downloader interface {
 	Branch() string
 	SetBranch(branch string)
 	DownloadRepo(branch string) (string, error)
+	CurrentBranch(path string) (string, error)
+	UpdateRepo(path string) error
+	CleanupRepo(path string, branchName string) error
+	LocalDiff(path string) ([]byte, error)
 }
 
 type GenericDownloader struct {
@@ -66,42 +71,57 @@ type LocalDownloader struct {
 	Path string
 }
 
-func checkout(repoDir string, commit string) error {
-	// Retrieve the current directory so that we can get back to where we
-	// started after the download completes.
-	pwd, err := os.Getwd()
+func executeGitCommand(dir string, cmd []string) ([]byte, error) {
+	wd, err := os.Getwd()
 	if err != nil {
-		return util.NewNewtError(err.Error())
+		return nil, util.NewNewtError(err.Error())
 	}
 
 	gitPath, err := exec.LookPath("git")
 	if err != nil {
-		return util.NewNewtError(fmt.Sprintf("Can't find git binary: %s\n",
+		return nil, util.NewNewtError(fmt.Sprintf("Can't find git binary: %s\n",
 			err.Error()))
 	}
 	gitPath = filepath.ToSlash(gitPath)
 
-	if err := os.Chdir(repoDir); err != nil {
-		return util.NewNewtError(err.Error())
+	if err := os.Chdir(dir); err != nil {
+		return nil, util.NewNewtError(err.Error())
 	}
 
-	// Checkout the specified commit.
+	defer os.Chdir(wd)
+
+	gitCmd := []string{gitPath}
+	gitCmd = append(gitCmd, cmd...)
+	output, err := util.ShellCommand(gitCmd, nil)
+	if err != nil {
+		return nil, err
+	}
+
+	return output, nil
+}
+
+func checkout(repoDir string, commit string) error {
 	cmd := []string{
-		gitPath,
 		"checkout",
 		commit,
 	}
+	_, err := executeGitCommand(repoDir, cmd)
+	return err
+}
 
-	if o, err := util.ShellCommand(cmd, nil); err != nil {
-		return util.NewNewtError(string(o))
-	}
+func pull(repoDir string) error {
+	_, err := executeGitCommand(repoDir, []string{"pull"})
+	return err
+}
 
-	// Go back to original directory.
-	if err := os.Chdir(pwd); err != nil {
-		return util.NewNewtError(err.Error())
-	}
+func stash(repoDir string) error {
+	_, err := executeGitCommand(repoDir, []string{"stash"})
+	return err
+}
 
-	return nil
+func clean(repoDir string) error {
+	_, err := executeGitCommand(repoDir, []string{"clean", "-f"})
+	return err
 }
 
 func (gd *GenericDownloader) Branch() string {
@@ -172,6 +192,39 @@ func (gd *GithubDownloader) FetchFile(name string, dest string) error {
 	return nil
 }
 
+func (gd *GithubDownloader) CurrentBranch(path string) (string, error) {
+	cmd := []string{"rev-parse", "--abbrev-ref", "HEAD"}
+	branch, err := executeGitCommand(path, cmd)
+	return strings.Trim(string(branch), "\r\n"), err
+}
+
+func (gd *GithubDownloader) UpdateRepo(path string) error {
+	return pull(path)
+}
+
+func (gd *GithubDownloader) CleanupRepo(path string, branchName string) error {
+	err := stash(path)
+	if err != nil {
+		return err
+	}
+
+	err = clean(path)
+	if err != nil {
+		return err
+	}
+
+	err = checkout(path, branchName)
+	if err != nil {
+		return err
+	}
+
+	return pull(path)
+}
+
+func (gd *GithubDownloader) LocalDiff(path string) ([]byte, error) {
+	return executeGitCommand(path, []string{"diff"})
+}
+
 func (gd *GithubDownloader) DownloadRepo(commit string) (string, error) {
 	// Get a temporary directory, and copy the repository into that directory.
 	tmpdir, err := ioutil.TempDir("", "newt-repo")
@@ -243,6 +296,27 @@ func (ld *LocalDownloader) FetchFile(name string, dest string) error {
 	return nil
 }
 
+func (ld *LocalDownloader) CurrentBranch(path string) (string, error) {
+	cmd := []string{"rev-parse", "--abbrev-ref", "HEAD"}
+	branch, err := executeGitCommand(path, cmd)
+	return strings.Trim(string(branch), "\r\n"), err
+}
+
+// NOTE: intentionally always error...
+func (ld *LocalDownloader) UpdateRepo(path string) error {
+	return util.NewNewtError(fmt.Sprintf("Can't pull from a local repo\n"))
+}
+
+func (ld *LocalDownloader) CleanupRepo(path string, branchName string) error {
+	os.RemoveAll(path)
+	_, err := ld.DownloadRepo(branchName)
+	return err
+}
+
+func (ld *LocalDownloader) LocalDiff(path string) ([]byte, error) {
+	return executeGitCommand(path, []string{"diff"})
+}
+
 func (ld *LocalDownloader) DownloadRepo(commit string) (string, error) {
 	// Get a temporary directory, and copy the repository into that directory.
 	tmpdir, err := ioutil.TempDir("", "newt-repo")

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0196ba53/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index a2331f7..a4a916f 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -25,6 +25,7 @@ import (
 	"os"
 	"path/filepath"
 	"strings"
+	"time"
 
 	log "github.com/Sirupsen/logrus"
 	"github.com/spf13/cast"
@@ -347,6 +348,11 @@ func (r *Repo) repoFilePath() string {
 		".configs/" + r.name + "/"
 }
 
+func (r *Repo) patchesFilePath() string {
+	return interfaces.GetProject().Path() + "/" + REPOS_DIR +
+		"/.patches/"
+}
+
 func (r *Repo) downloadRepo(branchName string) error {
 	dl := r.downloader
 
@@ -368,6 +374,66 @@ func (r *Repo) downloadRepo(branchName string) error {
 	return nil
 }
 
+func (r *Repo) checkExists() bool {
+	return util.NodeExist(r.Path())
+}
+
+func (r *Repo) updateRepo() error {
+	dl := r.downloader
+	err := dl.UpdateRepo(r.Path())
+	if err != nil {
+		return util.NewNewtError(fmt.Sprintf("\tError updating\n"))
+	}
+	return nil
+}
+
+func (r *Repo) cleanupRepo(branchName string) error {
+	dl := r.downloader
+	err := dl.CleanupRepo(r.Path(), branchName)
+	if err != nil {
+		return util.NewNewtError(fmt.Sprintf("\tError cleaning and updating\n"))
+	}
+	return nil
+}
+
+func (r *Repo) saveLocalDiff() (string, error) {
+	dl := r.downloader
+	diff, err := dl.LocalDiff(r.Path())
+	if err != nil {
+		return "", util.NewNewtError(fmt.Sprintf(
+			"Error creating diff for \"%s\" : %s", r.Name(), err.Error()))
+	}
+
+	// NOTE: date was not a typo: https://golang.org/pkg/time/#Time.Format
+	timenow := time.Now().Format("20060102_150405")
+	filename := r.patchesFilePath() + r.Name() + "_" + timenow + ".diff"
+
+	f, err := os.Create(filename)
+	if err != nil {
+		return "", util.NewNewtError(fmt.Sprintf(
+			"Error creating repo diff file \"%s\"", filename))
+	}
+	defer f.Close()
+
+	_, err = f.Write(diff)
+	if err != nil {
+		return "", util.NewNewtError(fmt.Sprintf(
+			"Error writing repo diff file \"%s\"", filename))
+	}
+
+	return filename, nil
+}
+
+func (r *Repo) currentBranch() (string, error) {
+	dl := r.downloader
+	branch, err := dl.CurrentBranch(r.Path())
+	if err != nil {
+		return "", util.NewNewtError(fmt.Sprintf("Error finding current branch for \"%s\" : %s",
+			r.Name(), err.Error()))
+	}
+	return branch, nil
+}
+
 func (r *Repo) checkForceInstall(force bool) (error, bool) {
 	// Copy the git repo into /repos/, error'ing out if the repo already exists
 	if util.NodeExist(r.Path()) {
@@ -407,33 +473,82 @@ func (r *Repo) Install(force bool) (*Version, error) {
 	return vers, nil
 }
 
-func (r *Repo) Sync(vers *Version, force bool) (error, bool) {
+func (r *Repo) Sync(vers *Version, force bool) (bool, bool, error) {
 	var exists bool
 	var err error
+	var currBranch string
 
-	if err, exists = r.checkForceInstall(force); err != nil {
-		return err, exists
-	}
-	if exists && !force {
-		return nil, exists
-	}
+	exists = r.checkExists()
 
 	// Update the repo description
 	if _, updated, err := r.UpdateDesc(); updated != true || err != nil {
-		return util.NewNewtError("Cannot update repository description."), exists
+		return exists, false, util.NewNewtError("Cannot update repository description.")
 	}
 
-	branchName, vers, found := r.rdesc.MatchVersion(vers)
+	branchName, _, found := r.rdesc.MatchVersion(vers)
 	if found == false {
-		return util.NewNewtError(fmt.Sprintf("Branch description for %s not found",
-			r.Name())), exists
+		return exists, false, util.NewNewtError(fmt.Sprintf(
+			"Branch description for %s not found", r.Name()))
 	}
 
-	if err := r.downloadRepo(branchName); err != nil {
-		return err, exists
+	if exists {
+		// Here assuming that if the branch was changed by the user,
+		// the user must know what he's doing...
+		// but, if -f is passed let's just save the work and re-clone
+		currBranch, err = r.currentBranch()
+		if err != nil {
+			return exists, false, err
+		} else if currBranch != branchName {
+			msg := "Unexpected local branch for %s: \"%s\" != \"%s\""
+			if force {
+				util.StatusMessage(util.VERBOSITY_VERBOSE,
+					msg, r.rdesc.name, currBranch, branchName)
+			} else {
+				err = util.NewNewtError(
+					fmt.Sprintf(msg, r.rdesc.name, currBranch, branchName))
+				return exists, false, err
+			}
+		}
+
+		// Don't try updating if on an invalid branch...
+		if currBranch == branchName {
+			util.StatusMessage(util.VERBOSITY_VERBOSE, "\tTrying to update repository... ")
+			err = r.updateRepo()
+			if err == nil {
+				util.StatusMessage(util.VERBOSITY_VERBOSE, " success!\n")
+				return exists, true, err
+			} else {
+				util.StatusMessage(util.VERBOSITY_VERBOSE, " failed!\n")
+				if !force {
+					return exists, false, err
+				}
+			}
+		}
+
+		filename, err := r.saveLocalDiff()
+		if err != nil {
+			return exists, false, err
+		}
+		wd, _ := os.Getwd()
+		filename, _ = filepath.Rel(wd, filename)
+
+		util.StatusMessage(util.VERBOSITY_DEFAULT, "Saved local diff: "+
+			"\"%s\"\n", filename)
+
+		err = r.cleanupRepo(branchName)
+		if err != nil {
+			return exists, false, err
+		}
+
+	} else {
+		// fresh or updating was unsuccessfull and force was given...
+		err = r.downloadRepo(branchName)
+		if err != nil {
+			return exists, false, err
+		}
 	}
 
-	return nil, exists
+	return exists, true, nil
 }
 
 func (r *Repo) UpdateDesc() ([]*Repo, bool, error) {
@@ -443,7 +558,7 @@ func (r *Repo) UpdateDesc() ([]*Repo, bool, error) {
 		return nil, false, nil
 	}
 
-	util.StatusMessage(util.VERBOSITY_DEFAULT, "%s\n", r.Name())
+	util.StatusMessage(util.VERBOSITY_VERBOSE, "[%s]:\n", r.Name())
 
 	if err = r.DownloadDesc(); err != nil {
 		return nil, false, err
@@ -463,8 +578,8 @@ func (r *Repo) UpdateDesc() ([]*Repo, bool, error) {
 func (r *Repo) DownloadDesc() error {
 	dl := r.downloader
 
-	util.StatusMessage(util.VERBOSITY_VERBOSE, "Downloading "+
-		"repository description for %s...\n", r.Name())
+	util.StatusMessage(util.VERBOSITY_VERBOSE, "\tDownloading "+
+		"repository description... ")
 
 	// Configuration path
 	cpath := r.repoFilePath()
@@ -481,6 +596,14 @@ func (r *Repo) DownloadDesc() error {
 		return err
 	}
 
+	// also create a directory to save diffs for sync
+	cpath = r.patchesFilePath()
+	if util.NodeNotExist(cpath) {
+		if err := os.MkdirAll(cpath, REPO_DEFAULT_PERMS); err != nil {
+			return util.NewNewtError(err.Error())
+		}
+	}
+
 	util.StatusMessage(util.VERBOSITY_VERBOSE, " success!\n")
 
 	return nil

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0196ba53/newt/vendor/mynewt.apache.org/newt/util/util.go
----------------------------------------------------------------------
diff --git a/newt/vendor/mynewt.apache.org/newt/util/util.go b/newt/vendor/mynewt.apache.org/newt/util/util.go
index fa3e60f..083ee9c 100644
--- a/newt/vendor/mynewt.apache.org/newt/util/util.go
+++ b/newt/vendor/mynewt.apache.org/newt/util/util.go
@@ -300,7 +300,6 @@ func ShellCommandLimitDbgOutput(
 	}
 
 	o, err := cmd.CombinedOutput()
-
 	if maxDbgOutputChrs < 0 || len(o) <= maxDbgOutputChrs {
 		dbgStr := string(o)
 		log.Debugf("o=%s", dbgStr)


[15/23] incubator-mynewt-newt git commit: MYNEWT-660 newt - Quotes get stripped from syscfg

Posted by cc...@apache.org.
MYNEWT-660 newt - Quotes get stripped from syscfg


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

Branch: refs/heads/master
Commit: f753f2bbaa7cb02a8ecd1c3200d3df05fa22fb1d
Parents: 0f9e3f7
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Mar 15 14:23:59 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Mar 15 14:23:59 2017 -0700

----------------------------------------------------------------------
 newt/pkg/localpackage.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f753f2bb/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 3ce55e6..7a6beb4 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -249,7 +249,7 @@ func (lpkg *LocalPackage) SaveSyscfgVals() error {
 	fmt.Fprintf(file, "\n")
 	fmt.Fprintf(file, "syscfg.vals:\n")
 	for _, name := range names {
-		fmt.Fprintf(file, "    %s: %s\n", name, syscfgVals[name])
+		fmt.Fprintf(file, "    %s: %s\n", name, yaml.EscapeString(syscfgVals[name]))
 	}
 
 	return nil


[05/23] incubator-mynewt-newt git commit: MYNEWT-655 newt - Detect repo/newt ver incompat.

Posted by cc...@apache.org.
MYNEWT-655 newt - Detect repo/newt ver incompat.

This is done with a separate map "repo.newt_compatibility" in the repo's
repository.yml file.

Example:

repo.newt_compatibility:
    1.0.0:
        1.1.0: error
        1.0.0: good
        0.9.99: warn
        0.9.9: error

This says that this version 1.0.0 of this repo is compatible with newt
versions [1.0.0, 1.1.0). Newt versions in the range [0.9.99, 1.0.0)
elicit a warning message. All other newt versions generate an error.


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

Branch: refs/heads/master
Commit: f264e6767fbfd26ff24f31b55e63fd8b189daa9f
Parents: 1fb9697
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Mar 7 12:11:12 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Mar 7 12:22:06 2017 -0800

----------------------------------------------------------------------
 newt/newtutil/newtutil.go |  71 ++++++++---
 newt/project/project.go   |  18 +++
 newt/repo/compat.go       | 284 +++++++++++++++++++++++++++++++++++++++++
 newt/repo/repo.go         | 114 +++++------------
 newt/repo/version.go      |   9 ++
 5 files changed, 397 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f264e676/newt/newtutil/newtutil.go
----------------------------------------------------------------------
diff --git a/newt/newtutil/newtutil.go b/newt/newtutil/newtutil.go
index 48ef4a0..98307ec 100644
--- a/newt/newtutil/newtutil.go
+++ b/newt/newtutil/newtutil.go
@@ -34,6 +34,7 @@ import (
 	"mynewt.apache.org/newt/viper"
 )
 
+var NewtVersion Version = Version{1, 0, 0}
 var NewtVersionStr string = "Apache Newt (incubating) version: 1.0.0-dev"
 var NewtBlinkyTag string = "develop"
 var NewtNumJobs int
@@ -45,27 +46,59 @@ const REPOS_FILENAME string = "repos.yml"
 const CORE_REPO_NAME string = "apache-mynewt-core"
 const ARDUINO_ZERO_REPO_NAME string = "mynewt_arduino_zero"
 
-type RepoCommitEntry struct {
-	Version     string
-	Hash        string
-	Description string
+type Version struct {
+	Major    int64
+	Minor    int64
+	Revision int64
 }
 
-// A warning is displayed if newt requires a newer version of a repo.
-var RepoMinCommits = map[string]*RepoCommitEntry{
-	// Newt no longer cd's to a source directory when it compiles its contents.
-	// Consequently, package include flags need to be relative to the project
-	// directory, not the package source directory.
-	CORE_REPO_NAME: &RepoCommitEntry{
-		Version:     "develop",
-		Hash:        "cd99344df197d5b9e372b93142184a39ec078f69",
-		Description: "Include paths now relative to project base.",
-	},
-	ARDUINO_ZERO_REPO_NAME: &RepoCommitEntry{
-		Version:     "develop",
-		Hash:        "a6348961fef56dbfe09a1b9418d3add3ad22eaf2",
-		Description: "Include paths now relative to project base.",
-	},
+func ParseVersion(s string) (Version, error) {
+	v := Version{}
+	parseErr := util.FmtNewtError("Invalid version string: %s", s)
+
+	parts := strings.Split(s, ".")
+	if len(parts) != 3 {
+		return v, parseErr
+	}
+
+	var err error
+
+	v.Major, err = strconv.ParseInt(parts[0], 10, 64)
+	if err != nil {
+		return v, parseErr
+	}
+
+	v.Minor, err = strconv.ParseInt(parts[1], 10, 64)
+	if err != nil {
+		return v, parseErr
+	}
+
+	v.Revision, err = strconv.ParseInt(parts[2], 10, 64)
+	if err != nil {
+		return v, parseErr
+	}
+
+	return v, nil
+}
+
+func (v *Version) String() string {
+	return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Revision)
+}
+
+func VerCmp(v1 Version, v2 Version) int64 {
+	if r := v1.Major - v2.Major; r != 0 {
+		return r
+	}
+
+	if r := v1.Minor - v2.Minor; r != 0 {
+		return r
+	}
+
+	if r := v1.Revision - v2.Revision; r != 0 {
+		return r
+	}
+
+	return 0
 }
 
 // Contains general newt settings read from $HOME/.newt

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f264e676/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index cc68c30..bf4b00e 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -416,6 +416,24 @@ func (proj *Project) loadRepo(rname string, v *viper.Viper) error {
 
 	proj.localRepo.AddDependency(rd)
 
+	// Read the repo's descriptor file so that we have its newt version
+	// compatibility map.
+	_, _, err = r.ReadDesc()
+	if err != nil {
+		return util.FmtNewtError("Failed to read repo descriptor; %s",
+			err.Error())
+	}
+
+	rvers := proj.projState.GetInstalledVersion(rname)
+	code, msg := r.CheckNewtCompatibility(rvers, newtutil.NewtVersion)
+	switch code {
+	case repo.NEWT_COMPAT_GOOD:
+	case repo.NEWT_COMPAT_WARN:
+		util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s.\n", msg)
+	case repo.NEWT_COMPAT_ERROR:
+		return util.NewNewtError(msg)
+	}
+
 	log.Debugf("Loaded repository %s (type: %s, user: %s, repo: %s)", rname,
 		repoVars["type"], repoVars["user"], repoVars["repo"])
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f264e676/newt/repo/compat.go
----------------------------------------------------------------------
diff --git a/newt/repo/compat.go b/newt/repo/compat.go
new file mode 100644
index 0000000..cd9fc82
--- /dev/null
+++ b/newt/repo/compat.go
@@ -0,0 +1,284 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package repo
+
+import (
+	"fmt"
+	"math"
+	"sort"
+
+	"github.com/spf13/cast"
+
+	"mynewt.apache.org/newt/newt/newtutil"
+	"mynewt.apache.org/newt/util"
+	"mynewt.apache.org/newt/viper"
+)
+
+type NewtCompatCode int
+
+const (
+	NEWT_COMPAT_GOOD NewtCompatCode = iota
+	NEWT_COMPAT_WARN
+	NEWT_COMPAT_ERROR
+)
+
+var NewtCompatCodeNames = map[NewtCompatCode]string{
+	NEWT_COMPAT_GOOD:  "good",
+	NEWT_COMPAT_WARN:  "warn",
+	NEWT_COMPAT_ERROR: "error",
+}
+
+type NewtCompatEntry struct {
+	code       NewtCompatCode
+	minNewtVer newtutil.Version
+}
+
+type NewtCompatTable struct {
+	// Sorted in ascending order by newt version number.
+	entries []NewtCompatEntry
+}
+
+type NewtCompatMap struct {
+	verTableMap map[newtutil.Version]NewtCompatTable
+}
+
+func newNewtCompatMap() *NewtCompatMap {
+	return &NewtCompatMap{
+		verTableMap: map[newtutil.Version]NewtCompatTable{},
+	}
+}
+
+func newtCompatCodeToString(code NewtCompatCode) string {
+	return NewtCompatCodeNames[code]
+}
+
+func newtCompatCodeFromString(codeStr string) (NewtCompatCode, error) {
+	for c, s := range NewtCompatCodeNames {
+		if codeStr == s {
+			return c, nil
+		}
+	}
+
+	return NewtCompatCode(0),
+		util.FmtNewtError("Invalid newt compatibility code: %s", codeStr)
+}
+
+func parseNcEntry(verStr string, codeStr string) (NewtCompatEntry, error) {
+	entry := NewtCompatEntry{}
+	var err error
+
+	entry.minNewtVer, err = newtutil.ParseVersion(verStr)
+	if err != nil {
+		return entry, err
+	}
+
+	entry.code, err = newtCompatCodeFromString(codeStr)
+	if err != nil {
+		return entry, err
+	}
+
+	return entry, nil
+}
+
+func parseNcTable(strMap map[string]string) (NewtCompatTable, error) {
+	tbl := NewtCompatTable{}
+
+	for c, v := range strMap {
+		entry, err := parseNcEntry(c, v)
+		if err != nil {
+			return tbl, err
+		}
+
+		tbl.entries = append(tbl.entries, entry)
+	}
+
+	sortEntries(tbl.entries)
+
+	return tbl, nil
+}
+
+func readNcMap(v *viper.Viper) (*NewtCompatMap, error) {
+	mp := newNewtCompatMap()
+	ncMap := v.GetStringMap("repo.newt_compatibility")
+
+	for k, v := range ncMap {
+		repoVer, err := newtutil.ParseVersion(k)
+		if err != nil {
+			return nil, util.FmtNewtError("Newt compatibility table contains " +
+				"invalid repo version \"%s\"")
+		}
+
+		if _, ok := mp.verTableMap[repoVer]; ok {
+			return nil, util.FmtNewtError("Newt compatibility table contains "+
+				"duplicate version specifier: %s", repoVer.String())
+		}
+
+		strMap := cast.ToStringMapString(v)
+		tbl, err := parseNcTable(strMap)
+		if err != nil {
+			return nil, err
+		}
+
+		mp.verTableMap[repoVer] = tbl
+	}
+
+	return mp, nil
+}
+
+func (tbl *NewtCompatTable) matchIdx(newtVer newtutil.Version) int {
+	// Iterate the table backwards.  The first entry whose version is less than
+	// or equal to the specified version is the match.
+	for i := 0; i < len(tbl.entries); i++ {
+		idx := len(tbl.entries) - i - 1
+		entry := &tbl.entries[idx]
+		cmp := newtutil.VerCmp(entry.minNewtVer, newtVer)
+		if cmp <= 0 {
+			return idx
+		}
+	}
+
+	return -1
+}
+
+func (tbl *NewtCompatTable) newIdxRange(i int, j int) []int {
+	if i >= len(tbl.entries) {
+		return []int{j, i}
+	}
+
+	if j >= len(tbl.entries) {
+		return []int{i, j}
+	}
+
+	e1 := tbl.entries[i]
+	e2 := tbl.entries[j]
+
+	if newtutil.VerCmp(e1.minNewtVer, e2.minNewtVer) < 0 {
+		return []int{i, j}
+	} else {
+		return []int{j, i}
+	}
+}
+
+func (tbl *NewtCompatTable) idxRangesWithCode(c NewtCompatCode) [][]int {
+	ranges := [][]int{}
+
+	curi := -1
+	for i, e := range tbl.entries {
+		if curi == -1 {
+			if e.code == c {
+				curi = i
+			}
+		} else {
+			if e.code != c {
+				ranges = append(ranges, tbl.newIdxRange(curi, i))
+				curi = -1
+			}
+		}
+	}
+
+	if curi != -1 {
+		ranges = append(ranges, tbl.newIdxRange(curi, len(tbl.entries)))
+	}
+	return ranges
+}
+
+func (tbl *NewtCompatTable) minMaxTgtVers(goodRange []int) (
+	newtutil.Version, newtutil.Version, newtutil.Version) {
+
+	minVer := tbl.entries[goodRange[0]].minNewtVer
+
+	var maxVer newtutil.Version
+	if goodRange[1] < len(tbl.entries) {
+		maxVer = tbl.entries[goodRange[1]].minNewtVer
+	} else {
+		maxVer = newtutil.Version{math.MaxInt64, math.MaxInt64, math.MaxInt64}
+	}
+
+	targetVer := tbl.entries[goodRange[1]-1].minNewtVer
+
+	return minVer, maxVer, targetVer
+}
+
+// @return NewtCompatCode       The severity of the newt incompatibility
+//         string               The warning or error message to display in case
+//                                  of incompatibility.
+func (tbl *NewtCompatTable) CheckNewtVer(
+	newtVer newtutil.Version) (NewtCompatCode, string) {
+
+	var code NewtCompatCode
+	idx := tbl.matchIdx(newtVer)
+	if idx == -1 {
+		// This version of newt is older than every entry in the table.
+		code = NEWT_COMPAT_ERROR
+	} else {
+		code = tbl.entries[idx].code
+		if code == NEWT_COMPAT_GOOD {
+			return NEWT_COMPAT_GOOD, ""
+		}
+	}
+
+	goodRanges := tbl.idxRangesWithCode(NEWT_COMPAT_GOOD)
+	for i := 0; i < len(goodRanges); i++ {
+		minVer, maxVer, tgtVer := tbl.minMaxTgtVers(goodRanges[i])
+
+		if newtutil.VerCmp(newtVer, minVer) < 0 {
+			return code, fmt.Sprintf("Please upgrade your newt tool to "+
+				"version %s", tgtVer.String())
+		}
+
+		if newtutil.VerCmp(newtVer, maxVer) >= 0 {
+			return code, "Please upgrade your repos with \"newt upgrade\""
+		}
+	}
+
+	return code, ""
+}
+
+type entrySorter struct {
+	entries []NewtCompatEntry
+}
+
+func (s entrySorter) Len() int {
+	return len(s.entries)
+}
+func (s entrySorter) Swap(i, j int) {
+	s.entries[i], s.entries[j] = s.entries[j], s.entries[i]
+}
+func (s entrySorter) Less(i, j int) bool {
+	e1 := s.entries[i]
+	e2 := s.entries[j]
+
+	cmp := newtutil.VerCmp(e1.minNewtVer, e2.minNewtVer)
+	if cmp < 0 {
+		return true
+	} else if cmp > 0 {
+		return false
+	}
+
+	return false
+}
+
+func sortEntries(entries []NewtCompatEntry) {
+	sorter := entrySorter{
+		entries: entries,
+	}
+
+	sort.Sort(sorter)
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f264e676/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index a2331f7..a534ea3 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -52,10 +52,7 @@ type Repo struct {
 	ignDirs    []string
 	updated    bool
 	local      bool
-
-	// The minimim git commit the repo must have to interoperate with this
-	// version of newt.
-	minCommit *newtutil.RepoCommitEntry
+	ncMap      *NewtCompatMap
 }
 
 type RepoDesc struct {
@@ -475,8 +472,8 @@ func (r *Repo) DownloadDesc() error {
 	}
 
 	dl.SetBranch("master")
-	if err := dl.FetchFile("repository.yml",
-		cpath+"/"+"repository.yml"); err != nil {
+	if err := dl.FetchFile(REPO_FILE_NAME,
+		cpath+"/"+REPO_FILE_NAME); err != nil {
 		util.StatusMessage(util.VERBOSITY_VERBOSE, " failed\n")
 		return err
 	}
@@ -553,60 +550,13 @@ func (r *Repo) ReadDesc() (*RepoDesc, []*Repo, error) {
 		return nil, nil, err
 	}
 
-	return rdesc, repos, nil
-}
-
-// Checks if the specified repo is compatible with this version of newt.  This
-// function only verifies that the repo is new enough; it doesn't check that
-// newt is new enough.
-func (r *Repo) HasMinCommit() (bool, error) {
-	if r.minCommit == nil {
-		return true, nil
-	}
-
-	// Change back to the initial directory when this function returns.
-	cwd, err := os.Getwd()
-	if err != nil {
-		return false, util.ChildNewtError(err)
-	}
-	defer os.Chdir(cwd)
-
-	if err := os.Chdir(r.localPath); err != nil {
-		return false, util.ChildNewtError(err)
-	}
-
-	cmd := []string{
-		"git",
-		"merge-base",
-		r.minCommit.Hash,
-		"HEAD",
-	}
-	mergeBase, err := util.ShellCommand(cmd, nil)
-	if err != nil {
-		if strings.Contains(err.Error(), "Not a valid commit name") {
-			return false, nil
-		} else {
-			return false, util.ChildNewtError(err)
-		}
-	}
-	if len(mergeBase) == 0 {
-		// No output means the commit does not exist in the current branch.
-		return false, nil
-	}
-
-	cmd = []string{
-		"git",
-		"rev-parse",
-		"--verify",
-		r.minCommit.Hash,
-	}
-	revParse, err := util.ShellCommand(cmd, nil)
+	// Read the newt version compatibility map.
+	r.ncMap, err = readNcMap(v)
 	if err != nil {
-		return false, util.ChildNewtError(err)
+		return nil, nil, err
 	}
 
-	// The commit exists in HEAD if the two commands produced identical output.
-	return string(mergeBase) == string(revParse), nil
+	return rdesc, repos, nil
 }
 
 func (r *Repo) Init(repoName string, rversreq string, d downloader.Downloader) error {
@@ -626,38 +576,41 @@ func (r *Repo) Init(repoName string, rversreq string, d downloader.Downloader) e
 		r.localPath = filepath.ToSlash(filepath.Clean(path))
 	} else {
 		r.localPath = filepath.ToSlash(filepath.Clean(path + "/" + REPOS_DIR + "/" + r.name))
-		r.minCommit = newtutil.RepoMinCommits[repoName]
+	}
 
-		upToDate, err := r.HasMinCommit()
-		if err != nil {
-			// If there is an error checking the repo's commit log, just abort
-			// the check.  An error could have many possible causes: repo not
-			// installed, network issue, etc.  In none of these cases does it
-			// makes sense to warn about an out of date repo.  If the issue is
-			// a real one, it will be handled when it prevents forward
-			// progress.
-			return nil
-		}
+	return nil
+}
 
-		if !upToDate {
-			util.ErrorMessage(util.VERBOSITY_QUIET,
-				"Warning: repo \"%s\" is out of date for this version of "+
-					"newt.  Please upgrade the repo to meet these "+
-					"requirements:\n"+
-					"    * Version: %s\n"+
-					"    * Commit: %s\n"+
-					"    * Change: %s\n",
-				r.name, r.minCommit.Version, r.minCommit.Hash,
-				r.minCommit.Description)
-		}
+func (r *Repo) CheckNewtCompatibility(rvers *Version, nvers newtutil.Version) (
+	NewtCompatCode, string) {
+
+	// If this repo doesn't have a newt compatibility map, just assume there is
+	// no incompatibility.
+	if len(r.ncMap.verTableMap) == 0 {
+		return NEWT_COMPAT_GOOD, ""
 	}
 
-	return nil
+	rnuver := rvers.ToNuVersion()
+	tbl, ok := r.ncMap.verTableMap[rnuver]
+	if !ok {
+		// Unknown repo version.
+		return NEWT_COMPAT_WARN, "Repo version missing from compatibility map"
+	}
+
+	code, text := tbl.CheckNewtVer(nvers)
+	if code == NEWT_COMPAT_GOOD {
+		return code, text
+	}
+
+	return code, fmt.Sprintf("This version of newt (%s) is incompatible with "+
+		"your version of the %s repo (%s); %s",
+		nvers.String(), r.name, rnuver.String(), text)
 }
 
 func NewRepo(repoName string, rversreq string, d downloader.Downloader) (*Repo, error) {
 	r := &Repo{
 		local: false,
+		ncMap: newNewtCompatMap(),
 	}
 
 	if err := r.Init(repoName, rversreq, d); err != nil {
@@ -670,6 +623,7 @@ func NewRepo(repoName string, rversreq string, d downloader.Downloader) (*Repo,
 func NewLocalRepo(repoName string) (*Repo, error) {
 	r := &Repo{
 		local: true,
+		ncMap: newNewtCompatMap(),
 	}
 
 	if err := r.Init(repoName, "", nil); err != nil {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f264e676/newt/repo/version.go
----------------------------------------------------------------------
diff --git a/newt/repo/version.go b/newt/repo/version.go
index ce81ef2..bbf5b56 100644
--- a/newt/repo/version.go
+++ b/newt/repo/version.go
@@ -26,6 +26,7 @@ import (
 	"strings"
 
 	"mynewt.apache.org/newt/newt/interfaces"
+	"mynewt.apache.org/newt/newt/newtutil"
 	"mynewt.apache.org/newt/util"
 )
 
@@ -137,6 +138,14 @@ func (vers *Version) String() string {
 	return fmt.Sprintf(VERSION_FORMAT, vers.Major(), vers.Minor(), vers.Revision(), vers.Stability())
 }
 
+func (vers *Version) ToNuVersion() newtutil.Version {
+	return newtutil.Version{
+		Major:    vers.major,
+		Minor:    vers.minor,
+		Revision: vers.revision,
+	}
+}
+
 func LoadVersion(versStr string) (*Version, error) {
 	var err error
 


[20/23] incubator-mynewt-newt git commit: unixchild - prevent half-started state

Posted by cc...@apache.org.
unixchild - prevent half-started state

This fix consists of two parts:

1. Remove thread-safety where it is not necessary.  There weren't any
bugs here, but it was complicating the code needlessly.

2. Don't automatically restart the child process when it terminates.  It
is up to the client to do this.


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

Branch: refs/heads/master
Commit: 1a0a9ef725ab6ce5ba41855f4b681deae61f952c
Parents: df67437
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Mar 31 16:42:41 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Mar 31 16:42:41 2017 -0700

----------------------------------------------------------------------
 util/unixchild/unixchild.go | 128 ++++++++++++---------------------------
 1 file changed, 39 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1a0a9ef7/util/unixchild/unixchild.go
----------------------------------------------------------------------
diff --git a/util/unixchild/unixchild.go b/util/unixchild/unixchild.go
index b8be35d..b417187 100644
--- a/util/unixchild/unixchild.go
+++ b/util/unixchild/unixchild.go
@@ -60,14 +60,12 @@ type Config struct {
 	Depth         int
 	MaxMsgSz      int
 	AcceptTimeout time.Duration
-	Restart       bool
 }
 
 type clientState uint32
 
 const (
 	CLIENT_STATE_STOPPED clientState = iota
-	CLIENT_STATE_STARTING
 	CLIENT_STATE_STARTED
 	CLIENT_STATE_STOPPING
 )
@@ -81,11 +79,9 @@ type Client struct {
 	childArgs     []string
 	maxMsgSz      int
 	acceptTimeout time.Duration
-	restart       bool
 	stop          chan bool
 	stopped       chan bool
 	state         clientState
-	stateMutex    sync.Mutex
 }
 
 func New(conf Config) *Client {
@@ -98,7 +94,6 @@ func New(conf Config) *Client {
 		ToChild:       make(chan []byte, conf.Depth),
 		ErrChild:      make(chan error),
 		acceptTimeout: conf.AcceptTimeout,
-		restart:       conf.Restart,
 		stop:          make(chan bool),
 		stopped:       make(chan bool),
 	}
@@ -110,42 +105,6 @@ func New(conf Config) *Client {
 	return c
 }
 
-func (c *Client) getState() clientState {
-	c.stateMutex.Lock()
-	defer c.stateMutex.Unlock()
-
-	return c.state
-}
-
-func (c *Client) setState(toState clientState) {
-	c.stateMutex.Lock()
-	defer c.stateMutex.Unlock()
-
-	c.state = toState
-}
-
-func (c *Client) setStateIf(toState clientState,
-	pred func(st clientState) bool) (bool, clientState) {
-
-	c.stateMutex.Lock()
-	defer c.stateMutex.Unlock()
-
-	if pred(c.state) {
-		c.state = toState
-		return true, toState
-	}
-
-	return false, c.state
-
-}
-
-func (c *Client) setStateFrom(fromState clientState,
-	toState clientState) (bool, clientState) {
-
-	return c.setStateIf(toState,
-		func(st clientState) bool { return st == fromState })
-}
-
 func (c *Client) startChild() (*exec.Cmd, error) {
 	subProcess := exec.Command(c.childPath, c.childArgs...)
 
@@ -249,20 +208,18 @@ func (c *Client) handleChild(con net.Conn) {
 }
 
 func (c *Client) Stop() {
-	ok, _ := c.setStateIf(CLIENT_STATE_STOPPING,
-		func(st clientState) bool {
-			return st != CLIENT_STATE_STOPPING
-		})
-	if !ok {
+	if c.state != CLIENT_STATE_STARTED {
 		return
 	}
 
+	c.state = CLIENT_STATE_STOPPING
 	log.Debugf("Stopping client")
 
 	c.stop <- true
 
 	select {
 	case <-c.stopped:
+		c.state = CLIENT_STATE_STOPPED
 		log.Debugf("Stopped client")
 		return
 	}
@@ -277,63 +234,56 @@ func (c *Client) acceptDeadline() *time.Time {
 	return &t
 }
 
+func (c *Client) deleteSocket() {
+	log.Debugf("deleting socket")
+	os.Remove(c.sockPath)
+}
+
 func (c *Client) Start() error {
-	ok, state := c.setStateFrom(CLIENT_STATE_STOPPED, CLIENT_STATE_STARTING)
-	if !ok {
-		return fmt.Errorf("client in invalid state for stating: %d", state)
+	if c.state != CLIENT_STATE_STOPPED {
+		return fmt.Errorf("Attempt to start unixchild twice")
 	}
 
 	l, err := net.Listen("unix", c.sockPath)
 	if err != nil {
-		c.setState(CLIENT_STATE_STOPPED)
 		return err
 	}
 
-	var cmd *exec.Cmd
+	cmd, err := c.startChild()
+	if err != nil {
+		err = fmt.Errorf("unixchild start error: %s", err.Error())
+		log.Debugf("%s", err.Error())
+		c.deleteSocket()
+		return err
+	}
+
+	if t := c.acceptDeadline(); t != nil {
+		l.(*net.UnixListener).SetDeadline(*t)
+	}
+	fd, err := l.Accept()
+	if err != nil {
+		err = NewUcAcceptError(fmt.Sprintf("unixchild accept error: %s",
+			err.Error()))
+		c.deleteSocket()
+		return err
+	}
+
+	c.state = CLIENT_STATE_STARTED
 
 	go func() {
-		for {
-			var err error
-			cmd, err = c.startChild()
-			if err != nil {
-				log.Debugf("unixchild start error: %s", err.Error())
-				c.ErrChild <- fmt.Errorf("Child start error: %s", err.Error())
-			} else {
-				if t := c.acceptDeadline(); t != nil {
-					l.(*net.UnixListener).SetDeadline(*t)
-				}
-				fd, err := l.Accept()
-				if err != nil {
-					text := fmt.Sprintf("unixchild accept error: %s",
-						err.Error())
-					c.ErrChild <- NewUcAcceptError(text)
-				} else {
-					c.setState(CLIENT_STATE_STARTED)
-					c.handleChild(fd)
-					c.ErrChild <- fmt.Errorf("Child exited")
-				}
-			}
-			if c.getState() == CLIENT_STATE_STOPPING {
-				log.Debugf("unixchild exit loop")
-				return
-			}
-			time.Sleep(time.Second)
-		}
+		c.handleChild(fd)
+		c.Stop()
+		c.ErrChild <- fmt.Errorf("child process terminated")
 	}()
 
 	go func() {
-		select {
-		case <-c.stop:
-			if c.getState() == CLIENT_STATE_STARTED {
-				l.Close()
-			}
-			if cmd != nil {
-				cmd.Process.Kill()
-			}
-			log.Debugf("deleting socket")
-			os.Remove(c.sockPath)
-			c.stopped <- true
+		<-c.stop
+		l.Close()
+		if cmd != nil {
+			cmd.Process.Kill()
 		}
+		c.deleteSocket()
+		c.stopped <- true
 	}()
 
 	return nil


[16/23] incubator-mynewt-newt git commit: MYNEWT-674 newt - Remove use of new io.SeekCurrent

Posted by cc...@apache.org.
MYNEWT-674 newt - Remove use of new io.SeekCurrent

This constant was added in go 1.7. A lot of package manager repos only
carry go 1.6, so the use of this constant makes newt unbuildable for a
lot of users.


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

Branch: refs/heads/master
Commit: eee86aafbd9932dd80ba84d4f2ecfc4179b0ca8c
Parents: f753f2b
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Mar 16 08:47:33 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Mar 16 08:47:47 2017 -0700

----------------------------------------------------------------------
 newt/image/image.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/eee86aaf/newt/image/image.go
----------------------------------------------------------------------
diff --git a/newt/image/image.go b/newt/image/image.go
index dd09b16..8e33273 100644
--- a/newt/image/image.go
+++ b/newt/image/image.go
@@ -611,7 +611,8 @@ func (image *Image) Generate(loader *Image) error {
 		"Computed Hash for image %s as %s \n",
 		image.TargetImg, hex.EncodeToString(image.Hash))
 
-	sz, err := imgFile.Seek(0, io.SeekCurrent)
+	// XXX: Replace "1" with io.SeekCurrent when go 1.7 becomes mainstream.
+	sz, err := imgFile.Seek(0, 1)
 	if err != nil {
 		return util.FmtNewtError("Failed to calculate file size of generated "+
 			"image %s: %s", image.TargetImg, err.Error())


[08/23] incubator-mynewt-newt git commit: MYNEWT-655 newt - Detect newt version incompat.

Posted by cc...@apache.org.
MYNEWT-655 newt - Detect newt version incompat.

Correctly handle case where project imposes no newt version
restrictions.


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

Branch: refs/heads/master
Commit: cd6aa05ad717f1cf1b3e13c04cb46795c8123e20
Parents: b1ecb9f
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Mar 7 14:03:48 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Mar 7 14:03:48 2017 -0800

----------------------------------------------------------------------
 newt/project/project.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/cd6aa05a/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index 6778c8b..42015bb 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -443,7 +443,7 @@ func (proj *Project) checkNewtVer() error {
 	compatSms := proj.v.GetStringMapString("project.newt_compatibility")
 	// If this project doesn't have a newt compatibility map, just assume there
 	// is no incompatibility.
-	if compatSms == nil {
+	if len(compatSms) == 0 {
 		return nil
 	}
 


[21/23] incubator-mynewt-newt git commit: Add PrintStacks util function.

Posted by cc...@apache.org.
Add PrintStacks util function.


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

Branch: refs/heads/master
Commit: 74d851283af3c31e79cd6f0432c0aa02d93c13f5
Parents: 1a0a9ef
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Mar 31 17:07:54 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Mar 31 17:07:54 2017 -0700

----------------------------------------------------------------------
 util/util.go | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/74d85128/util/util.go
----------------------------------------------------------------------
diff --git a/util/util.go b/util/util.go
index fa3e60f..3e144e6 100644
--- a/util/util.go
+++ b/util/util.go
@@ -620,3 +620,9 @@ func IntMin(a, b int) int {
 		return b
 	}
 }
+
+func PrintStacks() {
+	buf := make([]byte, 1024*1024)
+	stacklen := runtime.Stack(buf, true)
+	fmt.Printf("*** goroutine dump\n%s\n*** end\n", buf[:stacklen])
+}


[04/23] incubator-mynewt-newt git commit: Warns on unmatched pkg.name and pkg.path

Posted by cc...@apache.org.
Warns on unmatched pkg.name and pkg.path

Add a warning (in verbose mode, -v) if the pkg.name doesn't match the path.


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

Branch: refs/heads/master
Commit: 1193eccf6c89dec384d0578c19e968f351ff853e
Parents: 1fb9697
Author: Fabio Utzig <ut...@utzig.org>
Authored: Tue Mar 7 16:48:43 2017 -0300
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Tue Mar 7 16:52:51 2017 -0300

----------------------------------------------------------------------
 newt/interfaces/interfaces.go |  1 +
 newt/pkg/package.go           |  2 ++
 newt/project/project.go       | 27 +++++++++++++++++++++++++++
 3 files changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1193eccf/newt/interfaces/interfaces.go
----------------------------------------------------------------------
diff --git a/newt/interfaces/interfaces.go b/newt/interfaces/interfaces.go
index 6d54f8a..c12b58b 100644
--- a/newt/interfaces/interfaces.go
+++ b/newt/interfaces/interfaces.go
@@ -22,6 +22,7 @@ package interfaces
 type PackageInterface interface {
 	Name() string
 	FullName() string
+	BasePath() string
 	Repo() RepoInterface
 	Type() PackageType
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1193eccf/newt/pkg/package.go
----------------------------------------------------------------------
diff --git a/newt/pkg/package.go b/newt/pkg/package.go
index d5d9403..58bf523 100644
--- a/newt/pkg/package.go
+++ b/newt/pkg/package.go
@@ -71,6 +71,8 @@ type Package interface {
 	FullName() string
 	// The type of package (lib, target, bsp, etc.)
 	Type() interfaces.PackageType
+	// BasePath is the path on disk if it's a local package
+	BasePath() string
 	// Hash of the contents of the package
 	Hash() (string, error)
 	// Description of this package

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1193eccf/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index cc68c30..cec5102 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -497,15 +497,42 @@ func (proj *Project) Init(dir string) error {
 	return nil
 }
 
+func matchNamePath(name, path string) bool {
+	// assure that name and path use the same path separator...
+	names := filepath.SplitList(name)
+	name = filepath.Join(names...)
+
+	if strings.HasSuffix(path, name) {
+		return true
+	}
+	return false
+}
+
 func (proj *Project) ResolveDependency(dep interfaces.DependencyInterface) interfaces.PackageInterface {
+	type NamePath struct {
+		name string
+		path string
+	}
+
+	var errorPkgs []NamePath
 	for _, pkgList := range proj.packages {
 		for _, pkg := range *pkgList {
+			name := pkg.Name()
+			path := pkg.BasePath()
+			if !matchNamePath(name, path) {
+				errorPkgs = append(errorPkgs, NamePath{name: name, path: path})
+			}
 			if dep.SatisfiesDependency(pkg) {
 				return pkg
 			}
 		}
 	}
 
+	for _, namepath := range errorPkgs {
+		util.StatusMessage(util.VERBOSITY_VERBOSE,
+			"Package name \"%s\" doesn't match path \"%s\"\n", namepath.name, namepath.path)
+	}
+
 	return nil
 }
 


[03/23] incubator-mynewt-newt git commit: Updates to sync/upgrade/install inner working

Posted by cc...@apache.org.
Updates to sync/upgrade/install inner working

- sync now creates a new branch when checking out a tag commit
- sync flow now:
  1) stash changes
  2) fetch branchs/tags from origin
  3) merges in changes on master and develop
  4) checks out old branch or new branch (creating if necessary)
  5) stash pops if the previous stash was succesful
- upgrade/install now try first to cleanup and existing repo and if it
  fails do the old style remove+clone.


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

Branch: refs/heads/master
Commit: 0418ceab007a703ca86652adb7455958d5eac24b
Parents: 0196ba5
Author: Fabio Utzig <ut...@utzig.org>
Authored: Tue Mar 7 11:33:01 2017 -0300
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Tue Mar 7 11:33:01 2017 -0300

----------------------------------------------------------------------
 newt/downloader/downloader.go | 116 +++++++++++++++++++++++++++++++------
 newt/repo/repo.go             |  78 ++++++++++++-------------
 2 files changed, 138 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0418ceab/newt/downloader/downloader.go
----------------------------------------------------------------------
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index e57ecfa..c8e13c6 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -41,7 +41,7 @@ type Downloader interface {
 	SetBranch(branch string)
 	DownloadRepo(branch string) (string, error)
 	CurrentBranch(path string) (string, error)
-	UpdateRepo(path string) error
+	UpdateRepo(path string, branchName string) error
 	CleanupRepo(path string, branchName string) error
 	LocalDiff(path string) ([]byte, error)
 }
@@ -100,22 +100,86 @@ func executeGitCommand(dir string, cmd []string) ([]byte, error) {
 	return output, nil
 }
 
+func isTag(repoDir string, branchName string) bool {
+	cmd := []string{"tag", "--list"}
+	output, _ := executeGitCommand(repoDir, cmd)
+	return strings.Contains(string(output), branchName)
+}
+
+func branchExists(repoDir string, branchName string) bool {
+	cmd := []string{"show-ref", "--verify", "--quiet", "refs/heads/" + branchName}
+	_, err := executeGitCommand(repoDir, cmd)
+	return err == nil
+}
+
+// checkout does checkout a branch, or create a new branch from a tag name
+// if the commit supplied is a tag. sha1 based commits have no special
+// handling and result in dettached from HEAD state.
 func checkout(repoDir string, commit string) error {
-	cmd := []string{
-		"checkout",
-		commit,
+	var cmd []string
+	if isTag(repoDir, commit) && !branchExists(repoDir, commit) {
+		util.StatusMessage(util.VERBOSITY_VERBOSE, "Will create new branch %s"+
+			" from tag %s\n", commit, "tags/"+commit)
+		cmd = []string{
+			"checkout",
+			"tags/" + commit,
+			"-b",
+			commit,
+		}
+	} else {
+		util.StatusMessage(util.VERBOSITY_VERBOSE, "Will checkout branch %s\n",
+			commit)
+		cmd = []string{
+			"checkout",
+			commit,
+		}
 	}
 	_, err := executeGitCommand(repoDir, cmd)
 	return err
 }
 
-func pull(repoDir string) error {
-	_, err := executeGitCommand(repoDir, []string{"pull"})
+// mergeBranches applies upstream changes to the local copy and must be
+// preceeded by a "fetch" to achieve any meaningful result.
+func mergeBranches(repoDir string) {
+	branches := []string{"master", "develop"}
+	for _, branch := range branches {
+		err := checkout(repoDir, branch)
+		if err != nil {
+			continue
+		}
+		_, err = executeGitCommand(repoDir, []string{"merge", "origin/" + branch})
+		if err != nil {
+			util.StatusMessage(util.VERBOSITY_VERBOSE, "Merging changes from origin/%s: %s\n",
+				branch, err)
+		} else {
+			util.StatusMessage(util.VERBOSITY_VERBOSE, "Merging changes from origin/%s\n",
+				branch)
+		}
+		// XXX: ignore error, probably resulting from a branch not available at
+		//      origin anymore.
+	}
+}
+
+func fetch(repoDir string) error {
+	util.StatusMessage(util.VERBOSITY_VERBOSE, "Fetching new remote branches/tags\n")
+	_, err := executeGitCommand(repoDir, []string{"fetch", "--tags"})
 	return err
 }
 
-func stash(repoDir string) error {
-	_, err := executeGitCommand(repoDir, []string{"stash"})
+// stash saves current changes locally and returns if a new stash was
+// created (if there where no changes, there's no need to stash)
+func stash(repoDir string) (bool, error) {
+	util.StatusMessage(util.VERBOSITY_VERBOSE, "Stashing local changes\n")
+	output, err := executeGitCommand(repoDir, []string{"stash"})
+	if err != nil {
+		return false, err
+	}
+	return strings.Contains(string(output), "Saved"), nil
+}
+
+func stashPop(repoDir string) error {
+	util.StatusMessage(util.VERBOSITY_VERBOSE, "Un-stashing local changes\n")
+	_, err := executeGitCommand(repoDir, []string{"stash", "pop"})
 	return err
 }
 
@@ -198,27 +262,45 @@ func (gd *GithubDownloader) CurrentBranch(path string) (string, error) {
 	return strings.Trim(string(branch), "\r\n"), err
 }
 
-func (gd *GithubDownloader) UpdateRepo(path string) error {
-	return pull(path)
-}
-
-func (gd *GithubDownloader) CleanupRepo(path string, branchName string) error {
-	err := stash(path)
+func (gd *GithubDownloader) UpdateRepo(path string, branchName string) error {
+	err := fetch(path)
 	if err != nil {
 		return err
 	}
 
-	err = clean(path)
+	stashed, err := stash(path)
 	if err != nil {
 		return err
 	}
 
+	mergeBranches(path)
+
 	err = checkout(path, branchName)
 	if err != nil {
 		return err
 	}
 
-	return pull(path)
+	if stashed {
+		return stashPop(path)
+	}
+
+	return nil
+}
+
+func (gd *GithubDownloader) CleanupRepo(path string, branchName string) error {
+	_, err := stash(path)
+	if err != nil {
+		return err
+	}
+
+	err = clean(path)
+	if err != nil {
+		return err
+	}
+
+	// TODO: needs handling of non-tracked files
+
+	return gd.UpdateRepo(path, branchName)
 }
 
 func (gd *GithubDownloader) LocalDiff(path string) ([]byte, error) {
@@ -303,7 +385,7 @@ func (ld *LocalDownloader) CurrentBranch(path string) (string, error) {
 }
 
 // NOTE: intentionally always error...
-func (ld *LocalDownloader) UpdateRepo(path string) error {
+func (ld *LocalDownloader) UpdateRepo(path string, branchName string) error {
 	return util.NewNewtError(fmt.Sprintf("Can't pull from a local repo\n"))
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0418ceab/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index a4a916f..139c499 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -378,11 +378,11 @@ func (r *Repo) checkExists() bool {
 	return util.NodeExist(r.Path())
 }
 
-func (r *Repo) updateRepo() error {
+func (r *Repo) updateRepo(branchName string) error {
 	dl := r.downloader
-	err := dl.UpdateRepo(r.Path())
+	err := dl.UpdateRepo(r.Path(), branchName)
 	if err != nil {
-		return util.NewNewtError(fmt.Sprintf("\tError updating\n"))
+		return util.NewNewtError(fmt.Sprintf("Error updating\n"))
 	}
 	return nil
 }
@@ -391,7 +391,7 @@ func (r *Repo) cleanupRepo(branchName string) error {
 	dl := r.downloader
 	err := dl.CleanupRepo(r.Path(), branchName)
 	if err != nil {
-		return util.NewNewtError(fmt.Sprintf("\tError cleaning and updating\n"))
+		return util.NewNewtError(fmt.Sprintf("Error cleaning and updating\n"))
 	}
 	return nil
 }
@@ -431,33 +431,15 @@ func (r *Repo) currentBranch() (string, error) {
 		return "", util.NewNewtError(fmt.Sprintf("Error finding current branch for \"%s\" : %s",
 			r.Name(), err.Error()))
 	}
-	return branch, nil
-}
-
-func (r *Repo) checkForceInstall(force bool) (error, bool) {
-	// Copy the git repo into /repos/, error'ing out if the repo already exists
-	if util.NodeExist(r.Path()) {
-		if force {
-			if err := os.RemoveAll(r.Path()); err != nil {
-				return util.NewNewtError(err.Error()), true
-			}
-		}
-		return nil, true
-	}
-	return nil, false
+	return filepath.Base(branch), nil
 }
 
 func (r *Repo) Install(force bool) (*Version, error) {
-	if err, exists := r.checkForceInstall(force); err != nil || exists {
-		if err == nil {
-			if !force {
-				return nil, util.NewNewtError(fmt.Sprintf(
-					"Repository %s already exists, provide the -f option "+
-						"to overwrite", r.Name()))
-			}
-		} else {
-			return nil, err
-		}
+	exists := util.NodeExist(r.Path())
+	if exists && !force {
+		return nil, util.NewNewtError(fmt.Sprintf(
+			"Repository %s already exists, provide the -f option "+
+				"to overwrite", r.Name()))
 	}
 
 	branchName, vers, found := r.rdesc.Match(r)
@@ -466,6 +448,20 @@ func (r *Repo) Install(force bool) (*Version, error) {
 			r.rdesc.String()))
 	}
 
+	// if the repo is already cloned, try to cleanup and checkout the requested branch
+	if exists {
+		err := r.cleanupRepo(branchName)
+		if err == nil {
+			return vers, nil
+		}
+
+		// cleanup failed, so remove current copy and let download clone again...
+		if err := os.RemoveAll(r.Path()); err != nil {
+			return nil, util.NewNewtError(err.Error())
+		}
+	}
+
+	// repo was not already cloned or cleanup failed...
 	if err := r.downloadRepo(branchName); err != nil {
 		return nil, err
 	}
@@ -496,10 +492,13 @@ func (r *Repo) Sync(vers *Version, force bool) (bool, bool, error) {
 		// the user must know what he's doing...
 		// but, if -f is passed let's just save the work and re-clone
 		currBranch, err = r.currentBranch()
+
+		// currBranch == HEAD means we're dettached from HEAD, so
+		// ignore and move to "new" tag
 		if err != nil {
 			return exists, false, err
-		} else if currBranch != branchName {
-			msg := "Unexpected local branch for %s: \"%s\" != \"%s\""
+		} else if currBranch != "HEAD" && currBranch != branchName {
+			msg := "Unexpected local branch for %s: \"%s\" != \"%s\"\n"
 			if force {
 				util.StatusMessage(util.VERBOSITY_VERBOSE,
 					msg, r.rdesc.name, currBranch, branchName)
@@ -511,14 +510,14 @@ func (r *Repo) Sync(vers *Version, force bool) (bool, bool, error) {
 		}
 
 		// Don't try updating if on an invalid branch...
-		if currBranch == branchName {
-			util.StatusMessage(util.VERBOSITY_VERBOSE, "\tTrying to update repository... ")
-			err = r.updateRepo()
+		if currBranch == "HEAD" || currBranch == branchName {
+			util.StatusMessage(util.VERBOSITY_VERBOSE, "Updating repository...\n")
+			err = r.updateRepo(branchName)
 			if err == nil {
-				util.StatusMessage(util.VERBOSITY_VERBOSE, " success!\n")
+				util.StatusMessage(util.VERBOSITY_VERBOSE, "Update successful!\n")
 				return exists, true, err
 			} else {
-				util.StatusMessage(util.VERBOSITY_VERBOSE, " failed!\n")
+				util.StatusMessage(util.VERBOSITY_VERBOSE, "Update failed!\n")
 				if !force {
 					return exists, false, err
 				}
@@ -566,6 +565,7 @@ func (r *Repo) UpdateDesc() ([]*Repo, bool, error) {
 
 	_, repos, err := r.ReadDesc()
 	if err != nil {
+		fmt.Printf("ReadDesc: %v\n", err)
 		return nil, false, err
 	}
 
@@ -578,8 +578,8 @@ func (r *Repo) UpdateDesc() ([]*Repo, bool, error) {
 func (r *Repo) DownloadDesc() error {
 	dl := r.downloader
 
-	util.StatusMessage(util.VERBOSITY_VERBOSE, "\tDownloading "+
-		"repository description... ")
+	util.StatusMessage(util.VERBOSITY_VERBOSE, "Downloading "+
+		"repository description\n")
 
 	// Configuration path
 	cpath := r.repoFilePath()
@@ -592,7 +592,7 @@ func (r *Repo) DownloadDesc() error {
 	dl.SetBranch("master")
 	if err := dl.FetchFile("repository.yml",
 		cpath+"/"+"repository.yml"); err != nil {
-		util.StatusMessage(util.VERBOSITY_VERBOSE, " failed\n")
+		util.StatusMessage(util.VERBOSITY_VERBOSE, "Download failed\n")
 		return err
 	}
 
@@ -604,7 +604,7 @@ func (r *Repo) DownloadDesc() error {
 		}
 	}
 
-	util.StatusMessage(util.VERBOSITY_VERBOSE, " success!\n")
+	util.StatusMessage(util.VERBOSITY_VERBOSE, "Download successful!\n")
 
 	return nil
 }


[11/23] incubator-mynewt-newt git commit: newt; go version requirement is now 1.7.

Posted by cc...@apache.org.
newt; go version requirement is now 1.7.


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

Branch: refs/heads/master
Commit: 23ce34bce0a18e50f07e795d5983978376548b77
Parents: 7a6d02d
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Mar 8 14:45:39 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Mar 9 14:00:33 2017 -0800

----------------------------------------------------------------------
 INSTALLING.md | 2 +-
 build.sh      | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/23ce34bc/INSTALLING.md
----------------------------------------------------------------------
diff --git a/INSTALLING.md b/INSTALLING.md
index 885f6cf..0718925 100644
--- a/INSTALLING.md
+++ b/INSTALLING.md
@@ -11,7 +11,7 @@ when available.  To find these, please go to https://mynewt.apache.org/.
 # Installing From Source
 
 The newt tool is written in Go (https://golang.org/).  In order to build Apache
-Mynewt, you must have Go 1.5 or later installed on your system.  Please visit
+Mynewt, you must have Go 1.7 or later installed on your system.  Please visit
 the Golang website for more information on installing Go (https://golang.org/).
 
 Once you have Go installed, you can build newt by running the contained

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/23ce34bc/build.sh
----------------------------------------------------------------------
diff --git a/build.sh b/build.sh
index d4f108f..9405e6b 100755
--- a/build.sh
+++ b/build.sh
@@ -26,7 +26,7 @@ expandpath() {
     )
 }
 
-### Ensure >= go1.5 is installed.
+### Ensure >= go1.7 is installed.
 go_ver_str="$(go version | cut -d ' ' -f 3)"
 go_ver="${go_ver_str#go}"
 
@@ -49,9 +49,9 @@ then
     go_min=0
 fi
 
-if [ ! "$go_maj" -gt 1 ] && [ ! "$go_min" -ge 5 ]
+if [ ! "$go_maj" -gt 1 ] && [ ! "$go_min" -ge 7 ]
 then
-    printf "* Error: go 1.5 or later is required (detected version: %s)\n" \
+    printf "* Error: go 1.7 or later is required (detected version: %s)\n" \
         "$go_maj"."$go_min".X
     exit 1
 fi


[23/23] incubator-mynewt-newt git commit: Merge remote-tracking branch 'apache/develop'

Posted by cc...@apache.org.
Merge remote-tracking branch 'apache/develop'

* apache/develop:
  unixchild - Ensure socket gets deleted on stop.
  Add PrintStacks util function.
  unixchild - prevent half-started state
  unixchild additions
  unixchild util library
  MYNEWT-674 newt - Remove use of new io.SeekCurrent
  MYNEWT-660 newt - Quotes get stripped from syscfg
  Add env to verbose output, remove duplicated msg
  newt; go version requirement is now 1.7.
  Update release notes; date and remove comment saying that this is a beta.
  MYNEWT-655 newt - Detect newt version incompat.
  Fix to print correct pkg dependecy
  MYNEWT-655 newt - Detect proj/newt ver incompat.
  MYNEWT-655 newt - Detect repo/newt ver incompat.
  Warns on unmatched pkg.name and pkg.path
  Updates to sync/upgrade/install inner working
  Remove trailing slash using pkg commands in the shell
  MYNEWT-495: updates to sync 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/a895dc5c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a895dc5c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a895dc5c

Branch: refs/heads/master
Commit: a895dc5cb357dc86c297919f1dc77c78423c7dea
Parents: 4e940c1 9de7460
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Apr 7 12:35:32 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Apr 7 12:35:32 2017 -0700

----------------------------------------------------------------------
 INSTALLING.md                                   |   2 +-
 RELEASE_NOTES.md                                |  10 +-
 build.sh                                        |   6 +-
 newt/builder/load.go                            |   6 +-
 newt/cli/pkg_cmds.go                            |   2 +-
 newt/cli/project_cmds.go                        |  23 +-
 newt/compat/compat.go                           | 275 ++++++++++++++++
 newt/downloader/downloader.go                   | 194 ++++++++++--
 newt/interfaces/interfaces.go                   |   1 +
 newt/newtutil/newtutil.go                       |  74 +++--
 newt/pkg/localpackage.go                        |   2 +-
 newt/pkg/package.go                             |   2 +
 newt/project/project.go                         |  77 +++++
 newt/repo/repo.go                               | 313 ++++++++++++-------
 newt/repo/version.go                            |   9 +
 newt/resolve/resolve.go                         |   7 +-
 newt/vendor/mynewt.apache.org/newt/util/util.go |   1 -
 util/unixchild/unixchild.go                     | 292 +++++++++++++++++
 util/util.go                                    |   6 +
 19 files changed, 1120 insertions(+), 182 deletions(-)
----------------------------------------------------------------------



[09/23] incubator-mynewt-newt git commit: This closes #48.

Posted by cc...@apache.org.
This closes #48.

Merge branch 'sync-refactor' of https://github.com/utzig/incubator-mynewt-newt into develop


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

Branch: refs/heads/master
Commit: 737da68ddcda814d009902abef8bdfcf1f1c8802
Parents: cd6aa05 0418cea
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Mar 7 15:49:17 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Mar 7 15:49:17 2017 -0800

----------------------------------------------------------------------
 newt/cli/project_cmds.go                        |  23 ++-
 newt/downloader/downloader.go                   | 194 ++++++++++++++++--
 newt/repo/repo.go                               | 199 +++++++++++++++----
 newt/vendor/mynewt.apache.org/newt/util/util.go |   1 -
 4 files changed, 351 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/737da68d/newt/repo/repo.go
----------------------------------------------------------------------
diff --cc newt/repo/repo.go
index a2b98c9,139c499..e058466
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@@ -473,9 -590,9 +588,9 @@@ func (r *Repo) DownloadDesc() error 
  	}
  
  	dl.SetBranch("master")
 -	if err := dl.FetchFile("repository.yml",
 -		cpath+"/"+"repository.yml"); err != nil {
 +	if err := dl.FetchFile(REPO_FILE_NAME,
 +		cpath+"/"+REPO_FILE_NAME); err != nil {
- 		util.StatusMessage(util.VERBOSITY_VERBOSE, " failed\n")
+ 		util.StatusMessage(util.VERBOSITY_VERBOSE, "Download failed\n")
  		return err
  	}
  


[02/23] incubator-mynewt-newt git commit: Remove trailing slash using pkg commands in the shell

Posted by cc...@apache.org.
Remove trailing slash using pkg commands in the shell


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

Branch: refs/heads/master
Commit: 008834c57cdedf0b2117fcc4f440f01b2f162feb
Parents: 7ecee8b
Author: Fabio Utzig <ut...@utzig.org>
Authored: Mon Mar 6 15:54:18 2017 -0300
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Mon Mar 6 15:54:18 2017 -0300

----------------------------------------------------------------------
 newt/cli/pkg_cmds.go      | 2 +-
 newt/newtutil/newtutil.go | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/008834c5/newt/cli/pkg_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/pkg_cmds.go b/newt/cli/pkg_cmds.go
index 315ae89..472369b 100644
--- a/newt/cli/pkg_cmds.go
+++ b/newt/cli/pkg_cmds.go
@@ -60,7 +60,7 @@ func pkgNewCmd(cmd *cobra.Command, args []string) {
 type dirOperation func(string, string) error
 
 func pkgCopyCmd(cmd *cobra.Command, args []string) {
-	pkgCloneOrMoveCmd(cmd, args, util.CopyDir, "Cloning")
+	pkgCloneOrMoveCmd(cmd, args, util.CopyDir, "Copying")
 }
 
 func pkgMoveCmd(cmd *cobra.Command, args []string) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/008834c5/newt/newtutil/newtutil.go
----------------------------------------------------------------------
diff --git a/newt/newtutil/newtutil.go b/newt/newtutil/newtutil.go
index 48ef4a0..83e0179 100644
--- a/newt/newtutil/newtutil.go
+++ b/newt/newtutil/newtutil.go
@@ -213,6 +213,9 @@ func GetStringSliceFeatures(v *viper.Viper, features map[string]bool,
 //         string               package name
 //         error                if invalid package string
 func ParsePackageString(pkgStr string) (string, string, error) {
+	// remove possible trailing '/'
+	pkgStr = strings.TrimSuffix(pkgStr, "/")
+
 	if strings.HasPrefix(pkgStr, "@") {
 		nameParts := strings.SplitN(pkgStr[1:], "/", 2)
 		if len(nameParts) == 1 {


[18/23] incubator-mynewt-newt git commit: unixchild util library

Posted by cc...@apache.org.
unixchild util library


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

Branch: refs/heads/master
Commit: aa7aa137139fd41b2c0cd22220c802314e21889b
Parents: 9797af3
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Mar 10 18:09:13 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Mar 30 20:23:55 2017 -0700

----------------------------------------------------------------------
 util/unixchild/unixchild.go | 244 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 244 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/aa7aa137/util/unixchild/unixchild.go
----------------------------------------------------------------------
diff --git a/util/unixchild/unixchild.go b/util/unixchild/unixchild.go
new file mode 100644
index 0000000..bc311fc
--- /dev/null
+++ b/util/unixchild/unixchild.go
@@ -0,0 +1,244 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package unixchild
+
+import (
+	"bufio"
+	"encoding/binary"
+	"errors"
+	"fmt"
+	"io"
+	"net"
+	"os"
+	"os/exec"
+	"strings"
+	"sync"
+	"time"
+
+	log "github.com/Sirupsen/logrus"
+)
+
+type Config struct {
+	SockPath  string
+	ChildPath string
+	ChildArgs []string
+	Depth     int
+	MaxMsgSz  int
+}
+
+type Client struct {
+	FromChild chan []byte
+	ToChild   chan []byte
+	ErrChild  chan error
+	childPath string
+	sockPath  string
+	childArgs []string
+	maxMsgSz  int
+	stopping  bool
+	stop      chan bool
+	stopped   chan bool
+}
+
+func New(conf Config) *Client {
+	c := &Client{
+		childPath: conf.ChildPath,
+		sockPath:  conf.SockPath,
+		childArgs: conf.ChildArgs,
+		maxMsgSz:  conf.MaxMsgSz,
+		FromChild: make(chan []byte, conf.Depth),
+		ToChild:   make(chan []byte, conf.Depth),
+		ErrChild:  make(chan error),
+		stop:      make(chan bool),
+		stopped:   make(chan bool),
+	}
+
+	if c.maxMsgSz == 0 {
+		c.maxMsgSz = 1024
+	}
+
+	return c
+}
+
+func (c *Client) startChild() (*exec.Cmd, error) {
+	subProcess := exec.Command(c.childPath, c.childArgs...)
+
+	stdin, err := subProcess.StdinPipe()
+	if err != nil {
+		return nil, err
+	}
+	stdin.Close()
+
+	stdout, _ := subProcess.StdoutPipe()
+	stderr, _ := subProcess.StderrPipe()
+
+	if err = subProcess.Start(); err != nil {
+		return nil, err
+	}
+
+	go func() {
+		br := bufio.NewReader(stdout)
+		for {
+			s, err := br.ReadString('\n')
+			if err != nil {
+				return
+			}
+			log.Debugf("child stdout: %s", strings.TrimSuffix(s, "\n"))
+		}
+	}()
+
+	go func() {
+		br := bufio.NewReader(stderr)
+		for {
+			s, err := br.ReadString('\n')
+			if err != nil {
+				return
+			}
+			log.Debugf("child stderr: %s", strings.TrimSuffix(s, "\n"))
+		}
+	}()
+
+	go subProcess.Wait() // reap dead children
+
+	return subProcess, nil
+}
+
+func (c *Client) handleChild(con net.Conn) {
+	var wg sync.WaitGroup
+
+	bail := make(chan bool)
+
+	fromDataPump := func() {
+		defer wg.Done()
+		for {
+			var mlen uint16
+
+			err := binary.Read(con, binary.BigEndian, &mlen)
+			if err != nil {
+				log.Debugln("fromDataPump error: ", err)
+				bail <- true
+				return
+			}
+
+			buf := make([]byte, mlen)
+			_, err = io.ReadFull(con, buf)
+			if err != nil {
+				log.Debugln("fromDataPump error: ", err)
+				bail <- true
+				return
+			}
+
+			c.FromChild <- buf
+		}
+	}
+
+	toDataPump := func() {
+		defer wg.Done()
+		for {
+			select {
+			case buf := <-c.ToChild:
+				mlen := uint16(len(buf))
+				err := binary.Write(con, binary.BigEndian, mlen)
+				if err != nil {
+					log.Debugln("toDataPump error: ", err)
+					return
+				}
+				_, err = con.Write(buf)
+				if err != nil {
+					log.Debugln("toDataPump error: ", err)
+					return
+				}
+			case <-bail:
+				log.Debugln("toDataPump bail")
+				return
+			}
+		}
+	}
+
+	wg.Add(1)
+	go fromDataPump()
+	wg.Add(1)
+	go toDataPump()
+	wg.Wait()
+}
+
+func (c *Client) Stop() {
+	if c.stopping {
+		return
+	}
+	c.stopping = true
+	log.Debugf("Stopping client")
+
+	c.stop <- true
+
+	select {
+	case <-c.stopped:
+		log.Debugf("Stopped client")
+		return
+	}
+}
+
+func (c *Client) Start() error {
+
+	l, err := net.Listen("unix", c.sockPath)
+	if err != nil {
+		return err
+	}
+
+	var cmd *exec.Cmd
+
+	go func() {
+		for {
+			var err error
+			cmd, err = c.startChild()
+			if err != nil {
+				log.Debugf("unixchild start error: %s", err.Error())
+				c.ErrChild <- fmt.Errorf("Child start error: %s", err.Error())
+			} else {
+				fd, err := l.Accept()
+				if err != nil {
+					log.Debugf("unixchild accept error: %s", err.Error())
+				} else {
+					c.handleChild(fd)
+				}
+				cmd.Process.Kill()
+				c.ErrChild <- errors.New("Child exited")
+			}
+			if c.stopping {
+				log.Debugf("unixchild exit loop")
+				return
+			}
+			time.Sleep(time.Second)
+		}
+	}()
+
+	go func() {
+		select {
+		case <-c.stop:
+			l.Close()
+			if cmd != nil {
+				cmd.Process.Kill()
+			}
+			os.Remove(c.sockPath)
+			c.stopped <- true
+		}
+	}()
+
+	return nil
+}


[10/23] incubator-mynewt-newt git commit: Update release notes; date and remove comment saying that this is a beta.

Posted by cc...@apache.org.
Update release notes; date and remove comment saying that this is
a beta.


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

Branch: refs/heads/master
Commit: 7a6d02d57c880c45dede4a4f017ff0ce4324e716
Parents: 737da68
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Mar 7 16:12:08 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Mar 9 14:00:15 2017 -0800

----------------------------------------------------------------------
 RELEASE_NOTES.md | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7a6d02d5/RELEASE_NOTES.md
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 7137962..e92398b 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -1,6 +1,6 @@
 # RELEASE NOTES
 
-22 Nov 2016 - Apache Newt v1.0.0-b1
+7 March 2017 - Apache Newt v1.0.0
 
 For full release notes, please visit the
 [Apache Mynewt Wiki](https://cwiki.apache.org/confluence/display/MYNEWT/Release+Notes).
@@ -9,11 +9,9 @@ Apache Newt is the build and package management system for the Apache Mynewt
 project.  More information on Newt can be found
 [here](http://mail-archives.apache.org/mod_mbox/incubator-mynewt-dev/201603.mbox/%3C56E21C13.9050303%40apache.org%3E)
 
-As a beta release of Apache Newt, the normal caveat applies: APIs and commands
-are subject to change.  However, Apache Mynewt continues to stabilize with each
-release, and we believe this release is a further step forward.  People who are
-interested in playing around, and trying Newt, are encouraged to download and
-begin to evaluate it.
+Apache Mynewt continues to stabilize with each release, and we believe this
+release is a further step forward.  People who are interested in playing
+around, and trying Newt, are encouraged to download and begin evaluating it.
 
 Future versions will add:
 


[12/23] incubator-mynewt-newt git commit: This closes #52

Posted by cc...@apache.org.
This closes #52

This adds a warning (when running in verbose mode) if a pkg.name is not equal to the current pkg path.


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

Branch: refs/heads/master
Commit: 04972811d14bcf5e5460de01a498db765004ff17
Parents: 23ce34b 437fbb5
Author: Sterling Hughes <st...@runtime.io>
Authored: Thu Mar 9 15:15:38 2017 -0800
Committer: Sterling Hughes <st...@runtime.io>
Committed: Thu Mar 9 15:15:38 2017 -0800

----------------------------------------------------------------------
 newt/interfaces/interfaces.go |  1 +
 newt/pkg/package.go           |  2 ++
 newt/project/project.go       | 27 +++++++++++++++++++++++++++
 newt/resolve/resolve.go       |  7 ++++---
 4 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/04972811/newt/project/project.go
----------------------------------------------------------------------


[13/23] incubator-mynewt-newt git commit: This closes #51.

Posted by cc...@apache.org.
This closes #51.

Merge remote-tracking branch 'utzig/fix-trailing-slash' into develop

* utzig/fix-trailing-slash:
  Remove trailing slash using pkg commands in the shell


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

Branch: refs/heads/master
Commit: 0f9e3f78d731e9364264f664350ff6c7eb8b94f2
Parents: 0497281 008834c
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Mar 9 15:28:23 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Mar 9 15:28:23 2017 -0800

----------------------------------------------------------------------
 newt/cli/pkg_cmds.go      | 2 +-
 newt/newtutil/newtutil.go | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/0f9e3f78/newt/newtutil/newtutil.go
----------------------------------------------------------------------


[14/23] incubator-mynewt-newt git commit: Add env to verbose output, remove duplicated msg

Posted by cc...@apache.org.
Add env to verbose output, remove duplicated msg


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

Branch: refs/heads/master
Commit: af4896556d85f6846a6247ecf04ab5567f28b57d
Parents: 0f9e3f7
Author: Fabio Utzig <ut...@utzig.org>
Authored: Mon Mar 13 10:06:57 2017 -0300
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Mon Mar 13 10:06:57 2017 -0300

----------------------------------------------------------------------
 newt/builder/load.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/af489655/newt/builder/load.go
----------------------------------------------------------------------
diff --git a/newt/builder/load.go b/newt/builder/load.go
index eb7396e..fafd4b8 100644
--- a/newt/builder/load.go
+++ b/newt/builder/load.go
@@ -86,6 +86,10 @@ func Load(binBaseName string, bspPkg *pkg.BspPackage,
 
 	util.StatusMessage(util.VERBOSITY_VERBOSE, "Load command: %s\n",
 		strings.Join(cmd, " "))
+	util.StatusMessage(util.VERBOSITY_VERBOSE, "Environment:\n")
+	for _, v := range env {
+		util.StatusMessage(util.VERBOSITY_VERBOSE, "* %s\n", v)
+	}
 	if _, err := util.ShellCommand(cmd, env); err != nil {
 		return err
 	}
@@ -145,8 +149,6 @@ func (b *Builder) Load(imageSlot int, extraJtagCmd string) error {
 		return err
 	}
 
-	util.StatusMessage(util.VERBOSITY_VERBOSE, "Successfully loaded image.\n")
-
 	return nil
 }
 


[06/23] incubator-mynewt-newt git commit: MYNEWT-655 newt - Detect proj/newt ver incompat.

Posted by cc...@apache.org.
MYNEWT-655 newt - Detect proj/newt ver incompat.

Projects can specify newt version restrictions as follows (project.yml):

project.newt_compatibility:
    1.1.0: error
    1.0.0: good
    0.9.99: warn
    0.9.9: error


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

Branch: refs/heads/master
Commit: b1ecb9f835549ee275c4e50c03a22b9c9fa7cc6d
Parents: f264e67
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Mar 7 13:16:04 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Mar 7 13:16:04 2017 -0800

----------------------------------------------------------------------
 newt/compat/compat.go   | 275 +++++++++++++++++++++++++++++++++++++++++
 newt/project/project.go |  48 ++++++--
 newt/repo/compat.go     | 284 -------------------------------------------
 newt/repo/repo.go       |  20 +--
 4 files changed, 325 insertions(+), 302 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b1ecb9f8/newt/compat/compat.go
----------------------------------------------------------------------
diff --git a/newt/compat/compat.go b/newt/compat/compat.go
new file mode 100644
index 0000000..2e4355f
--- /dev/null
+++ b/newt/compat/compat.go
@@ -0,0 +1,275 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package compat
+
+import (
+	"fmt"
+	"math"
+	"sort"
+
+	"github.com/spf13/cast"
+
+	"mynewt.apache.org/newt/newt/newtutil"
+	"mynewt.apache.org/newt/util"
+	"mynewt.apache.org/newt/viper"
+)
+
+type NewtCompatCode int
+
+const (
+	NEWT_COMPAT_GOOD NewtCompatCode = iota
+	NEWT_COMPAT_WARN
+	NEWT_COMPAT_ERROR
+)
+
+var NewtCompatCodeNames = map[NewtCompatCode]string{
+	NEWT_COMPAT_GOOD:  "good",
+	NEWT_COMPAT_WARN:  "warn",
+	NEWT_COMPAT_ERROR: "error",
+}
+
+type NewtCompatEntry struct {
+	code       NewtCompatCode
+	minNewtVer newtutil.Version
+}
+
+// Sorted in ascending order by newt version number.
+type NewtCompatTable []NewtCompatEntry
+
+type NewtCompatMap map[newtutil.Version]NewtCompatTable
+
+func newtCompatCodeToString(code NewtCompatCode) string {
+	return NewtCompatCodeNames[code]
+}
+
+func newtCompatCodeFromString(codeStr string) (NewtCompatCode, error) {
+	for c, s := range NewtCompatCodeNames {
+		if codeStr == s {
+			return c, nil
+		}
+	}
+
+	return NewtCompatCode(0),
+		util.FmtNewtError("Invalid newt compatibility code: %s", codeStr)
+}
+
+func parseNcEntry(verStr string, codeStr string) (NewtCompatEntry, error) {
+	entry := NewtCompatEntry{}
+	var err error
+
+	entry.minNewtVer, err = newtutil.ParseVersion(verStr)
+	if err != nil {
+		return entry, err
+	}
+
+	entry.code, err = newtCompatCodeFromString(codeStr)
+	if err != nil {
+		return entry, err
+	}
+
+	return entry, nil
+}
+
+func ParseNcTable(strMap map[string]string) (NewtCompatTable, error) {
+	tbl := NewtCompatTable{}
+
+	for v, c := range strMap {
+		entry, err := parseNcEntry(v, c)
+		if err != nil {
+			return tbl, err
+		}
+
+		tbl = append(tbl, entry)
+	}
+
+	sortEntries(tbl)
+
+	return tbl, nil
+}
+
+func ReadNcMap(v *viper.Viper) (NewtCompatMap, error) {
+	mp := NewtCompatMap{}
+	ncMap := v.GetStringMap("repo.newt_compatibility")
+
+	for k, v := range ncMap {
+		repoVer, err := newtutil.ParseVersion(k)
+		if err != nil {
+			return nil, util.FmtNewtError("Newt compatibility table contains " +
+				"invalid repo version \"%s\"")
+		}
+
+		if _, ok := mp[repoVer]; ok {
+			return nil, util.FmtNewtError("Newt compatibility table contains "+
+				"duplicate version specifier: %s", repoVer.String())
+		}
+
+		strMap := cast.ToStringMapString(v)
+		tbl, err := ParseNcTable(strMap)
+		if err != nil {
+			return nil, err
+		}
+
+		mp[repoVer] = tbl
+	}
+
+	return mp, nil
+}
+
+func (tbl NewtCompatTable) matchIdx(newtVer newtutil.Version) int {
+	// Iterate the table backwards.  The first entry whose version is less than
+	// or equal to the specified version is the match.
+	for i := 0; i < len(tbl); i++ {
+		idx := len(tbl) - i - 1
+		entry := &tbl[idx]
+		cmp := newtutil.VerCmp(entry.minNewtVer, newtVer)
+		if cmp <= 0 {
+			return idx
+		}
+	}
+
+	return -1
+}
+
+func (tbl NewtCompatTable) newIdxRange(i int, j int) []int {
+	if i >= len(tbl) {
+		return []int{j, i}
+	}
+
+	if j >= len(tbl) {
+		return []int{i, j}
+	}
+
+	e1 := tbl[i]
+	e2 := tbl[j]
+
+	if newtutil.VerCmp(e1.minNewtVer, e2.minNewtVer) < 0 {
+		return []int{i, j}
+	} else {
+		return []int{j, i}
+	}
+}
+
+func (tbl NewtCompatTable) idxRangesWithCode(c NewtCompatCode) [][]int {
+	ranges := [][]int{}
+
+	curi := -1
+	for i, e := range tbl {
+		if curi == -1 {
+			if e.code == c {
+				curi = i
+			}
+		} else {
+			if e.code != c {
+				ranges = append(ranges, tbl.newIdxRange(curi, i))
+				curi = -1
+			}
+		}
+	}
+
+	if curi != -1 {
+		ranges = append(ranges, tbl.newIdxRange(curi, len(tbl)))
+	}
+	return ranges
+}
+
+func (tbl NewtCompatTable) minMaxTgtVers(goodRange []int) (
+	newtutil.Version, newtutil.Version, newtutil.Version) {
+
+	minVer := tbl[goodRange[0]].minNewtVer
+
+	var maxVer newtutil.Version
+	if goodRange[1] < len(tbl) {
+		maxVer = tbl[goodRange[1]].minNewtVer
+	} else {
+		maxVer = newtutil.Version{math.MaxInt64, math.MaxInt64, math.MaxInt64}
+	}
+
+	targetVer := tbl[goodRange[1]-1].minNewtVer
+
+	return minVer, maxVer, targetVer
+}
+
+// @return NewtCompatCode       The severity of the newt incompatibility
+//         string               The warning or error message to display in case
+//                                  of incompatibility.
+func (tbl NewtCompatTable) CheckNewtVer(
+	newtVer newtutil.Version) (NewtCompatCode, string) {
+
+	var code NewtCompatCode
+	idx := tbl.matchIdx(newtVer)
+	if idx == -1 {
+		// This version of newt is older than every entry in the table.
+		code = NEWT_COMPAT_ERROR
+	} else {
+		code = tbl[idx].code
+		if code == NEWT_COMPAT_GOOD {
+			return NEWT_COMPAT_GOOD, ""
+		}
+	}
+
+	goodRanges := tbl.idxRangesWithCode(NEWT_COMPAT_GOOD)
+	for i := 0; i < len(goodRanges); i++ {
+		minVer, maxVer, tgtVer := tbl.minMaxTgtVers(goodRanges[i])
+
+		if newtutil.VerCmp(newtVer, minVer) < 0 {
+			return code, fmt.Sprintf("Please upgrade your newt tool to "+
+				"version %s", tgtVer.String())
+		}
+
+		if newtutil.VerCmp(newtVer, maxVer) >= 0 {
+			return code, fmt.Sprintf("Please upgrade your project "+
+				"or downgrade newt to %s", tgtVer.String())
+		}
+	}
+
+	return code, ""
+}
+
+type entrySorter struct {
+	entries []NewtCompatEntry
+}
+
+func (s entrySorter) Len() int {
+	return len(s.entries)
+}
+func (s entrySorter) Swap(i, j int) {
+	s.entries[i], s.entries[j] = s.entries[j], s.entries[i]
+}
+func (s entrySorter) Less(i, j int) bool {
+	e1 := s.entries[i]
+	e2 := s.entries[j]
+
+	cmp := newtutil.VerCmp(e1.minNewtVer, e2.minNewtVer)
+	if cmp < 0 {
+		return true
+	} else if cmp > 0 {
+		return false
+	}
+
+	return false
+}
+
+func sortEntries(entries []NewtCompatEntry) {
+	sorter := entrySorter{
+		entries: entries,
+	}
+
+	sort.Sort(sorter)
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b1ecb9f8/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index bf4b00e..6778c8b 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -29,6 +29,7 @@ import (
 
 	log "github.com/Sirupsen/logrus"
 
+	"mynewt.apache.org/newt/newt/compat"
 	"mynewt.apache.org/newt/newt/downloader"
 	"mynewt.apache.org/newt/newt/interfaces"
 	"mynewt.apache.org/newt/newt/newtutil"
@@ -100,6 +101,7 @@ func TryGetProject() (*Project, error) {
 	}
 	return globalProject, nil
 }
+
 func GetProject() *Project {
 	if _, err := TryGetProject(); err != nil {
 		panic(err.Error())
@@ -418,19 +420,15 @@ func (proj *Project) loadRepo(rname string, v *viper.Viper) error {
 
 	// Read the repo's descriptor file so that we have its newt version
 	// compatibility map.
-	_, _, err = r.ReadDesc()
-	if err != nil {
-		return util.FmtNewtError("Failed to read repo descriptor; %s",
-			err.Error())
-	}
+	r.ReadDesc()
 
 	rvers := proj.projState.GetInstalledVersion(rname)
 	code, msg := r.CheckNewtCompatibility(rvers, newtutil.NewtVersion)
 	switch code {
-	case repo.NEWT_COMPAT_GOOD:
-	case repo.NEWT_COMPAT_WARN:
+	case compat.NEWT_COMPAT_GOOD:
+	case compat.NEWT_COMPAT_WARN:
 		util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s.\n", msg)
-	case repo.NEWT_COMPAT_ERROR:
+	case compat.NEWT_COMPAT_ERROR:
 		return util.NewNewtError(msg)
 	}
 
@@ -441,6 +439,36 @@ func (proj *Project) loadRepo(rname string, v *viper.Viper) error {
 	return nil
 }
 
+func (proj *Project) checkNewtVer() error {
+	compatSms := proj.v.GetStringMapString("project.newt_compatibility")
+	// If this project doesn't have a newt compatibility map, just assume there
+	// is no incompatibility.
+	if compatSms == nil {
+		return nil
+	}
+
+	tbl, err := compat.ParseNcTable(compatSms)
+	if err != nil {
+		return util.FmtNewtError("Error reading project.yml: %s", err.Error())
+	}
+
+	code, msg := tbl.CheckNewtVer(newtutil.NewtVersion)
+	msg = fmt.Sprintf("This version of newt (%s) is incompatible with "+
+		"your project; %s", newtutil.NewtVersion.String(), msg)
+
+	switch code {
+	case compat.NEWT_COMPAT_GOOD:
+		return nil
+	case compat.NEWT_COMPAT_WARN:
+		util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s.\n", msg)
+		return nil
+	case compat.NEWT_COMPAT_ERROR:
+		return util.NewNewtError(msg)
+	default:
+		return nil
+	}
+}
+
 func (proj *Project) loadConfig() error {
 	v, err := util.ReadConfig(proj.BasePath,
 		strings.TrimSuffix(PROJECT_FILE_NAME, ".yml"))
@@ -496,6 +524,10 @@ func (proj *Project) loadConfig() error {
 		r.AddIgnoreDir(dirName)
 	}
 
+	if err := proj.checkNewtVer(); err != nil {
+		return err
+	}
+
 	return nil
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b1ecb9f8/newt/repo/compat.go
----------------------------------------------------------------------
diff --git a/newt/repo/compat.go b/newt/repo/compat.go
deleted file mode 100644
index cd9fc82..0000000
--- a/newt/repo/compat.go
+++ /dev/null
@@ -1,284 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package repo
-
-import (
-	"fmt"
-	"math"
-	"sort"
-
-	"github.com/spf13/cast"
-
-	"mynewt.apache.org/newt/newt/newtutil"
-	"mynewt.apache.org/newt/util"
-	"mynewt.apache.org/newt/viper"
-)
-
-type NewtCompatCode int
-
-const (
-	NEWT_COMPAT_GOOD NewtCompatCode = iota
-	NEWT_COMPAT_WARN
-	NEWT_COMPAT_ERROR
-)
-
-var NewtCompatCodeNames = map[NewtCompatCode]string{
-	NEWT_COMPAT_GOOD:  "good",
-	NEWT_COMPAT_WARN:  "warn",
-	NEWT_COMPAT_ERROR: "error",
-}
-
-type NewtCompatEntry struct {
-	code       NewtCompatCode
-	minNewtVer newtutil.Version
-}
-
-type NewtCompatTable struct {
-	// Sorted in ascending order by newt version number.
-	entries []NewtCompatEntry
-}
-
-type NewtCompatMap struct {
-	verTableMap map[newtutil.Version]NewtCompatTable
-}
-
-func newNewtCompatMap() *NewtCompatMap {
-	return &NewtCompatMap{
-		verTableMap: map[newtutil.Version]NewtCompatTable{},
-	}
-}
-
-func newtCompatCodeToString(code NewtCompatCode) string {
-	return NewtCompatCodeNames[code]
-}
-
-func newtCompatCodeFromString(codeStr string) (NewtCompatCode, error) {
-	for c, s := range NewtCompatCodeNames {
-		if codeStr == s {
-			return c, nil
-		}
-	}
-
-	return NewtCompatCode(0),
-		util.FmtNewtError("Invalid newt compatibility code: %s", codeStr)
-}
-
-func parseNcEntry(verStr string, codeStr string) (NewtCompatEntry, error) {
-	entry := NewtCompatEntry{}
-	var err error
-
-	entry.minNewtVer, err = newtutil.ParseVersion(verStr)
-	if err != nil {
-		return entry, err
-	}
-
-	entry.code, err = newtCompatCodeFromString(codeStr)
-	if err != nil {
-		return entry, err
-	}
-
-	return entry, nil
-}
-
-func parseNcTable(strMap map[string]string) (NewtCompatTable, error) {
-	tbl := NewtCompatTable{}
-
-	for c, v := range strMap {
-		entry, err := parseNcEntry(c, v)
-		if err != nil {
-			return tbl, err
-		}
-
-		tbl.entries = append(tbl.entries, entry)
-	}
-
-	sortEntries(tbl.entries)
-
-	return tbl, nil
-}
-
-func readNcMap(v *viper.Viper) (*NewtCompatMap, error) {
-	mp := newNewtCompatMap()
-	ncMap := v.GetStringMap("repo.newt_compatibility")
-
-	for k, v := range ncMap {
-		repoVer, err := newtutil.ParseVersion(k)
-		if err != nil {
-			return nil, util.FmtNewtError("Newt compatibility table contains " +
-				"invalid repo version \"%s\"")
-		}
-
-		if _, ok := mp.verTableMap[repoVer]; ok {
-			return nil, util.FmtNewtError("Newt compatibility table contains "+
-				"duplicate version specifier: %s", repoVer.String())
-		}
-
-		strMap := cast.ToStringMapString(v)
-		tbl, err := parseNcTable(strMap)
-		if err != nil {
-			return nil, err
-		}
-
-		mp.verTableMap[repoVer] = tbl
-	}
-
-	return mp, nil
-}
-
-func (tbl *NewtCompatTable) matchIdx(newtVer newtutil.Version) int {
-	// Iterate the table backwards.  The first entry whose version is less than
-	// or equal to the specified version is the match.
-	for i := 0; i < len(tbl.entries); i++ {
-		idx := len(tbl.entries) - i - 1
-		entry := &tbl.entries[idx]
-		cmp := newtutil.VerCmp(entry.minNewtVer, newtVer)
-		if cmp <= 0 {
-			return idx
-		}
-	}
-
-	return -1
-}
-
-func (tbl *NewtCompatTable) newIdxRange(i int, j int) []int {
-	if i >= len(tbl.entries) {
-		return []int{j, i}
-	}
-
-	if j >= len(tbl.entries) {
-		return []int{i, j}
-	}
-
-	e1 := tbl.entries[i]
-	e2 := tbl.entries[j]
-
-	if newtutil.VerCmp(e1.minNewtVer, e2.minNewtVer) < 0 {
-		return []int{i, j}
-	} else {
-		return []int{j, i}
-	}
-}
-
-func (tbl *NewtCompatTable) idxRangesWithCode(c NewtCompatCode) [][]int {
-	ranges := [][]int{}
-
-	curi := -1
-	for i, e := range tbl.entries {
-		if curi == -1 {
-			if e.code == c {
-				curi = i
-			}
-		} else {
-			if e.code != c {
-				ranges = append(ranges, tbl.newIdxRange(curi, i))
-				curi = -1
-			}
-		}
-	}
-
-	if curi != -1 {
-		ranges = append(ranges, tbl.newIdxRange(curi, len(tbl.entries)))
-	}
-	return ranges
-}
-
-func (tbl *NewtCompatTable) minMaxTgtVers(goodRange []int) (
-	newtutil.Version, newtutil.Version, newtutil.Version) {
-
-	minVer := tbl.entries[goodRange[0]].minNewtVer
-
-	var maxVer newtutil.Version
-	if goodRange[1] < len(tbl.entries) {
-		maxVer = tbl.entries[goodRange[1]].minNewtVer
-	} else {
-		maxVer = newtutil.Version{math.MaxInt64, math.MaxInt64, math.MaxInt64}
-	}
-
-	targetVer := tbl.entries[goodRange[1]-1].minNewtVer
-
-	return minVer, maxVer, targetVer
-}
-
-// @return NewtCompatCode       The severity of the newt incompatibility
-//         string               The warning or error message to display in case
-//                                  of incompatibility.
-func (tbl *NewtCompatTable) CheckNewtVer(
-	newtVer newtutil.Version) (NewtCompatCode, string) {
-
-	var code NewtCompatCode
-	idx := tbl.matchIdx(newtVer)
-	if idx == -1 {
-		// This version of newt is older than every entry in the table.
-		code = NEWT_COMPAT_ERROR
-	} else {
-		code = tbl.entries[idx].code
-		if code == NEWT_COMPAT_GOOD {
-			return NEWT_COMPAT_GOOD, ""
-		}
-	}
-
-	goodRanges := tbl.idxRangesWithCode(NEWT_COMPAT_GOOD)
-	for i := 0; i < len(goodRanges); i++ {
-		minVer, maxVer, tgtVer := tbl.minMaxTgtVers(goodRanges[i])
-
-		if newtutil.VerCmp(newtVer, minVer) < 0 {
-			return code, fmt.Sprintf("Please upgrade your newt tool to "+
-				"version %s", tgtVer.String())
-		}
-
-		if newtutil.VerCmp(newtVer, maxVer) >= 0 {
-			return code, "Please upgrade your repos with \"newt upgrade\""
-		}
-	}
-
-	return code, ""
-}
-
-type entrySorter struct {
-	entries []NewtCompatEntry
-}
-
-func (s entrySorter) Len() int {
-	return len(s.entries)
-}
-func (s entrySorter) Swap(i, j int) {
-	s.entries[i], s.entries[j] = s.entries[j], s.entries[i]
-}
-func (s entrySorter) Less(i, j int) bool {
-	e1 := s.entries[i]
-	e2 := s.entries[j]
-
-	cmp := newtutil.VerCmp(e1.minNewtVer, e2.minNewtVer)
-	if cmp < 0 {
-		return true
-	} else if cmp > 0 {
-		return false
-	}
-
-	return false
-}
-
-func sortEntries(entries []NewtCompatEntry) {
-	sorter := entrySorter{
-		entries: entries,
-	}
-
-	sort.Sort(sorter)
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b1ecb9f8/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index a534ea3..a2b98c9 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -29,6 +29,7 @@ import (
 	log "github.com/Sirupsen/logrus"
 	"github.com/spf13/cast"
 
+	"mynewt.apache.org/newt/newt/compat"
 	"mynewt.apache.org/newt/newt/downloader"
 	"mynewt.apache.org/newt/newt/interfaces"
 	"mynewt.apache.org/newt/newt/newtutil"
@@ -52,7 +53,7 @@ type Repo struct {
 	ignDirs    []string
 	updated    bool
 	local      bool
-	ncMap      *NewtCompatMap
+	ncMap      compat.NewtCompatMap
 }
 
 type RepoDesc struct {
@@ -551,7 +552,7 @@ func (r *Repo) ReadDesc() (*RepoDesc, []*Repo, error) {
 	}
 
 	// Read the newt version compatibility map.
-	r.ncMap, err = readNcMap(v)
+	r.ncMap, err = compat.ReadNcMap(v)
 	if err != nil {
 		return nil, nil, err
 	}
@@ -582,23 +583,24 @@ func (r *Repo) Init(repoName string, rversreq string, d downloader.Downloader) e
 }
 
 func (r *Repo) CheckNewtCompatibility(rvers *Version, nvers newtutil.Version) (
-	NewtCompatCode, string) {
+	compat.NewtCompatCode, string) {
 
 	// If this repo doesn't have a newt compatibility map, just assume there is
 	// no incompatibility.
-	if len(r.ncMap.verTableMap) == 0 {
-		return NEWT_COMPAT_GOOD, ""
+	if len(r.ncMap) == 0 {
+		return compat.NEWT_COMPAT_GOOD, ""
 	}
 
 	rnuver := rvers.ToNuVersion()
-	tbl, ok := r.ncMap.verTableMap[rnuver]
+	tbl, ok := r.ncMap[rnuver]
 	if !ok {
 		// Unknown repo version.
-		return NEWT_COMPAT_WARN, "Repo version missing from compatibility map"
+		return compat.NEWT_COMPAT_WARN,
+			"Repo version missing from compatibility map"
 	}
 
 	code, text := tbl.CheckNewtVer(nvers)
-	if code == NEWT_COMPAT_GOOD {
+	if code == compat.NEWT_COMPAT_GOOD {
 		return code, text
 	}
 
@@ -610,7 +612,6 @@ func (r *Repo) CheckNewtCompatibility(rvers *Version, nvers newtutil.Version) (
 func NewRepo(repoName string, rversreq string, d downloader.Downloader) (*Repo, error) {
 	r := &Repo{
 		local: false,
-		ncMap: newNewtCompatMap(),
 	}
 
 	if err := r.Init(repoName, rversreq, d); err != nil {
@@ -623,7 +624,6 @@ func NewRepo(repoName string, rversreq string, d downloader.Downloader) (*Repo,
 func NewLocalRepo(repoName string) (*Repo, error) {
 	r := &Repo{
 		local: true,
-		ncMap: newNewtCompatMap(),
 	}
 
 	if err := r.Init(repoName, "", nil); err != nil {


[07/23] incubator-mynewt-newt git commit: Fix to print correct pkg dependecy

Posted by cc...@apache.org.
Fix to print correct pkg dependecy


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

Branch: refs/heads/master
Commit: 437fbb55c542c9d147e34446644b78cc79dc8c21
Parents: 1193ecc
Author: Fabio Utzig <ut...@utzig.org>
Authored: Tue Mar 7 18:29:49 2017 -0300
Committer: Fabio Utzig <ut...@utzig.org>
Committed: Tue Mar 7 18:29:49 2017 -0300

----------------------------------------------------------------------
 newt/resolve/resolve.go | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/437fbb55/newt/resolve/resolve.go
----------------------------------------------------------------------
diff --git a/newt/resolve/resolve.go b/newt/resolve/resolve.go
index 283e96c..6e03592 100644
--- a/newt/resolve/resolve.go
+++ b/newt/resolve/resolve.go
@@ -131,12 +131,12 @@ func NewResolvePkg(lpkg *pkg.LocalPackage) *ResolvePackage {
 	}
 }
 
-func (r *Resolver) resolveDep(dep *pkg.Dependency) (*pkg.LocalPackage, error) {
+func (r *Resolver) resolveDep(dep *pkg.Dependency, depender string) (*pkg.LocalPackage, error) {
 	proj := project.GetProject()
 
 	if proj.ResolveDependency(dep) == nil {
 		return nil, util.FmtNewtError("Could not resolve package dependency: "+
-			"%s; depender: %s", dep.String(), dep.Name)
+			"%s; depender: %s", dep.String(), depender)
 	}
 	lpkg := proj.ResolveDependency(dep).(*pkg.LocalPackage)
 
@@ -284,13 +284,14 @@ func (r *Resolver) loadDepsForPkg(rpkg *ResolvePackage) (bool, error) {
 	changed := false
 	newDeps := newtutil.GetStringSliceFeatures(rpkg.Lpkg.PkgV, features,
 		"pkg.deps")
+	depender := rpkg.Lpkg.Name()
 	for _, newDepStr := range newDeps {
 		newDep, err := pkg.NewDependency(rpkg.Lpkg.Repo(), newDepStr)
 		if err != nil {
 			return false, err
 		}
 
-		lpkg, err := r.resolveDep(newDep)
+		lpkg, err := r.resolveDep(newDep, depender)
 		if err != nil {
 			return false, err
 		}


[19/23] incubator-mynewt-newt git commit: unixchild additions

Posted by cc...@apache.org.
unixchild additions

* User specifies socket accept timeout
* New error type indicating accept error
* Don't allow double start or stop


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

Branch: refs/heads/master
Commit: df674371e341eeb3761c734aa596cc37b6c67ef9
Parents: aa7aa13
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Mar 10 11:10:40 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Mar 30 20:23:55 2017 -0700

----------------------------------------------------------------------
 util/unixchild/unixchild.go | 160 +++++++++++++++++++++++++++++++--------
 1 file changed, 128 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/df674371/util/unixchild/unixchild.go
----------------------------------------------------------------------
diff --git a/util/unixchild/unixchild.go b/util/unixchild/unixchild.go
index bc311fc..b8be35d 100644
--- a/util/unixchild/unixchild.go
+++ b/util/unixchild/unixchild.go
@@ -22,7 +22,6 @@ package unixchild
 import (
 	"bufio"
 	"encoding/binary"
-	"errors"
 	"fmt"
 	"io"
 	"net"
@@ -35,38 +34,73 @@ import (
 	log "github.com/Sirupsen/logrus"
 )
 
+type UcAcceptError struct {
+	Text string
+}
+
+func (err *UcAcceptError) Error() string {
+	return err.Text
+}
+
+func NewUcAcceptError(text string) *UcAcceptError {
+	return &UcAcceptError{
+		Text: text,
+	}
+}
+
+func IsUcAcceptError(err error) bool {
+	_, ok := err.(*UcAcceptError)
+	return ok
+}
+
 type Config struct {
-	SockPath  string
-	ChildPath string
-	ChildArgs []string
-	Depth     int
-	MaxMsgSz  int
+	SockPath      string
+	ChildPath     string
+	ChildArgs     []string
+	Depth         int
+	MaxMsgSz      int
+	AcceptTimeout time.Duration
+	Restart       bool
 }
 
+type clientState uint32
+
+const (
+	CLIENT_STATE_STOPPED clientState = iota
+	CLIENT_STATE_STARTING
+	CLIENT_STATE_STARTED
+	CLIENT_STATE_STOPPING
+)
+
 type Client struct {
-	FromChild chan []byte
-	ToChild   chan []byte
-	ErrChild  chan error
-	childPath string
-	sockPath  string
-	childArgs []string
-	maxMsgSz  int
-	stopping  bool
-	stop      chan bool
-	stopped   chan bool
+	FromChild     chan []byte
+	ToChild       chan []byte
+	ErrChild      chan error
+	childPath     string
+	sockPath      string
+	childArgs     []string
+	maxMsgSz      int
+	acceptTimeout time.Duration
+	restart       bool
+	stop          chan bool
+	stopped       chan bool
+	state         clientState
+	stateMutex    sync.Mutex
 }
 
 func New(conf Config) *Client {
 	c := &Client{
-		childPath: conf.ChildPath,
-		sockPath:  conf.SockPath,
-		childArgs: conf.ChildArgs,
-		maxMsgSz:  conf.MaxMsgSz,
-		FromChild: make(chan []byte, conf.Depth),
-		ToChild:   make(chan []byte, conf.Depth),
-		ErrChild:  make(chan error),
-		stop:      make(chan bool),
-		stopped:   make(chan bool),
+		childPath:     conf.ChildPath,
+		sockPath:      conf.SockPath,
+		childArgs:     conf.ChildArgs,
+		maxMsgSz:      conf.MaxMsgSz,
+		FromChild:     make(chan []byte, conf.Depth),
+		ToChild:       make(chan []byte, conf.Depth),
+		ErrChild:      make(chan error),
+		acceptTimeout: conf.AcceptTimeout,
+		restart:       conf.Restart,
+		stop:          make(chan bool),
+		stopped:       make(chan bool),
 	}
 
 	if c.maxMsgSz == 0 {
@@ -76,6 +110,42 @@ func New(conf Config) *Client {
 	return c
 }
 
+func (c *Client) getState() clientState {
+	c.stateMutex.Lock()
+	defer c.stateMutex.Unlock()
+
+	return c.state
+}
+
+func (c *Client) setState(toState clientState) {
+	c.stateMutex.Lock()
+	defer c.stateMutex.Unlock()
+
+	c.state = toState
+}
+
+func (c *Client) setStateIf(toState clientState,
+	pred func(st clientState) bool) (bool, clientState) {
+
+	c.stateMutex.Lock()
+	defer c.stateMutex.Unlock()
+
+	if pred(c.state) {
+		c.state = toState
+		return true, toState
+	}
+
+	return false, c.state
+
+}
+
+func (c *Client) setStateFrom(fromState clientState,
+	toState clientState) (bool, clientState) {
+
+	return c.setStateIf(toState,
+		func(st clientState) bool { return st == fromState })
+}
+
 func (c *Client) startChild() (*exec.Cmd, error) {
 	subProcess := exec.Command(c.childPath, c.childArgs...)
 
@@ -179,10 +249,14 @@ func (c *Client) handleChild(con net.Conn) {
 }
 
 func (c *Client) Stop() {
-	if c.stopping {
+	ok, _ := c.setStateIf(CLIENT_STATE_STOPPING,
+		func(st clientState) bool {
+			return st != CLIENT_STATE_STOPPING
+		})
+	if !ok {
 		return
 	}
-	c.stopping = true
+
 	log.Debugf("Stopping client")
 
 	c.stop <- true
@@ -194,10 +268,24 @@ func (c *Client) Stop() {
 	}
 }
 
+func (c *Client) acceptDeadline() *time.Time {
+	if c.acceptTimeout == 0 {
+		return nil
+	}
+
+	t := time.Now().Add(c.acceptTimeout)
+	return &t
+}
+
 func (c *Client) Start() error {
+	ok, state := c.setStateFrom(CLIENT_STATE_STOPPED, CLIENT_STATE_STARTING)
+	if !ok {
+		return fmt.Errorf("client in invalid state for stating: %d", state)
+	}
 
 	l, err := net.Listen("unix", c.sockPath)
 	if err != nil {
+		c.setState(CLIENT_STATE_STOPPED)
 		return err
 	}
 
@@ -211,16 +299,21 @@ func (c *Client) Start() error {
 				log.Debugf("unixchild start error: %s", err.Error())
 				c.ErrChild <- fmt.Errorf("Child start error: %s", err.Error())
 			} else {
+				if t := c.acceptDeadline(); t != nil {
+					l.(*net.UnixListener).SetDeadline(*t)
+				}
 				fd, err := l.Accept()
 				if err != nil {
-					log.Debugf("unixchild accept error: %s", err.Error())
+					text := fmt.Sprintf("unixchild accept error: %s",
+						err.Error())
+					c.ErrChild <- NewUcAcceptError(text)
 				} else {
+					c.setState(CLIENT_STATE_STARTED)
 					c.handleChild(fd)
+					c.ErrChild <- fmt.Errorf("Child exited")
 				}
-				cmd.Process.Kill()
-				c.ErrChild <- errors.New("Child exited")
 			}
-			if c.stopping {
+			if c.getState() == CLIENT_STATE_STOPPING {
 				log.Debugf("unixchild exit loop")
 				return
 			}
@@ -231,10 +324,13 @@ func (c *Client) Start() error {
 	go func() {
 		select {
 		case <-c.stop:
-			l.Close()
+			if c.getState() == CLIENT_STATE_STARTED {
+				l.Close()
+			}
 			if cmd != nil {
 				cmd.Process.Kill()
 			}
+			log.Debugf("deleting socket")
 			os.Remove(c.sockPath)
 			c.stopped <- true
 		}


[22/23] incubator-mynewt-newt git commit: unixchild - Ensure socket gets deleted on stop.

Posted by cc...@apache.org.
unixchild - Ensure socket gets deleted on stop.


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

Branch: refs/heads/master
Commit: 9de7460f1fc510d724a507692abcd8e45f9e5f02
Parents: 74d8512
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Apr 3 16:48:20 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Apr 3 16:53:26 2017 -0700

----------------------------------------------------------------------
 util/unixchild/unixchild.go | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/9de7460f/util/unixchild/unixchild.go
----------------------------------------------------------------------
diff --git a/util/unixchild/unixchild.go b/util/unixchild/unixchild.go
index b417187..91930c0 100644
--- a/util/unixchild/unixchild.go
+++ b/util/unixchild/unixchild.go
@@ -219,6 +219,7 @@ func (c *Client) Stop() {
 
 	select {
 	case <-c.stopped:
+		c.deleteSocket()
 		c.state = CLIENT_STATE_STOPPED
 		log.Debugf("Stopped client")
 		return
@@ -246,6 +247,7 @@ func (c *Client) Start() error {
 
 	l, err := net.Listen("unix", c.sockPath)
 	if err != nil {
+		c.deleteSocket()
 		return err
 	}
 


[17/23] incubator-mynewt-newt git commit: This closes #53.

Posted by cc...@apache.org.
This closes #53.

Merge branch 'more-verbose-load' of https://github.com/utzig/incubator-mynewt-newt into develop


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

Branch: refs/heads/master
Commit: 9797af33e3b7f4b8e5cd53cc0677742780c98d45
Parents: eee86aa af48965
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Mar 22 14:24:48 2017 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Mar 22 14:24:48 2017 -0700

----------------------------------------------------------------------
 newt/builder/load.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------