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/11/03 19:15:19 UTC
incubator-mynewt-newt git commit: newt - continue parsing yaml files
on syntax err
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop 8bc10df34 -> fe7be9fe5
newt - continue parsing yaml files on syntax err
Newt now warns about bad files, but proceeds to parse files.
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/fe7be9fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/fe7be9fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/fe7be9fe
Branch: refs/heads/develop
Commit: fe7be9fe50c8451dcea6d5ab134a137ab324a91b
Parents: 8bc10df
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Nov 3 12:14:28 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Nov 3 12:15:11 2016 -0700
----------------------------------------------------------------------
newt/cli/build_cmds.go | 25 ++------
newt/cli/image_cmds.go | 5 +-
newt/cli/mfg_cmds.go | 6 +-
newt/cli/project_cmds.go | 20 ++-----
newt/cli/run_cmds.go | 5 +-
newt/cli/target_cmds.go | 27 ++-------
newt/cli/util.go | 15 +++++
newt/cli/vars.go | 6 +-
newt/newt.go | 5 --
newt/pkg/localpackage.go | 62 ++++++++++++--------
newt/project/project.go | 13 +++-
newt/vendor/mynewt.apache.org/newt/util/util.go | 17 ++++--
util/util.go | 24 ++++----
13 files changed, 109 insertions(+), 121 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/newt/cli/build_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/build_cmds.go b/newt/cli/build_cmds.go
index 50f77c0..e688d16 100644
--- a/newt/cli/build_cmds.go
+++ b/newt/cli/build_cmds.go
@@ -106,9 +106,7 @@ func buildRunCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, nil)
}
- if _, err := project.TryGetProject(); err != nil {
- NewtUsage(nil, err)
- }
+ InitProject()
// Verify and resolve each specified package.
targets, all, err := ResolveTargetsOrAll(args...)
@@ -175,9 +173,7 @@ func cleanRunCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- if _, err := project.TryGetProject(); err != nil {
- NewtUsage(nil, err)
- }
+ InitProject()
cleanAll := false
targets := []*target.Target{}
@@ -217,10 +213,7 @@ func testRunCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, nil)
}
- proj, err := project.TryGetProject()
- if err != nil {
- NewtUsage(nil, err)
- }
+ proj := InitProject()
// Verify and resolve each specified package.
testAll := false
@@ -328,9 +321,7 @@ func loadRunCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- if _, err := project.TryGetProject(); err != nil {
- NewtUsage(nil, err)
- }
+ InitProject()
t := ResolveTarget(args[0])
if t == nil {
@@ -352,9 +343,7 @@ func debugRunCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- if _, err := project.TryGetProject(); err != nil {
- NewtUsage(nil, err)
- }
+ InitProject()
t := ResolveTarget(args[0])
if t == nil {
@@ -376,9 +365,7 @@ func sizeRunCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- if _, err := project.TryGetProject(); err != nil {
- NewtUsage(nil, err)
- }
+ InitProject()
t := ResolveTarget(args[0])
if t == nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/newt/cli/image_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/image_cmds.go b/newt/cli/image_cmds.go
index 36e481b..dac2fc2 100644
--- a/newt/cli/image_cmds.go
+++ b/newt/cli/image_cmds.go
@@ -24,7 +24,6 @@ import (
"github.com/spf13/cobra"
"mynewt.apache.org/newt/newt/builder"
- "mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
)
@@ -36,9 +35,7 @@ func createImageRunCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, util.NewNewtError("Must specify target and version"))
}
- if _, err := project.TryGetProject(); err != nil {
- NewtUsage(nil, err)
- }
+ InitProject()
targetName := args[0]
t := ResolveTarget(targetName)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/newt/cli/mfg_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/mfg_cmds.go b/newt/cli/mfg_cmds.go
index c306b45..78a2299 100644
--- a/newt/cli/mfg_cmds.go
+++ b/newt/cli/mfg_cmds.go
@@ -24,15 +24,11 @@ import (
"mynewt.apache.org/newt/newt/mfg"
"mynewt.apache.org/newt/newt/pkg"
- "mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
)
func ResolveMfgPkg(pkgName string) (*pkg.LocalPackage, error) {
- proj, err := project.TryGetProject()
- if err != nil {
- return nil, err
- }
+ proj := InitProject()
lpkg, err := proj.ResolvePackage(proj.LocalRepo(), pkgName)
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/newt/cli/project_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/project_cmds.go b/newt/cli/project_cmds.go
index e1377a8..7c0d268 100644
--- a/newt/cli/project_cmds.go
+++ b/newt/cli/project_cmds.go
@@ -75,10 +75,7 @@ func newRunCmd(cmd *cobra.Command, args []string) {
}
func installRunCmd(cmd *cobra.Command, args []string) {
- proj, err := project.TryGetProject()
- if err != nil {
- NewtUsage(nil, err)
- }
+ proj := InitProject()
interfaces.SetProject(proj)
if err := proj.Install(false, projectForce); err != nil {
@@ -87,10 +84,7 @@ func installRunCmd(cmd *cobra.Command, args []string) {
}
func upgradeRunCmd(cmd *cobra.Command, args []string) {
- proj, err := project.TryGetProject()
- if err != nil {
- NewtUsage(nil, err)
- }
+ proj := InitProject()
interfaces.SetProject(proj)
if err := proj.Upgrade(projectForce); err != nil {
@@ -104,10 +98,7 @@ func infoRunCmd(cmd *cobra.Command, args []string) {
reqRepoName = strings.TrimPrefix(args[0], "@")
}
- proj, err := project.TryGetProject()
- if err != nil {
- NewtUsage(nil, err)
- }
+ proj := InitProject()
repoNames := []string{}
for repoName, _ := range proj.PackageList() {
@@ -160,10 +151,7 @@ func infoRunCmd(cmd *cobra.Command, args []string) {
}
func syncRunCmd(cmd *cobra.Command, args []string) {
- proj, err := project.TryGetProject()
- if err != nil {
- NewtUsage(nil, err)
- }
+ proj := InitProject()
repos := proj.Repos()
ps, err := project.LoadProjectState()
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/newt/cli/run_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/run_cmds.go b/newt/cli/run_cmds.go
index 22164a7..ee72e87 100644
--- a/newt/cli/run_cmds.go
+++ b/newt/cli/run_cmds.go
@@ -24,7 +24,6 @@ import (
"github.com/spf13/cobra"
"mynewt.apache.org/newt/newt/builder"
- "mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
)
@@ -33,9 +32,7 @@ func runRunCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
- if _, err := project.TryGetProject(); err != nil {
- NewtUsage(nil, err)
- }
+ InitProject()
t := ResolveTarget(args[0])
if t == nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/newt/cli/target_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go
index a91647e..bb82f32 100644
--- a/newt/cli/target_cmds.go
+++ b/newt/cli/target_cmds.go
@@ -32,7 +32,6 @@ import (
"github.com/spf13/cobra"
"mynewt.apache.org/newt/newt/builder"
"mynewt.apache.org/newt/newt/pkg"
- "mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/newt/syscfg"
"mynewt.apache.org/newt/newt/target"
"mynewt.apache.org/newt/util"
@@ -85,9 +84,7 @@ func pkgVarSliceString(pack *pkg.LocalPackage, key string) string {
}
func targetShowCmd(cmd *cobra.Command, args []string) {
- if _, err := project.TryGetProject(); err != nil {
- NewtUsage(nil, err)
- }
+ InitProject()
targetNames := []string{}
if len(args) == 0 {
for name, _ := range target.GetTargets() {
@@ -196,9 +193,7 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
"(target-name & k=v) to set"))
}
- if _, err := project.TryGetProject(); err != nil {
- NewtUsage(nil, err)
- }
+ InitProject()
// Parse target name.
t, err := resolveExistingTargetArg(args[0])
@@ -278,10 +273,7 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, util.NewNewtError("Missing target name"))
}
- proj, err := project.TryGetProject()
- if err != nil {
- NewtUsage(nil, err)
- }
+ proj := InitProject()
pkgName, err := ResolveNewTargetName(args[0])
if err != nil {
@@ -339,9 +331,7 @@ func targetDelCmd(cmd *cobra.Command, args []string) {
"target to delete"))
}
- if _, err := project.TryGetProject(); err != nil {
- NewtUsage(nil, err)
- }
+ InitProject()
targets, err := ResolveTargets(args...)
if err != nil {
@@ -361,10 +351,7 @@ func targetCopyCmd(cmd *cobra.Command, args []string) {
"source target and one destination target"))
}
- proj, err := project.TryGetProject()
- if err != nil {
- NewtUsage(nil, err)
- }
+ proj := InitProject()
srcTarget, err := resolveExistingTargetArg(args[0])
if err != nil {
@@ -471,9 +458,7 @@ func targetConfigCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, util.NewNewtError("Must specify target name"))
}
- if _, err := project.TryGetProject(); err != nil {
- NewtUsage(nil, err)
- }
+ InitProject()
t, err := resolveExistingTargetArg(args[0])
if err != nil {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/newt/cli/util.go
----------------------------------------------------------------------
diff --git a/newt/cli/util.go b/newt/cli/util.go
index 31bd5b9..46ee9b0 100644
--- a/newt/cli/util.go
+++ b/newt/cli/util.go
@@ -197,3 +197,18 @@ func ResetGlobalState() error {
return nil
}
+
+func InitProject() *project.Project {
+ var p *project.Project
+ var err error
+
+ if p, err = project.TryGetProject(); err != nil {
+ NewtUsage(nil, err)
+ }
+
+ for _, w := range p.Warnings() {
+ util.ErrorMessage(util.VERBOSITY_QUIET, "* Warning: %s\n", w)
+ }
+
+ return p
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/newt/cli/vars.go
----------------------------------------------------------------------
diff --git a/newt/cli/vars.go b/newt/cli/vars.go
index 91fe4f4..f741b59 100644
--- a/newt/cli/vars.go
+++ b/newt/cli/vars.go
@@ -25,13 +25,15 @@ import (
"sort"
"strings"
- . "mynewt.apache.org/newt/newt/interfaces"
+ "mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
)
-func varsFromPackageType(pt PackageType, fullPath bool) ([]string, error) {
+func varsFromPackageType(
+ pt interfaces.PackageType, fullPath bool) ([]string, error) {
+
values := []string{}
packs := project.GetProject().PackagesOfType(pt)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index 6135aca..64fa13c 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -116,10 +116,6 @@ func newtCmd() *cobra.Command {
func main() {
cmd := newtCmd()
- /* some of the setup code logs which messes with autocomplete */
- hold_lvl := log.GetLevel()
- log.SetLevel(log.FatalLevel)
-
cli.AddBuildCommands(cmd)
cli.AddCompleteCommands(cmd)
cli.AddImageCommands(cmd)
@@ -147,6 +143,5 @@ func main() {
cmd.SilenceUsage = false
}
- log.SetLevel(hold_lvl)
cmd.Execute()
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 3e8e325..d984a73 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -401,11 +401,13 @@ func LocalPackageSpecialName(dirName string) bool {
func ReadLocalPackageRecursive(repo *repo.Repo,
pkgList map[string]interfaces.PackageInterface, basePath string,
- pkgName string) error {
+ pkgName string) ([]string, error) {
+
+ var warnings []string
dirList, err := repo.FilteredSearchList(pkgName)
if err != nil {
- return util.NewNewtError(err.Error())
+ return warnings, util.NewNewtError(err.Error())
}
for _, name := range dirList {
@@ -413,41 +415,52 @@ func ReadLocalPackageRecursive(repo *repo.Repo,
continue
}
- if err := ReadLocalPackageRecursive(repo, pkgList, basePath,
- filepath.Join(pkgName, name)); err != nil {
- return err
+ subWarnings, err := ReadLocalPackageRecursive(repo, pkgList,
+ basePath, filepath.Join(pkgName, name))
+ warnings = append(warnings, subWarnings...)
+ if err != nil {
+ return warnings, err
}
}
- if util.NodeNotExist(filepath.Join(basePath, pkgName, PACKAGE_FILE_NAME)) {
- return nil
+ if util.NodeNotExist(filepath.Join(basePath, pkgName,
+ PACKAGE_FILE_NAME)) {
+
+ return warnings, nil
}
pkg, err := LoadLocalPackage(repo, filepath.Join(basePath, pkgName))
if err != nil {
- return err
+ warnings = append(warnings, err.Error())
+ return warnings, nil
}
if oldPkg, ok := pkgList[pkg.Name()]; ok {
oldlPkg := oldPkg.(*LocalPackage)
- return util.FmtNewtError("Multiple packages with same pkg.name=%s "+
- "in repo %s; path1=%s path2=%s", oldlPkg.Name(), repo.Name(),
- oldlPkg.BasePath(), pkg.BasePath())
+ warnings = append(warnings,
+ fmt.Sprintf("Multiple packages with same pkg.name=%s "+
+ "in repo %s; path1=%s path2=%s", oldlPkg.Name(), repo.Name(),
+ oldlPkg.BasePath(), pkg.BasePath()))
+
+ return warnings, nil
}
pkgList[pkg.Name()] = pkg
- return nil
+ return warnings, nil
}
-func ReadLocalPackages(repo *repo.Repo,
- basePath string) (*map[string]interfaces.PackageInterface, error) {
+func ReadLocalPackages(repo *repo.Repo, basePath string) (
+ pkgMap *map[string]interfaces.PackageInterface,
+ warnings []string,
+ err error) {
- pkgList := map[string]interfaces.PackageInterface{}
+ pkgMap = &map[string]interfaces.PackageInterface{}
+ warnings = []string{}
searchPaths, err := repo.FilteredSearchList("")
if err != nil {
- return nil, err
+ return
}
for _, path := range searchPaths {
@@ -457,18 +470,21 @@ func ReadLocalPackages(repo *repo.Repo,
continue
}
- dirList, err := repo.FilteredSearchList(path)
- if err != nil {
- return nil, util.NewNewtError(err.Error())
+ var dirList []string
+ if dirList, err = repo.FilteredSearchList(path); err != nil {
+ return
}
for _, subDir := range dirList {
- if err := ReadLocalPackageRecursive(repo, pkgList, basePath,
- filepath.Join(path, subDir)); err != nil {
- return nil, err
+ var subWarnings []string
+ subWarnings, err = ReadLocalPackageRecursive(repo, *pkgMap,
+ basePath, filepath.Join(path, subDir))
+ warnings = append(warnings, subWarnings...)
+ if err != nil {
+ return
}
}
}
- return &pkgList, nil
+ return
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/newt/project/project.go
----------------------------------------------------------------------
diff --git a/newt/project/project.go b/newt/project/project.go
index 857bcfb..95ee367 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -58,7 +58,8 @@ type Project struct {
projState *ProjectState
// Repositories configured on this project
- repos map[string]*repo.Repo
+ repos map[string]*repo.Repo
+ warnings []string
localRepo *repo.Repo
@@ -156,6 +157,10 @@ func (proj *Project) LocalRepo() *repo.Repo {
return proj.localRepo
}
+func (proj *Project) Warnings() []string {
+ return proj.warnings
+}
+
func (proj *Project) upgradeCheck(r *repo.Repo, vers *repo.Version,
force bool) (bool, error) {
rdesc, err := r.GetRepoDesc()
@@ -578,12 +583,14 @@ func (proj *Project) loadPackageList() error {
// packages / store them in the project package list.
repos := proj.Repos()
for name, repo := range repos {
- list, err := pkg.ReadLocalPackages(repo, repo.Path())
+ list, warnings, err := pkg.ReadLocalPackages(repo, repo.Path())
if err != nil {
return err
+ } else {
+ proj.packages[name] = list
}
- proj.packages[name] = list
+ proj.warnings = append(proj.warnings, warnings...)
}
return nil
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/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 d43f709..21c67bb 100644
--- a/newt/vendor/mynewt.apache.org/newt/util/util.go
+++ b/newt/vendor/mynewt.apache.org/newt/util/util.go
@@ -105,11 +105,13 @@ func ChildNewtError(parent error) *NewtError {
}
// Print Silent, Quiet and Verbose aware status messages to stdout.
-func StatusMessage(level int, message string, args ...interface{}) {
+func WriteMessage(f *os.File, level int, message string,
+ args ...interface{}) {
+
if Verbosity >= level {
str := fmt.Sprintf(message, args...)
- os.Stdout.WriteString(str)
- os.Stdout.Sync()
+ f.WriteString(str)
+ f.Sync()
if logFile != nil {
logFile.WriteString(str)
@@ -117,11 +119,14 @@ func StatusMessage(level int, message string, args ...interface{}) {
}
}
+// Print Silent, Quiet and Verbose aware status messages to stdout.
+func StatusMessage(level int, message string, args ...interface{}) {
+ WriteMessage(os.Stdout, level, message, args...)
+}
+
// Print Silent, Quiet and Verbose aware status messages to stderr.
func ErrorMessage(level int, message string, args ...interface{}) {
- if Verbosity >= level {
- fmt.Fprintf(os.Stderr, message, args...)
- }
+ WriteMessage(os.Stderr, level, message, args...)
}
func NodeExist(path string) bool {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/fe7be9fe/util/util.go
----------------------------------------------------------------------
diff --git a/util/util.go b/util/util.go
index 56cb5c0..21c67bb 100644
--- a/util/util.go
+++ b/util/util.go
@@ -105,11 +105,13 @@ func ChildNewtError(parent error) *NewtError {
}
// Print Silent, Quiet and Verbose aware status messages to stdout.
-func StatusMessage(level int, message string, args ...interface{}) {
+func WriteMessage(f *os.File, level int, message string,
+ args ...interface{}) {
+
if Verbosity >= level {
str := fmt.Sprintf(message, args...)
- os.Stdout.WriteString(str)
- os.Stdout.Sync()
+ f.WriteString(str)
+ f.Sync()
if logFile != nil {
logFile.WriteString(str)
@@ -117,11 +119,14 @@ func StatusMessage(level int, message string, args ...interface{}) {
}
}
+// Print Silent, Quiet and Verbose aware status messages to stdout.
+func StatusMessage(level int, message string, args ...interface{}) {
+ WriteMessage(os.Stdout, level, message, args...)
+}
+
// Print Silent, Quiet and Verbose aware status messages to stderr.
func ErrorMessage(level int, message string, args ...interface{}) {
- if Verbosity >= level {
- fmt.Fprintf(os.Stderr, message, args...)
- }
+ WriteMessage(os.Stderr, level, message, args...)
}
func NodeExist(path string) bool {
@@ -384,13 +389,6 @@ func CopyFile(srcFile string, dstFile string) error {
return ChildNewtError(err)
}
- if err := in.Close(); err != nil {
- return err
- }
- if err := out.Close(); err != nil {
- return err
- }
-
return nil
}