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 21.4.2



details:   https://anonhg.NetBSD.org/pkgsrc/rev/272ba9935c82
branches:  trunk
changeset: 371942:272ba9935c82
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sun Jan 16 19:14:51 2022 +0000

description:
pkgtools/pkglint: update to 21.4.2

Changes since 21.4.1:

When checking a package, check for naming collision with other packages
from the same category, on case-insensitive file systems.  For packages
from pkgsrc-wip, additionally perform the same check for the main
category of the package, to prepare for importing the package.

diffstat:

 pkgtools/pkglint/Makefile                      |   5 +-
 pkgtools/pkglint/files/category.go             |  37 +++++++++++---
 pkgtools/pkglint/files/category_test.go        |  65 ++++++++++++++++++++++----
 pkgtools/pkglint/files/check_test.go           |  43 ++++++++++++++---
 pkgtools/pkglint/files/mkassignchecker_test.go |   2 +-
 pkgtools/pkglint/files/pkglint.go              |  32 ++++++++++++-
 pkgtools/pkglint/files/redundantscope_test.go  |   2 +-
 pkgtools/pkglint/files/util.go                 |  20 ++++----
 8 files changed, 164 insertions(+), 42 deletions(-)

diffs (truncated from 405 to 300 lines):

diff -r dd842984f87c -r 272ba9935c82 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sun Jan 16 18:09:32 2022 +0000
+++ b/pkgtools/pkglint/Makefile Sun Jan 16 19:14:51 2022 +0000
@@ -1,7 +1,6 @@
-# $NetBSD: Makefile,v 1.708 2022/01/09 20:10:37 bsiegert Exp $
+# $NetBSD: Makefile,v 1.709 2022/01/16 19:14:51 rillig Exp $
 
-PKGNAME=       pkglint-21.4.1
-PKGREVISION=   1
+PKGNAME=       pkglint-21.4.2
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r dd842984f87c -r 272ba9935c82 pkgtools/pkglint/files/category.go
--- a/pkgtools/pkglint/files/category.go        Sun Jan 16 18:09:32 2022 +0000
+++ b/pkgtools/pkglint/files/category.go        Sun Jan 16 19:14:51 2022 +0000
@@ -5,7 +5,7 @@
        "strings"
 )
 
-func CheckdirCategory(dir CurrPath) {
+func CheckdirCategory(dir CurrPath, recurse bool) {
        if trace.Tracing {
                defer trace.Call(dir)()
        }
@@ -48,6 +48,7 @@
 
        var fSubdirs []RelPath
        var mSubdirs []subdir
+       var recurseInto []CurrPath
 
        for _, subdir := range getSubdirs(dir) {
                if dir.JoinNoClean(subdir).JoinNoClean("Makefile").IsFile() {
@@ -96,6 +97,9 @@
                        }
 
                        mSubdirs = append(mSubdirs, subdir{sub, mkline})
+                       if recurse && !mkline.IsCommentedVarassign() {
+                               recurseInto = append(recurseInto, dir.JoinNoClean(sub))
+                       }
 
                } else {
                        if !mkline.IsEmpty() {
@@ -168,13 +172,30 @@
 
        mklines.SaveAutofixChanges()
 
-       if G.Recursive {
-               var recurseInto []CurrPath
-               for _, msub := range mSubdirs {
-                       if !msub.line.IsCommentedVarassign() {
-                               recurseInto = append(recurseInto, dir.JoinNoClean(msub.name))
+       G.Todo.PushFront(recurseInto...)
+}
+
+func CheckPackageDirCollision(dir CurrPath, pkgdir RelPath) {
+       mklines := LoadMk(dir.JoinNoClean("Makefile").CleanDot(), nil, 0)
+       if mklines == nil {
+               return
+       }
+
+       lowerPkgdir := strings.ToLower(pkgdir.String())
+       mklines.ForEach(func(mkline *MkLine) {
+               if mkline.IsVarassignMaybeCommented() && mkline.Varname() == "SUBDIR" {
+                       value := NewPath(mkline.Value())
+                       if value.IsAbs() {
+                               return
+                       }
+                       sub := NewRelPath(value)
+                       lowerSub := strings.ToLower(sub.String())
+                       if lowerSub == lowerPkgdir && sub != pkgdir {
+                               // TODO: Merge duplicate code from CheckdirCategory.
+                               mkline.Errorf("On case-insensitive file systems, "+
+                                       "%q is the same as %q.",
+                                       sub, pkgdir)
                        }
                }
-               G.Todo.PushFront(recurseInto...)
-       }
+       })
 }
diff -r dd842984f87c -r 272ba9935c82 pkgtools/pkglint/files/category_test.go
--- a/pkgtools/pkglint/files/category_test.go   Sun Jan 16 18:09:32 2022 +0000
+++ b/pkgtools/pkglint/files/category_test.go   Sun Jan 16 19:14:51 2022 +0000
@@ -14,7 +14,7 @@
                "",
                ".include \"../mk/category.mk\"")
 
-       CheckdirCategory(t.File("archivers"))
+       CheckdirCategory(t.File("archivers"), false)
 
        t.CheckOutputLines(
                "ERROR: ~/archivers/Makefile:1: Expected \"# $"+"NetBSD$\".",
@@ -53,7 +53,7 @@
        t.CreateFileLines("mk/misc/category.mk",
                "# dummy")
 
-       CheckdirCategory(t.File("archivers"))
+       CheckdirCategory(t.File("archivers"), true)
 
        t.CheckOutputLines(
                "WARN: ~/archivers/Makefile:3: COMMENT contains invalid characters (\\ $ $ $ $ \").")
@@ -118,7 +118,7 @@
                ".include \"../mk/misc/category.mk\"")
        t.FinishSetUp()
 
-       CheckdirCategory(t.File("category"))
+       CheckdirCategory(t.File("category"), false)
 
        t.CheckOutputLines(
                "ERROR: ~/category/Makefile:7: \"duplicate\" must only appear once, already seen in line 5.",
@@ -148,7 +148,7 @@
                ".include \"../mk/misc/category.mk\"")
        t.FinishSetUp()
 
-       CheckdirCategory(t.File("category"))
+       CheckdirCategory(t.File("category"), false)
 
        t.CheckOutputLines(
                "ERROR: ~/category/Makefile:5: "+
@@ -175,7 +175,7 @@
                ".include \"../mk/misc/category.mk\"")
        t.FinishSetUp()
 
-       CheckdirCategory(t.File("category"))
+       CheckdirCategory(t.File("category"), false)
 
        t.CheckOutputLines(
                "ERROR: ~/category/Makefile:5: Package \"above-only-in-fs\" must be listed here.",
@@ -208,7 +208,7 @@
        // but close enough for this test.
        t.CheckDeepEquals(G.Todo.entries, []CurrPath{"."})
 
-       CheckdirCategory(".")
+       CheckdirCategory(".", true)
 
        t.CheckOutputEmpty()
        t.CheckDeepEquals(G.Todo.entries, []CurrPath{"./package", "."})
@@ -240,7 +240,7 @@
                ".include \"../mk/misc/category.mk\"")
        t.FinishSetUp()
 
-       CheckdirCategory(t.File("category"))
+       CheckdirCategory(t.File("category"), false)
 
        t.CheckOutputLines(
                "ERROR: ~/category/Makefile:6: Package \"zzz-fs-only\" must be listed here.",
@@ -265,7 +265,7 @@
                ".include \"../mk/misc/category.mk\"")
        t.FinishSetUp()
 
-       CheckdirCategory(t.File("category"))
+       CheckdirCategory(t.File("category"), false)
 
        t.CheckOutputLines(
                "NOTE: ~/category/Makefile:5: This variable value should be aligned " +
@@ -290,7 +290,7 @@
                ".include \"../mk/misc/category.mk\"")
        t.FinishSetUp()
 
-       CheckdirCategory(t.File("category"))
+       CheckdirCategory(t.File("category"), false)
 
        // These are quite a few warnings and errors, just because there is
        // an additional comment above the COMMENT definition.
@@ -321,7 +321,7 @@
                "SUBDIR+=\tpackage")
        t.FinishSetUp()
 
-       CheckdirCategory(t.File("category"))
+       CheckdirCategory(t.File("category"), false)
 
        // Doesn't happen in practice since categories are created very seldom.
        t.CheckOutputLines(
@@ -466,3 +466,48 @@
                "ERROR: Makefile:7: On case-insensitive file systems, "+
                        "\"package\" is the same as \"PACKAGE\" from line 5.")
 }
+
+func (s *Suite) Test_CheckPackageDirCollision__main(c *check.C) {
+       t := s.Init(c)
+
+       // on case-insensitive filesystems, the packages 'Package' and 'package'
+       // overwrite 'PACKAGE'.
+       t.SetUpPackage("category/PACKAGE")
+       t.SetUpPackage("category/Package")
+       t.SetUpPackage("category/package")
+       t.CreateFileLines("mk/misc/category.mk")
+       t.Chdir("category/package")
+       t.FinishSetUp()
+
+       G.Check(".")
+
+       t.CheckOutputLines(
+               "ERROR: ../Makefile:5: On case-insensitive file systems, "+
+                       "\"PACKAGE\" is the same as \"package\".",
+               "ERROR: ../Makefile:6: On case-insensitive file systems, "+
+                       "\"Package\" is the same as \"package\".")
+}
+
+func (s *Suite) Test_CheckPackageDirCollision__wip(c *check.C) {
+       t := s.Init(c)
+
+       // on case-insensitive filesystems, the package 'Package' overwrites
+       // 'PACKAGE'.
+       t.SetUpPackage("category/PACKAGE")
+       t.SetUpPackage("category/Package")
+       t.SetUpPackage("wip/package",
+               "CATEGORIES=\tcategory")
+       t.CreateFileLines("mk/misc/category.mk")
+       t.Chdir("wip/package")
+       t.FinishSetUp()
+
+       G.Check(".")
+
+       t.CheckOutputLines(
+               "ERROR: ../../category/Makefile:5: "+
+                       "On case-insensitive file systems, "+
+                       "\"PACKAGE\" is the same as \"package\".",
+               "ERROR: ../../category/Makefile:6: "+
+                       "On case-insensitive file systems, "+
+                       "\"Package\" is the same as \"package\".")
+}
diff -r dd842984f87c -r 272ba9935c82 pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go      Sun Jan 16 18:09:32 2022 +0000
+++ b/pkgtools/pkglint/files/check_test.go      Sun Jan 16 19:14:51 2022 +0000
@@ -9,6 +9,7 @@
        "netbsd.org/pkglint/regex"
        "os"
        "regexp"
+       "sort"
        "strconv"
        "strings"
        "testing"
@@ -413,16 +414,42 @@
        t.seenSetupPkgsrc++
 }
 
-// SetUpCategory makes the given category valid by creating a dummy Makefile.
+// SetUpCategory makes the given category valid by creating a realistic
+// Makefile.
 // After that, it can be mentioned in the CATEGORIES variable of a package.
-func (t *Tester) SetUpCategory(name RelPath) {
-       assert(G.Pkgsrc.Rel(t.File(name)).Count() == 1)
+func (t *Tester) SetUpCategory(name RelPath, pkgdir RelPath) {
+       categoryDir := G.Pkgsrc.Rel(t.File(name))
+       assert(categoryDir.Count() == 1)
 
-       makefile := name.JoinNoClean("Makefile")
-       if !t.File(makefile).IsFile() {
-               t.CreateFileLines(makefile,
-                       MkCvsID)
+       categoryMakefile := name.JoinNoClean("Makefile")
+       text, err := t.File(categoryMakefile).ReadString()
+       oldLines := strings.Split(text, "\n")
+       if err != nil {
+               oldLines = []string{
+                       MkCvsID,
+                       "",
+                       "COMMENT=\tComment for the category",
+                       "",
+                       // The SUBDIRs will be added here later.
+                       "",
+                       ".include \"../mk/misc/category.mk\""}
+       } else {
+               oldLines = oldLines[:len(oldLines)-1]
        }
+
+       subdirs := NewStringSet()
+       if pkgdir != "" {
+               subdirs.Add("SUBDIR+=\t" + pkgdir.String())
+       }
+       subdirs.AddAll(oldLines[4 : len(oldLines)-2])
+       sort.Strings(subdirs.Elements)
+
+       var newLines []string
+       newLines = append(newLines, oldLines[:4]...)
+       newLines = append(newLines, subdirs.Elements...)
+       newLines = append(newLines, oldLines[len(oldLines)-2:]...)
+
+       t.CreateFileLines(categoryMakefile, newLines...)
 }
 
 // SetUpPackage sets up all files for a package (including the pkgsrc
@@ -457,7 +484,7 @@
        }
 
        t.SetUpPkgsrc()
-       t.SetUpCategory(category)
+       t.SetUpCategory(category, distname)
 
        t.CreateFileLines(pkgpath.JoinNoClean("DESCR"),
                "Package description")
diff -r dd842984f87c -r 272ba9935c82 pkgtools/pkglint/files/mkassignchecker_test.go
--- a/pkgtools/pkglint/files/mkassignchecker_test.go    Sun Jan 16 18:09:32 2022 +0000
+++ b/pkgtools/pkglint/files/mkassignchecker_test.go    Sun Jan 16 19:14:51 2022 +0000
@@ -858,7 +858,7 @@
                "CATEGORIES=\tregress")
        t.SetUpPackage("regress/misc-package",
                "CATEGORIES=\tmisc")



Home | Main Index | Thread Index | Old Index