summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2022-11-28 23:33:28 +0000
committerrillig <rillig@pkgsrc.org>2022-11-28 23:33:28 +0000
commit88bc85721db509eb0def3f5d486f0ce66fc81506 (patch)
tree1c9d57c0bb155e9601dc553b3925bfe2d65f642e
parent6b84f84454929a65628f4b945203bb4f5ac2e4bd (diff)
downloadpkgsrc-88bc85721db509eb0def3f5d486f0ce66fc81506.tar.gz
pkgtools/pkglint: update to 22.3.2
Changes since 22.3.1: Complain about conditions of the form '_PYTHON_VERSION < 38', as they lead to 'Malformed conditional' when _PYTHON_VERSION is 'none' instead of a number.
-rw-r--r--pkgtools/pkglint/Makefile4
-rw-r--r--pkgtools/pkglint/files/mkcondchecker.go28
-rw-r--r--pkgtools/pkglint/files/mkcondchecker_test.go45
-rw-r--r--pkgtools/pkglint/files/mkshparser.go2
-rw-r--r--pkgtools/pkglint/files/pkgver/vercmp.go5
-rw-r--r--pkgtools/pkglint/files/pkgver/vercmp_test.go1
6 files changed, 77 insertions, 8 deletions
diff --git a/pkgtools/pkglint/Makefile b/pkgtools/pkglint/Makefile
index 6ecea60d2e4..ebf01ee2fd9 100644
--- a/pkgtools/pkglint/Makefile
+++ b/pkgtools/pkglint/Makefile
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.734 2022/11/19 10:51:07 rillig Exp $
+# $NetBSD: Makefile,v 1.735 2022/11/28 23:33:28 rillig Exp $
-PKGNAME= pkglint-22.3.1
+PKGNAME= pkglint-22.3.2
CATEGORIES= pkgtools
MAINTAINER= rillig@NetBSD.org
diff --git a/pkgtools/pkglint/files/mkcondchecker.go b/pkgtools/pkglint/files/mkcondchecker.go
index cc0a65c4b12..0efa154e515 100644
--- a/pkgtools/pkglint/files/mkcondchecker.go
+++ b/pkgtools/pkglint/files/mkcondchecker.go
@@ -165,7 +165,7 @@ var mkCondModifierPatternLiteral = textproc.NewByteSet("-+,./0-9<=>@A-Z_a-z")
func (ck *MkCondChecker) checkCompare(left *MkCondTerm, op string, right *MkCondTerm) {
switch {
case right.Num != "":
- ck.checkCompareVarNum(op, right.Num)
+ ck.checkCompareVarNum(left, op, right.Num)
case left.Var != nil && right.Var == nil:
ck.checkCompareVarStr(left.Var, op, right.Str)
}
@@ -209,7 +209,12 @@ func (ck *MkCondChecker) checkCompareVarStr(varuse *MkVarUse, op string, str str
}
}
-func (ck *MkCondChecker) checkCompareVarNum(op string, num string) {
+func (ck *MkCondChecker) checkCompareVarNum(left *MkCondTerm, op string, num string) {
+ ck.checkCompareVarNumVersion(op, num)
+ ck.checkCompareVarNumPython(left, op, num)
+}
+
+func (ck *MkCondChecker) checkCompareVarNumVersion(op string, num string) {
if !contains(num, ".") {
return
}
@@ -231,6 +236,25 @@ func (ck *MkCondChecker) checkCompareVarNum(op string, num string) {
"the version number 1.11 would also match, which is not intended.")
}
+func (ck *MkCondChecker) checkCompareVarNumPython(left *MkCondTerm, op string, num string) {
+ if left.Var != nil && left.Var.varname == "_PYTHON_VERSION" &&
+ op != "==" && op != "!=" &&
+ matches(num, `^\d+$`) {
+
+ ck.MkLine.Errorf("The Python version must not be compared numerically.")
+ ck.MkLine.Explain(
+ "The variable _PYTHON_VERSION must not be compared",
+ "against an integer number, as these comparisons are",
+ "not meaningful.",
+ "For example, 27 < 39 < 40 < 41 < 310, which means that",
+ "Python 3.10 would be considered newer than a",
+ "possible future Python 4.0.",
+ "",
+ "In addition, _PYTHON_VERSION can be \"none\",",
+ "which is not a number.")
+ }
+}
+
func (ck *MkCondChecker) checkCompareVarStrCompiler(op string, value string) {
if !matches(value, `^\w+$`) {
return
diff --git a/pkgtools/pkglint/files/mkcondchecker_test.go b/pkgtools/pkglint/files/mkcondchecker_test.go
index 207a6f309e3..65d34ccc02e 100644
--- a/pkgtools/pkglint/files/mkcondchecker_test.go
+++ b/pkgtools/pkglint/files/mkcondchecker_test.go
@@ -605,6 +605,24 @@ func (s *Suite) Test_MkCondChecker_checkCompareVarNum(c *check.C) {
mklines := t.NewMkLines("filename.mk",
MkCvsID,
"",
+ "OS_VERSION=\t6.0",
+ ".if ${OS_VERSION} > 6.5 || ${_PYTHON_VERSION} < 38",
+ ".endif")
+
+ mklines.Check()
+
+ t.CheckOutputLines(
+ "WARN: filename.mk:4: Numeric comparison > 6.5.",
+ "ERROR: filename.mk:4: The Python version must not be compared numerically.",
+ "WARN: filename.mk:4: _PYTHON_VERSION is used but not defined.")
+}
+
+func (s *Suite) Test_MkCondChecker_checkCompareVarNumVersion(c *check.C) {
+ t := s.Init(c)
+
+ mklines := t.NewMkLines("filename.mk",
+ MkCvsID,
+ "",
"OS_VERSION=\t9.0",
"",
".if ${OS_VERSION} > 6.5",
@@ -620,6 +638,33 @@ func (s *Suite) Test_MkCondChecker_checkCompareVarNum(c *check.C) {
"WARN: filename.mk:8: Numeric comparison == 6.5.")
}
+func (s *Suite) Test_MkCondChecker_checkCompareVarNumPython(c *check.C) {
+ t := s.Init(c)
+
+ mklines := t.NewMkLines("filename.mk",
+ MkCvsID,
+ "",
+ "_PYTHON_VERSION=\tnone",
+ "",
+ ".if ${_PYTHON_VERSION} < 38",
+ ".endif",
+ "",
+ ".if ${_PYTHON_VERSION} < 310",
+ ".endif")
+
+ mklines.Check()
+
+ t.CheckOutputLines(
+ "WARN: filename.mk:3: "+
+ "Variable names starting with an underscore "+
+ "(_PYTHON_VERSION) are reserved "+
+ "for internal pkgsrc use.",
+ "ERROR: filename.mk:5: "+
+ "The Python version must not be compared numerically.",
+ "ERROR: filename.mk:8: "+
+ "The Python version must not be compared numerically.")
+}
+
func (s *Suite) Test_MkCondChecker_checkCompareVarStrCompiler(c *check.C) {
t := s.Init(c)
diff --git a/pkgtools/pkglint/files/mkshparser.go b/pkgtools/pkglint/files/mkshparser.go
index 060839f32ba..7dc3f9e882a 100644
--- a/pkgtools/pkglint/files/mkshparser.go
+++ b/pkgtools/pkglint/files/mkshparser.go
@@ -250,7 +250,7 @@ func (lex *ShellLexer) Lex(lval *shyySymType) (ttype int) {
lval.Word = p.ShToken()
lex.atCommandStart = false
- // Inside of a case statement, ${PATTERNS:@p@ (${p}) continue ;; @} expands to
+ // Inside a case statement, ${PATTERNS:@p@ (${p}) continue ;; @} expands to
// a list of case-items, and after this list a new command starts.
// This is necessary to return a following "esac" as tkESAC instead of a
// simple word.
diff --git a/pkgtools/pkglint/files/pkgver/vercmp.go b/pkgtools/pkglint/files/pkgver/vercmp.go
index 945bbc936ed..c6bae87304b 100644
--- a/pkgtools/pkglint/files/pkgver/vercmp.go
+++ b/pkgtools/pkglint/files/pkgver/vercmp.go
@@ -44,10 +44,9 @@ type version struct {
}
func newVersion(vstr string) *version {
- v := new(version)
+ var v version
lex := textproc.NewLexer(strings.ToLower(vstr))
for !lex.EOF() {
-
switch {
case lex.TestByteSet(textproc.Digit):
num := lex.NextBytesSet(textproc.Digit)
@@ -76,7 +75,7 @@ func newVersion(vstr string) *version {
lex.Skip(1)
}
}
- return v
+ return &v
}
//go:noinline
diff --git a/pkgtools/pkglint/files/pkgver/vercmp_test.go b/pkgtools/pkglint/files/pkgver/vercmp_test.go
index aa7da499879..21bbed8a160 100644
--- a/pkgtools/pkglint/files/pkgver/vercmp_test.go
+++ b/pkgtools/pkglint/files/pkgver/vercmp_test.go
@@ -115,6 +115,7 @@ func Test_newVersion(t *testing.T) {
func (s *Suite) Test_newVersion(c *check.C) {
// See Test_newVersion.
+ _ = c
}
func (s *Suite) Test__qa(c *check.C) {