pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint Update pkglint to 5.5.10.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/fa284fdb48e5
branches:  trunk
changeset: 379515:fa284fdb48e5
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Tue May 01 23:30:11 2018 +0000

description:
Update pkglint to 5.5.10.

Changes since 5.5.9:

* Fix wrong pkglint behavior for .include lines that are guarded by
  corresponding .if exists(...)
* A little bit of refactoring, as always.

diffstat:

 pkgtools/pkglint/Makefile               |   4 +-
 pkgtools/pkglint/files/mkline.go        |  31 +++++++++++++-
 pkgtools/pkglint/files/mkline_test.go   |   5 +-
 pkgtools/pkglint/files/mklinechecker.go |  24 ++++-------
 pkgtools/pkglint/files/mklines.go       |   4 +-
 pkgtools/pkglint/files/mklines_test.go  |   4 +-
 pkgtools/pkglint/files/package.go       |  33 ++++++++++++++-
 pkgtools/pkglint/files/package_test.go  |  69 +++++++++++++++++++++++++++++++++
 pkgtools/pkglint/files/pkglint.go       |   2 +-
 pkgtools/pkglint/files/pkglint_test.go  |  16 +++---
 pkgtools/pkglint/files/pkgsrc.go        |  44 ++++++++++-----------
 pkgtools/pkglint/files/pkgsrc_test.go   |   6 +-
 pkgtools/pkglint/files/vardefs.go       |   2 +-
 13 files changed, 180 insertions(+), 64 deletions(-)

diffs (truncated from 611 to 300 lines):

diff -r 9fe8e9bef18a -r fa284fdb48e5 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Tue May 01 21:20:45 2018 +0000
+++ b/pkgtools/pkglint/Makefile Tue May 01 23:30:11 2018 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.536 2018/04/28 23:32:52 rillig Exp $
+# $NetBSD: Makefile,v 1.537 2018/05/01 23:30:11 rillig Exp $
 
-PKGNAME=       pkglint-5.5.9
+PKGNAME=       pkglint-5.5.10
 DISTFILES=     # none
 CATEGORIES=    pkgtools
 
diff -r 9fe8e9bef18a -r fa284fdb48e5 pkgtools/pkglint/files/mkline.go
--- a/pkgtools/pkglint/files/mkline.go  Tue May 01 21:20:45 2018 +0000
+++ b/pkgtools/pkglint/files/mkline.go  Tue May 01 23:30:11 2018 +0000
@@ -724,19 +724,28 @@
 }
 
 // Indentation remembers the stack of preprocessing directives and their
-// indentation.  By convention, each directive is indented by 2 spaces.
+// indentation. By convention, each directive is indented by 2 spaces.
 // An excepting are multiple-inclusion guards, they don't increase the
 // indentation.
 type Indentation struct {
        depth         []int      // Number of space characters; always a multiple of 2
        conditionVars [][]string // Variables on which the current path depends
+
+       // Files whose existence has been checked in a related path.
+       // The check counts for both the "if" and the "else" branch,
+       // but that sloppiness will be discovered by functional tests.
+       checkedFiles [][]string
 }
 
 func (ind *Indentation) Len() int {
        return len(ind.depth)
 }
 
-func (ind *Indentation) Depth() int {
+func (ind *Indentation) Depth(directive string) int {
+       switch directive {
+       case "elif", "else", "endfor", "endif":
+               return ind.depth[imax(0, len(ind.depth)-2)]
+       }
        return ind.depth[len(ind.depth)-1]
 }
 
@@ -744,11 +753,13 @@
        newlen := ind.Len() - 1
        ind.depth = ind.depth[:newlen]
        ind.conditionVars = ind.conditionVars[:newlen]
+       ind.checkedFiles = ind.checkedFiles[:newlen]
 }
 
 func (ind *Indentation) Push(indent int) {
        ind.depth = append(ind.depth, indent)
        ind.conditionVars = append(ind.conditionVars, nil)
+       ind.checkedFiles = append(ind.checkedFiles, nil)
 }
 
 func (ind *Indentation) AddVar(varname string) {
@@ -797,6 +808,22 @@
        return varnames
 }
 
+func (ind *Indentation) AddCheckedFile(filename string) {
+       level := ind.Len() - 1
+       ind.checkedFiles[level] = append(ind.checkedFiles[level], filename)
+}
+
+func (ind *Indentation) IsCheckedFile(filename string) bool {
+       for _, levelFilenames := range ind.checkedFiles {
+               for _, levelFilename := range levelFilenames {
+                       if filename == levelFilename {
+                               return true
+                       }
+               }
+       }
+       return false
+}
+
 func MatchVarassign(text string) (m, commented bool, varname, spaceAfterVarname, op, valueAlign, value, spaceAfterValue, comment string) {
        i, n := 0, len(text)
 
diff -r 9fe8e9bef18a -r fa284fdb48e5 pkgtools/pkglint/files/mkline_test.go
--- a/pkgtools/pkglint/files/mkline_test.go     Tue May 01 21:20:45 2018 +0000
+++ b/pkgtools/pkglint/files/mkline_test.go     Tue May 01 23:30:11 2018 +0000
@@ -850,12 +850,13 @@
 
        ind.Push(0)
 
-       c.Check(ind.Depth(), equals, 0)
+       c.Check(ind.Depth("if"), equals, 0)
        c.Check(ind.DependsOn("VARNAME"), equals, false)
 
        ind.Push(2)
 
-       c.Check(ind.Depth(), equals, 2)
+       c.Check(ind.Depth("if"), equals, 2)
+       c.Check(ind.Depth("endfor"), equals, 0)
 
        ind.AddVar("LEVEL1.VAR1")
 
diff -r 9fe8e9bef18a -r fa284fdb48e5 pkgtools/pkglint/files/mklinechecker.go
--- a/pkgtools/pkglint/files/mklinechecker.go   Tue May 01 21:20:45 2018 +0000
+++ b/pkgtools/pkglint/files/mklinechecker.go   Tue May 01 23:30:11 2018 +0000
@@ -46,7 +46,7 @@
 
        mkline := ck.MkLine
        if mkline.Indent() != "" {
-               ck.checkDirectiveIndentation(G.Mk.indentation.Depth())
+               ck.checkDirectiveIndentation(G.Mk.indentation.Depth("include"))
        }
 
        includefile := mkline.Includefile()
@@ -98,8 +98,14 @@
        directive := mkline.Directive()
        args := mkline.Args()
 
-       switch directive {
-       case "endif", "endfor":
+       expectedDepth := indentation.Depth(directive)
+       ck.checkDirectiveIndentation(expectedDepth)
+
+       if directive == "if" && matches(args, `^!defined\([\w]+_MK\)$`) {
+               indentation.Push(indentation.Depth(directive))
+       } else if matches(directive, `^(?:if|ifdef|ifndef|for)$`) {
+               indentation.Push(indentation.Depth(directive) + 2)
+       } else if directive == "endfor" || directive == "endif" {
                if indentation.Len() > 1 {
                        indentation.Pop()
                } else {
@@ -107,18 +113,6 @@
                }
        }
 
-       expectedDepth := indentation.Depth()
-       if directive == "elif" || directive == "else" {
-               expectedDepth = indentation.depth[len(indentation.depth)-2]
-       }
-       ck.checkDirectiveIndentation(expectedDepth)
-
-       if directive == "if" && matches(args, `^!defined\([\w]+_MK\)$`) {
-               indentation.Push(indentation.Depth())
-       } else if matches(directive, `^(?:if|ifdef|ifndef|for)$`) {
-               indentation.Push(indentation.Depth() + 2)
-       }
-
        needsArgument := matches(directive, `^(?:if|ifdef|ifndef|elif|for|undef)$`)
        if needsArgument != (args != "") {
                if needsArgument {
diff -r 9fe8e9bef18a -r fa284fdb48e5 pkgtools/pkglint/files/mklines.go
--- a/pkgtools/pkglint/files/mklines.go Tue May 01 21:20:45 2018 +0000
+++ b/pkgtools/pkglint/files/mklines.go Tue May 01 23:30:11 2018 +0000
@@ -134,8 +134,8 @@
 
        ChecklinesTrailingEmptyLines(mklines.lines)
 
-       if indentation.Len() != 1 && indentation.Depth() != 0 {
-               lastMkline.Errorf("Directive indentation is not 0, but %d.", indentation.Depth())
+       if indentation.Len() != 1 && indentation.Depth("") != 0 {
+               lastMkline.Errorf("Directive indentation is not 0, but %d.", indentation.Depth(""))
        }
 
        SaveAutofixChanges(mklines.lines)
diff -r 9fe8e9bef18a -r fa284fdb48e5 pkgtools/pkglint/files/mklines_test.go
--- a/pkgtools/pkglint/files/mklines_test.go    Tue May 01 21:20:45 2018 +0000
+++ b/pkgtools/pkglint/files/mklines_test.go    Tue May 01 23:30:11 2018 +0000
@@ -414,8 +414,8 @@
                "NOTE: options.mk:12: This directive should be indented by 2 spaces.",
                "NOTE: options.mk:13: This directive should be indented by 0 spaces.",
                "NOTE: options.mk:14: This directive should be indented by 0 spaces.",
-               "ERROR: options.mk:15: Unmatched .endif.",
-               "NOTE: options.mk:15: This directive should be indented by 0 spaces.")
+               "NOTE: options.mk:15: This directive should be indented by 0 spaces.",
+               "ERROR: options.mk:15: Unmatched .endif.")
 }
 
 // Demonstrates how to define your own make(1) targets.
diff -r 9fe8e9bef18a -r fa284fdb48e5 pkgtools/pkglint/files/package.go
--- a/pkgtools/pkglint/files/package.go Tue May 01 21:20:45 2018 +0000
+++ b/pkgtools/pkglint/files/package.go Tue May 01 23:30:11 2018 +0000
@@ -286,6 +286,28 @@
                allLines.mklines = append(allLines.mklines, mkline)
                allLines.lines = append(allLines.lines, mkline.Line)
 
+               if mkline.IsCond() {
+                       ind := &fileMklines.indentation
+                       switch mkline.Directive() {
+                       case "if", "ifdef", "ifndef", "for":
+                               ind.Push(0) // Dummy indentation, only the checkedFiles are interesting
+                       case "endfor", "endif":
+                               if ind.Len() > 1 {
+                                       ind.Pop()
+                               }
+                       }
+
+                       if mkline.Directive() == "if" {
+                               args := mkline.Args()
+                               if contains(args, "exists") {
+                                       cond := NewMkParser(mkline.Line, args, false).MkCond()
+                                       cond.Visit("exists", func(node *Tree) {
+                                               ind.AddCheckedFile(node.args[0].(string))
+                                       })
+                               }
+                       }
+               }
+
                var includeFile, incDir, incBase string
                if mkline.IsInclude() {
                        inc := mkline.Includefile()
@@ -334,7 +356,11 @@
                                // current file and in the current working directory.
                                // Pkglint doesn't have an include dir list, like make(1) does.
                                if !fileExists(dirname + "/" + includeFile) {
-                                       if dirname != G.CurrentDir { // Prevent unnecessary syscalls
+
+                                       if fileMklines.indentation.IsCheckedFile(includeFile) {
+                                               continue // See https://github.com/rillig/pkglint/issues/1
+
+                                       } else if dirname != G.CurrentDir { // Prevent unnecessary syscalls
                                                dirname = G.CurrentDir
                                                if !fileExists(dirname + "/" + includeFile) {
                                                        mkline.Errorf("Cannot read %q.", dirname+"/"+includeFile)
@@ -346,8 +372,9 @@
                                if trace.Tracing {
                                        trace.Step1("Including %q.", dirname+"/"+includeFile)
                                }
-                               includingFname := ifelseStr(incBase == "Makefile.common" && incDir != "", fname, "")
-                               if !pkg.readMakefile(dirname+"/"+includeFile, mainLines, allLines, includingFname) {
+                               absIncluding := ifelseStr(incBase == "Makefile.common" && incDir != "", fname, "")
+                               absIncluded := dirname + "/" + includeFile
+                               if !pkg.readMakefile(absIncluded, mainLines, allLines, absIncluding) {
                                        return false
                                }
                        }
diff -r 9fe8e9bef18a -r fa284fdb48e5 pkgtools/pkglint/files/package_test.go
--- a/pkgtools/pkglint/files/package_test.go    Tue May 01 21:20:45 2018 +0000
+++ b/pkgtools/pkglint/files/package_test.go    Tue May 01 23:30:11 2018 +0000
@@ -469,3 +469,72 @@
                "WARN: ~/category/package/options.mk:6: \"../../sysutils/coreutils/buildlink3.mk\" is "+
                        "included unconditionally here and conditionally in Makefile:7 (depending on OPSYS).")
 }
+
+// See https://github.com/rillig/pkglint/issues/1
+func (s *Suite) Test_Package_includeWithoutExists(c *check.C) {
+       t := s.Init(c)
+
+       t.SetupVartypes()
+       t.CreateFileLines("mk/bsd.pkg.mk")
+       t.CreateFileLines("category/package/Makefile",
+               MkRcsID,
+               "",
+               ".include \"options.mk\"",
+               "",
+               ".include \"../../mk/bsd.pkg.mk\"")
+
+       G.CurrentDir = t.TempFilename("category/package")
+       G.checkdirPackage(G.CurrentDir)
+
+       t.CheckOutputLines(
+               "ERROR: ~/category/package/options.mk: Cannot be read.")
+}
+
+// See https://github.com/rillig/pkglint/issues/1
+func (s *Suite) Test_Package_includeAfterExists(c *check.C) {
+       t := s.Init(c)
+
+       t.SetupVartypes()
+       t.CreateFileLines("mk/bsd.pkg.mk")
+       t.CreateFileLines("category/package/Makefile",
+               MkRcsID,
+               "",
+               ".if exists(options.mk)",
+               ".  include \"options.mk\"",
+               ".endif",
+               "",
+               ".include \"../../mk/bsd.pkg.mk\"")
+
+       G.CurrentDir = t.TempFilename("category/package")
+       G.checkdirPackage(G.CurrentDir)
+
+       t.CheckOutputLines(
+               "WARN: ~/category/package/Makefile: Neither PLIST nor PLIST.common exist, and PLIST_SRC is unset. Are you sure PLIST handling is ok?",
+               "WARN: ~/category/package/distinfo: File not found. Please run \"@BMAKE@ makesum\" or define NO_CHECKSUM=yes in the package Makefile.",
+               "ERROR: ~/category/package/Makefile: Each package must define its LICENSE.",
+               "WARN: ~/category/package/Makefile: No COMMENT given.",
+               "ERROR: ~/category/package/Makefile:4: \"options.mk\" does not exist.",
+               "ERROR: ~/category/package/Makefile:7: \"/mk/bsd.pkg.mk\" does not exist.")
+}
+
+// See https://github.com/rillig/pkglint/issues/1
+func (s *Suite) Test_Package_includeOtherAfterExists(c *check.C) {
+       t := s.Init(c)
+
+       t.SetupVartypes()
+       t.CreateFileLines("mk/bsd.pkg.mk")
+       t.CreateFileLines("category/package/Makefile",
+               MkRcsID,
+               "",
+               ".if exists(options.mk)",



Home | Main Index | Thread Index | Old Index