mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject incubator-mynewt-newt git commit: newt - Allow "install" from local machine
Date Tue, 15 Nov 2016 02:40:10 GMT
Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop 00ec2a349 -> 496fc3327


newt - Allow "install" from local machine

This commit is to aid in testing of unreleased version of Mynewt.

Prior to his change, newt needed to clone a repo in order to determine
which branch or tag it should check out.

Now, a project.yml file can specify a repo type of "local".  When
installing from a local repo, newt assumes an up-to-date clone exists at
the specified path, so it just copies the directory rather than cloning
with git.

Example local repo (project.yml):

    repository.apache-mynewt-core:
        type: local
        vers: 0-latest
        path: "/Users/ccollins/repos/tmp/core"


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

Branch: refs/heads/develop
Commit: 496fc3327f8e5a8d028c356c769164d5fe30ff53
Parents: 00ec2a3
Author: Christopher Collins <ccollins@apache.org>
Authored: Mon Nov 14 18:35:24 2016 -0800
Committer: Christopher Collins <ccollins@apache.org>
Committed: Mon Nov 14 18:35:24 2016 -0800

----------------------------------------------------------------------
 newt/downloader/downloader.go | 85 ++++++++++++++++++++++++++++++++++++++
 newt/project/project.go       | 33 ++-------------
 newt/repo/repo.go             | 15 +++----
 3 files changed, 95 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/496fc332/newt/downloader/downloader.go
----------------------------------------------------------------------
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index 7cf1892..29c0677 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -30,6 +30,7 @@ import (
 
 	log "github.com/Sirupsen/logrus"
 
+	"mynewt.apache.org/newt/newt/newtutil"
 	"mynewt.apache.org/newt/util"
 )
 
@@ -57,6 +58,13 @@ type GithubDownloader struct {
 	Password string
 }
 
+type LocalDownloader struct {
+	GenericDownloader
+
+	// Path to parent directory of repository.yml file.
+	Path string
+}
+
 func (gd *GenericDownloader) Branch() string {
 	return gd.branch
 }
@@ -194,3 +202,80 @@ func (gd *GithubDownloader) DownloadRepo(commit string) (string, error)
{
 func NewGithubDownloader() *GithubDownloader {
 	return &GithubDownloader{}
 }
+
+func (ld *LocalDownloader) FetchFile(name string, dest string) error {
+	srcPath := ld.Path + "/" + name
+
+	log.Debugf("Fetching file %s to %s", srcPath, dest)
+	if err := util.CopyFile(srcPath, dest); err != nil {
+		return err
+	}
+
+	return nil
+}
+
+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")
+	if err != nil {
+		return "", err
+	}
+
+	util.StatusMessage(util.VERBOSITY_VERBOSE,
+		"Downloading local repository %s\n", ld.Path)
+
+	if err := util.CopyDir(ld.Path, tmpdir); err != nil {
+		return "", err
+	}
+
+	return tmpdir, nil
+}
+
+func NewLocalDownloader() *LocalDownloader {
+	return &LocalDownloader{}
+}
+
+func LoadDownloader(repoName string, repoVars map[string]string) (
+	Downloader, error) {
+
+	switch repoVars["type"] {
+	case "github":
+		gd := NewGithubDownloader()
+
+		gd.User = repoVars["user"]
+		gd.Repo = repoVars["repo"]
+
+		// The project.yml file can contain github access tokens and
+		// authentication credentials, but this file is probably world-readable
+		// and therefore not a great place for this.
+		gd.Token = repoVars["token"]
+		gd.Login = repoVars["login"]
+		gd.Password = repoVars["password"]
+
+		// Alternatively, the user can put security material in
+		// $HOME/.newt/repos.yml.
+		newtrc := newtutil.Newtrc()
+		privRepo := newtrc.GetStringMapString("repository." + repoName)
+		if privRepo != nil {
+			if gd.Token == "" {
+				gd.Token = privRepo["token"]
+			}
+			if gd.Login == "" {
+				gd.Login = privRepo["login"]
+			}
+			if gd.Password == "" {
+				gd.Password = privRepo["password"]
+			}
+		}
+		return gd, nil
+
+	case "local":
+		ld := NewLocalDownloader()
+		ld.Path = repoVars["path"]
+		return ld, nil
+
+	default:
+		return nil, util.FmtNewtError("Invalid repository type: %s",
+			repoVars["type"])
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/496fc332/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index e9c38ad..e7fe60d 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -383,38 +383,13 @@ func (proj *Project) loadRepo(rname string, v *viper.Viper) error {
 		return util.NewNewtError(fmt.Sprintf("Missing type for repository " +
 			rname))
 	}
-	if repoVars["type"] != "github" {
-		return util.NewNewtError("Only github repositories are currently supported.")
-	}
-	rversreq := repoVars["vers"]
 
-	dl := downloader.NewGithubDownloader()
-	dl.User = repoVars["user"]
-	dl.Repo = repoVars["repo"]
-
-	// The project.yml file can contain github access tokens and authentication
-	// credentials, but this file is probably world-readable and therefore not
-	// a great place for this.
-	dl.Token = repoVars["token"]
-	dl.Login = repoVars["login"]
-	dl.Password = repoVars["password"]
-
-	// Alternatively, the user can put security material in
-	// $HOME/.newt/repos.yml.
-	newtrc := newtutil.Newtrc()
-	privRepo := newtrc.GetStringMapString("repository." + rname)
-	if privRepo != nil {
-		if dl.Token == "" {
-			dl.Token = privRepo["token"]
-		}
-		if dl.Login == "" {
-			dl.Login = privRepo["login"]
-		}
-		if dl.Password == "" {
-			dl.Password = privRepo["password"]
-		}
+	dl, err := downloader.LoadDownloader(rname, repoVars)
+	if err != nil {
+		return err
 	}
 
+	rversreq := repoVars["vers"]
 	r, err := repo.NewRepo(rname, rversreq, dl)
 	if err != nil {
 		return err

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/496fc332/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 369e4ba..159c66d 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -27,6 +27,7 @@ import (
 	"strings"
 
 	log "github.com/Sirupsen/logrus"
+	"github.com/spf13/cast"
 
 	"mynewt.apache.org/newt/newt/downloader"
 	"mynewt.apache.org/newt/newt/interfaces"
@@ -469,17 +470,14 @@ func (r *Repo) readDepRepos(v *viper.Viper) ([]*Repo, error) {
 
 	repoList := v.GetStringMap(repoTag)
 	for repoName, repoItf := range repoList {
-		repoVars := repoItf.(map[interface{}]interface{})
+		repoVars := cast.ToStringMapString(repoItf)
 
-		if repoVars["type"] != "github" {
-			return nil, util.NewNewtError("Only github repositories are currently supported.")
+		dl, err := downloader.LoadDownloader(repoName, repoVars)
+		if err != nil {
+			return nil, err
 		}
 
-		rversreq := repoVars["vers"].(string)
-		dl := downloader.NewGithubDownloader()
-		dl.User = repoVars["user"].(string)
-		dl.Repo = repoVars["repo"].(string)
-
+		rversreq := repoVars["vers"]
 		newRepo, err := NewRepo(repoName, rversreq, dl)
 		if err != nil {
 			return nil, err
@@ -495,7 +493,6 @@ func (r *Repo) readDepRepos(v *viper.Viper) ([]*Repo, error) {
 
 		repos = append(repos, newRepo)
 	}
-
 	return repos, nil
 }
 


Mime
View raw message