pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint Updated pkglint to 5.4.10.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/33211b2ec45c
branches:  trunk
changeset: 354553:33211b2ec45c
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Tue Nov 01 21:40:25 2016 +0000

description:
Updated pkglint to 5.4.10.

Changes since 5.4.9:

* Check for mismatch between conditional and unconditional includes
  of other files (mostly depending on PKG_OPTIONS or OPSYS)
* Check that PLIST files contain "man" instead of "${PKGMANDIR}"

diffstat:

 pkgtools/pkglint/Makefile              |   5 +-
 pkgtools/pkglint/files/mkline.go       |  72 ++++++++++++++++++++++++---------
 pkgtools/pkglint/files/mkline_test.go  |  40 ++++++++++++++++++
 pkgtools/pkglint/files/mklines.go      |   3 +
 pkgtools/pkglint/files/mklines_test.go |  41 +++++++++++++++++++
 pkgtools/pkglint/files/package.go      |  59 +++++++++++++++++++++------
 pkgtools/pkglint/files/package_test.go |  44 ++++++++++++++++++++
 pkgtools/pkglint/files/pkglint.go      |  21 ++++-----
 pkgtools/pkglint/files/plist.go        |   8 +++
 pkgtools/pkglint/files/plist_test.go   |  36 ++++++++++++++++-
 10 files changed, 280 insertions(+), 49 deletions(-)

diffs (truncated from 518 to 300 lines):

diff -r 86e4787f9432 -r 33211b2ec45c pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Tue Nov 01 20:44:22 2016 +0000
+++ b/pkgtools/pkglint/Makefile Tue Nov 01 21:40:25 2016 +0000
@@ -1,7 +1,6 @@
-# $NetBSD: Makefile,v 1.498 2016/10/29 08:59:48 bsiegert Exp $
+# $NetBSD: Makefile,v 1.499 2016/11/01 21:40:25 rillig Exp $
 
-PKGNAME=       pkglint-5.4.9.1
-PKGREVISION=   1
+PKGNAME=       pkglint-5.4.10
 DISTFILES=     # none
 CATEGORIES=    pkgtools
 
diff -r 86e4787f9432 -r 33211b2ec45c pkgtools/pkglint/files/mkline.go
--- a/pkgtools/pkglint/files/mkline.go  Tue Nov 01 20:44:22 2016 +0000
+++ b/pkgtools/pkglint/files/mkline.go  Tue Nov 01 21:40:25 2016 +0000
@@ -34,9 +34,10 @@
        args      string
 }
 type mkLineInclude struct {
-       mustexist   bool
-       indent      string
-       includeFile string
+       mustexist     bool
+       indent        string
+       includeFile   string
+       conditionVars string // (filled in later)
 }
 type mkLineDependency struct {
        targets string
@@ -119,13 +120,13 @@
 
        if m, indent, directive, includefile := match3(text, reMkInclude); m {
                mkline.xtype = 6
-               mkline.data = mkLineInclude{directive == "include", indent, includefile}
+               mkline.data = mkLineInclude{directive == "include", indent, includefile, ""}
                return
        }
 
        if m, indent, directive, includefile := match3(text, `^\.(\s*)(s?include)\s+<([^>]+)>\s*(?:#.*)?$`); m {
                mkline.xtype = 7
-               mkline.data = mkLineInclude{directive == "include", indent, includefile}
+               mkline.data = mkLineInclude{directive == "include", indent, includefile, ""}
                return
        }
 
@@ -208,7 +209,7 @@
        }
 
        if mkline.Indent() != "" {
-               mkline.checkDirectiveIndentation()
+               mkline.checkDirectiveIndentation(G.Mk.indentation.Depth())
        }
 
        includefile := mkline.Includefile()
@@ -260,7 +261,7 @@
        indentation := &G.Mk.indentation
 
        switch directive {
-       case "endif", "endfor", "elif", "else":
+       case "endif", "endfor":
                if indentation.Len() > 1 {
                        indentation.Pop()
                } else {
@@ -268,12 +269,15 @@
                }
        }
 
-       mkline.checkDirectiveIndentation()
+       expectedDepth := indentation.Depth()
+       if directive == "elif" || directive == "else" {
+               expectedDepth = indentation.depth[len(indentation.depth)-2]
+       }
+       mkline.checkDirectiveIndentation(expectedDepth)
 
        if directive == "if" && matches(args, `^!defined\([\w]+_MK\)$`) {
                indentation.Push(indentation.Depth())
-
-       } else if matches(directive, `^(?:if|ifdef|ifndef|for|elif|else)$`) {
+       } else if matches(directive, `^(?:if|ifdef|ifndef|for)$`) {
                indentation.Push(indentation.Depth() + 2)
        }
 
@@ -340,15 +344,14 @@
        }
 }
 
-func (mkline *MkLine) checkDirectiveIndentation() {
+func (mkline *MkLine) checkDirectiveIndentation(expectedDepth int) {
        if G.Mk == nil {
                return
        }
        indent := mkline.Indent()
-       indentation := G.Mk.indentation
-       if expected := strings.Repeat(" ", indentation.Depth()); indent != expected {
+       if expected := strings.Repeat(" ", expectedDepth); indent != expected {
                if G.opts.WarnSpace && !mkline.Line.AutofixReplace("."+indent, "."+expected) {
-                       mkline.Line.Notef("This directive should be indented by %d spaces.", indentation.Depth())
+                       mkline.Line.Notef("This directive should be indented by %d spaces.", expectedDepth)
                }
        }
 }
@@ -1671,8 +1674,8 @@
 }
 
 type Indentation struct {
-       depth         []int             // Number of space characters; always a multiple of 2
-       conditionVars []map[string]bool // Variables on which the current path depends
+       depth         []int      // Number of space characters; always a multiple of 2
+       conditionVars [][]string // Variables on which the current path depends
 }
 
 func (ind *Indentation) Len() int {
@@ -1696,17 +1699,46 @@
 
 func (ind *Indentation) AddVar(varname string) {
        level := ind.Len() - 1
-       if ind.conditionVars[level] == nil {
-               ind.conditionVars[level] = make(map[string]bool)
+       if hasSuffix(varname, "_MK") {
+               return
        }
-       ind.conditionVars[level][varname] = true
+       for _, existingVarname := range ind.conditionVars[level] {
+               if varname == existingVarname {
+                       return
+               }
+       }
+
+       ind.conditionVars[level] = append(ind.conditionVars[level], varname)
 }
 
 func (ind *Indentation) DependsOn(varname string) bool {
+       for _, levelVarnames := range ind.conditionVars {
+               for _, levelVarname := range levelVarnames {
+                       if varname == levelVarname {
+                               return true
+                       }
+               }
+       }
+       return false
+}
+
+func (ind *Indentation) IsConditional() bool {
        for _, vars := range ind.conditionVars {
-               if vars[varname] {
+               if len(vars) > 0 {
                        return true
                }
        }
        return false
 }
+
+func (ind *Indentation) Varnames() string {
+       sep := ""
+       varnames := ""
+       for _, levelVarnames := range ind.conditionVars {
+               for _, levelVarname := range levelVarnames {
+                       varnames += sep + levelVarname
+                       sep = ", "
+               }
+       }
+       return varnames
+}
diff -r 86e4787f9432 -r 33211b2ec45c pkgtools/pkglint/files/mkline_test.go
--- a/pkgtools/pkglint/files/mkline_test.go     Tue Nov 01 20:44:22 2016 +0000
+++ b/pkgtools/pkglint/files/mkline_test.go     Tue Nov 01 21:40:25 2016 +0000
@@ -858,3 +858,43 @@
                "WARN: Makefile:2: Unknown compiler flag \"-bs\".\n"+
                "WARN: Makefile:2: Compiler flag \"%s\\\\\\\"\" should start with a hyphen.\n")
 }
+
+func (s *Suite) Test_Indentation(c *check.C) {
+       ind := &Indentation{}
+
+       ind.Push(0)
+
+       c.Check(ind.Depth(), equals, 0)
+       c.Check(ind.DependsOn("VARNAME"), equals, false)
+
+       ind.Push(2)
+
+       c.Check(ind.Depth(), equals, 2)
+
+       ind.AddVar("LEVEL1.VAR1")
+
+       c.Check(ind.Varnames(), equals, "LEVEL1.VAR1")
+
+       ind.AddVar("LEVEL1.VAR2")
+
+       c.Check(ind.Varnames(), equals, "LEVEL1.VAR1, LEVEL1.VAR2")
+       c.Check(ind.DependsOn("LEVEL1.VAR1"), equals, true)
+       c.Check(ind.DependsOn("OTHER_VAR"), equals, false)
+
+       ind.Push(2)
+
+       ind.AddVar("LEVEL2.VAR")
+
+       c.Check(ind.Varnames(), equals, "LEVEL1.VAR1, LEVEL1.VAR2, LEVEL2.VAR")
+
+       ind.Pop()
+
+       c.Check(ind.Varnames(), equals, "LEVEL1.VAR1, LEVEL1.VAR2")
+       c.Check(ind.IsConditional(), equals, true)
+
+       ind.Pop()
+
+       c.Check(ind.Varnames(), equals, "")
+       c.Check(ind.IsConditional(), equals, false)
+
+}
diff -r 86e4787f9432 -r 33211b2ec45c pkgtools/pkglint/files/mklines.go
--- a/pkgtools/pkglint/files/mklines.go Tue Nov 01 20:44:22 2016 +0000
+++ b/pkgtools/pkglint/files/mklines.go Tue Nov 01 21:40:25 2016 +0000
@@ -123,6 +123,9 @@
                        case "bsd.prefs.mk", "bsd.fast.prefs.mk", "bsd.builtin.mk":
                                mklines.setSeenBsdPrefsMk()
                        }
+                       if G.Pkg != nil {
+                               G.Pkg.CheckInclude(mkline, indentation)
+                       }
 
                case mkline.IsCond():
                        mkline.checkCond(mklines.forVars)
diff -r 86e4787f9432 -r 33211b2ec45c pkgtools/pkglint/files/mklines_test.go
--- a/pkgtools/pkglint/files/mklines_test.go    Tue Nov 01 20:44:22 2016 +0000
+++ b/pkgtools/pkglint/files/mklines_test.go    Tue Nov 01 21:40:25 2016 +0000
@@ -413,3 +413,44 @@
 
        c.Check(s.Output(), equals, "")
 }
+
+func (s *Suite) Test_MkLines_Check_indentation(c *check.C) {
+       s.UseCommandLine(c, "-Wall")
+       mklines := s.NewMkLines("options.mk",
+               mkrcsid,
+               ". if !defined(GUARD_MK)",
+               ". if ${OPSYS} == ${OPSYS}",
+               ".   for i in ${FILES}",
+               ".     if !defined(GUARD2_MK)",
+               ".     else",
+               ".     endif",
+               ".   endfor",
+               ".   if ${COND1}",
+               ".   elif ${COND2}",
+               ".   else ${COND3}",
+               ".   endif",
+               ". endif",
+               ". endif",
+               ". endif")
+
+       mklines.Check()
+
+       c.Check(s.Output(), equals, ""+
+               "NOTE: options.mk:2: This directive should be indented by 0 spaces.\n"+
+               "NOTE: options.mk:3: This directive should be indented by 0 spaces.\n"+
+               "NOTE: options.mk:4: This directive should be indented by 2 spaces.\n"+
+               "NOTE: options.mk:5: This directive should be indented by 4 spaces.\n"+
+               "NOTE: options.mk:6: This directive should be indented by 4 spaces.\n"+
+               "NOTE: options.mk:7: This directive should be indented by 4 spaces.\n"+
+               "NOTE: options.mk:8: This directive should be indented by 2 spaces.\n"+
+               "NOTE: options.mk:9: This directive should be indented by 2 spaces.\n"+
+               "NOTE: options.mk:10: This directive should be indented by 2 spaces.\n"+
+               "NOTE: options.mk:11: This directive should be indented by 2 spaces.\n"+
+               "ERROR: options.mk:11: \".else\" does not take arguments.\n"+
+               "NOTE: options.mk:11: If you meant \"else if\", use \".elif\".\n"+
+               "NOTE: options.mk:12: This directive should be indented by 2 spaces.\n"+
+               "NOTE: options.mk:13: This directive should be indented by 0 spaces.\n"+
+               "NOTE: options.mk:14: This directive should be indented by 0 spaces.\n"+
+               "ERROR: options.mk:15: Unmatched .endif.\n"+
+               "NOTE: options.mk:15: This directive should be indented by 0 spaces.\n")
+}
diff -r 86e4787f9432 -r 33211b2ec45c pkgtools/pkglint/files/package.go
--- a/pkgtools/pkglint/files/package.go Tue Nov 01 20:44:22 2016 +0000
+++ b/pkgtools/pkglint/files/package.go Tue Nov 01 21:40:25 2016 +0000
@@ -22,24 +22,28 @@
        EffectivePkgnameLine *MkLine // The origin of the three effective_* values
        SeenBsdPrefsMk       bool    // Has bsd.prefs.mk already been included?
 
-       vardef             map[string]*MkLine // (varname, varcanon) => line
-       varuse             map[string]*MkLine // (varname, varcanon) => line
-       bl3                map[string]*Line   // buildlink3.mk name => line; contains only buildlink3.mk files that are directly included.
-       plistSubstCond     map[string]bool    // varname => true; list of all variables that are used as conditionals (@comment or nothing) in PLISTs.
-       included           map[string]*Line   // fname => line
-       seenMakefileCommon bool               // Does the package have any .includes?
-       loadTimeTools      map[string]bool    // true=ok, false=not ok, absent=not mentioned in USE_TOOLS.
+       vardef                map[string]*MkLine // (varname, varcanon) => line
+       varuse                map[string]*MkLine // (varname, varcanon) => line
+       bl3                   map[string]*Line   // buildlink3.mk name => line; contains only buildlink3.mk files that are directly included.
+       plistSubstCond        map[string]bool    // varname => true; list of all variables that are used as conditionals (@comment or nothing) in PLISTs.
+       included              map[string]*Line   // fname => line
+       seenMakefileCommon    bool               // Does the package have any .includes?
+       loadTimeTools         map[string]bool    // true=ok, false=not ok, absent=not mentioned in USE_TOOLS.
+       conditionalIncludes   map[string]*MkLine
+       unconditionalIncludes map[string]*MkLine
 }
 
 func NewPackage(pkgpath string) *Package {
        pkg := &Package{
-               Pkgpath:        pkgpath,



Home | Main Index | Thread Index | Old Index