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 19.3.14



details:   https://anonhg.NetBSD.org/pkgsrc/rev/c5e1de08ecd4
branches:  trunk
changeset: 405780:c5e1de08ecd4
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sun Dec 08 00:06:37 2019 +0000

description:
pkgtools/pkglint: update to 19.3.14

Changes since 19.3.13:

When pkglint suggests to replace !empty(VARNAME:Mfixed) with ${VARNAME}
== fixed, the exact suggested expression is now part of the diagnostic.
The check and the autofix have been improved. They now apply only to the
last modifier in the whole chain, everything else was a bug in pkglint.

Pkglint now knows the scope of variables better than before. It knows
the difference between variables from <sys.mk> like MACHINE_ARCH, which
are always in scope, and those from mk/defaults/mk.conf, which only come
into scope later, after bsd.prefs.mk has been included. It warns when
variables are used too early, for example in .if conditions.

The pathnames in ALTERNATIVES files are now checked for absolute
pathnames. This mistake doesn't happen in practice, but the code for
converting the different path types internally made it necessary to add
these checks. At least this prevents typos.

The special check for obsolete licenses has been removed since their
license files have been removed and that is checked as well.

Variables named *_AWK may be appended to.

The variables _PKG_SILENT and _PKG_DEBUG are no longer deprecated, they
are obsolete now. They are not used in main pkgsrc and pkgsrc-wip
anymore.

When a package sets a default value for a user-settable variable (which
is something that should not happen anyway), it should .include
bsd.prefs.mk before, in order to not accidentally overwrite the
user-specified value.

Variable modifiers of the form :from=to are now parsed like in bmake.
They are greedy and eat up any following colons as well. This means that
${VAR:.c=.o:Q} replaces source.c with source.o:Q, instead of quoting it.
Pkglint now warns about such cases.

The handling of relative paths in diagnostics is now consistent. All
paths that are part of a diagnostic are relative to the line that issues
the diagnostic.

Fatal errors are no longer suppressed in --autofix mode.

Plus lots of refactoring, to prevent accidental mixing of incompatible
relative paths.

diffstat:

 pkgtools/pkglint/Makefile                      |     4 +-
 pkgtools/pkglint/PLIST                         |    14 +-
 pkgtools/pkglint/files/alternatives.go         |   147 +-
 pkgtools/pkglint/files/alternatives_test.go    |   153 +-
 pkgtools/pkglint/files/autofix.go              |     6 +
 pkgtools/pkglint/files/autofix_test.go         |     9 +-
 pkgtools/pkglint/files/buildlink3.go           |    10 +-
 pkgtools/pkglint/files/buildlink3_test.go      |   305 +-
 pkgtools/pkglint/files/category.go             |    10 +-
 pkgtools/pkglint/files/check_test.go           |   120 +-
 pkgtools/pkglint/files/distinfo.go             |    32 +-
 pkgtools/pkglint/files/files_test.go           |    14 +
 pkgtools/pkglint/files/intqa/ideas.go          |     8 +
 pkgtools/pkglint/files/intqa/qa.go             |    42 +-
 pkgtools/pkglint/files/intqa/qa_test.go        |    25 +-
 pkgtools/pkglint/files/licenses.go             |    25 +-
 pkgtools/pkglint/files/licenses_test.go        |     8 +-
 pkgtools/pkglint/files/line.go                 |    29 +-
 pkgtools/pkglint/files/linelexer.go            |   153 -
 pkgtools/pkglint/files/linelexer_test.go       |    66 -
 pkgtools/pkglint/files/lineslexer.go           |   153 +
 pkgtools/pkglint/files/lineslexer_test.go      |    66 +
 pkgtools/pkglint/files/logging.go              |    38 +-
 pkgtools/pkglint/files/mkassignchecker.go      |   558 +++++
 pkgtools/pkglint/files/mkassignchecker_test.go |  1058 ++++++++++
 pkgtools/pkglint/files/mkcondchecker.go        |   303 +++
 pkgtools/pkglint/files/mkcondchecker_test.go   |  1083 ++++++++++
 pkgtools/pkglint/files/mklexer.go              |   194 +-
 pkgtools/pkglint/files/mklexer_test.go         |   549 ++++-
 pkgtools/pkglint/files/mkline.go               |    50 +-
 pkgtools/pkglint/files/mkline_test.go          |   138 +-
 pkgtools/pkglint/files/mklinechecker.go        |  1348 +-------------
 pkgtools/pkglint/files/mklinechecker_test.go   |  2377 +-----------------------
 pkgtools/pkglint/files/mklineparser.go         |     6 +-
 pkgtools/pkglint/files/mklineparser_test.go    |     4 +-
 pkgtools/pkglint/files/mklines.go              |   112 +-
 pkgtools/pkglint/files/mklines_test.go         |   152 +-
 pkgtools/pkglint/files/mkparser.go             |    18 +-
 pkgtools/pkglint/files/mkparser_test.go        |    16 +
 pkgtools/pkglint/files/mktypes.go              |    13 +-
 pkgtools/pkglint/files/mktypes_test.go         |    46 +-
 pkgtools/pkglint/files/mkvarusechecker.go      |   683 ++++++
 pkgtools/pkglint/files/mkvarusechecker_test.go |  1138 +++++++++++
 pkgtools/pkglint/files/options_test.go         |    14 +-
 pkgtools/pkglint/files/package.go              |   163 +-
 pkgtools/pkglint/files/package_test.go         |   235 ++-
 pkgtools/pkglint/files/patches.go              |    17 +-
 pkgtools/pkglint/files/patches_test.go         |   104 +
 pkgtools/pkglint/files/path.go                 |    83 +-
 pkgtools/pkglint/files/path_test.go            |   510 +++-
 pkgtools/pkglint/files/pkglint.1               |     2 +-
 pkgtools/pkglint/files/pkglint.go              |    20 +-
 pkgtools/pkglint/files/pkglint_test.go         |     4 +-
 pkgtools/pkglint/files/pkgsrc.go               |    49 +-
 pkgtools/pkglint/files/pkgsrc_test.go          |    94 +-
 pkgtools/pkglint/files/plist.go                |    25 +-
 pkgtools/pkglint/files/plist_test.go           |     4 +-
 pkgtools/pkglint/files/redundantscope.go       |    25 +-
 pkgtools/pkglint/files/redundantscope_test.go  |    67 +-
 pkgtools/pkglint/files/shell.go                |    21 +-
 pkgtools/pkglint/files/shell_test.go           |   216 ++-
 pkgtools/pkglint/files/shtokenizer.go          |    12 +-
 pkgtools/pkglint/files/shtokenizer_test.go     |    25 +
 pkgtools/pkglint/files/substcontext.go         |     2 +-
 pkgtools/pkglint/files/tools.go                |     4 +-
 pkgtools/pkglint/files/tools_test.go           |    31 +
 pkgtools/pkglint/files/toplevel.go             |     4 +-
 pkgtools/pkglint/files/util.go                 |    41 +-
 pkgtools/pkglint/files/util_test.go            |    84 +-
 pkgtools/pkglint/files/var.go                  |     4 +-
 pkgtools/pkglint/files/varalignblock.go        |     1 -
 pkgtools/pkglint/files/vardefs.go              |   154 +-
 pkgtools/pkglint/files/vardefs_test.go         |    23 +
 pkgtools/pkglint/files/vargroups.go            |     2 +-
 pkgtools/pkglint/files/vargroups_test.go       |     8 +-
 pkgtools/pkglint/files/vartype.go              |   101 +-
 pkgtools/pkglint/files/vartype_test.go         |    81 +-
 pkgtools/pkglint/files/vartypecheck.go         |    31 +-
 pkgtools/pkglint/files/vartypecheck_test.go    |    49 +-
 79 files changed, 8606 insertions(+), 4987 deletions(-)

diffs (truncated from 17613 to 300 lines):

diff -r b84c27aab2c8 -r c5e1de08ecd4 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sat Dec 07 21:35:18 2019 +0000
+++ b/pkgtools/pkglint/Makefile Sun Dec 08 00:06:37 2019 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.613 2019/12/02 23:32:09 rillig Exp $
+# $NetBSD: Makefile,v 1.614 2019/12/08 00:06:37 rillig Exp $
 
-PKGNAME=       pkglint-19.3.13
+PKGNAME=       pkglint-19.3.14
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r b84c27aab2c8 -r c5e1de08ecd4 pkgtools/pkglint/PLIST
--- a/pkgtools/pkglint/PLIST    Sat Dec 07 21:35:18 2019 +0000
+++ b/pkgtools/pkglint/PLIST    Sun Dec 08 00:06:37 2019 +0000
@@ -1,4 +1,4 @@
-@comment $NetBSD: PLIST,v 1.19 2019/12/02 23:32:09 rillig Exp $
+@comment $NetBSD: PLIST,v 1.20 2019/12/08 00:06:38 rillig Exp $
 bin/pkglint
 gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint.a
 gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/getopt.a
@@ -43,12 +43,16 @@
 gopkg/src/netbsd.org/pkglint/line_test.go
 gopkg/src/netbsd.org/pkglint/linechecker.go
 gopkg/src/netbsd.org/pkglint/linechecker_test.go
-gopkg/src/netbsd.org/pkglint/linelexer.go
-gopkg/src/netbsd.org/pkglint/linelexer_test.go
 gopkg/src/netbsd.org/pkglint/lines.go
 gopkg/src/netbsd.org/pkglint/lines_test.go
+gopkg/src/netbsd.org/pkglint/lineslexer.go
+gopkg/src/netbsd.org/pkglint/lineslexer_test.go
 gopkg/src/netbsd.org/pkglint/logging.go
 gopkg/src/netbsd.org/pkglint/logging_test.go
+gopkg/src/netbsd.org/pkglint/mkassignchecker.go
+gopkg/src/netbsd.org/pkglint/mkassignchecker_test.go
+gopkg/src/netbsd.org/pkglint/mkcondchecker.go
+gopkg/src/netbsd.org/pkglint/mkcondchecker_test.go
 gopkg/src/netbsd.org/pkglint/mklexer.go
 gopkg/src/netbsd.org/pkglint/mklexer_test.go
 gopkg/src/netbsd.org/pkglint/mkline.go
@@ -71,6 +75,8 @@
 gopkg/src/netbsd.org/pkglint/mktokenslexer_test.go
 gopkg/src/netbsd.org/pkglint/mktypes.go
 gopkg/src/netbsd.org/pkglint/mktypes_test.go
+gopkg/src/netbsd.org/pkglint/mkvarusechecker.go
+gopkg/src/netbsd.org/pkglint/mkvarusechecker_test.go
 gopkg/src/netbsd.org/pkglint/options.go
 gopkg/src/netbsd.org/pkglint/options_test.go
 gopkg/src/netbsd.org/pkglint/package.go
@@ -128,5 +134,5 @@
 gopkg/src/netbsd.org/pkglint/vartype_test.go
 gopkg/src/netbsd.org/pkglint/vartypecheck.go
 gopkg/src/netbsd.org/pkglint/vartypecheck_test.go
-man/cat1/pkglint.0
 man/man1/pkglint.1
+@pkgdir man/cat1
diff -r b84c27aab2c8 -r c5e1de08ecd4 pkgtools/pkglint/files/alternatives.go
--- a/pkgtools/pkglint/files/alternatives.go    Sat Dec 07 21:35:18 2019 +0000
+++ b/pkgtools/pkglint/files/alternatives.go    Sun Dec 08 00:06:37 2019 +0000
@@ -11,72 +11,103 @@
                return
        }
 
-       var plist PlistContent
-       if G.Pkg != nil {
-               plist = G.Pkg.Plist
-       }
-
-       checkPlistWrapper := func(line *Line, wrapper Path) {
-               if plist.Files[wrapper] != nil {
-                       line.Errorf("Alternative wrapper %q must not appear in the PLIST.", wrapper)
-               }
-       }
+       var ck AlternativesChecker
+       ck.Check(lines, G.Pkg)
+}
 
-       checkPlistAlternative := func(line *Line, alternative string) {
-               relImplementation := strings.Replace(alternative, "@PREFIX@/", "", 1)
-               plistName := replaceAll(relImplementation, `@(\w+)@`, "${$1}")
-               if plist.Files[NewPath(plistName)] != nil || G.Pkg.vars.IsDefined("ALTERNATIVES_SRC") {
-                       return
-               }
-               if plist.Files[NewPath(strings.Replace(plistName, "${PKGMANDIR}", "man", 1))] != nil {
-                       return
-               }
-
-               switch {
+type AlternativesChecker struct{}
 
-               case hasPrefix(alternative, "/"):
-                       // It's possible but unusual to refer to a fixed absolute path.
-                       // These cannot be mentioned in the PLIST since they are not part of the package.
-                       break
-
-               case plistName == alternative:
-                       line.Errorf("Alternative implementation %q must appear in the PLIST.", alternative)
-
-               default:
-                       line.Errorf("Alternative implementation %q must appear in the PLIST as %q.", alternative, plistName)
-               }
+func (ck *AlternativesChecker) Check(lines *Lines, pkg *Package) {
+       var plistFiles map[RelPath]*PlistLine
+       if pkg != nil {
+               plistFiles = pkg.Plist.Files
        }
 
        for _, line := range lines.Lines {
-               m, wrapper, space, alternative := match3(line.Text, `^([^\t ]+)([ \t]+)([^\t ]+)`)
-               if !m {
-                       line.Errorf("Invalid line %q.", line.Text)
-                       line.Explain(
-                               sprintf("Run %q for more information.", bmakeHelp("alternatives")))
-                       continue
-               }
+               ck.checkLine(line, plistFiles)
+       }
+}
 
-               if plist.Files != nil {
-                       checkPlistWrapper(line, NewPath(wrapper))
-                       checkPlistAlternative(line, alternative)
-               }
+// checkLine checks a single line for the following format:
+//  wrapper alternative [optional arguments]
+func (ck *AlternativesChecker) checkLine(line *Line, plistFiles map[RelPath]*PlistLine) {
+       // TODO: Add $ to the regex, just for confidence
+       m, wrapper, space, alternative := match3(line.Text, `^([^\t ]+)([ \t]+)([^\t ]+)`)
+       if !m {
+               line.Errorf("Invalid line %q.", line.Text)
+               line.Explain(
+                       sprintf("Run %q for more information.", bmakeHelp("alternatives")))
+               return
+       }
 
-               switch {
-               case hasPrefix(alternative, "/"), hasPrefix(alternative, "@"):
-                       break
+       if ck.checkWrapperAbs(line, NewPath(wrapper)) && plistFiles != nil {
+               ck.checkWrapperPlist(line, NewRelPathString(wrapper), plistFiles)
+       }
+       if plistFiles != nil {
+               ck.checkAlternativePlist(line, alternative, plistFiles)
+       }
+
+       ck.checkAlternativeAbs(alternative, line, space)
+}
 
-               case textproc.NewLexer(alternative).NextByteSet(textproc.Alnum) != -1:
-                       fix := line.Autofix()
-                       fix.Errorf("Alternative implementation %q must be an absolute path.", alternative)
-                       fix.Explain(
-                               "It usually starts with @PREFIX@/... to refer to a path inside the installation prefix.")
-                       fix.ReplaceAfter(space, alternative, "@PREFIX@/"+alternative)
-                       fix.Apply()
+func (ck *AlternativesChecker) checkWrapperAbs(line *Line, wrapper Path) bool {
+       if !wrapper.IsAbs() {
+               return true
+       }
 
-               default:
-                       line.Errorf("Alternative implementation %q must be an absolute path.", alternative)
-                       line.Explain(
-                               "It usually starts with @PREFIX@/... to refer to a path inside the installation prefix.")
-               }
+       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)
+
+       if lex.SkipByte('/') || lex.SkipByte('@') {
+               return
+       }
+
+       fix := line.Autofix()
+       fix.Errorf("Alternative implementation %q must be an absolute path.", alternative)
+       fix.Explain(
+               "It usually starts with @PREFIX@/... to refer to a path inside the installation prefix.")
+       if lex.TestByteSet(textproc.Alnum) {
+               fix.ReplaceAfter(space, alternative, "@PREFIX@/"+alternative)
+       }
+       fix.Apply()
+}
+
+func (ck *AlternativesChecker) checkAlternativePlist(line *Line, alternative string,
+       plistFiles map[RelPath]*PlistLine) {
+
+       relImplementation := strings.Replace(alternative, "@PREFIX@/", "", 1)
+       plistName := replaceAll(relImplementation, `@(\w+)@`, "${$1}")
+       if NewPath(plistName).IsAbs() {
+               // It's possible but unusual to refer to a fixed absolute path.
+               // These cannot be mentioned in the PLIST since they are not part of the package.
+               return
+       }
+
+       rel := NewRelPathString(plistName)
+       if plistFiles[rel] != nil || G.Pkg.vars.IsDefined("ALTERNATIVES_SRC") {
+               return
+       }
+       if plistFiles[rel.Replace("${PKGMANDIR}", "man")] != nil {
+               return
+       }
+
+       if plistName == alternative {
+               line.Errorf("Alternative implementation %q must appear in the PLIST.",
+                       alternative)
+       } else {
+               line.Errorf("Alternative implementation %q must appear in the PLIST as %q.",
+                       alternative, plistName)
+       }
+}
diff -r b84c27aab2c8 -r c5e1de08ecd4 pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go       Sat Dec 07 21:35:18 2019 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go       Sun Dec 08 00:06:37 2019 +0000
@@ -2,7 +2,43 @@
 
 import "gopkg.in/check.v1"
 
-func (s *Suite) Test_CheckFileAlternatives__PLIST(c *check.C) {
+func (s *Suite) Test_CheckFileAlternatives__empty(c *check.C) {
+       t := s.Init(c)
+
+       t.Chdir("category/package")
+       t.CreateFileLines("ALTERNATIVES")
+
+       G.Pkg = NewPackage(".")
+
+       CheckFileAlternatives("ALTERNATIVES")
+
+       t.CheckOutputLines(
+               "ERROR: ALTERNATIVES: Must not be empty.")
+}
+
+func (s *Suite) Test_CheckFileAlternatives__ALTERNATIVES_SRC(c *check.C) {
+       t := s.Init(c)
+
+       // It's a strange situation, having an ALTERNATIVES file defined by
+       // the package but then referring to another package's file by means
+       // of ALTERNATIVES_SRC. As of February 2019 I don't remember if I
+       // really had this case in mind when I initially wrote the code in
+       // CheckFileAlternatives.
+       t.SetUpPackage("category/package",
+               "ALTERNATIVES_SRC=\talts")
+       t.CreateFileLines("category/package/ALTERNATIVES",
+               "bin/pgm @PREFIX@/bin/gnu-program",
+               "bin/pgm @PREFIX@/bin/nb-program")
+       t.FinishSetUp()
+
+       G.Check(t.File("category/package"))
+
+       // The ALTERNATIVES file in this package is not checked at all.
+       // If it were, there would be an error for the repeated bin/pgm.
+       t.CheckOutputEmpty()
+}
+
+func (s *Suite) Test_AlternativesChecker_Check__PLIST(c *check.C) {
        t := s.Init(c)
 
        t.SetUpPackage("category/package")
@@ -47,11 +83,88 @@
                "AUTOFIX: ALTERNATIVES:4: Replacing \"bin/vim\" with \"@PREFIX@/bin/vim\".")
 }
 
+func (s *Suite) Test_AlternativesChecker_checkLine(c *check.C) {
+       t := s.Init(c)
+
+       t.SetUpPackage("category/package")
+       t.Chdir("category/package")
+       t.CreateFileLines("ALTERNATIVES",
+               "bin/no-args @PREFIX@/bin/echo",
+               "bin/with-args @PREFIX@/bin/echo hello,",
+               "bin/with-quoted-args @PREFIX@/bin/echo \"hello, world\" \\ cowboy",
+               "bin/trailing @PREFIX@/bin/echo spaces ", // TODO: warn about this
+               "/abs-echo @PREFIX@/bin/echo")
+       t.CreateFileLines("PLIST",
+               PlistCvsID,
+               "bin/echo")
+       t.FinishSetUp()
+
+       G.Check(".")
+
+       t.CheckOutputLines(
+               "ERROR: ALTERNATIVES:5: Alternative wrapper \"/abs-echo\" " +
+                       "must be relative to PREFIX.")
+}
+
+func (s *Suite) Test_AlternativesChecker_checkWrapperAbs(c *check.C) {
+       t := s.Init(c)
+
+       t.CreateFileLines("ALTERNATIVES",



Home | Main Index | Thread Index | Old Index