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:           Wed Jul  6 06:14:24 UTC 2022

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

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


To generate a diff of this commit:
cvs rdiff -u -r1.719 -r1.720 pkgsrc/pkgtools/pkglint/Makefile
cvs rdiff -u -r1.11 -r1.12 pkgsrc/pkgtools/pkglint/files/mkcondchecker.go
cvs rdiff -u -r1.10 -r1.11 \
    pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go
cvs rdiff -u -r1.46 -r1.47 pkgsrc/pkgtools/pkglint/files/patches.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.719 pkgsrc/pkgtools/pkglint/Makefile:1.720
--- pkgsrc/pkgtools/pkglint/Makefile:1.719      Tue Jun 28 11:35:26 2022
+++ pkgsrc/pkgtools/pkglint/Makefile    Wed Jul  6 06:14:24 2022
@@ -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/}

Index: pkgsrc/pkgtools/pkglint/files/mkcondchecker.go
diff -u pkgsrc/pkgtools/pkglint/files/mkcondchecker.go:1.11 pkgsrc/pkgtools/pkglint/files/mkcondchecker.go:1.12
--- pkgsrc/pkgtools/pkglint/files/mkcondchecker.go:1.11 Sun Jun  6 11:46:43 2021
+++ pkgsrc/pkgtools/pkglint/files/mkcondchecker.go      Wed Jul  6 06:14:24 2022
@@ -168,14 +168,13 @@ var mkCondModifierPatternLiteral = textp
 // * 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 @@ func (ck *MkCondChecker) simplify(varuse
                        condStr(fromEmpty, ")", "}"))
 
                needsQuotes := textproc.NewLexer(pattern).NextBytesSet(mkCondStringLiteralUnquoted) != pattern ||
+                       pattern == "" ||
                        matches(pattern, `^\d+\.?\d*$`)
                quote := condStr(needsQuotes, "\"", "")
 
@@ -242,6 +242,32 @@ func (ck *MkCondChecker) simplify(varuse
                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,

Index: pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go
diff -u pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go:1.10 pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go:1.11
--- pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go:1.10    Fri Jun 24 07:16:23 2022
+++ pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go Wed Jul  6 06:14:24 2022
@@ -1133,32 +1133,37 @@ func (s *Suite) Test_MkCondChecker_simpl
 
                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) {

Index: pkgsrc/pkgtools/pkglint/files/patches.go
diff -u pkgsrc/pkgtools/pkglint/files/patches.go:1.46 pkgsrc/pkgtools/pkglint/files/patches.go:1.47
--- pkgsrc/pkgtools/pkglint/files/patches.go:1.46       Sat Apr 17 18:10:14 2021
+++ pkgsrc/pkgtools/pkglint/files/patches.go    Wed Jul  6 06:14:24 2022
@@ -219,6 +219,9 @@ func (ck *PatchChecker) checkBeginDiff(l
                        "\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