summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2020-05-29 20:13:17 +0000
committerrillig <rillig@pkgsrc.org>2020-05-29 20:13:17 +0000
commit6022dabbb127321fb07aa25bf2d2c9f192af6809 (patch)
tree790d4170364cfd138026bd7b8dcfdc322303b6d5 /pkgtools
parente2340b8002f58eb2a254438dda157c6d553405c1 (diff)
downloadpkgsrc-6022dabbb127321fb07aa25bf2d2c9f192af6809.tar.gz
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 (limited to 'pkgtools')
-rw-r--r--pkgtools/pkglint/Makefile4
-rw-r--r--pkgtools/pkglint/files/mkline.go67
-rw-r--r--pkgtools/pkglint/files/patches.go19
-rw-r--r--pkgtools/pkglint/files/patches_test.go26
-rw-r--r--pkgtools/pkglint/files/vartypecheck.go8
-rw-r--r--pkgtools/pkglint/files/vartypecheck_test.go10
6 files changed, 96 insertions, 38 deletions
diff --git a/pkgtools/pkglint/Makefile b/pkgtools/pkglint/Makefile
index 23fa1b611fd..d744a5ce368 100644
--- a/pkgtools/pkglint/Makefile
+++ b/pkgtools/pkglint/Makefile
@@ -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 --git a/pkgtools/pkglint/files/mkline.go b/pkgtools/pkglint/files/mkline.go
index 2e024d0566f..57ff4a23e16 100644
--- a/pkgtools/pkglint/files/mkline.go
+++ b/pkgtools/pkglint/files/mkline.go
@@ -821,57 +821,54 @@ func (mkline *MkLine) VariableNeedsQuoting(mklines *MkLines, varuse *MkVarUse, v
// 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 --git a/pkgtools/pkglint/files/patches.go b/pkgtools/pkglint/files/patches.go
index 736f22d9c76..7cef0e9225f 100644
--- a/pkgtools/pkglint/files/patches.go
+++ b/pkgtools/pkglint/files/patches.go
@@ -101,6 +101,7 @@ func (ck *PatchChecker) Check(pkg *Package) {
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(patchedFile Path) {
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 --git a/pkgtools/pkglint/files/patches_test.go b/pkgtools/pkglint/files/patches_test.go
index 6be95daba67..9a1041988da 100644
--- a/pkgtools/pkglint/files/patches_test.go
+++ b/pkgtools/pkglint/files/patches_test.go
@@ -619,7 +619,7 @@ func (s *Suite) Test_PatchChecker_Check__add_hardcoded_usr_pkg(c *check.C) {
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_checkUnifiedDiff__lines_at_end(c *check.C) {
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 --git a/pkgtools/pkglint/files/vartypecheck.go b/pkgtools/pkglint/files/vartypecheck.go
index 0eb70082d2e..a2e11fdcb0c 100644
--- a/pkgtools/pkglint/files/vartypecheck.go
+++ b/pkgtools/pkglint/files/vartypecheck.go
@@ -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()
diff --git a/pkgtools/pkglint/files/vartypecheck_test.go b/pkgtools/pkglint/files/vartypecheck_test.go
index 2bc22a0cca8..cce97c099a1 100644
--- a/pkgtools/pkglint/files/vartypecheck_test.go
+++ b/pkgtools/pkglint/files/vartypecheck_test.go
@@ -1620,6 +1620,16 @@ func (s *Suite) Test_VartypeCheck_PrefixPathname(c *check.C) {
"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) {