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.13



details:   https://anonhg.NetBSD.org/pkgsrc/rev/c36bcc4d71bf
branches:  trunk
changeset: 433471:c36bcc4d71bf
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Tue Jun 02 17:52:26 2020 +0000

description:
pkgtools/pkglint: update to 20.1.13

Changes since 20.1.12:

Numeric comparison in conditions should not be used.  It is currently
only used for comparing version numbers.

https://mail-index.netbsd.org/pkgsrc-changes/2020/06/02/msg215278.html

diffstat:

 pkgtools/pkglint/Makefile                    |   4 ++--
 pkgtools/pkglint/files/mkcondchecker.go      |  24 ++++++++++++++++++++++++
 pkgtools/pkglint/files/mkcondchecker_test.go |  21 +++++++++++++++++++++
 3 files changed, 47 insertions(+), 2 deletions(-)

diffs (84 lines):

diff -r bf088b9b235f -r c36bcc4d71bf pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Tue Jun 02 17:40:00 2020 +0000
+++ b/pkgtools/pkglint/Makefile Tue Jun 02 17:52:26 2020 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.651 2020/06/01 20:49:54 rillig Exp $
+# $NetBSD: Makefile,v 1.652 2020/06/02 17:52:26 rillig Exp $
 
-PKGNAME=       pkglint-20.1.12
+PKGNAME=       pkglint-20.1.13
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r bf088b9b235f -r c36bcc4d71bf pkgtools/pkglint/files/mkcondchecker.go
--- a/pkgtools/pkglint/files/mkcondchecker.go   Tue Jun 02 17:40:00 2020 +0000
+++ b/pkgtools/pkglint/files/mkcondchecker.go   Tue Jun 02 17:52:26 2020 +0000
@@ -266,6 +266,8 @@
 
 func (ck *MkCondChecker) checkCompare(left *MkCondTerm, op string, right *MkCondTerm) {
        switch {
+       case right.Num != "":
+               ck.checkCompareVarNum(op, right.Num)
        case left.Var != nil && right.Var == nil && right.Num == "":
                ck.checkCompareVarStr(left.Var, op, right.Str)
        }
@@ -309,6 +311,28 @@
        }
 }
 
+func (ck *MkCondChecker) checkCompareVarNum(op string, num string) {
+       if !contains(num, ".") {
+               return
+       }
+
+       mkline := ck.MkLine
+       mkline.Warnf("Numeric comparison %s %s.", op, num)
+       mkline.Explain(
+               "The numeric comparison of bmake is not suitable for version numbers",
+               "since 5.1 == 5.10 == 5.1000000.",
+               "",
+               "To fix this, either enclose the number in double quotes,",
+               "or use pattern matching:",
+               "",
+               "\t${OS_VERSION} == \"6.5\"",
+               "\t${OS_VERSION:M1.[1-9]} || ${OS_VERSION:M1.[1-9].*}",
+               "",
+               "The second example needs to be split into two parts",
+               "since with a single comparison of the form ${OS_VERSION:M1.[1-9]*},",
+               "the version number 1.11 would also match, which is not intended.")
+}
+
 func (ck *MkCondChecker) checkCompareVarStrCompiler(op string, value string) {
        if !matches(value, `^\w+$`) {
                return
diff -r bf088b9b235f -r c36bcc4d71bf pkgtools/pkglint/files/mkcondchecker_test.go
--- a/pkgtools/pkglint/files/mkcondchecker_test.go      Tue Jun 02 17:40:00 2020 +0000
+++ b/pkgtools/pkglint/files/mkcondchecker_test.go      Tue Jun 02 17:52:26 2020 +0000
@@ -1147,6 +1147,27 @@
        t.CheckOutputEmpty()
 }
 
+func (s *Suite) Test_MkCondChecker_checkCompareVarNum(c *check.C) {
+       t := s.Init(c)
+
+       mklines := t.NewMkLines("filename.mk",
+               MkCvsID,
+               "",
+               "OS_VERSION=\t9.0",
+               "",
+               ".if ${OS_VERSION} > 6.5",
+               ".endif",
+               "",
+               ".if ${OS_VERSION} == 6.5",
+               ".endif")
+
+       mklines.Check()
+
+       t.CheckOutputLines(
+               "WARN: filename.mk:5: Numeric comparison > 6.5.",
+               "WARN: filename.mk:8: Numeric comparison == 6.5.")
+}
+
 func (s *Suite) Test_MkCondChecker_checkCompareVarStrCompiler(c *check.C) {
        t := s.Init(c)
 



Home | Main Index | Thread Index | Old Index