pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint/files pkgtools/pkglint: update to 5.6.10



details:   https://anonhg.NetBSD.org/pkgsrc/rev/ddedb2b6cd4f
branches:  trunk
changeset: 389122:ddedb2b6cd4f
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Dec 21 08:05:24 2018 +0000

description:
pkgtools/pkglint: update to 5.6.10

Changes since 5.6.9:

* ALTERNATIVES files are correctly checked now. Before, pkglint had
  suggested to remove the @PREFIX/ from the alternative, which was
  wrong and simply didn't work.

* Diagnostics about variable assignments are ordered to report the
  left-hand side first and then everything to the right of the
  assignment operator.

* The pkglint output is escaped properly to avoid sending unwanted
  escape sequences to the terminal.

* The items in .for loops are parsed taking "double" and 'single'
  quotes into account since bmake does it in the same way since 2015.

* In DESCR files, overly long lines are only warned about if they
  contain a space and therefore can be made shorter.

* In DESCR files, text like ${PREFIX} only gets a note if it refers
  to a commonly known pkgsrc variable. This avoids distraction when
  a package mentions ${prefix}/bin or ${template.property}.

* Lots of refactorings and small changes.

diffstat:

 pkgtools/pkglint/files/alternatives.go       |   86 +++++++---
 pkgtools/pkglint/files/alternatives_test.go  |   30 ++-
 pkgtools/pkglint/files/autofix_test.go       |    6 +-
 pkgtools/pkglint/files/buildlink3.go         |    4 +-
 pkgtools/pkglint/files/buildlink3_test.go    |   62 ++++----
 pkgtools/pkglint/files/category_test.go      |    2 +-
 pkgtools/pkglint/files/check_test.go         |    2 +-
 pkgtools/pkglint/files/distinfo.go           |    4 +-
 pkgtools/pkglint/files/distinfo_test.go      |   24 +-
 pkgtools/pkglint/files/line.go               |   15 +-
 pkgtools/pkglint/files/linechecker.go        |   20 +-
 pkgtools/pkglint/files/linechecker_test.go   |   13 +
 pkgtools/pkglint/files/lines_test.go         |   12 +-
 pkgtools/pkglint/files/logging.go            |    2 +-
 pkgtools/pkglint/files/logging_test.go       |    9 +-
 pkgtools/pkglint/files/mkline_test.go        |   12 +-
 pkgtools/pkglint/files/mklinechecker.go      |  117 ++++++---------
 pkgtools/pkglint/files/mklinechecker_test.go |   38 +++-
 pkgtools/pkglint/files/mklines.go            |    4 +-
 pkgtools/pkglint/files/mktypes.go            |    4 +-
 pkgtools/pkglint/files/options.go            |    4 +-
 pkgtools/pkglint/files/options_test.go       |   12 +-
 pkgtools/pkglint/files/package.go            |    4 +-
 pkgtools/pkglint/files/package_test.go       |   48 +++---
 pkgtools/pkglint/files/patches.go            |    4 +-
 pkgtools/pkglint/files/patches_test.go       |  110 +++++++-------
 pkgtools/pkglint/files/pkglint.go            |  205 +++++++++++++++-----------
 pkgtools/pkglint/files/pkglint_test.go       |  180 +++++++++++------------
 pkgtools/pkglint/files/pkgsrc.go             |    2 +-
 pkgtools/pkglint/files/pkgsrc_test.go        |   22 +-
 pkgtools/pkglint/files/pkgver/vercmp.go      |    5 +-
 pkgtools/pkglint/files/plist.go              |    8 +-
 pkgtools/pkglint/files/plist_test.go         |   70 ++++----
 pkgtools/pkglint/files/shell.go              |    9 +-
 pkgtools/pkglint/files/shell_test.go         |    6 +-
 pkgtools/pkglint/files/substcontext.go       |    2 +-
 pkgtools/pkglint/files/substcontext_test.go  |    2 +-
 pkgtools/pkglint/files/tools.go              |    4 +-
 pkgtools/pkglint/files/tools_test.go         |    2 +-
 pkgtools/pkglint/files/trace/tracing.go      |   10 +-
 pkgtools/pkglint/files/util.go               |   15 +-
 pkgtools/pkglint/files/util_test.go          |    5 +-
 pkgtools/pkglint/files/vardefs.go            |   72 ++++----
 pkgtools/pkglint/files/vardefs_test.go       |    8 +-
 pkgtools/pkglint/files/vartype.go            |   10 +-
 pkgtools/pkglint/files/vartype_test.go       |    2 +-
 pkgtools/pkglint/files/vartypecheck.go       |    8 +-
 pkgtools/pkglint/files/vartypecheck_test.go  |    4 +
 48 files changed, 696 insertions(+), 603 deletions(-)

diffs (truncated from 4011 to 300 lines):

diff -r 3bf5d399d9aa -r ddedb2b6cd4f pkgtools/pkglint/files/alternatives.go
--- a/pkgtools/pkglint/files/alternatives.go    Fri Dec 21 07:06:03 2018 +0000
+++ b/pkgtools/pkglint/files/alternatives.go    Fri Dec 21 08:05:24 2018 +0000
@@ -1,8 +1,11 @@
 package pkglint
 
-import "strings"
+import (
+       "netbsd.org/pkglint/textproc"
+       "strings"
+)
 
-func CheckfileAlternatives(filename string) {
+func CheckFileAlternatives(filename string) {
        lines := Load(filename, NotEmpty|LogErrors)
        if lines == nil {
                return
@@ -13,35 +16,64 @@
                plist = G.Pkg.Plist
        }
 
-       for _, line := range lines.Lines {
-               if m, wrapper, space, alternative := match3(line.Text, `^([^\t ]+)([ \t]+)([^\t ]+)`); m {
-                       if plist.Files != nil {
-                               if plist.Files[wrapper] {
-                                       line.Errorf("Alternative wrapper %q must not appear in the PLIST.", wrapper)
-                               }
+       checkPlistWrapper := func(line Line, wrapper string) {
+               if plist.Files[wrapper] {
+                       line.Errorf("Alternative wrapper %q must not appear in the PLIST.", wrapper)
+               }
+       }
+
+       checkPlistAlternative := func(line Line, alternative string) {
+               relImplementation := strings.Replace(alternative, "@PREFIX@/", "", 1)
+               plistName := replaceAll(relImplementation, `@(\w+)@`, "${$1}")
+               if plist.Files[plistName] || G.Pkg.vars.Defined("ALTERNATIVES_SRC") {
+                       return
+               }
+
+               switch {
 
-                               relImplementation := strings.Replace(alternative, "@PREFIX@/", "", 1)
-                               plistName := replaceAll(relImplementation, `@(\w+)@`, "${$1}")
-                               if !plist.Files[plistName] && !G.Pkg.vars.Defined("ALTERNATIVES_SRC") {
-                                       if plistName != alternative {
-                                               line.Errorf("Alternative implementation %q must appear in the PLIST as %q.", alternative, plistName)
-                                       } else {
-                                               line.Errorf("Alternative implementation %q must appear in the PLIST.", alternative)
-                                       }
-                               }
-                       }
+               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)
 
-                       fix := line.Autofix()
-                       fix.Notef("@PREFIX@/ can be omitted from the filename.")
-                       fix.Explain(
-                               "The alternative implementation is always interpreted relative to",
-                               "${PREFIX}.")
-                       fix.ReplaceAfter(space, "@PREFIX@/", "")
-                       fix.Apply()
-               } else {
-                       line.Errorf("Invalid ALTERNATIVES line %q.", line.Text)
+               default:
+                       line.Errorf("Alternative implementation %q must appear in the PLIST as %q.", alternative, plistName)
+               }
+       }
+
+       for _, line := range lines.Lines {
+               m, wrapper, space, alternative := match3(line.Text, `^([^\t ]+)([ \t]+)([^\t ]+)$`)
+               if !m {
+                       line.Errorf("Invalid line %q.", line.Text)
                        G.Explain(
                                sprintf("Run %q for more information.", makeHelp("alternatives")))
+                       continue
+               }
+
+               if plist.Files != nil {
+                       checkPlistWrapper(line, wrapper)
+                       checkPlistAlternative(line, alternative)
+               }
+
+               switch {
+               case hasPrefix(alternative, "/"), hasPrefix(alternative, "@"):
+                       break
+
+               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()
+
+               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.")
                }
        }
 }
diff -r 3bf5d399d9aa -r ddedb2b6cd4f pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go       Fri Dec 21 07:06:03 2018 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go       Fri Dec 21 08:05:24 2018 +0000
@@ -2,7 +2,7 @@
 
 import "gopkg.in/check.v1"
 
-func (s *Suite) Test_CheckfileAlternatives__PLIST(c *check.C) {
+func (s *Suite) Test_CheckFileAlternatives__PLIST(c *check.C) {
        t := s.Init(c)
 
        t.SetupPackage("category/package")
@@ -12,26 +12,40 @@
                "sbin/sendmail @PREFIX@/sbin/sendmail.exim@EXIMVER@",
                "bin/echo bin/gnu-echo",
                "bin/editor bin/vim -e",
-               "invalid")
+               "invalid",
+               "bin/browser\t${PREFIX}/bin/firefox",
+               "highscores   @VARBASE@/game/scores",
+               "sbin/init /sbin/init")
        t.CreateFileLines("PLIST",
                PlistRcsID,
                "bin/echo",
                "bin/vim",
                "sbin/sendmail.exim${EXIMVER}")
 
-       G.CheckDirent(".")
+       G.Check(".")
 
        t.CheckOutputLines(
                "ERROR: ALTERNATIVES:1: Alternative implementation \"@PREFIX@/sbin/sendmail.postfix@POSTFIXVER@\" "+
                        "must appear in the PLIST as \"sbin/sendmail.postfix${POSTFIXVER}\".",
-               "NOTE: ALTERNATIVES:1: @PREFIX@/ can be omitted from the filename.",
-               "NOTE: ALTERNATIVES:2: @PREFIX@/ can be omitted from the filename.",
                "ERROR: ALTERNATIVES:3: Alternative wrapper \"bin/echo\" must not appear in the PLIST.",
                "ERROR: ALTERNATIVES:3: Alternative implementation \"bin/gnu-echo\" must appear in the PLIST.",
-               "ERROR: ALTERNATIVES:5: Invalid ALTERNATIVES line \"invalid\".")
+               "ERROR: ALTERNATIVES:3: Alternative implementation \"bin/gnu-echo\" must be an absolute path.",
+               "ERROR: ALTERNATIVES:4: Invalid line \"bin/editor bin/vim -e\".",
+               "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 implementation \"@VARBASE@/game/scores\" "+
+                       "must appear in the PLIST as \"${VARBASE}/game/scores\".")
+
+       t.SetupCommandLine("--autofix")
+
+       G.Check(".")
+
+       t.CheckOutputLines(
+               "AUTOFIX: ALTERNATIVES:3: Replacing \"bin/gnu-echo\" with \"@PREFIX@/bin/gnu-echo\".")
 }
 
-func (s *Suite) Test_CheckfileAlternatives__empty(c *check.C) {
+func (s *Suite) Test_CheckFileAlternatives__empty(c *check.C) {
        t := s.Init(c)
 
        t.Chdir("category/package")
@@ -39,7 +53,7 @@
 
        G.Pkg = NewPackage(".")
 
-       CheckfileAlternatives("ALTERNATIVES")
+       CheckFileAlternatives("ALTERNATIVES")
 
        t.CheckOutputLines(
                "ERROR: ALTERNATIVES: Must not be empty.")
diff -r 3bf5d399d9aa -r ddedb2b6cd4f pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Fri Dec 21 07:06:03 2018 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Fri Dec 21 08:05:24 2018 +0000
@@ -865,8 +865,8 @@
        G.Pkgsrc.LoadInfrastructure()
        t.Chdir(".")
 
-       G.CheckDirent("x11/xorg-cf-files")
-       G.CheckDirent("x11/xorgproto")
+       G.Check("x11/xorg-cf-files")
+       G.Check("x11/xorgproto")
 
        t.CheckOutputLines(
                ">\tPRE_XORGPROTO_LIST_MISSING =\tapplewmproto",
@@ -886,7 +886,7 @@
        G.Pkgsrc.LoadInfrastructure()
        t.Chdir(".")
 
-       G.CheckDirent("print/tex-bibtex8")
+       G.Check("print/tex-bibtex8")
 
        t.CheckOutputLines(
                ">\tMAKE_FLAGS+=\tCFLAGS=${CFLAGS.${PKGSRC_COMPILER}}",
diff -r 3bf5d399d9aa -r ddedb2b6cd4f pkgtools/pkglint/files/buildlink3.go
--- a/pkgtools/pkglint/files/buildlink3.go      Fri Dec 21 07:06:03 2018 +0000
+++ b/pkgtools/pkglint/files/buildlink3.go      Fri Dec 21 08:05:24 2018 +0000
@@ -13,7 +13,7 @@
        abi, api         *DependencyPattern
 }
 
-func ChecklinesBuildlink3Mk(mklines MkLines) {
+func CheckLinesBuildlink3Mk(mklines MkLines) {
        (&Buildlink3Checker{mklines: mklines}).Check()
 }
 
@@ -64,7 +64,7 @@
 
        if G.Pkg != nil {
                // TODO: Commenting this line doesn't make any test fail, but it should.
-               G.Pkg.checklinesBuildlink3Inclusion(mklines)
+               G.Pkg.checkLinesBuildlink3Inclusion(mklines)
        }
 
        mklines.SaveAutofixChanges()
diff -r 3bf5d399d9aa -r ddedb2b6cd4f pkgtools/pkglint/files/buildlink3_test.go
--- a/pkgtools/pkglint/files/buildlink3_test.go Fri Dec 21 07:06:03 2018 +0000
+++ b/pkgtools/pkglint/files/buildlink3_test.go Fri Dec 21 08:05:24 2018 +0000
@@ -2,7 +2,7 @@
 
 import "gopkg.in/check.v1"
 
-func (s *Suite) Test_ChecklinesBuildlink3Mk__unfinished_url2pkg(c *check.C) {
+func (s *Suite) Test_CheckLinesBuildlink3Mk__unfinished_url2pkg(c *check.C) {
        t := s.Init(c)
 
        t.SetupVartypes()
@@ -27,7 +27,7 @@
                "",
                "BUILDLINK_TREE+=\t-Xbae")
 
-       ChecklinesBuildlink3Mk(mklines)
+       CheckLinesBuildlink3Mk(mklines)
 
        t.CheckOutputLines(
                "ERROR: ~/category/package/buildlink3.mk:2: This comment indicates unfinished work (url2pkg).")
@@ -39,7 +39,7 @@
 //
 // Since then, pkglint also looks at files from mk/ when they are directly
 // included, and therefore finds the default definition for PKGNAME.
-func (s *Suite) Test_ChecklinesBuildlink3Mk__name_mismatch_Haskell_incomplete(c *check.C) {
+func (s *Suite) Test_CheckLinesBuildlink3Mk__name_mismatch_Haskell_incomplete(c *check.C) {
        t := s.Init(c)
 
        t.SetupPackage("x11/hs-X11",
@@ -60,7 +60,7 @@
                "",
                "BUILDLINK_TREE+=\t-hs-X11")
 
-       G.CheckDirent(".")
+       G.Check(".")
 
        // This warning only occurs because pkglint cannot see mk/haskell.mk in this test.
        t.CheckOutputLines(
@@ -73,7 +73,7 @@
 //
 // Since then, pkglint also looks at files from mk/ when they are directly
 // included, and therefore finds the default definition for PKGNAME.
-func (s *Suite) Test_ChecklinesBuildlink3Mk__name_mismatch_Haskell_complete(c *check.C) {
+func (s *Suite) Test_CheckLinesBuildlink3Mk__name_mismatch_Haskell_complete(c *check.C) {
        t := s.Init(c)
 
        t.CreateFileLines("mk/haskell.mk",
@@ -99,12 +99,12 @@
                "",
                "BUILDLINK_TREE+=\t-hs-X11")
 
-       G.CheckDirent(".")
+       G.Check(".")
 
        t.CheckOutputEmpty()
 }
 
-func (s *Suite) Test_ChecklinesBuildlink3Mk__name_mismatch_multiple_inclusion(c *check.C) {
+func (s *Suite) Test_CheckLinesBuildlink3Mk__name_mismatch_multiple_inclusion(c *check.C) {
        t := s.Init(c)
 
        t.SetupVartypes()
@@ -120,7 +120,7 @@
                "",
                "BUILDLINK_TREE+=\t-pkgbase1")
 
-       ChecklinesBuildlink3Mk(mklines)
+       CheckLinesBuildlink3Mk(mklines)
 
        t.CheckOutputLines(
                "ERROR: buildlink3.mk:5: Package name mismatch between multiple-inclusion guard \"PKGBASE2\" "+
@@ -128,7 +128,7 @@
                "WARN: buildlink3.mk:9: Definition of BUILDLINK_API_DEPENDS is missing.")
 }
 
-func (s *Suite) Test_ChecklinesBuildlink3Mk__name_mismatch_abi_api(c *check.C) {
+func (s *Suite) Test_CheckLinesBuildlink3Mk__name_mismatch_abi_api(c *check.C) {
        t := s.Init(c)
 
        t.SetupVartypes()



Home | Main Index | Thread Index | Old Index