You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/12/06 01:29:05 UTC

[2/2] incubator-mynewt-newt git commit: MYNEWT-504 newt - Verify repo isn't too old

MYNEWT-504 newt - Verify repo isn't too old

Check 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.  Verifying the opposite case would
require some larger changes.


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

Branch: refs/heads/develop
Commit: 8e6024c5a2144a508f1064f8a32facb50cc11051
Parents: 9b02be4
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Dec 5 17:27:59 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Dec 5 17:27:59 2016 -0800

----------------------------------------------------------------------
 newt/newtutil/newtutil.go | 17 ++++++++++++
 newt/repo/repo.go         | 59 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/8e6024c5/newt/newtutil/newtutil.go
----------------------------------------------------------------------
diff --git a/newt/newtutil/newtutil.go b/newt/newtutil/newtutil.go
index f10c9d5..2c433fd 100644
--- a/newt/newtutil/newtutil.go
+++ b/newt/newtutil/newtutil.go
@@ -39,6 +39,23 @@ var NewtBlinkyTag string = "develop"
 const NEWTRC_DIR string = ".newt"
 const REPOS_FILENAME string = "repos.yml"
 
+const CORE_REPO_NAME string = "apache-mynewt-core"
+
+type RepoCommitEntry struct {
+	Version string
+	Hash    string
+}
+
+// A warning is displayed if newt requires a newer version of a repo.
+var RepoMinCommits = map[string]*RepoCommitEntry{
+	// Newt no longer invokes the shell for external commands.  Some YAML files
+	// in core had to be fixed to accommodate this change.
+	CORE_REPO_NAME: &RepoCommitEntry{
+		Version: "develop",
+		Hash:    "5c5a987ef72ae9b3eb682f19d7d0bdc85f7e500c",
+	},
+}
+
 // Contains general newt settings read from $HOME/.newt
 var newtrc *viper.Viper
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/8e6024c5/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 25c0d94..83ff137 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -31,6 +31,7 @@ import (
 
 	"mynewt.apache.org/newt/newt/downloader"
 	"mynewt.apache.org/newt/newt/interfaces"
+	"mynewt.apache.org/newt/newt/newtutil"
 	"mynewt.apache.org/newt/util"
 	"mynewt.apache.org/newt/viper"
 )
@@ -51,6 +52,10 @@ 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
 }
 
 type RepoDesc struct {
@@ -551,6 +556,44 @@ func (r *Repo) ReadDesc() (*RepoDesc, []*Repo, error) {
 	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",
+		"rev-list",
+		r.minCommit.Hash + "..HEAD",
+	}
+
+	o, err := util.ShellCommand(cmd, nil)
+	if err != nil {
+		return false, util.ChildNewtError(err)
+	}
+
+	if len(o) == 0 {
+		// No output means the commit does not exist in the current branch.
+		return false, nil
+	}
+
+	return true, nil
+}
+
 func (r *Repo) Init(repoName string, rversreq string, d downloader.Downloader) error {
 	var err error
 
@@ -568,6 +611,22 @@ func (r *Repo) Init(repoName string, rversreq string, d downloader.Downloader) e
 		r.localPath = filepath.Clean(path)
 	} else {
 		r.localPath = filepath.Clean(path + "/" + REPOS_DIR + "/" + r.name)
+		r.minCommit = newtutil.RepoMinCommits[repoName]
+
+		upToDate, err := r.HasMinCommit()
+		if err != nil {
+			return err
+		}
+
+		if !upToDate {
+			util.StatusMessage(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",
+				r.name, r.minCommit.Version, r.minCommit.Hash)
+		}
 	}
 
 	return nil