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



details:   https://anonhg.NetBSD.org/pkgsrc/rev/1b7cd1ec1af0
branches:  trunk
changeset: 450487:1b7cd1ec1af0
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Apr 17 18:10:14 2021 +0000

description:
pkgtools/pkglint: update to 21.1.1

Changes since 21.1.0:

Added check for packages that have been migrated to Meson but still
refer to their previous build system, most often involving GNU make and
GNU autotools.  Suggested by nia.

diffstat:

 pkgtools/pkglint/Makefile              |   4 +-
 pkgtools/pkglint/files/mkline.go       |   5 +-
 pkgtools/pkglint/files/package.go      |  61 +++++++++++++++++++++++++++++
 pkgtools/pkglint/files/package_test.go |  71 ++++++++++++++++++++++++++++++++++
 pkgtools/pkglint/files/patches.go      |  13 ++---
 pkgtools/pkglint/files/path.go         |   5 +-
 6 files changed, 146 insertions(+), 13 deletions(-)

diffs (256 lines):

diff -r 3dfc61ebe335 -r 1b7cd1ec1af0 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sat Apr 17 17:48:10 2021 +0000
+++ b/pkgtools/pkglint/Makefile Sat Apr 17 18:10:14 2021 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.682 2021/03/25 21:55:05 rillig Exp $
+# $NetBSD: Makefile,v 1.683 2021/04/17 18:10:14 rillig Exp $
 
-PKGNAME=       pkglint-21.1.0
+PKGNAME=       pkglint-21.1.1
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 3dfc61ebe335 -r 1b7cd1ec1af0 pkgtools/pkglint/files/mkline.go
--- a/pkgtools/pkglint/files/mkline.go  Sat Apr 17 17:48:10 2021 +0000
+++ b/pkgtools/pkglint/files/mkline.go  Sat Apr 17 18:10:14 2021 +0000
@@ -935,12 +935,13 @@
                return
        }
 
-       if !mkline.once.FirstTimeSlice("unintended file globbing", string(ch)) {
+       chStr := string(rune(ch))
+       if !mkline.once.FirstTimeSlice("unintended file globbing", chStr) {
                return
        }
 
        mkline.Warnf("The %q in the word %q may lead to unintended file globbing.",
-               string(ch), str)
+               chStr, str)
        mkline.Explain(
                "To fix this, enclose the word in \"double\" or 'single' quotes.")
 }
diff -r 3dfc61ebe335 -r 1b7cd1ec1af0 pkgtools/pkglint/files/package.go
--- a/pkgtools/pkglint/files/package.go Sat Apr 17 17:48:10 2021 +0000
+++ b/pkgtools/pkglint/files/package.go Sat Apr 17 18:10:14 2021 +0000
@@ -735,6 +735,8 @@
 
        pkg.CheckVarorder(mklines)
 
+       pkg.checkMeson(mklines)
+
        SaveAutofixChanges(mklines.lines)
 }
 
@@ -1178,6 +1180,65 @@
        })
 }
 
+// checkMeson checks for typical leftover snippets from packages that used
+// GNU autotools or another build system, before being migrated to Meson.
+func (pkg *Package) checkMeson(mklines *MkLines) {
+
+       if pkg.Includes("../../devel/meson/build.mk") == nil {
+               return
+       }
+
+       pkg.checkMesonGnuMake(mklines)
+       pkg.checkMesonConfigureArgs()
+       pkg.checkMesonPython(mklines)
+}
+
+func (pkg *Package) checkMesonGnuMake(mklines *MkLines) {
+       gmake := mklines.Tools.ByName("gmake")
+       if gmake != nil && gmake.UsableAtRunTime() {
+               mkline := NewLineWhole(pkg.File("."))
+               mkline.Warnf("Meson packages usually don't need GNU make.")
+               mkline.Explain(
+                       "After migrating a package from GNU make to Meson,",
+                       "GNU make is typically not needed anymore.")
+       }
+}
+
+func (pkg *Package) checkMesonConfigureArgs() {
+       if mkline := pkg.vars.FirstDefinition("CONFIGURE_ARGS"); mkline != nil {
+               mkline.Warnf("Meson packages usually don't need CONFIGURE_ARGS.")
+               mkline.Explain(
+                       "After migrating a package from GNU make to Meson,",
+                       "CONFIGURE_ARGS are typically not needed anymore.")
+       }
+}
+
+func (pkg *Package) checkMesonPython(mklines *MkLines) {
+
+       if mklines.allVars.IsDefined("PYTHON_FOR_BUILD_ONLY") {
+               return
+       }
+
+       for path := range pkg.unconditionalIncludes {
+               if path.ContainsPath("lang/python") {
+                       goto warn
+               }
+       }
+       return
+
+warn:
+       mkline := NewLineWhole(pkg.File("."))
+       mkline.Warnf("Meson packages usually need Python only at build time.")
+       mkline.Explain(
+               "The Meson build system is implemented in Python,",
+               "therefore packages that use Meson need Python",
+               "as a build-time dependency.",
+               "After building the package, it is typically independent from Python.",
+               "",
+               "To change the Python dependency to build-time,",
+               "set PYTHON_FOR_BUILD_ONLY=yes in the package Makefile.")
+}
+
 func (pkg *Package) determineEffectivePkgVars() {
        distnameLine := pkg.vars.FirstDefinition("DISTNAME")
        pkgnameLine := pkg.vars.FirstDefinition("PKGNAME")
diff -r 3dfc61ebe335 -r 1b7cd1ec1af0 pkgtools/pkglint/files/package_test.go
--- a/pkgtools/pkglint/files/package_test.go    Sat Apr 17 17:48:10 2021 +0000
+++ b/pkgtools/pkglint/files/package_test.go    Sat Apr 17 18:10:14 2021 +0000
@@ -2618,6 +2618,77 @@
                        "Modifying USE_LANGUAGES after including ../../mk/compiler.mk has no effect.")
 }
 
+func (s *Suite) Test_Package_checkMesonGnuMake(c *check.C) {
+       t := s.Init(c)
+
+       t.CreateFileLines("devel/meson/build.mk")
+       t.SetUpTool("gmake", "", AtRunTime)
+       t.SetUpPackage("category/package",
+               "USE_TOOLS+=\tgmake",
+               "",
+               ".include \"../../devel/meson/build.mk\"")
+       t.Chdir("category/package")
+       t.FinishSetUp()
+
+       G.Check(".")
+
+       // XXX: Giving the line number would be nice.
+       t.CheckOutputLines(
+               "WARN: Meson packages usually don't need GNU make.")
+}
+
+func (s *Suite) Test_Package_checkMesonConfigureArgs(c *check.C) {
+       t := s.Init(c)
+
+       t.CreateFileLines("devel/meson/build.mk")
+       t.SetUpPackage("category/package",
+               "CONFIGURE_ARGS+=\t--enable-feature",
+               "",
+               ".include \"../../devel/meson/build.mk\"")
+       t.Chdir("category/package")
+       t.FinishSetUp()
+
+       G.Check(".")
+
+       t.CheckOutputLines(
+               "WARN: Makefile:20: Meson packages usually don't need CONFIGURE_ARGS.")
+}
+
+func (s *Suite) Test_Package_checkMesonPython(c *check.C) {
+       t := s.Init(c)
+
+       t.CreateFileLines("devel/meson/build.mk")
+       t.CreateFileLines("lang/python/application.mk")
+       t.SetUpPackage("category/package",
+               "PYTHON_FOR_BUILD_ONLY=\ttool",
+               "",
+               ".include \"../../lang/python/application.mk\"",
+               ".include \"../../devel/meson/build.mk\"")
+       t.Chdir("category/package")
+       t.FinishSetUp()
+
+       G.Check(".")
+
+       t.CheckOutputEmpty()
+}
+
+func (s *Suite) Test_Package_checkMesonPython__missing_PYTHON_FOR_BUILD_ONLY(c *check.C) {
+       t := s.Init(c)
+
+       t.CreateFileLines("devel/meson/build.mk")
+       t.CreateFileLines("lang/python/application.mk")
+       t.SetUpPackage("category/package",
+               ".include \"../../lang/python/application.mk\"",
+               ".include \"../../devel/meson/build.mk\"")
+       t.Chdir("category/package")
+       t.FinishSetUp()
+
+       G.Check(".")
+
+       t.CheckOutputLines(
+               "WARN: Meson packages usually need Python only at build time.")
+}
+
 // PKGNAME is stronger than DISTNAME.
 func (s *Suite) Test_Package_determineEffectivePkgVars__precedence(c *check.C) {
        t := s.Init(c)
diff -r 3dfc61ebe335 -r 1b7cd1ec1af0 pkgtools/pkglint/files/patches.go
--- a/pkgtools/pkglint/files/patches.go Sat Apr 17 17:48:10 2021 +0000
+++ b/pkgtools/pkglint/files/patches.go Sat Apr 17 18:10:14 2021 +0000
@@ -15,11 +15,7 @@
        previousLineEmpty bool
 }
 
-const (
-       rePatchUniFileDel = `^---[\t ]([^\t ]+)(?:[\t ]+(.*))?$`
-       rePatchUniFileAdd = `^\+\+\+[\t ]([^\t ]+)(?:[\t ]+(.*))?$`
-       rePatchUniHunk    = `^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$`
-)
+const rePatchUniFileDel = `^---[\t ]([^\t ]+)(?:[\t ]+(.*))?$`
 
 func (ck *PatchChecker) Check(pkg *Package) {
        if ck.lines.CheckCvsID(0, ``, "") {
@@ -35,6 +31,9 @@
        var patchedFiles []Path
        for !ck.llex.EOF() {
                line := ck.llex.CurrentLine()
+
+               const rePatchUniFileAdd = `^\+\+\+[\t ]([^\t ]+)(?:[\t ]+(.*))?$`
+
                if ck.llex.SkipRegexp(rePatchUniFileDel) {
                        if m := ck.llex.NextRegexp(rePatchUniFileAdd); m != nil {
                                patchedFile := NewPath(m[1])
@@ -104,7 +103,7 @@
        linesDiff := 0
        hasHunks := false
        for {
-               m := ck.llex.NextRegexp(rePatchUniHunk)
+               m := ck.llex.NextRegexp(`^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$`)
                if m == nil {
                        break
                }
@@ -396,7 +395,7 @@
                return
        }
        if m, tagname := match1(text, `\$(Author|Date|Header|Id|Locker|Log|Name|RCSfile|Revision|Source|State|NetBSD)(?::[^\$]*)?\$`); m {
-               if matches(text, rePatchUniHunk) {
+               if matches(text, `^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$`) {
                        ck.llex.PreviousLine().Warnf("Found CVS tag \"$%s$\". Please remove it.", tagname)
                } else {
                        ck.llex.PreviousLine().Warnf("Found CVS tag \"$%s$\". Please remove it by reducing the number of context lines using pkgdiff or \"diff -U[210]\".", tagname)
diff -r 3dfc61ebe335 -r 1b7cd1ec1af0 pkgtools/pkglint/files/path.go
--- a/pkgtools/pkglint/files/path.go    Sat Apr 17 17:48:10 2021 +0000
+++ b/pkgtools/pkglint/files/path.go    Sat Apr 17 18:10:14 2021 +0000
@@ -25,7 +25,7 @@
 // which is usually a sign of an uninitialized variable.
 func (p Path) IsEmpty() bool { return p == "" }
 
-// Returns the directory of the path, with only minimal cleaning.
+// Dir returns the directory of the path, with only minimal cleaning.
 // Only redundant dots and slashes are removed, and only at the end.
 func (p Path) Dir() Path {
        s := p.String()
@@ -188,7 +188,8 @@
        return NewPath(strings.Join(parts, "/"))
 }
 
-// Differs from path.Clean in that only "../../" is replaced, not "../".
+// CleanPath is similar to path.Clean.
+// The difference is that only "../../" is replaced, not "../".
 // Also, the initial directory is always kept.
 // This is to provide the package path as context in deeply nested .include chains.
 func (p Path) CleanPath() Path {



Home | Main Index | Thread Index | Old Index