Received: by mail.netbsd.org (Postfix, from userid 605) id EDB0B84EC1; Wed, 6 Jul 2022 06:14:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.netbsd.org (Postfix) with ESMTP id 34F7784E97 for ; Wed, 6 Jul 2022 06:14:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at netbsd.org Received: from mail.netbsd.org ([127.0.0.1]) by localhost (mail.netbsd.org [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id 0f3NhatYwln1 for ; Wed, 6 Jul 2022 06:14:24 +0000 (UTC) Received: from cvs.NetBSD.org (ivanova.NetBSD.org [IPv6:2001:470:a085:999:28c:faff:fe03:5984]) by mail.netbsd.org (Postfix) with ESMTP id 658E784D4A for ; Wed, 6 Jul 2022 06:14:24 +0000 (UTC) Received: by cvs.NetBSD.org (Postfix, from userid 500) id 5F473FB1A; Wed, 6 Jul 2022 06:14:24 +0000 (UTC) Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_165708806443890" MIME-Version: 1.0 Date: Wed, 6 Jul 2022 06:14:24 +0000 From: "Roland Illig" Subject: CVS commit: pkgsrc/pkgtools/pkglint To: pkgsrc-changes@NetBSD.org Reply-To: rillig@netbsd.org X-Mailer: log_accum Message-Id: <20220706061424.5F473FB1A@cvs.NetBSD.org> Sender: pkgsrc-changes-owner@NetBSD.org List-Id: Precedence: bulk List-Unsubscribe: This is a multi-part message in MIME format. --_----------=_165708806443890 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" 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. --_----------=_165708806443890 Content-Disposition: inline Content-Length: 5551 Content-Transfer-Encoding: binary Content-Type: text/x-diff; charset=us-ascii 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.", "", --_----------=_165708806443890--