pkgsrc-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 22.3.2



details:   https://anonhg.NetBSD.org/pkgsrc/rev/66bb2f38246c
branches:  trunk
changeset: 389014:66bb2f38246c
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Mon Nov 28 23:33:28 2022 +0000

description:
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.

diffstat:

 pkgtools/pkglint/Makefile                    |   4 +-
 pkgtools/pkglint/files/mkcondchecker.go      |  28 ++++++++++++++++-
 pkgtools/pkglint/files/mkcondchecker_test.go |  45 ++++++++++++++++++++++++++++
 pkgtools/pkglint/files/mkshparser.go         |   2 +-
 pkgtools/pkglint/files/pkgver/vercmp.go      |   5 +-
 pkgtools/pkglint/files/pkgver/vercmp_test.go |   1 +
 6 files changed, 77 insertions(+), 8 deletions(-)

diffs (173 lines):

diff -r 5c348a1e8a1f -r 66bb2f38246c pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Mon Nov 28 23:15:34 2022 +0000
+++ b/pkgtools/pkglint/Makefile Mon Nov 28 23:33:28 2022 +0000
@@ -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@localhost
diff -r 5c348a1e8a1f -r 66bb2f38246c pkgtools/pkglint/files/mkcondchecker.go
--- a/pkgtools/pkglint/files/mkcondchecker.go   Mon Nov 28 23:15:34 2022 +0000
+++ b/pkgtools/pkglint/files/mkcondchecker.go   Mon Nov 28 23:33:28 2022 +0000
@@ -165,7 +165,7 @@
 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) 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 @@
                "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 -r 5c348a1e8a1f -r 66bb2f38246c pkgtools/pkglint/files/mkcondchecker_test.go
--- a/pkgtools/pkglint/files/mkcondchecker_test.go      Mon Nov 28 23:15:34 2022 +0000
+++ b/pkgtools/pkglint/files/mkcondchecker_test.go      Mon Nov 28 23:33:28 2022 +0000
@@ -605,6 +605,24 @@
        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 @@
                "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 -r 5c348a1e8a1f -r 66bb2f38246c pkgtools/pkglint/files/mkshparser.go
--- a/pkgtools/pkglint/files/mkshparser.go      Mon Nov 28 23:15:34 2022 +0000
+++ b/pkgtools/pkglint/files/mkshparser.go      Mon Nov 28 23:33:28 2022 +0000
@@ -250,7 +250,7 @@
                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 -r 5c348a1e8a1f -r 66bb2f38246c pkgtools/pkglint/files/pkgver/vercmp.go
--- a/pkgtools/pkglint/files/pkgver/vercmp.go   Mon Nov 28 23:15:34 2022 +0000
+++ b/pkgtools/pkglint/files/pkgver/vercmp.go   Mon Nov 28 23:33:28 2022 +0000
@@ -44,10 +44,9 @@
 }
 
 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 @@
                        lex.Skip(1)
                }
        }
-       return v
+       return &v
 }
 
 //go:noinline
diff -r 5c348a1e8a1f -r 66bb2f38246c pkgtools/pkglint/files/pkgver/vercmp_test.go
--- a/pkgtools/pkglint/files/pkgver/vercmp_test.go      Mon Nov 28 23:15:34 2022 +0000
+++ b/pkgtools/pkglint/files/pkgver/vercmp_test.go      Mon Nov 28 23:33:28 2022 +0000
@@ -115,6 +115,7 @@
 
 func (s *Suite) Test_newVersion(c *check.C) {
        // See Test_newVersion.
+       _ = c
 }
 
 func (s *Suite) Test__qa(c *check.C) {



Home | Main Index | Thread Index | Old Index