Source-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 20.1.12



details:   https://anonhg.NetBSD.org/pkgsrc/rev/38214c58abbc
branches:  trunk
changeset: 433387:38214c58abbc
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Mon Jun 01 20:49:54 2020 +0000

description:
pkgtools/pkglint: update to 20.1.12

Changes since 20.1.11:

The file bsd.pkg.mk must only ever be included by package Makefiles
directly, not by other Makefile fragments.  Seen in www/w3m.

The variable BUILDLINK_PREFIX.* should only be used for packages that
have actually been included by the package.  This catches the use of
BUILDLINK_PREFIX.libiconv, which should have been iconv instead.

Allow comments before line 3 in buildlink3.mk files. This is necessary
for mariadb55-client since its buildlink identifier is mysql-client,
which is so non-obvious that it needs to be documented.

diffstat:

 pkgtools/pkglint/Makefile                      |   4 +-
 pkgtools/pkglint/files/buildlink3.go           |  75 ++++++++++++++-----------
 pkgtools/pkglint/files/buildlink3_test.go      |  29 ++++++++++
 pkgtools/pkglint/files/check_test.go           |  12 ++--
 pkgtools/pkglint/files/distinfo.go             |   2 +-
 pkgtools/pkglint/files/line.go                 |   2 +-
 pkgtools/pkglint/files/lines.go                |   2 +-
 pkgtools/pkglint/files/mkassignchecker.go      |   4 +-
 pkgtools/pkglint/files/mkline.go               |   4 +
 pkgtools/pkglint/files/mklinechecker.go        |   6 +-
 pkgtools/pkglint/files/mklinechecker_test.go   |  12 +++-
 pkgtools/pkglint/files/mkvarusechecker.go      |  42 ++++++++++++++
 pkgtools/pkglint/files/mkvarusechecker_test.go |  19 ++++++
 pkgtools/pkglint/files/package.go              |  20 +++---
 pkgtools/pkglint/files/patches.go              |   4 +-
 pkgtools/pkglint/files/path.go                 |  10 +-
 pkgtools/pkglint/files/path_test.go            |   8 +-
 pkgtools/pkglint/files/pkglint.go              |  50 ++++++++--------
 pkgtools/pkglint/files/pkgsrc.go               |   4 +-
 pkgtools/pkglint/files/plist.go                |  10 +-
 pkgtools/pkglint/files/tools.go                |   4 +-
 pkgtools/pkglint/files/util.go                 |   2 +-
 pkgtools/pkglint/files/vardefs.go              |   4 +-
 pkgtools/pkglint/files/vartype.go              |   4 +-
 pkgtools/pkglint/files/vartypecheck.go         |   2 +-
 pkgtools/pkglint/files/vartypecheck_test.go    |  34 +++++++++++
 26 files changed, 259 insertions(+), 110 deletions(-)

diffs (truncated from 965 to 300 lines):

diff -r 2db98c441174 -r 38214c58abbc pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Mon Jun 01 20:32:37 2020 +0000
+++ b/pkgtools/pkglint/Makefile Mon Jun 01 20:49:54 2020 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.650 2020/05/29 20:13:17 rillig Exp $
+# $NetBSD: Makefile,v 1.651 2020/06/01 20:49:54 rillig Exp $
 
-PKGNAME=       pkglint-20.1.11
+PKGNAME=       pkglint-20.1.12
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 2db98c441174 -r 38214c58abbc pkgtools/pkglint/files/buildlink3.go
--- a/pkgtools/pkglint/files/buildlink3.go      Mon Jun 01 20:32:37 2020 +0000
+++ b/pkgtools/pkglint/files/buildlink3.go      Mon Jun 01 20:49:54 2020 +0000
@@ -72,6 +72,9 @@
 
 func (ck *Buildlink3Checker) checkFirstParagraph(mlex *MkLinesLexer) bool {
 
+       for mlex.SkipPrefix("#") {
+       }
+
        // First paragraph: Introduction of the package identifier
        m := mlex.NextRegexp(`^BUILDLINK_TREE\+=[\t ]*([^\t ]+)$`)
        if m == nil {
@@ -104,7 +107,7 @@
        }
 
        dirname := G.Pkgsrc.Rel(mkline.Filename().Dir()).Base()
-       base, name := trimCommon(pkgbase, dirname)
+       base, name := trimCommon(pkgbase, dirname.String())
        if base == "" && matches(name, `^(\d*|-cvs|-fossil|-git|-hg|-svn|-devel|-snapshot)$`) {
                return
        }
@@ -315,6 +318,7 @@
 
 type Buildlink3Data struct {
        id             Buildlink3ID
+       prefix         Path
        pkgsrcdir      PackagePath
        apiDepends     *DependencyPattern
        apiDependsLine *MkLine
@@ -331,43 +335,50 @@
 
 func LoadBuildlink3Data(mklines *MkLines) *Buildlink3Data {
        var data Buildlink3Data
+
        mklines.ForEach(func(mkline *MkLine) {
-               if mkline.IsVarassign() {
-                       varname := mkline.Varname()
-                       varbase := varnameBase(varname)
-                       varid := Buildlink3ID(varnameParam(varname))
-
-                       if varname == "BUILDLINK_TREE" {
-                               value := mkline.Value()
-                               if !hasPrefix(value, "-") {
-                                       data.id = Buildlink3ID(mkline.Value())
-                               }
-                       }
+               if !mkline.IsVarassign() {
+                       return
+               }
 
-                       if varbase == "BUILDLINK_API_DEPENDS" && varid == data.id {
-                               p := NewMkParser(nil, mkline.Value())
-                               dep := p.DependencyPattern()
-                               if dep != nil && p.EOF() {
-                                       data.apiDepends = dep
-                                       data.apiDependsLine = mkline
-                               }
-                       }
+               varname := mkline.Varname()
+               varbase := varnameBase(varname)
+               varid := Buildlink3ID(varnameParam(varname))
 
-                       if varbase == "BUILDLINK_ABI_DEPENDS" && varid == data.id {
-                               p := NewMkParser(nil, mkline.Value())
-                               dep := p.DependencyPattern()
-                               if dep != nil && p.EOF() {
-                                       data.abiDepends = dep
-                                       data.abiDependsLine = mkline
-                               }
-                       }
-
-                       if varbase == "BUILDLINK_PKGSRCDIR" && varid == data.id {
-                               data.pkgsrcdir = NewPackagePathString(mkline.Value())
+               if varname == "BUILDLINK_TREE" {
+                       value := mkline.Value()
+                       if !hasPrefix(value, "-") {
+                               data.id = Buildlink3ID(mkline.Value())
                        }
                }
+
+               if varbase == "BUILDLINK_API_DEPENDS" && varid == data.id {
+                       p := NewMkParser(nil, mkline.Value())
+                       dep := p.DependencyPattern()
+                       if dep != nil && p.EOF() {
+                               data.apiDepends = dep
+                               data.apiDependsLine = mkline
+                       }
+               }
+
+               if varbase == "BUILDLINK_ABI_DEPENDS" && varid == data.id {
+                       p := NewMkParser(nil, mkline.Value())
+                       dep := p.DependencyPattern()
+                       if dep != nil && p.EOF() {
+                               data.abiDepends = dep
+                               data.abiDependsLine = mkline
+                       }
+               }
+
+               if varbase == "BUILDLINK_PREFIX" && varid == data.id {
+                       data.prefix = NewPath(mkline.Value())
+               }
+               if varbase == "BUILDLINK_PKGSRCDIR" && varid == data.id {
+                       data.pkgsrcdir = NewPackagePathString(mkline.Value())
+               }
        })
-       if data.id != "" && !data.pkgsrcdir.IsEmpty() && data.apiDepends != nil && data.abiDepends != nil {
+
+       if data.id != "" {
                return &data
        }
        return nil
diff -r 2db98c441174 -r 38214c58abbc pkgtools/pkglint/files/buildlink3_test.go
--- a/pkgtools/pkglint/files/buildlink3_test.go Mon Jun 01 20:32:37 2020 +0000
+++ b/pkgtools/pkglint/files/buildlink3_test.go Mon Jun 01 20:49:54 2020 +0000
@@ -506,6 +506,35 @@
        t.CheckOutputEmpty()
 }
 
+func (s *Suite) Test_Buildlink3Checker_checkFirstParagraph__comment_before_tree(c *check.C) {
+       t := s.Init(c)
+
+       t.SetUpPkgsrc()
+       t.SetUpPackage("category/package")
+       t.CreateFileLines("category/package/buildlink3.mk",
+               MkCvsID,
+               "",
+               "# comment",
+               "BUILDLINK_TREE+=\tpackage",
+               "",
+               ".if !defined(PACKAGE_BUILDLINK3_MK)",
+               "PACKAGE_BUILDLINK3_MK:=",
+               "",
+               "BUILDLINK_API_DEPENDS.package+=\tpackage>=0",
+               "BUILDLINK_PKGSRCDIR.package?=\t../../category/package",
+               "BUILDLINK_DEPMETHOD.package?=\tbuild",
+               "",
+               ".endif # PACKAGE_BUILDLINK3_MK",
+               "",
+               "BUILDLINK_TREE+=\t-package")
+       t.FinishSetUp()
+
+       G.Check(t.File("category/package/buildlink3.mk"))
+
+       // No warning in line 3. Comments are ok there.
+       t.CheckOutputEmpty()
+}
+
 func (s *Suite) Test_Buildlink3Checker_checkUniquePkgbase(c *check.C) {
        t := s.Init(c)
 
diff -r 2db98c441174 -r 38214c58abbc pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go      Mon Jun 01 20:32:37 2020 +0000
+++ b/pkgtools/pkglint/files/check_test.go      Mon Jun 01 20:49:54 2020 +0000
@@ -498,7 +498,7 @@
        mlines := []string{
                MkCvsID,
                "",
-               "DISTNAME=\t" + distname + "-1.0",
+               "DISTNAME=\t" + distname.String() + "-1.0",
                "#PKGNAME=\tpackage-1.0",
                "CATEGORIES=\t" + category.String(),
                "MASTER_SITES=\t# none",
@@ -589,7 +589,7 @@
 
 func (t *Tester) CreateFileBuildlink3(filename RelPath, customLines ...string) {
        lower := filename.Dir().Base()
-       t.CreateFileBuildlink3Id(filename, lower, customLines...)
+       t.CreateFileBuildlink3Id(filename, lower.String(), customLines...)
 }
 
 func (t *Tester) CreateFileBuildlink3Id(filename RelPath, id string, customLines ...string) {
@@ -739,7 +739,7 @@
                fromDir := including.Dir().Clean()
                to := basedir.Rel(included.AsPath())
                if fromDir == to.Dir() {
-                       return NewRelPathString(to.Base())
+                       return to.Base()
                } else {
                        return fromDir.Rel(basedir).JoinNoClean(to).CleanDot()
                }
@@ -1001,9 +1001,9 @@
 func (t *Tester) NewMkLine(filename CurrPath, lineno int, text string) *MkLine {
        basename := filename.Base()
        assertf(
-               hasSuffix(basename, ".mk") ||
+               basename.HasSuffixText(".mk") ||
                        basename == "Makefile" ||
-                       hasPrefix(basename, "Makefile.") ||
+                       basename.HasPrefixText("Makefile.") ||
                        basename == "mk.conf",
                "filename %q must be realistic, otherwise the variable permissions are wrong", filename)
 
@@ -1053,7 +1053,7 @@
 func (t *Tester) NewMkLinesPkg(filename CurrPath, pkg *Package, lines ...string) *MkLines {
        basename := filename.Base()
        assertf(
-               hasSuffix(basename, ".mk") || basename == "Makefile" || hasPrefix(basename, "Makefile."),
+               basename.HasSuffixText(".mk") || basename == "Makefile" || basename.HasPrefixText("Makefile."),
                "filename %q must be realistic, otherwise the variable permissions are wrong", filename)
 
        var rawText strings.Builder
diff -r 2db98c441174 -r 38214c58abbc pkgtools/pkglint/files/distinfo.go
--- a/pkgtools/pkglint/files/distinfo.go        Mon Jun 01 20:32:37 2020 +0000
+++ b/pkgtools/pkglint/files/distinfo.go        Mon Jun 01 20:49:54 2020 +0000
@@ -35,7 +35,7 @@
        ck.checkUnrecordedPatches()
 
        if pkg != nil {
-               pkg.distinfoDistfiles = make(map[string]bool)
+               pkg.distinfoDistfiles = make(map[RelPath]bool)
                for path := range ck.infos {
                        pkg.distinfoDistfiles[path.Base()] = true
                }
diff -r 2db98c441174 -r 38214c58abbc pkgtools/pkglint/files/line.go
--- a/pkgtools/pkglint/files/line.go    Mon Jun 01 20:32:37 2020 +0000
+++ b/pkgtools/pkglint/files/line.go    Mon Jun 01 20:49:54 2020 +0000
@@ -56,7 +56,7 @@
        // TODO: Consider storing pointers to the Filename and Basename instead of strings to save memory.
        //  But first find out where and why pkglint needs so much memory (200 MB for a full recursive run over pkgsrc + wip).
        Location Location
-       Basename string // the last component of the Filename
+       Basename RelPath // the last component of the Filename
 
        // the text of the line, without the trailing newline character;
        // in Makefiles, also contains the text from the continuation lines,
diff -r 2db98c441174 -r 38214c58abbc pkgtools/pkglint/files/lines.go
--- a/pkgtools/pkglint/files/lines.go   Mon Jun 01 20:32:37 2020 +0000
+++ b/pkgtools/pkglint/files/lines.go   Mon Jun 01 20:49:54 2020 +0000
@@ -6,7 +6,7 @@
 
 type Lines struct {
        Filename CurrPath
-       BaseName string // TODO: consider converting to Path
+       BaseName RelPath
        Lines    []*Line
 }
 
diff -r 2db98c441174 -r 38214c58abbc pkgtools/pkglint/files/mkassignchecker.go
--- a/pkgtools/pkglint/files/mkassignchecker.go Mon Jun 01 20:32:37 2020 +0000
+++ b/pkgtools/pkglint/files/mkassignchecker.go Mon Jun 01 20:49:54 2020 +0000
@@ -387,7 +387,7 @@
        primary := categories[0]
        dir := G.Pkgsrc.Rel(mkline.Filename()).Dir().Dir().Base()
 
-       if primary == dir || dir == "wip" || dir == "regress" {
+       if primary == dir.String() || dir == "wip" || dir == "regress" {
                return
        }
 
@@ -397,7 +397,7 @@
                "The primary category of a package should be its location in the",
                "pkgsrc directory tree, to make it easy to find the package.",
                "All other categories may be added after this primary category.")
-       if len(categories) > 1 && categories[1] == dir {
+       if len(categories) > 1 && categories[1] == dir.String() {
                fix.Replace(primary+" "+categories[1], categories[1]+" "+primary)
        }
        fix.Apply()
diff -r 2db98c441174 -r 38214c58abbc pkgtools/pkglint/files/mkline.go
--- a/pkgtools/pkglint/files/mkline.go  Mon Jun 01 20:32:37 2020 +0000
+++ b/pkgtools/pkglint/files/mkline.go  Mon Jun 01 20:49:54 2020 +0000
@@ -270,6 +270,10 @@
 
 func (mkline *MkLine) ShellCommand() string { return mkline.data.(mkLineShell).command }
 
+// Indent returns the whitespace between the dot and the directive.
+//
+// For the following example line it returns two spaces:
+//  .  include "other.mk"
 func (mkline *MkLine) Indent() string {
        if mkline.IsDirective() {
                return mkline.data.(*mkLineDirective).indent
diff -r 2db98c441174 -r 38214c58abbc pkgtools/pkglint/files/mklinechecker.go
--- a/pkgtools/pkglint/files/mklinechecker.go   Mon Jun 01 20:32:37 2020 +0000
+++ b/pkgtools/pkglint/files/mklinechecker.go   Mon Jun 01 20:49:54 2020 +0000
@@ -245,7 +245,6 @@
        if trace.Tracing {
                trace.Stepf("includingFile=%s includedFile=%s", mkline.Filename(), includedFile)
        }
-       // TODO: Not every path is relative to the package directory.
        ck.CheckRelativePath(NewPackagePath(includedFile), includedFile, mustExist)
 
        switch {
@@ -257,7 +256,10 @@
                        "module.mk or similar.",
                        "After that, both this one and the other package should include the newly created file.")
 



Home | Main Index | Thread Index | Old Index