Source-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint pkgtools/pkglint: update to 20.1.11



details:   https://anonhg.NetBSD.org/pkgsrc/rev/74240f8dcf59
branches:  trunk
changeset: 433010:74240f8dcf59
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri May 29 20:13:17 2020 +0000

description:
pkgtools/pkglint: update to 20.1.11

Changes since 20.1.10:

PKG_SYSCONFDIR and VARBASE must not appear in INSTALLATION_DIRS.

Patch files in which the line number have been edited manually are marked
with notes.

diffstat:

 pkgtools/pkglint/Makefile                   |   4 +-
 pkgtools/pkglint/files/mkline.go            |  67 +++++++++++++---------------
 pkgtools/pkglint/files/patches.go           |  19 ++++++++
 pkgtools/pkglint/files/patches_test.go      |  26 ++++++++++-
 pkgtools/pkglint/files/vartypecheck.go      |   8 +++
 pkgtools/pkglint/files/vartypecheck_test.go |  10 ++++
 6 files changed, 96 insertions(+), 38 deletions(-)

diffs (224 lines):

diff -r 5dea1252b98a -r 74240f8dcf59 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Fri May 29 10:51:23 2020 +0000
+++ b/pkgtools/pkglint/Makefile Fri May 29 20:13:17 2020 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.649 2020/05/24 19:12:29 rillig Exp $
+# $NetBSD: Makefile,v 1.650 2020/05/29 20:13:17 rillig Exp $
 
-PKGNAME=       pkglint-20.1.10
+PKGNAME=       pkglint-20.1.11
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 5dea1252b98a -r 74240f8dcf59 pkgtools/pkglint/files/mkline.go
--- a/pkgtools/pkglint/files/mkline.go  Fri May 29 10:51:23 2020 +0000
+++ b/pkgtools/pkglint/files/mkline.go  Fri May 29 20:13:17 2020 +0000
@@ -821,57 +821,54 @@
 
 // ForEachUsed calls the action for each variable that is used in the line.
 func (mkline *MkLine) ForEachUsed(action func(varUse *MkVarUse, time VucTime)) {
-
-       var searchIn func(text string, time VucTime) // mutually recursive with searchInVarUse
-
-       searchInVarUse := func(varuse *MkVarUse, time VucTime) {
-               varname := varuse.varname
-               if !varuse.IsExpression() {
-                       action(varuse, time)
-               }
-               searchIn(varname, time)
-               for _, mod := range varuse.modifiers {
-                       searchIn(mod.Text, time)
-               }
-       }
-
-       searchIn = func(text string, time VucTime) {
-               if !contains(text, "$") {
-                       return
-               }
-
-               tokens, _ := NewMkLexer(text, nil).MkTokens()
-               for _, token := range tokens {
-                       if token.Varuse != nil {
-                               searchInVarUse(token.Varuse, time)
-                       }
-               }
-       }
-
        switch {
 
        case mkline.IsVarassign():
-               searchIn(mkline.Varname(), VucLoadTime)
-               searchIn(mkline.Value(), mkline.Op().Time())
+               mkline.ForEachUsedText(mkline.Varname(), VucLoadTime, action)
+               mkline.ForEachUsedText(mkline.Value(), mkline.Op().Time(), action)
 
        case mkline.IsDirective() && mkline.Directive() == "for":
-               searchIn(mkline.Args(), VucLoadTime)
+               mkline.ForEachUsedText(mkline.Args(), VucLoadTime, action)
 
        case mkline.IsDirective() && (mkline.Directive() == "if" || mkline.Directive() == "elif") && mkline.Cond() != nil:
                mkline.Cond().Walk(&MkCondCallback{
                        VarUse: func(varuse *MkVarUse) {
-                               searchInVarUse(varuse, VucLoadTime)
+                               mkline.ForEachUsedVarUse(varuse, VucLoadTime, action)
                        }})
 
        case mkline.IsShellCommand():
-               searchIn(mkline.ShellCommand(), VucRunTime)
+               mkline.ForEachUsedText(mkline.ShellCommand(), VucRunTime, action)
 
        case mkline.IsDependency():
-               searchIn(mkline.Targets(), VucLoadTime)
-               searchIn(mkline.Sources(), VucLoadTime)
+               mkline.ForEachUsedText(mkline.Targets(), VucLoadTime, action)
+               mkline.ForEachUsedText(mkline.Sources(), VucLoadTime, action)
 
        case mkline.IsInclude():
-               searchIn(mkline.IncludedFile().String(), VucLoadTime)
+               mkline.ForEachUsedText(mkline.IncludedFile().String(), VucLoadTime, action)
+       }
+}
+
+func (mkline *MkLine) ForEachUsedText(text string, time VucTime, action func(varUse *MkVarUse, time VucTime)) {
+       if !contains(text, "$") {
+               return
+       }
+
+       tokens, _ := NewMkLexer(text, nil).MkTokens()
+       for _, token := range tokens {
+               if token.Varuse != nil {
+                       mkline.ForEachUsedVarUse(token.Varuse, time, action)
+               }
+       }
+}
+
+func (mkline *MkLine) ForEachUsedVarUse(varuse *MkVarUse, time VucTime, action func(varUse *MkVarUse, time VucTime)) {
+       varname := varuse.varname
+       if !varuse.IsExpression() {
+               action(varuse, time)
+       }
+       mkline.ForEachUsedText(varname, time, action)
+       for _, mod := range varuse.modifiers {
+               mkline.ForEachUsedText(mod.Text, time, action)
        }
 }
 
diff -r 5dea1252b98a -r 74240f8dcf59 pkgtools/pkglint/files/patches.go
--- a/pkgtools/pkglint/files/patches.go Fri May 29 10:51:23 2020 +0000
+++ b/pkgtools/pkglint/files/patches.go Fri May 29 20:13:17 2020 +0000
@@ -101,6 +101,7 @@
 func (ck *PatchChecker) checkUnifiedDiff(patchedFile Path) {
        isConfigure := ck.isConfigure(patchedFile)
 
+       linesDiff := 0
        hasHunks := false
        for {
                m := ck.llex.NextRegexp(rePatchUniHunk)
@@ -110,8 +111,26 @@
 
                text := m[0]
                hasHunks = true
+               linenoDel := toInt(m[1], 0)
                linesToDel := toInt(m[2], 1)
+               linenoAdd := toInt(m[3], 0)
                linesToAdd := toInt(m[4], 1)
+               if linenoDel > 0 && linenoAdd > 0 && linenoDel+linesDiff != linenoAdd {
+                       line := ck.llex.PreviousLine()
+                       line.Notef("The difference between the line numbers %d and %d should be %d, not %d.",
+                               linenoDel, linenoAdd, linesDiff, linenoAdd-linenoDel)
+                       line.Explain(
+                               "This only happens when patches are edited manually.",
+                               "",
+                               "To fix this, either regenerate the line numbers by first running",
+                               bmake("patch"),
+                               "and then \"mkpatches\", or edit the line numbers by hand.",
+                               "",
+                               "While here, it's a good idea to make the patch apply really cleanly,",
+                               "by ensuring that the output from the patch command does not contain",
+                               "the word \"offset\", like in \"Hunk #11 succeeded at 2598 (offset 10 lines).")
+               }
+               linesDiff += linesToAdd - linesToDel
 
                ck.checktextUniHunkCr()
                ck.checktextCvsID(text)
diff -r 5dea1252b98a -r 74240f8dcf59 pkgtools/pkglint/files/patches_test.go
--- a/pkgtools/pkglint/files/patches_test.go    Fri May 29 10:51:23 2020 +0000
+++ b/pkgtools/pkglint/files/patches_test.go    Fri May 29 20:13:17 2020 +0000
@@ -619,7 +619,7 @@
 func (s *Suite) Test_PatchChecker_checkUnifiedDiff__lines_at_end(c *check.C) {
        t := s.Init(c)
 
-       lines := t.SetUpFileLines("patch-aa",
+       lines := t.NewLines("patch-aa",
                CvsID,
                "",
                "Documentation",
@@ -638,6 +638,30 @@
        t.CheckOutputEmpty()
 }
 
+func (s *Suite) Test_PatchChecker_checkUnifiedDiff__line_number_mismatch(c *check.C) {
+       t := s.Init(c)
+
+       lines := t.NewLines("patch-aa",
+               CvsID,
+               "",
+               "Documentation",
+               "",
+               "--- old",
+               "+++ new",
+               "@@ -2,1 +1,1 @@",
+               "- old",
+               "+ new",
+               "@@ -5,1 +7,1 @@",
+               "- old",
+               "+ new")
+
+       CheckLinesPatch(lines, nil)
+
+       t.CheckOutputLines(
+               "NOTE: patch-aa:7: The difference between the line numbers 2 and 1 should be 0, not -1.",
+               "NOTE: patch-aa:10: The difference between the line numbers 5 and 7 should be 0, not 2.")
+}
+
 func (s *Suite) Test_PatchChecker_checkBeginDiff__multiple_patches_without_documentation(c *check.C) {
        t := s.Init(c)
 
diff -r 5dea1252b98a -r 74240f8dcf59 pkgtools/pkglint/files/vartypecheck.go
--- a/pkgtools/pkglint/files/vartypecheck.go    Fri May 29 10:51:23 2020 +0000
+++ b/pkgtools/pkglint/files/vartypecheck.go    Fri May 29 20:13:17 2020 +0000
@@ -1142,6 +1142,14 @@
                return
        }
 
+       cv.MkLine.ForEachUsedText(cv.Value, VucRunTime, func(varUse *MkVarUse, time VucTime) {
+               varname := varUse.varname
+               if varname == "PKG_SYSCONFDIR" || varname == "VARBASE" {
+                       cv.Errorf("%s must not be used in %s since it is not relative to PREFIX.",
+                               varname, cv.Varname)
+               }
+       })
+
        if m, manSubdir := match1(cv.Value, `^man/(.+)`); m {
                from := "${PKGMANDIR}/" + manSubdir
                fix := cv.Autofix()
diff -r 5dea1252b98a -r 74240f8dcf59 pkgtools/pkglint/files/vartypecheck_test.go
--- a/pkgtools/pkglint/files/vartypecheck_test.go       Fri May 29 10:51:23 2020 +0000
+++ b/pkgtools/pkglint/files/vartypecheck_test.go       Fri May 29 20:13:17 2020 +0000
@@ -1620,6 +1620,16 @@
                        "Please use \"${PKGMANDIR}/man1\" instead of \"man/man1\".",
                "ERROR: filename.mk:3: The pathname \"/absolute\" in PKGMANDIR "+
                        "must be relative to ${PREFIX}.")
+
+       vt.Varname("INSTALLATION_DIRS")
+       vt.Values(
+               "bin ${PKG_SYSCONFDIR} ${VARBASE}")
+
+       vt.Output(
+               "ERROR: filename.mk:11: PKG_SYSCONFDIR must not be used in INSTALLATION_DIRS "+
+                       "since it is not relative to PREFIX.",
+               "ERROR: filename.mk:11: VARBASE must not be used in INSTALLATION_DIRS "+
+                       "since it is not relative to PREFIX.")
 }
 
 func (s *Suite) Test_VartypeCheck_PythonDependency(c *check.C) {



Home | Main Index | Thread Index | Old Index