pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/pkglint



Module Name:    pkgsrc
Committed By:   rillig
Date:           Fri May 29 20:13:17 UTC 2020

Modified Files:
        pkgsrc/pkgtools/pkglint: Makefile
        pkgsrc/pkgtools/pkglint/files: mkline.go patches.go patches_test.go
            vartypecheck.go vartypecheck_test.go

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.649 -r1.650 pkgsrc/pkgtools/pkglint/Makefile
cvs rdiff -u -r1.78 -r1.79 pkgsrc/pkgtools/pkglint/files/mkline.go
cvs rdiff -u -r1.40 -r1.41 pkgsrc/pkgtools/pkglint/files/patches.go
cvs rdiff -u -r1.39 -r1.40 pkgsrc/pkgtools/pkglint/files/patches_test.go
cvs rdiff -u -r1.88 -r1.89 pkgsrc/pkgtools/pkglint/files/vartypecheck.go
cvs rdiff -u -r1.79 -r1.80 pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/pkglint/Makefile
diff -u pkgsrc/pkgtools/pkglint/Makefile:1.649 pkgsrc/pkgtools/pkglint/Makefile:1.650
--- pkgsrc/pkgtools/pkglint/Makefile:1.649      Sun May 24 19:12:29 2020
+++ pkgsrc/pkgtools/pkglint/Makefile    Fri May 29 20:13:17 2020
@@ -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/}

Index: pkgsrc/pkgtools/pkglint/files/mkline.go
diff -u pkgsrc/pkgtools/pkglint/files/mkline.go:1.78 pkgsrc/pkgtools/pkglint/files/mkline.go:1.79
--- pkgsrc/pkgtools/pkglint/files/mkline.go:1.78        Fri May  8 19:50:04 2020
+++ pkgsrc/pkgtools/pkglint/files/mkline.go     Fri May 29 20:13:17 2020
@@ -821,57 +821,54 @@ func (mkline *MkLine) VariableNeedsQuoti
 
 // 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)
        }
 }
 

Index: pkgsrc/pkgtools/pkglint/files/patches.go
diff -u pkgsrc/pkgtools/pkglint/files/patches.go:1.40 pkgsrc/pkgtools/pkglint/files/patches.go:1.41
--- pkgsrc/pkgtools/pkglint/files/patches.go:1.40       Fri May  8 19:50:04 2020
+++ pkgsrc/pkgtools/pkglint/files/patches.go    Fri May 29 20:13:17 2020
@@ -101,6 +101,7 @@ func (ck *PatchChecker) Check(pkg *Packa
 func (ck *PatchChecker) checkUnifiedDiff(patchedFile Path) {
        isConfigure := ck.isConfigure(patchedFile)
 
+       linesDiff := 0
        hasHunks := false
        for {
                m := ck.llex.NextRegexp(rePatchUniHunk)
@@ -110,8 +111,26 @@ func (ck *PatchChecker) checkUnifiedDiff
 
                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)

Index: pkgsrc/pkgtools/pkglint/files/patches_test.go
diff -u pkgsrc/pkgtools/pkglint/files/patches_test.go:1.39 pkgsrc/pkgtools/pkglint/files/patches_test.go:1.40
--- pkgsrc/pkgtools/pkglint/files/patches_test.go:1.39  Fri May  8 19:50:04 2020
+++ pkgsrc/pkgtools/pkglint/files/patches_test.go       Fri May 29 20:13:17 2020
@@ -619,7 +619,7 @@ func (s *Suite) Test_PatchChecker_Check_
 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 @@ func (s *Suite) Test_PatchChecker_checkU
        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)
 

Index: pkgsrc/pkgtools/pkglint/files/vartypecheck.go
diff -u pkgsrc/pkgtools/pkglint/files/vartypecheck.go:1.88 pkgsrc/pkgtools/pkglint/files/vartypecheck.go:1.89
--- pkgsrc/pkgtools/pkglint/files/vartypecheck.go:1.88  Sat May 23 08:51:08 2020
+++ pkgsrc/pkgtools/pkglint/files/vartypecheck.go       Fri May 29 20:13:17 2020
@@ -1142,6 +1142,14 @@ func (cv *VartypeCheck) PrefixPathname()
                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()

Index: pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go
diff -u pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go:1.79 pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go:1.80
--- pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go:1.79     Mon Apr 13 19:46:44 2020
+++ pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go  Fri May 29 20:13:17 2020
@@ -1620,6 +1620,16 @@ func (s *Suite) Test_VartypeCheck_Prefix
                        "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