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:           Tue Jun  2 17:52:26 UTC 2020

Modified Files:
        pkgsrc/pkgtools/pkglint: Makefile
        pkgsrc/pkgtools/pkglint/files: mkcondchecker.go mkcondchecker_test.go

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


To generate a diff of this commit:
cvs rdiff -u -r1.651 -r1.652 pkgsrc/pkgtools/pkglint/Makefile
cvs rdiff -u -r1.6 -r1.7 pkgsrc/pkgtools/pkglint/files/mkcondchecker.go
cvs rdiff -u -r1.7 -r1.8 pkgsrc/pkgtools/pkglint/files/mkcondchecker_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.651 pkgsrc/pkgtools/pkglint/Makefile:1.652
--- pkgsrc/pkgtools/pkglint/Makefile:1.651      Mon Jun  1 20:49:54 2020
+++ pkgsrc/pkgtools/pkglint/Makefile    Tue Jun  2 17:52:26 2020
@@ -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/}

Index: pkgsrc/pkgtools/pkglint/files/mkcondchecker.go
diff -u pkgsrc/pkgtools/pkglint/files/mkcondchecker.go:1.6 pkgsrc/pkgtools/pkglint/files/mkcondchecker.go:1.7
--- pkgsrc/pkgtools/pkglint/files/mkcondchecker.go:1.6  Sun Mar 15 11:31:24 2020
+++ pkgsrc/pkgtools/pkglint/files/mkcondchecker.go      Tue Jun  2 17:52:26 2020
@@ -266,6 +266,8 @@ func (ck *MkCondChecker) simplify(varuse
 
 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) checkCompareVar
        }
 }
 
+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

Index: pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go
diff -u pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go:1.7 pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go:1.8
--- pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go:1.7     Sun Mar 15 11:31:24 2020
+++ pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go Tue Jun  2 17:52:26 2020
@@ -1147,6 +1147,27 @@ func (s *Suite) Test_MkCondChecker_check
        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