ccollins476ad closed pull request #107: newt - Only validate package name once
URL: https://github.com/apache/mynewt-newt/pull/107
 
 
   

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/cli/target_cmds.go b/newt/cli/target_cmds.go
index 96690b8..5a29df4 100644
--- a/newt/cli/target_cmds.go
+++ b/newt/cli/target_cmds.go
@@ -667,6 +667,8 @@ func targetConfigShowCmd(cmd *cobra.Command, args []string) 
{
                        util.NewNewtError("Must specify target or unittest 
name"))
        }
 
+       TryGetProject()
+
        for _, arg := range args {
                b, err := TargetBuilderForTargetOrUnittest(arg)
                if err != nil {
@@ -691,6 +693,8 @@ func targetConfigInitCmd(cmd *cobra.Command, args []string) 
{
                exists bool
        }
 
+       TryGetProject()
+
        anyExist := false
        entries := make([]entry, len(args))
        for i, pkgName := range args {
@@ -863,7 +867,6 @@ func AddTargetCommands(cmd *cobra.Command) {
        targetCmd.AddCommand(showCmd)
        AddTabCompleteFn(showCmd, targetList)
 
-
        cmakeHelpText := "Generate CMakeLists.txt for target specified " +
                "by <target-name>."
        cmakeHelpEx := "  newt target cmake <target-name>\n"
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 7919a06..efc6cd7 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -294,6 +294,17 @@ func (pkg *LocalPackage) Save() error {
        return nil
 }
 
+func matchNamePath(name, path string) bool {
+       // assure that name and path use the same path separator...
+       names := filepath.SplitList(name)
+       name = filepath.Join(names...)
+
+       if strings.HasSuffix(path, name) {
+               return true
+       }
+       return false
+}
+
 // Load reads everything that isn't identity specific into the package
 func (pkg *LocalPackage) Load() error {
        // Load configuration
@@ -316,6 +327,12 @@ func (pkg *LocalPackage) Load() error {
                        pkg.basePath)
        }
 
+       if !matchNamePath(pkg.name, pkg.basePath) {
+               return util.FmtNewtError(
+                       "Package \"%s\" has incorrect \"pkg.name\" field in its 
"+
+                               "`pkg.yml` file (pkg.name=%s)", pkg.basePath, 
pkg.name)
+       }
+
        typeString := pkg.PkgV.GetString("pkg.type")
        pkg.packageType = PACKAGE_TYPE_LIB
        for t, n := range PackageTypeNames {
diff --git a/newt/project/project.go b/newt/project/project.go
index 6cc858b..f26c97a 100644
--- a/newt/project/project.go
+++ b/newt/project/project.go
@@ -601,42 +601,20 @@ func (proj *Project) Init(dir string) error {
        return nil
 }
 
-func matchNamePath(name, path string) bool {
-       // assure that name and path use the same path separator...
-       names := filepath.SplitList(name)
-       name = filepath.Join(names...)
-
-       if strings.HasSuffix(path, name) {
-               return true
-       }
-       return false
-}
-
 func (proj *Project) ResolveDependency(dep interfaces.DependencyInterface) 
interfaces.PackageInterface {
        type NamePath struct {
                name string
                path string
        }
 
-       var errorPkgs []NamePath
        for _, pkgList := range proj.packages {
                for _, pkg := range *pkgList {
-                       name := pkg.Name()
-                       path := pkg.BasePath()
-                       if !matchNamePath(name, path) {
-                               errorPkgs = append(errorPkgs, NamePath{name: 
name, path: path})
-                       }
                        if dep.SatisfiesDependency(pkg) {
                                return pkg
                        }
                }
        }
 
-       for _, namepath := range errorPkgs {
-               util.StatusMessage(util.VERBOSITY_VERBOSE,
-                       "Package name \"%s\" doesn't match path \"%s\"\n", 
namepath.name, namepath.path)
-       }
-
        return nil
 }
 


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to