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



details:   https://anonhg.NetBSD.org/pkgsrc/rev/b5326bb101b6
branches:  trunk
changeset: 381390:b5326bb101b6
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Wed Jul 06 06:14:24 2022 +0000

description:
pkgtools/pkglint: update to 22.2.1

Changes since 22.2.0:

Suggest simpler condition when matching a variable against a pattern
(occurs 220 times in pkgsrc).

Improve explanation for documenting patches.

diffstat:

 pkgtools/pkglint/Makefile                    |   5 +--
 pkgtools/pkglint/files/mkcondchecker.go      |  32 +++++++++++++++++++++++++--
 pkgtools/pkglint/files/mkcondchecker_test.go |  25 +++++++++++++--------
 pkgtools/pkglint/files/patches.go            |   3 ++
 4 files changed, 49 insertions(+), 16 deletions(-)

diffs (138 lines):

diff -r d0c0112dc670 -r b5326bb101b6 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Wed Jul 06 05:03:09 2022 +0000
+++ b/pkgtools/pkglint/Makefile Wed Jul 06 06:14:24 2022 +0000
@@ -1,7 +1,6 @@
-# $NetBSD: Makefile,v 1.719 2022/06/28 11:35:26 wiz Exp $
+# $NetBSD: Makefile,v 1.720 2022/07/06 06:14:24 rillig Exp $
 
-PKGNAME=       pkglint-22.2.0
-PKGREVISION=   1
+PKGNAME=       pkglint-22.2.1
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r d0c0112dc670 -r b5326bb101b6 pkgtools/pkglint/files/mkcondchecker.go
--- a/pkgtools/pkglint/files/mkcondchecker.go   Wed Jul 06 05:03:09 2022 +0000
+++ b/pkgtools/pkglint/files/mkcondchecker.go   Wed Jul 06 06:14:24 2022 +0000
@@ -168,14 +168,13 @@
 // * neg is true for the form !empty(VAR...), and false for empty(VAR...).
 func (ck *MkCondChecker) simplify(varuse *MkVarUse, fromEmpty bool, neg bool) {
        varname := varuse.varname
-       mods := varuse.modifiers
-       modifiers := mods
+       modifiers := varuse.modifiers
 
        n := len(modifiers)
        if n == 0 {
                return
        }
-       modsExceptLast := NewMkVarUse("", mods[:n-1]...).Mod()
+       modsExceptLast := NewMkVarUse("", modifiers[:n-1]...).Mod()
        vartype := G.Pkgsrc.VariableType(ck.MkLines, varname)
 
        isDefined := func() bool {
@@ -226,6 +225,7 @@
                        condStr(fromEmpty, ")", "}"))
 
                needsQuotes := textproc.NewLexer(pattern).NextBytesSet(mkCondStringLiteralUnquoted) != pattern ||
+                       pattern == "" ||
                        matches(pattern, `^\d+\.?\d*$`)
                quote := condStr(needsQuotes, "\"", "")
 
@@ -242,6 +242,32 @@
                return
        }
 
+       // Replace !empty(VAR:M*.c) with ${VAR:M*.c}.
+       // Replace empty(VAR:M*.c) with !${VAR:M*.c}.
+       if fromEmpty && positive && !exact && vartype != nil && isDefined() &&
+               // Restrict replacements to very simple patterns with only few
+               // special characters.
+               // Before generalizing this to arbitrary strings, there has to be
+               // a proper code generator for these conditions that handles all
+               // possible escaping.
+               matches(varuse.Mod(), `^[*.:\w]+$`) {
+
+               fixedPart := varname + modsExceptLast + ":M" + pattern
+               from := condStr(neg, "!", "") + "empty(" + fixedPart + ")"
+               to := condStr(neg, "", "!") + "${" + fixedPart + "}"
+
+               fix := ck.MkLine.Autofix()
+               fix.Notef("%q can be simplified to %q.", from, to)
+               fix.Explain(
+                       "This variable is guaranteed to be defined at this point.",
+                       "Therefore it may occur on the left-hand side of a comparison",
+                       "and doesn't have to be guarded by the function 'empty'.")
+               fix.Replace(from, to)
+               fix.Apply()
+
+               return
+       }
+
        switch {
        case !exact,
                vartype == nil,
diff -r d0c0112dc670 -r b5326bb101b6 pkgtools/pkglint/files/mkcondchecker_test.go
--- a/pkgtools/pkglint/files/mkcondchecker_test.go      Wed Jul 06 05:03:09 2022 +0000
+++ b/pkgtools/pkglint/files/mkcondchecker_test.go      Wed Jul 06 06:14:24 2022 +0000
@@ -1133,32 +1133,37 @@
 
                nil...)
 
-       // FIXME: Syntax error in the generated code.
        testBeforeAndAfterPrefs(
                ".if !empty(IN_SCOPE_DEFINED:M)",
-               ".if ${IN_SCOPE_DEFINED} == ",
+               ".if ${IN_SCOPE_DEFINED} == \"\"",
 
                "NOTE: filename.mk:3: IN_SCOPE_DEFINED can be "+
-                       "compared using the simpler "+"\"${IN_SCOPE_DEFINED} == \" "+
+                       "compared using the simpler "+"\"${IN_SCOPE_DEFINED} == \"\"\" "+
                        "instead of matching against \":M\".",
                "AUTOFIX: filename.mk:3: "+
                        "Replacing \"!empty(IN_SCOPE_DEFINED:M)\" "+
-                       "with \"${IN_SCOPE_DEFINED} == \".",
+                       "with \"${IN_SCOPE_DEFINED} == \\\"\\\"\".",
        )
 
-       // TODO: Suggest the simpler '${IN_SCOPE_DEFINED:M*.c}'.
        testBeforeAndAfterPrefs(
                ".if !empty(IN_SCOPE_DEFINED:M*.c)",
-               ".if !empty(IN_SCOPE_DEFINED:M*.c)",
+               ".if ${IN_SCOPE_DEFINED:M*.c}",
 
-               nil...)
+               "NOTE: filename.mk:3: \"!empty(IN_SCOPE_DEFINED:M*.c)\" "+
+                       "can be simplified to \"${IN_SCOPE_DEFINED:M*.c}\".",
+               "AUTOFIX: filename.mk:3: "+
+                       "Replacing \"!empty(IN_SCOPE_DEFINED:M*.c)\" "+
+                       "with \"${IN_SCOPE_DEFINED:M*.c}\".")
 
-       // TODO: Suggest the simpler '!${IN_SCOPE_DEFINED:M*.c}'.
        testBeforeAndAfterPrefs(
                ".if empty(IN_SCOPE_DEFINED:M*.c)",
-               ".if empty(IN_SCOPE_DEFINED:M*.c)",
+               ".if !${IN_SCOPE_DEFINED:M*.c}",
 
-               nil...)
+               "NOTE: filename.mk:3: \"empty(IN_SCOPE_DEFINED:M*.c)\" "+
+                       "can be simplified to \"!${IN_SCOPE_DEFINED:M*.c}\".",
+               "AUTOFIX: filename.mk:3: "+
+                       "Replacing \"empty(IN_SCOPE_DEFINED:M*.c)\" "+
+                       "with \"!${IN_SCOPE_DEFINED:M*.c}\".")
 }
 
 func (s *Suite) Test_MkCondChecker_simplify__defined_in_same_file(c *check.C) {
diff -r d0c0112dc670 -r b5326bb101b6 pkgtools/pkglint/files/patches.go
--- a/pkgtools/pkglint/files/patches.go Wed Jul 06 05:03:09 2022 +0000
+++ b/pkgtools/pkglint/files/patches.go Wed Jul 06 06:14:24 2022 +0000
@@ -219,6 +219,9 @@
                        "\tPortability fixes for GCC 4.8 on Linux.",
                        "\tSee https://github.com/org/repo/issues/7";,
                        "",
+                       "\t--- old/file",
+                       "\t+++ new/file",
+                       "",
                        "Patches that are related to a security issue should mention the",
                        "corresponding CVE identifier.",
                        "",



Home | Main Index | Thread Index | Old Index