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 2018/11/19 18:22:32 UTC
[mynewt-newt] 01/03: Move `OneTimeWarning()` to util package
This is an automated email from the ASF dual-hosted git repository.
ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
commit 0934cdf5a99545e593e6d81b1eeb6b3bce8ad6e8
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Nov 7 17:16:37 2018 -0800
Move `OneTimeWarning()` to util package
This function used to be in the newtutil package. Keeping it in
newtutil leads to circular dependency issues: ycfg needs OneTimeWarning,
but newtutil requires ycfg.
---
newt/downloader/downloader.go | 3 +--
newt/install/install.go | 8 ++++----
newt/newtutil/newtutil.go | 22 ++++------------------
newt/project/project.go | 4 ++--
newt/repo/version.go | 6 +++---
newt/syscfg/restrict.go | 4 ++--
util/util.go | 15 +++++++++++++++
7 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index 02f54fa..60c2bd6 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -30,7 +30,6 @@ import (
log "github.com/Sirupsen/logrus"
- "mynewt.apache.org/newt/newt/newtutil"
"mynewt.apache.org/newt/newt/settings"
"mynewt.apache.org/newt/util"
)
@@ -421,7 +420,7 @@ func setRemoteUrl(path string, remote string, url string, logCmd bool) error {
}
func warnWrongOriginUrl(path string, curUrl string, goodUrl string) {
- newtutil.OneTimeWarning(
+ util.OneTimeWarning(
"Repo's \"origin\" remote points to unexpected URL: "+
"%s; correcting it to %s. Repo contents may be incorrect.",
curUrl, goodUrl)
diff --git a/newt/install/install.go b/newt/install/install.go
index 7f3d0d5..f09054f 100644
--- a/newt/install/install.go
+++ b/newt/install/install.go
@@ -157,7 +157,7 @@ func detectVersion(r *repo.Repo) (newtutil.RepoVersion, error) {
Commit: commit,
}
- newtutil.OneTimeWarning(
+ util.OneTimeWarning(
"Could not detect version of installed repo \"%s\"; assuming %s",
r.Name(), ver.String())
}
@@ -292,7 +292,7 @@ func (inst *Installer) inferReqVers(repos []*repo.Repo) error {
}
if ver == nil {
- newtutil.OneTimeWarning(
+ util.OneTimeWarning(
"Could not detect version of requested repo "+
"%s:%s; assuming 0.0.0",
r.Name(), req.Ver.Commit)
@@ -732,7 +732,7 @@ func verifyRepoDirtyState(repos []*repo.Repo, force bool) error {
s += "Specify the `-f` (force) switch to attempt anyway"
return util.NewNewtError(s)
} else {
- newtutil.OneTimeWarning("%s", s)
+ util.OneTimeWarning("%s", s)
}
}
@@ -749,7 +749,7 @@ func verifyNewtCompat(repos []*repo.Repo, vm deprepo.VersionMap) error {
switch code {
case compat.NEWT_COMPAT_WARN:
- newtutil.OneTimeWarning("%s", msg)
+ util.OneTimeWarning("%s", msg)
case compat.NEWT_COMPAT_ERROR:
errors = append(errors, msg)
}
diff --git a/newt/newtutil/newtutil.go b/newt/newtutil/newtutil.go
index c377bf3..96795cd 100644
--- a/newt/newtutil/newtutil.go
+++ b/newt/newtutil/newtutil.go
@@ -178,17 +178,17 @@ func MakeTempRepoDir() (string, error) {
func ReadConfigPath(path string) (ycfg.YCfg, error) {
file, err := ioutil.ReadFile(path)
if err != nil {
- return nil, util.NewNewtError(fmt.Sprintf("Error reading %s: %s",
- path, err.Error()))
+ return ycfg.YCfg{}, util.FmtNewtError("Error reading %s: %s",
+ path, err.Error())
}
settings := map[string]interface{}{}
if err := yaml.Unmarshal(file, &settings); err != nil {
- return nil, util.FmtNewtError("Failure parsing \"%s\": %s",
+ return ycfg.YCfg{}, util.FmtNewtError("Failure parsing \"%s\": %s",
path, err.Error())
}
- return ycfg.NewYCfg(settings)
+ return ycfg.NewYCfg(path, settings)
}
// Read in the configuration file specified by name, in path
@@ -201,17 +201,3 @@ func ReadConfig(dir string, filename string) (ycfg.YCfg, error) {
func YCfgToYaml(yc ycfg.YCfg) string {
return yaml.MapToYaml(yc.AllSettings())
}
-
-// Keeps track of warnings that have already been reported.
-// [warning-text] => struct{}
-var warnings = map[string]struct{}{}
-
-// Displays the specified warning if it has not been displayed yet.
-func OneTimeWarning(text string, args ...interface{}) {
- if _, ok := warnings[text]; !ok {
- warnings[text] = struct{}{}
-
- body := fmt.Sprintf(text, args...)
- util.StatusMessage(util.VERBOSITY_QUIET, "WARNING: %s\n", body)
- }
-}
diff --git a/newt/project/project.go b/newt/project/project.go
index 34adc7b..2de2aec 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -392,7 +392,7 @@ func (proj *Project) checkNewtVer() error {
case compat.NEWT_COMPAT_GOOD:
return nil
case compat.NEWT_COMPAT_WARN:
- newtutil.OneTimeWarning("%s", msg)
+ util.OneTimeWarning("%s", msg)
return nil
case compat.NEWT_COMPAT_ERROR:
return util.NewNewtError(msg)
@@ -496,7 +496,7 @@ func (proj *Project) verifyNewtCompat() error {
switch code {
case compat.NEWT_COMPAT_GOOD:
case compat.NEWT_COMPAT_WARN:
- newtutil.OneTimeWarning("%s", msg)
+ util.OneTimeWarning("%s", msg)
case compat.NEWT_COMPAT_ERROR:
errors = append(errors, msg)
}
diff --git a/newt/repo/version.go b/newt/repo/version.go
index d8dbfa2..89ecfac 100644
--- a/newt/repo/version.go
+++ b/newt/repo/version.go
@@ -392,7 +392,7 @@ func (r *Repo) inferVersion(commit string, vyVer *newtutil.RepoVersion) (
}
}
- newtutil.OneTimeWarning(
+ util.OneTimeWarning(
"Version mismatch in %s:%s; repository.yml:%s, version.yml:%s",
r.Name(), commit, versString(ryVers), vyVer.String())
} else {
@@ -463,11 +463,11 @@ func (r *Repo) NonInstalledVersion(
if ver == nil {
if versionYmlErr == versionYmlMissing {
- newtutil.OneTimeWarning(
+ util.OneTimeWarning(
"%s:%s does not contain a `version.yml` file.",
r.Name(), commit)
} else if versionYmlErr == versionYmlBad {
- newtutil.OneTimeWarning(
+ util.OneTimeWarning(
"%s:%s contains a malformed `version.yml` file.",
r.Name(), commit)
}
diff --git a/newt/syscfg/restrict.go b/newt/syscfg/restrict.go
index fe1ca83..ebfbffd 100644
--- a/newt/syscfg/restrict.go
+++ b/newt/syscfg/restrict.go
@@ -59,8 +59,8 @@ import (
log "github.com/Sirupsen/logrus"
- "mynewt.apache.org/newt/newt/newtutil"
"mynewt.apache.org/newt/newt/parse"
+ "mynewt.apache.org/newt/util"
)
type CfgRestrictionCode int
@@ -201,7 +201,7 @@ func (cfg *Cfg) restrictionMet(
val, err := parse.ParseAndEval(expr, settings)
if err != nil {
- newtutil.OneTimeWarning(
+ util.OneTimeWarning(
"Ignoring illegal expression for setting \"%s\": "+
"`%s` %s\n", r.BaseSetting, r.Expr, err.Error())
return true
diff --git a/util/util.go b/util/util.go
index d3abfc3..fa9098b 100644
--- a/util/util.go
+++ b/util/util.go
@@ -713,3 +713,18 @@ func FileContains(contents []byte, path string) (bool, error) {
rc := bytes.Compare(oldSrc, contents)
return rc == 0, nil
}
+
+// Keeps track of warnings that have already been reported.
+// [warning-text] => struct{}
+var warnings = map[string]struct{}{}
+
+// Displays the specified warning if it has not been displayed yet.
+func OneTimeWarning(text string, args ...interface{}) {
+ body := fmt.Sprintf(text, args...)
+ if _, ok := warnings[body]; !ok {
+ warnings[body] = struct{}{}
+
+ body := fmt.Sprintf(text, args...)
+ StatusMessage(VERBOSITY_QUIET, "WARNING: %s\n", body)
+ }
+}