diff options
author | rillig <rillig@pkgsrc.org> | 2020-06-02 17:52:26 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2020-06-02 17:52:26 +0000 |
commit | f4bedb2a96fa7de1b24f18e9b6b200864e47bfb5 (patch) | |
tree | 6d6d4b107106877c893f0cc9599c041c81762767 /pkgtools | |
parent | 5c468a605e2be8a1264cb692c906c5aad1853b97 (diff) | |
download | pkgsrc-f4bedb2a96fa7de1b24f18e9b6b200864e47bfb5.tar.gz |
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 (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkglint/Makefile | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/mkcondchecker.go | 24 | ||||
-rw-r--r-- | pkgtools/pkglint/files/mkcondchecker_test.go | 21 |
3 files changed, 47 insertions, 2 deletions
diff --git a/pkgtools/pkglint/Makefile b/pkgtools/pkglint/Makefile index c733d057e08..7ca56de8134 100644 --- a/pkgtools/pkglint/Makefile +++ b/pkgtools/pkglint/Makefile @@ -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 --git a/pkgtools/pkglint/files/mkcondchecker.go b/pkgtools/pkglint/files/mkcondchecker.go index 7617b04fa26..c1ca935f73f 100644 --- a/pkgtools/pkglint/files/mkcondchecker.go +++ b/pkgtools/pkglint/files/mkcondchecker.go @@ -266,6 +266,8 @@ func (ck *MkCondChecker) simplify(varuse *MkVarUse, fromEmpty bool, neg bool) { 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) checkCompareVarStr(varuse *MkVarUse, op string, str str } } +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 --git a/pkgtools/pkglint/files/mkcondchecker_test.go b/pkgtools/pkglint/files/mkcondchecker_test.go index b6ec7a31437..9b724837c11 100644 --- a/pkgtools/pkglint/files/mkcondchecker_test.go +++ b/pkgtools/pkglint/files/mkcondchecker_test.go @@ -1147,6 +1147,27 @@ func (s *Suite) Test_MkCondChecker_checkCompareVarStr__no_tracing(c *check.C) { 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) |