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



details:   https://anonhg.NetBSD.org/pkgsrc/rev/b33d927a62e9
branches:  trunk
changeset: 381027:b33d927a62e9
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Jun 24 07:16:23 2022 +0000

description:
pkgtools/pkglint: update to 22.2.0

Changes since 22.1.0:

In ALTERNATIVES files, the wrapper path must be either in bin,
@PKGMANDIR@ or sbin.  This catches typos like "in" instead of "bin", as
well as hard-coded "man".

diffstat:

 pkgtools/pkglint/Makefile                      |   5 +--
 pkgtools/pkglint/files/alternatives.go         |  35 ++++++++++-------------
 pkgtools/pkglint/files/alternatives_test.go    |  30 ++++++++++++++++++--
 pkgtools/pkglint/files/autofix.go              |   5 +++
 pkgtools/pkglint/files/check_test.go           |  10 +++---
 pkgtools/pkglint/files/mkassignchecker_test.go |   4 +-
 pkgtools/pkglint/files/mkcondchecker_test.go   |  39 ++++++++++++++++++++++----
 pkgtools/pkglint/files/mkline.go               |  10 ++++--
 pkgtools/pkglint/files/mkshparser.go           |   2 +-
 pkgtools/pkglint/files/mkvarusechecker_test.go |  30 ++++++++++----------
 pkgtools/pkglint/files/vartypecheck_test.go    |   2 +-
 11 files changed, 112 insertions(+), 60 deletions(-)

diffs (truncated from 411 to 300 lines):

diff -r 973039a4da09 -r b33d927a62e9 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Fri Jun 24 06:10:48 2022 +0000
+++ b/pkgtools/pkglint/Makefile Fri Jun 24 07:16:23 2022 +0000
@@ -1,7 +1,6 @@
-# $NetBSD: Makefile,v 1.717 2022/06/02 18:52:05 bsiegert Exp $
+# $NetBSD: Makefile,v 1.718 2022/06/24 07:16:23 rillig Exp $
 
-PKGNAME=       pkglint-22.1.0
-PKGREVISION=   3
+PKGNAME=       pkglint-22.2.0
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 973039a4da09 -r b33d927a62e9 pkgtools/pkglint/files/alternatives.go
--- a/pkgtools/pkglint/files/alternatives.go    Fri Jun 24 06:10:48 2022 +0000
+++ b/pkgtools/pkglint/files/alternatives.go    Fri Jun 24 07:16:23 2022 +0000
@@ -29,7 +29,7 @@
 }
 
 // checkLine checks a single line for the following format:
-//  wrapper alternative [optional arguments]
+//  wrapper alternative [arguments]
 func (ck *AlternativesChecker) checkLine(line *Line, plistFiles map[RelPath]*PlistLine, pkg *Package) {
        m, wrapper, space, alternative := match3(line.Text, `^([^\t ]+)([ \t]+)([^\t ]+).*$`)
        if !m {
@@ -39,9 +39,21 @@
                return
        }
 
-       if ck.checkWrapperAbs(line, NewPath(wrapper)) && plistFiles != nil {
-               ck.checkWrapperPlist(line, NewRelPathString(wrapper), plistFiles)
+       if wrapper := NewPath(wrapper); wrapper.IsAbs() {
+               line.Errorf("Alternative wrapper %q must be relative to PREFIX.", wrapper.String())
+       } else {
+               wrapper := NewRelPath(wrapper)
+               if plistFiles[wrapper] != nil {
+                       line.Errorf("Alternative wrapper %q must not appear in the PLIST.", wrapper)
+               }
+               if !wrapper.HasPrefixText("bin/") &&
+                       !wrapper.HasPrefixText("@PKGMANDIR@/") &&
+                       !wrapper.HasPrefixText("sbin/") {
+                       line.Errorf("Alternative wrapper %q must be in "+
+                               "\"bin\", \"@PKGMANDIR@\" or \"sbin\".", wrapper)
+               }
        }
+
        if plistFiles != nil {
                ck.checkAlternativePlist(line, alternative, plistFiles, pkg)
        }
@@ -51,23 +63,6 @@
        LineChecker{line}.CheckTrailingWhitespace()
 }
 
-func (ck *AlternativesChecker) checkWrapperAbs(line *Line, wrapper Path) bool {
-       if !wrapper.IsAbs() {
-               return true
-       }
-
-       line.Errorf("Alternative wrapper %q must be relative to PREFIX.", wrapper.String())
-       return false
-}
-
-func (ck *AlternativesChecker) checkWrapperPlist(line *Line, wrapper RelPath,
-       plistFiles map[RelPath]*PlistLine) {
-
-       if plistFiles[wrapper] != nil {
-               line.Errorf("Alternative wrapper %q must not appear in the PLIST.", wrapper)
-       }
-}
-
 func (ck *AlternativesChecker) checkAlternativeAbs(alternative string, line *Line, space string) {
        lex := textproc.NewLexer(alternative)
 
diff -r 973039a4da09 -r b33d927a62e9 pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go       Fri Jun 24 06:10:48 2022 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go       Fri Jun 24 07:16:23 2022 +0000
@@ -71,6 +71,8 @@
                "ERROR: ALTERNATIVES:5: Invalid line \"invalid\".",
                "ERROR: ALTERNATIVES:6: Alternative implementation \"${PREFIX}/bin/firefox\" must appear in the PLIST.",
                "ERROR: ALTERNATIVES:6: Alternative implementation \"${PREFIX}/bin/firefox\" must be an absolute path.",
+               "ERROR: ALTERNATIVES:7: Alternative wrapper \"highscores\" "+
+                       "must be in \"bin\", \"@PKGMANDIR@\" or \"sbin\".",
                "ERROR: ALTERNATIVES:7: Alternative implementation \"@VARBASE@/game/scores\" "+
                        "must appear in the PLIST as \"${VARBASE}/game/scores\".")
 
@@ -107,7 +109,7 @@
                        "must be relative to PREFIX.")
 }
 
-func (s *Suite) Test_AlternativesChecker_checkWrapperAbs(c *check.C) {
+func (s *Suite) Test_AlternativesChecker_checkLine__absolute(c *check.C) {
        t := s.Init(c)
 
        t.CreateFileLines("ALTERNATIVES",
@@ -117,11 +119,13 @@
        CheckFileAlternatives(t.File("ALTERNATIVES"), nil)
 
        t.CheckOutputLines(
-               "ERROR: ~/ALTERNATIVES:2: Alternative wrapper \"/absolute\" " +
+               "ERROR: ~/ALTERNATIVES:1: Alternative wrapper \"relative\" "+
+                       "must be in \"bin\", \"@PKGMANDIR@\" or \"sbin\".",
+               "ERROR: ~/ALTERNATIVES:2: Alternative wrapper \"/absolute\" "+
                        "must be relative to PREFIX.")
 }
 
-func (s *Suite) Test_AlternativesChecker_checkWrapperPlist(c *check.C) {
+func (s *Suite) Test_AlternativesChecker_checkLine__PLIST(c *check.C) {
        t := s.Init(c)
 
        t.SetUpPackage("category/package")
@@ -143,6 +147,26 @@
                        "must not appear in the PLIST.")
 }
 
+func (s *Suite) Test_AlternativesChecker_checkLine__dir(c *check.C) {
+       t := s.Init(c)
+
+       t.CreateFileLines("ALTERNATIVES",
+               "in/typo @PREFIX@/bin/typo",
+               "sbin/daemon @PREFIX@/sbin/daemon-impl",
+               "typo/program @PREFIX@/typo/program-impl",
+               "man/man1/program.1 @PREFIX@/man/man1/program-impl.1")
+
+       CheckFileAlternatives(t.File("ALTERNATIVES"), nil)
+
+       t.CheckOutputLines(
+               "ERROR: ~/ALTERNATIVES:1: Alternative wrapper \"in/typo\" "+
+                       "must be in \"bin\", \"@PKGMANDIR@\" or \"sbin\".",
+               "ERROR: ~/ALTERNATIVES:3: Alternative wrapper \"typo/program\" "+
+                       "must be in \"bin\", \"@PKGMANDIR@\" or \"sbin\".",
+               "ERROR: ~/ALTERNATIVES:4: Alternative wrapper \"man/man1/program.1\" "+
+                       "must be in \"bin\", \"@PKGMANDIR@\" or \"sbin\".")
+}
+
 func (s *Suite) Test_AlternativesChecker_checkAlternativeAbs(c *check.C) {
        t := s.Init(c)
 
diff -r 973039a4da09 -r b33d927a62e9 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Fri Jun 24 06:10:48 2022 +0000
+++ b/pkgtools/pkglint/files/autofix.go Fri Jun 24 07:16:23 2022 +0000
@@ -279,9 +279,14 @@
 // MkLines.Check.
 func (fix *Autofix) Apply() {
        // XXX: Make the following annotations actually do something.
+       // Their intention is to insert the following conditions around each
+       // function or method call expression in this function, ensuring that this
+       // function is properly covered in all 3 of pkglint's autofix modes.
+       //
        // gobco:beforeCall:!G.Opts.ShowAutofix && !G.Opts.Autofix
        // gobco:beforeCall:G.Opts.ShowAutofix
        // gobco:beforeCall:G.Opts.Autofix
+       //
        // See https://github.com/rillig/gobco
 
        line := fix.line
diff -r 973039a4da09 -r b33d927a62e9 pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go      Fri Jun 24 06:10:48 2022 +0000
+++ b/pkgtools/pkglint/files/check_test.go      Fri Jun 24 07:16:23 2022 +0000
@@ -233,7 +233,7 @@
 
 func (t *Tester) SetUpMasterSite(varname string, urls ...string) {
        if !G.Pkgsrc.vartypes.IsDefinedExact(varname) {
-               t.SetUpType(varname, BtFetchURL,
+               t.SetUpVarType(varname, BtFetchURL,
                        List|SystemProvided,
                        "buildlink3.mk: none",
                        "*: use")
@@ -255,13 +255,13 @@
        return G.Pkgsrc.Tools.def(name, varname, false, validity, nil)
 }
 
-// SetUpType defines a variable to have a certain type and access permissions,
-// like in the type definitions in vardefs.go.
+// SetUpVarType registers the type and access permissions for a variable, like
+// in the variable definitions in vardefs.go.
 //
 // Example:
-//  SetUpType("PKGPATH", BtPkgpath, DefinedIfInScope|NonemptyIfDefined,
+//  SetUpVarType("PKGPATH", BtPkgpath, DefinedIfInScope|NonemptyIfDefined,
 //      "Makefile, *.mk: default, set, append, use, use-loadtime")
-func (t *Tester) SetUpType(varname string, basicType *BasicType,
+func (t *Tester) SetUpVarType(varname string, basicType *BasicType,
        options vartypeOptions, aclEntries ...string) {
 
        if len(aclEntries) == 0 {
diff -r 973039a4da09 -r b33d927a62e9 pkgtools/pkglint/files/mkassignchecker_test.go
--- a/pkgtools/pkglint/files/mkassignchecker_test.go    Fri Jun 24 06:10:48 2022 +0000
+++ b/pkgtools/pkglint/files/mkassignchecker_test.go    Fri Jun 24 07:16:23 2022 +0000
@@ -457,9 +457,9 @@
 
        t.SetUpVartypes()
        t.SetUpTool("awk", "AWK", AtRunTime)
-       t.SetUpType("SET_ONLY", BtUnknown, NoVartypeOptions,
+       t.SetUpVarType("SET_ONLY", BtUnknown, NoVartypeOptions,
                "options.mk: set")
-       t.SetUpType("SET_ONLY_DEFAULT_ELSEWHERE", BtUnknown, NoVartypeOptions,
+       t.SetUpVarType("SET_ONLY_DEFAULT_ELSEWHERE", BtUnknown, NoVartypeOptions,
                "options.mk: set",
                "*.mk: default, set")
        mklines := t.NewMkLines("options.mk",
diff -r 973039a4da09 -r b33d927a62e9 pkgtools/pkglint/files/mkcondchecker_test.go
--- a/pkgtools/pkglint/files/mkcondchecker_test.go      Fri Jun 24 06:10:48 2022 +0000
+++ b/pkgtools/pkglint/files/mkcondchecker_test.go      Fri Jun 24 07:16:23 2022 +0000
@@ -560,17 +560,17 @@
        // Even when they are in scope, some variables such as PKGREVISION
        // or MAKE_JOBS may be undefined.
 
-       t.SetUpType("IN_SCOPE_DEFINED", btAnything, AlwaysInScope|DefinedIfInScope,
+       t.SetUpVarType("IN_SCOPE_DEFINED", btAnything, AlwaysInScope|DefinedIfInScope,
                "*.mk: use, use-loadtime")
-       t.SetUpType("IN_SCOPE", btAnything, AlwaysInScope,
+       t.SetUpVarType("IN_SCOPE", btAnything, AlwaysInScope,
                "*.mk: use, use-loadtime")
-       t.SetUpType("PREFS_DEFINED", btAnything, DefinedIfInScope,
+       t.SetUpVarType("PREFS_DEFINED", btAnything, DefinedIfInScope,
                "*.mk: use, use-loadtime")
-       t.SetUpType("PREFS", btAnything, NoVartypeOptions,
+       t.SetUpVarType("PREFS", btAnything, NoVartypeOptions,
                "*.mk: use, use-loadtime")
-       t.SetUpType("LATER_DEFINED", btAnything, DefinedIfInScope,
+       t.SetUpVarType("LATER_DEFINED", btAnything, DefinedIfInScope,
                "*.mk: use")
-       t.SetUpType("LATER", btAnything, NoVartypeOptions,
+       t.SetUpVarType("LATER", btAnything, NoVartypeOptions,
                "*.mk: use")
        // UNDEFINED is also used in the following tests, but is obviously
        // not defined here.
@@ -1132,6 +1132,33 @@
                ".if ${IN_SCOPE_DEFINED:M\"}",
 
                nil...)
+
+       // FIXME: Syntax error in the generated code.
+       testBeforeAndAfterPrefs(
+               ".if !empty(IN_SCOPE_DEFINED:M)",
+               ".if ${IN_SCOPE_DEFINED} == ",
+
+               "NOTE: filename.mk:3: IN_SCOPE_DEFINED can be "+
+                       "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} == \".",
+       )
+
+       // TODO: Suggest the simpler '${IN_SCOPE_DEFINED:M*.c}'.
+       testBeforeAndAfterPrefs(
+               ".if !empty(IN_SCOPE_DEFINED:M*.c)",
+               ".if !empty(IN_SCOPE_DEFINED:M*.c)",
+
+               nil...)
+
+       // TODO: Suggest the simpler '!${IN_SCOPE_DEFINED:M*.c}'.
+       testBeforeAndAfterPrefs(
+               ".if empty(IN_SCOPE_DEFINED:M*.c)",
+               ".if empty(IN_SCOPE_DEFINED:M*.c)",
+
+               nil...)
 }
 
 func (s *Suite) Test_MkCondChecker_simplify__defined_in_same_file(c *check.C) {
diff -r 973039a4da09 -r b33d927a62e9 pkgtools/pkglint/files/mkline.go
--- a/pkgtools/pkglint/files/mkline.go  Fri Jun 24 06:10:48 2022 +0000
+++ b/pkgtools/pkglint/files/mkline.go  Fri Jun 24 07:16:23 2022 +0000
@@ -83,7 +83,7 @@
 // and HOMEPAGE using http instead of https.
 //
 // To qualify as a rationale, the comment must contain any of the given
-// keywords. If no keywords are given, any comment qualifies.
+// keywords. If no keywords are given, any nonempty comment qualifies.
 func (mkline *MkLine) HasRationale(keywords ...string) bool {
        rationale := mkline.splitResult.rationale
        if rationale == "" {
@@ -116,8 +116,9 @@
 // entirely, they still count as variable assignments, which means that
 // their comment is the one after the value, if any.
 //
-// Shell commands (lines that start with a tab) cannot have comments, as
-// the # characters are passed uninterpreted to the shell.
+// In shell commands (lines that start with a tab), comments can only start at
+// the beginning of a line, as the first non-whitespace character. Any later
+// '#' is passed uninterpreted to the shell.
 //
 // Example:
 //  VAR=value # comment
@@ -166,8 +167,9 @@
 }
 
 // IsShellCommand returns true for tab-indented lines that are assigned to a Make
-// target. Example:
+// target.
 //
+// Example:
 //  pre-configure:    # IsDependency
 //          ${ECHO}   # IsShellCommand
 func (mkline *MkLine) IsShellCommand() bool {
diff -r 973039a4da09 -r b33d927a62e9 pkgtools/pkglint/files/mkshparser.go
--- a/pkgtools/pkglint/files/mkshparser.go      Fri Jun 24 06:10:48 2022 +0000
+++ b/pkgtools/pkglint/files/mkshparser.go      Fri Jun 24 07:16:23 2022 +0000
@@ -82,7 +82,7 @@



Home | Main Index | Thread Index | Old Index