You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/10/16 16:29:13 UTC

[GitHub] michal-narajowski closed pull request #219: Check newt compatibility on install/upgrade and other commands

michal-narajowski closed pull request #219: Check newt compatibility on install/upgrade and other commands
URL: https://github.com/apache/mynewt-newt/pull/219
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/newt/install/install.go b/newt/install/install.go
index c5fa0e8d..ce32349d 100644
--- a/newt/install/install.go
+++ b/newt/install/install.go
@@ -125,6 +125,7 @@ import (
 	"mynewt.apache.org/newt/newt/newtutil"
 	"mynewt.apache.org/newt/newt/repo"
 	"mynewt.apache.org/newt/util"
+	"mynewt.apache.org/newt/newt/compat"
 )
 
 type installOp int
@@ -735,6 +736,29 @@ func verifyRepoDirtyState(repos []*repo.Repo, force bool) error {
 		}
 	}
 
+	return nil
+
+}
+
+func verifyNewtCompat(repos []*repo.Repo, vm deprepo.VersionMap) error {
+	var errors []string
+
+	for _, r := range repos {
+		destVer := vm[r.Name()]
+		code, msg := r.CheckNewtCompatibility(destVer, newtutil.NewtVersion)
+
+		switch code {
+		case compat.NEWT_COMPAT_WARN:
+			util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s\n", msg)
+		case compat.NEWT_COMPAT_ERROR:
+			errors = append(errors, msg)
+		}
+	}
+
+	if errors != nil {
+		return util.NewNewtError(strings.Join(errors, "\n"))
+	}
+
 	return nil
 }
 
@@ -772,6 +796,10 @@ func (inst *Installer) Install(
 		return err
 	}
 
+	if err := verifyNewtCompat(repos, vm); err != nil {
+		return err
+	}
+
 	// For a forced install, delete all existing repos.
 	if force {
 		for _, r := range repos {
@@ -835,6 +863,10 @@ func (inst *Installer) Upgrade(candidates []*repo.Repo, force bool,
 		return err
 	}
 
+	if err := verifyNewtCompat(repos, vm); err != nil {
+		return err
+	}
+
 	// Upgrade each repo in the version map.
 	for _, r := range repos {
 		destVer := vm[r.Name()]
diff --git a/newt/project/project.go b/newt/project/project.go
index fb29d374..99ad3bd1 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -366,22 +366,6 @@ func (proj *Project) loadRepo(name string, fields map[string]string) (
 		return r, err
 	}
 
-	// Warn the user about incompatibilities with this version of newt.
-	ver, err := proj.GetRepoVersion(name)
-	if err != nil {
-		return nil, err
-	}
-	if ver != nil {
-		code, msg := r.CheckNewtCompatibility(*ver, newtutil.NewtVersion)
-		switch code {
-		case compat.NEWT_COMPAT_GOOD:
-		case compat.NEWT_COMPAT_WARN:
-			util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s.\n", msg)
-		case compat.NEWT_COMPAT_ERROR:
-			return nil, util.NewNewtError(msg)
-		}
-	}
-
 	// XXX: This log message assumes a "github" type repo.
 	log.Debugf("Loaded repository %s (type: %s, user: %s, repo: %s)", name,
 		fields["type"], fields["user"], fields["repo"])
@@ -491,6 +475,40 @@ func (proj *Project) downloadRepositoryYmlFiles() error {
 	return nil
 }
 
+func (proj *Project) verifyNewtCompat() error {
+	var errors []string
+
+	for name, r := range proj.repos {
+		// If a repo doesn't have a downloader then it is
+		// a project root that is not a repository
+		if r.Downloader() == nil {
+			continue
+		}
+
+		ver, err := proj.GetRepoVersion(name)
+		if err != nil {
+			return err
+		}
+
+		if ver != nil {
+			code, msg := r.CheckNewtCompatibility(*ver, newtutil.NewtVersion)
+			switch code {
+			case compat.NEWT_COMPAT_GOOD:
+			case compat.NEWT_COMPAT_WARN:
+				util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s.\n", msg)
+			case compat.NEWT_COMPAT_ERROR:
+				errors = append(errors, msg)
+			}
+		}
+	}
+
+	if errors != nil {
+		return util.NewNewtError(strings.Join(errors, "\n"))
+	}
+
+	return nil
+}
+
 func (proj *Project) loadConfig() error {
 	yc, err := newtutil.ReadConfig(proj.BasePath,
 		strings.TrimSuffix(PROJECT_FILE_NAME, ".yml"))
@@ -543,6 +561,11 @@ func (proj *Project) loadConfig() error {
 		return err
 	}
 
+	// Warn the user about incompatibilities with this version of newt.
+	if err := proj.verifyNewtCompat(); err != nil {
+		return err
+	}
+
 	ignoreDirs := yc.GetValStringSlice("project.ignore_dirs", nil)
 	for _, ignDir := range ignoreDirs {
 		repoName, dirName, err := newtutil.ParsePackageString(ignDir)
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index da381e7c..15d8f1bd 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -102,6 +102,10 @@ func (r *Repo) ignoreDir(dir string) bool {
 	return false
 }
 
+func (r *Repo) Downloader() downloader.Downloader {
+	return r.downloader
+}
+
 func (repo *Repo) FilteredSearchList(
 	curPath string, searchedMap map[string]struct{}) ([]string, error) {
 
diff --git a/newt/repo/version.go b/newt/repo/version.go
index d4ead9aa..ae00f7c5 100644
--- a/newt/repo/version.go
+++ b/newt/repo/version.go
@@ -76,6 +76,12 @@ func normalizeCommit(commit string) string {
 // Retrieves the repo's currently checked-out hash.
 func (r *Repo) CurrentHash() (string, error) {
 	dl := r.downloader
+	if dl == nil {
+		return "",
+			util.FmtNewtError("No downloader for %s",
+				r.Name())
+	}
+
 	commit, err := dl.HashFor(r.Path(), "HEAD")
 	if err != nil {
 		return "",


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services