pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/pkglint



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sat May 19 12:58:25 UTC 2018

Modified Files:
        pkgsrc/pkgtools/pkglint: Makefile
        pkgsrc/pkgtools/pkglint/files: distinfo.go distinfo_test.go licenses.go
            line.go package.go pkglint.go pkgsrc.go plist.go toplevel.go
            vartypecheck.go vartypecheck_test.go
Added Files:
        pkgsrc/pkgtools/pkglint/files: alternatives.go alternatives_test.go

Log Message:
pkgtools/pkglint: update to 5.5.12

Changes since 5.5.11:
* Improve support for TEST_DEPENDS and USE_TOOLS+= *:test (thanks @leot)
* Add checks for ALTERNATIVES files


To generate a diff of this commit:
cvs rdiff -u -r1.538 -r1.539 pkgsrc/pkgtools/pkglint/Makefile
cvs rdiff -u -r0 -r1.1 pkgsrc/pkgtools/pkglint/files/alternatives.go \
    pkgsrc/pkgtools/pkglint/files/alternatives_test.go
cvs rdiff -u -r1.19 -r1.20 pkgsrc/pkgtools/pkglint/files/distinfo.go
cvs rdiff -u -r1.13 -r1.14 pkgsrc/pkgtools/pkglint/files/distinfo_test.go
cvs rdiff -u -r1.11 -r1.12 pkgsrc/pkgtools/pkglint/files/licenses.go
cvs rdiff -u -r1.22 -r1.23 pkgsrc/pkgtools/pkglint/files/line.go
cvs rdiff -u -r1.29 -r1.30 pkgsrc/pkgtools/pkglint/files/package.go
cvs rdiff -u -r1.32 -r1.33 pkgsrc/pkgtools/pkglint/files/pkglint.go \
    pkgsrc/pkgtools/pkglint/files/vartypecheck.go
cvs rdiff -u -r1.3 -r1.4 pkgsrc/pkgtools/pkglint/files/pkgsrc.go
cvs rdiff -u -r1.24 -r1.25 pkgsrc/pkgtools/pkglint/files/plist.go \
    pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go
cvs rdiff -u -r1.9 -r1.10 pkgsrc/pkgtools/pkglint/files/toplevel.go

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/pkglint/Makefile
diff -u pkgsrc/pkgtools/pkglint/Makefile:1.538 pkgsrc/pkgtools/pkglint/Makefile:1.539
--- pkgsrc/pkgtools/pkglint/Makefile:1.538      Mon May 14 20:25:48 2018
+++ pkgsrc/pkgtools/pkglint/Makefile    Sat May 19 12:58:24 2018
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.538 2018/05/14 20:25:48 rillig Exp $
+# $NetBSD: Makefile,v 1.539 2018/05/19 12:58:24 rillig Exp $
 
-PKGNAME=       pkglint-5.5.11
+PKGNAME=       pkglint-5.5.12
 DISTFILES=     # none
 CATEGORIES=    pkgtools
 

Index: pkgsrc/pkgtools/pkglint/files/distinfo.go
diff -u pkgsrc/pkgtools/pkglint/files/distinfo.go:1.19 pkgsrc/pkgtools/pkglint/files/distinfo.go:1.20
--- pkgsrc/pkgtools/pkglint/files/distinfo.go:1.19      Sat Mar 24 14:32:49 2018
+++ pkgsrc/pkgtools/pkglint/files/distinfo.go   Sat May 19 12:58:25 2018
@@ -157,16 +157,17 @@ func (ck *distinfoLinesChecker) checkUnr
 
 // Inter-package check for differing distfile checksums.
 func (ck *distinfoLinesChecker) checkGlobalMismatch(line Line, fname, alg, hash string) {
-       if G.Hash != nil && !hasPrefix(fname, "patch-") { // Intentionally checking the filename instead of ck.isPatch
+       hashes := G.Pkgsrc.Hashes
+       if hashes != nil && !hasPrefix(fname, "patch-") { // Intentionally checking the filename instead of ck.isPatch
                key := alg + ":" + fname
-               otherHash := G.Hash[key]
+               otherHash := hashes[key]
                if otherHash != nil {
                        if otherHash.hash != hash {
                                line.Errorf("The hash %s for %s is %s, which differs from %s in %s.",
                                        alg, fname, hash, otherHash.hash, otherHash.line.ReferenceFrom(line))
                        }
                } else {
-                       G.Hash[key] = &Hash{hash, line}
+                       hashes[key] = &Hash{hash, line}
                }
        }
 }

Index: pkgsrc/pkgtools/pkglint/files/distinfo_test.go
diff -u pkgsrc/pkgtools/pkglint/files/distinfo_test.go:1.13 pkgsrc/pkgtools/pkglint/files/distinfo_test.go:1.14
--- pkgsrc/pkgtools/pkglint/files/distinfo_test.go:1.13 Mon Feb 19 12:40:38 2018
+++ pkgsrc/pkgtools/pkglint/files/distinfo_test.go      Sat May 19 12:58:25 2018
@@ -32,7 +32,7 @@ func (s *Suite) Test_ChecklinesDistinfo_
        t := s.Init(c)
 
        otherLine := t.NewLine("other/distinfo", 7, "dummy")
-       G.Hash = map[string]*Hash{"SHA512:pkgname-1.0.tar.gz": {"Some-512-bit-hash", otherLine}}
+       G.Pkgsrc.Hashes = map[string]*Hash{"SHA512:pkgname-1.0.tar.gz": {"Some-512-bit-hash", otherLine}}
        lines := t.NewLines("distinfo",
                RcsID,
                "",

Index: pkgsrc/pkgtools/pkglint/files/licenses.go
diff -u pkgsrc/pkgtools/pkglint/files/licenses.go:1.11 pkgsrc/pkgtools/pkglint/files/licenses.go:1.12
--- pkgsrc/pkgtools/pkglint/files/licenses.go:1.11      Sat Mar 24 14:32:49 2018
+++ pkgsrc/pkgtools/pkglint/files/licenses.go   Sat May 19 12:58:25 2018
@@ -6,7 +6,8 @@ import (
 )
 
 func checkToplevelUnusedLicenses() {
-       if G.UsedLicenses == nil {
+       usedLicenses := G.Pkgsrc.UsedLicenses
+       if usedLicenses == nil {
                return
        }
 
@@ -16,7 +17,7 @@ func checkToplevelUnusedLicenses() {
                licensename := licensefile.Name()
                licensepath := licensedir + "/" + licensename
                if fileExists(licensepath) {
-                       if !G.UsedLicenses[licensename] {
+                       if !usedLicenses[licensename] {
                                NewLineWhole(licensepath).Warnf("This license seems to be unused.")
                        }
                }
@@ -52,8 +53,8 @@ func (lc *LicenseChecker) checkLicenseNa
        }
        if licenseFile == "" {
                licenseFile = G.Pkgsrc.File("licenses/" + license)
-               if G.UsedLicenses != nil {
-                       G.UsedLicenses[license] = true
+               if G.Pkgsrc.UsedLicenses != nil {
+                       G.Pkgsrc.UsedLicenses[license] = true
                }
        }
 

Index: pkgsrc/pkgtools/pkglint/files/line.go
diff -u pkgsrc/pkgtools/pkglint/files/line.go:1.22 pkgsrc/pkgtools/pkglint/files/line.go:1.23
--- pkgsrc/pkgtools/pkglint/files/line.go:1.22  Sat Mar 24 14:32:49 2018
+++ pkgsrc/pkgtools/pkglint/files/line.go       Sat May 19 12:58:25 2018
@@ -162,7 +162,7 @@ func (line *LineImpl) String() string {
 
 // Usage:
 //
-//  fix := mkline.Line.Autofix()
+//  fix := line.Autofix()
 //
 //  fix.Errorf("Must not be ...")
 //  fix.Warnf("Should not be ...")
@@ -174,7 +174,7 @@ func (line *LineImpl) String() string {
 //
 //  fix.Replace("from", "to")
 //  fix.ReplaceAfter("prefix", "from", "to")
-//  fix.ReplaceRegex(`\s+`, "space", "from", "to")
+//  fix.ReplaceRegex(`\s+`, "space", -1)
 //  fix.InsertBefore("new line")
 //  fix.InsertAfter("new line")
 //  fix.Delete()

Index: pkgsrc/pkgtools/pkglint/files/package.go
diff -u pkgsrc/pkgtools/pkglint/files/package.go:1.29 pkgsrc/pkgtools/pkglint/files/package.go:1.30
--- pkgsrc/pkgtools/pkglint/files/package.go:1.29       Tue May  1 23:30:11 2018
+++ pkgsrc/pkgtools/pkglint/files/package.go    Sat May 19 12:58:25 2018
@@ -26,6 +26,7 @@ type Package struct {
        EffectivePkgnameLine MkLine          // The origin of the three effective_* values
        SeenBsdPrefsMk       bool            // Has bsd.prefs.mk already been included?
        PlistDirs            map[string]bool // Directories mentioned in the PLIST files
+       PlistFiles           map[string]bool // Regular files mentioned in the PLIST files
 
        vars                  Scope
        bl3                   map[string]Line // buildlink3.mk name => line; contains only buildlink3.mk files that are directly included.
@@ -42,6 +43,7 @@ func NewPackage(pkgpath string) *Package
        pkg := &Package{
                Pkgpath:               pkgpath,
                PlistDirs:             make(map[string]bool),
+               PlistFiles:            make(map[string]bool),
                vars:                  NewScope(),
                bl3:                   make(map[string]Line),
                plistSubstCond:        make(map[string]bool),
@@ -216,6 +218,14 @@ func (pkglint *Pkglint) checkdirPackage(
                }
        }
 
+       if G.opts.CheckAlternatives {
+               for _, fname := range files {
+                       if path.Base(fname) == "ALTERNATIVES" {
+                               CheckfileAlternatives(fname, pkg.PlistFiles)
+                       }
+               }
+       }
+
        if !isEmptyDir(G.CurrentDir + "/scripts") {
                NewLineWhole(G.CurrentDir + "/scripts").Warnf("This directory and its contents are deprecated! Please call the script(s) explicitly from the corresponding target(s) in the pkg's 
Makefile.")
        }
@@ -934,6 +944,7 @@ func (pkg *Package) loadPlistDirs(plistF
 
        for _, line := range lines {
                text := line.Text
+               pkg.PlistFiles[text] = true // XXX: ignores PLIST conditionals for now
                // Keep in sync with PlistChecker.collectFilesAndDirs
                if !contains(text, "$") && !contains(text, "@") {
                        for dir := path.Dir(text); dir != "."; dir = path.Dir(dir) {

Index: pkgsrc/pkgtools/pkglint/files/pkglint.go
diff -u pkgsrc/pkgtools/pkglint/files/pkglint.go:1.32 pkgsrc/pkgtools/pkglint/files/pkglint.go:1.33
--- pkgsrc/pkgtools/pkglint/files/pkglint.go:1.32       Tue May  1 23:30:11 2018
+++ pkgsrc/pkgtools/pkglint/files/pkglint.go    Sat May 19 12:58:25 2018
@@ -41,9 +41,6 @@ type Pkglint struct {
        CvsEntriesDir   string   // Cached to avoid I/O
        CvsEntriesLines []Line
 
-       Hash         map[string]*Hash // Maps "alg:fname" => hash (inter-package check).
-       UsedLicenses map[string]bool  // Maps "license name" => true (inter-package check).
-
        errors                int
        warnings              int
        explainNext           bool
Index: pkgsrc/pkgtools/pkglint/files/vartypecheck.go
diff -u pkgsrc/pkgtools/pkglint/files/vartypecheck.go:1.32 pkgsrc/pkgtools/pkglint/files/vartypecheck.go:1.33
--- pkgsrc/pkgtools/pkglint/files/vartypecheck.go:1.32  Sat Apr 28 23:32:52 2018
+++ pkgsrc/pkgtools/pkglint/files/vartypecheck.go       Sat May 19 12:58:25 2018
@@ -950,9 +950,9 @@ func (cv *VartypeCheck) Tool() {
                        cv.Line.Errorf("Unknown tool %q.", toolname)
                }
                switch tooldep {
-               case "", "bootstrap", "build", "pkgsrc", "run":
+               case "", "bootstrap", "build", "pkgsrc", "run", "test":
                default:
-                       cv.Line.Errorf("Unknown tool dependency %q. Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\".", tooldep)
+                       cv.Line.Errorf("Unknown tool dependency %q. Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\" or \"test\".", tooldep)
                }
        } else if cv.Op != opUseMatch {
                cv.Line.Errorf("Invalid tool syntax: %q.", cv.Value)

Index: pkgsrc/pkgtools/pkglint/files/pkgsrc.go
diff -u pkgsrc/pkgtools/pkglint/files/pkgsrc.go:1.3 pkgsrc/pkgtools/pkglint/files/pkgsrc.go:1.4
--- pkgsrc/pkgtools/pkglint/files/pkgsrc.go:1.3 Tue May  1 23:30:11 2018
+++ pkgsrc/pkgtools/pkglint/files/pkgsrc.go     Sat May 19 12:58:25 2018
@@ -35,6 +35,9 @@ type Pkgsrc struct {
        UserDefinedVars map[string]MkLine   // varname => line; used for checking BUILD_DEFS
        Deprecated      map[string]string   //
        vartypes        map[string]*Vartype // varcanon => type
+
+       Hashes       map[string]*Hash // Maps "alg:fname" => hash (inter-package check).
+       UsedLicenses map[string]bool  // Maps "license name" => true (inter-package check).
 }
 
 func NewPkgsrc(dir string) *Pkgsrc {
@@ -51,7 +54,9 @@ func NewPkgsrc(dir string) *Pkgsrc {
                make(map[string]string),
                make(map[string]MkLine),
                make(map[string]string),
-               make(map[string]*Vartype)}
+               make(map[string]*Vartype),
+               nil, // Only initialized when pkglint is run for a whole pkgsrc installation
+               nil}
 
        // Some user-defined variables do not influence the binary
        // package at all and therefore do not have to be added to

Index: pkgsrc/pkgtools/pkglint/files/plist.go
diff -u pkgsrc/pkgtools/pkglint/files/plist.go:1.24 pkgsrc/pkgtools/pkglint/files/plist.go:1.25
--- pkgsrc/pkgtools/pkglint/files/plist.go:1.24 Sat Mar 24 14:32:49 2018
+++ pkgsrc/pkgtools/pkglint/files/plist.go      Sat May 19 12:58:25 2018
@@ -402,8 +402,8 @@ func (pline *PlistLine) CheckDirective(c
        line := pline.line
 
        if cmd == "unexec" {
-               if m, arg := match1(arg, `^(?:rmdir|\$\{RMDIR\} \%D/)(.*)`); m {
-                       if !contains(arg, "true") && !contains(arg, "${TRUE}") {
+               if m, dir := match1(arg, `^(?:rmdir|\$\{RMDIR\} \%D/)(.*)`); m {
+                       if !contains(dir, "true") && !contains(dir, "${TRUE}") {
                                pline.line.Warnf("Please remove this line. It is no longer necessary.")
                        }
                }
Index: pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go
diff -u pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go:1.24 pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go:1.25
--- pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go:1.24     Sat Apr 28 23:32:52 2018
+++ pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go  Sat May 19 12:58:25 2018
@@ -554,7 +554,7 @@ func (s *Suite) Test_VartypeCheck_Tool(c
 
        t.CheckOutputLines(
                "ERROR: fname:2: Unknown tool dependency \"unknown\". " +
-                       "Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\".")
+                       "Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\" or \"test\".")
 
        runVartypeChecks(t, "USE_TOOLS.NetBSD", opAssignAppend, (*VartypeCheck).Tool,
                "tool3:run",
@@ -562,7 +562,7 @@ func (s *Suite) Test_VartypeCheck_Tool(c
 
        t.CheckOutputLines(
                "ERROR: fname:2: Unknown tool dependency \"unknown\". " +
-                       "Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\".")
+                       "Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\" or \"test\".")
 }
 
 func (s *Suite) Test_VartypeCheck_VariableName(c *check.C) {

Index: pkgsrc/pkgtools/pkglint/files/toplevel.go
diff -u pkgsrc/pkgtools/pkglint/files/toplevel.go:1.9 pkgsrc/pkgtools/pkglint/files/toplevel.go:1.10
--- pkgsrc/pkgtools/pkglint/files/toplevel.go:1.9       Mon Feb 19 12:40:38 2018
+++ pkgsrc/pkgtools/pkglint/files/toplevel.go   Sat May 19 12:58:25 2018
@@ -32,8 +32,8 @@ func CheckdirToplevel() {
 
        if G.opts.Recursive {
                if G.opts.CheckGlobal {
-                       G.UsedLicenses = make(map[string]bool)
-                       G.Hash = make(map[string]*Hash)
+                       G.Pkgsrc.UsedLicenses = make(map[string]bool)
+                       G.Pkgsrc.Hashes = make(map[string]*Hash)
                }
                G.Todo = append(append([]string(nil), ctx.subdirs...), G.Todo...)
        }

Added files:

Index: pkgsrc/pkgtools/pkglint/files/alternatives.go
diff -u /dev/null pkgsrc/pkgtools/pkglint/files/alternatives.go:1.1
--- /dev/null   Sat May 19 12:58:25 2018
+++ pkgsrc/pkgtools/pkglint/files/alternatives.go       Sat May 19 12:58:25 2018
@@ -0,0 +1,42 @@
+package main
+
+import (
+       "netbsd.org/pkglint/regex"
+       "strings"
+)
+
+func CheckfileAlternatives(filename string, plistFiles map[string]bool) {
+       lines, err := readLines(filename, false)
+       if err != nil {
+               return
+       }
+
+       for _, line := range lines {
+               if m, wrapper, space, implementation := match3(line.Text, `^(\S+)([ \t]+)(\S+)`); m {
+                       if plistFiles[wrapper] {
+                               line.Errorf("Alternative wrapper %q must not appear in the PLIST.", wrapper)
+                       }
+
+                       relImplementation := strings.Replace(implementation, "@PREFIX@/", "", 1)
+                       plistName := regex.Compile(`@(\w+)@`).ReplaceAllString(relImplementation, "${$1}")
+                       if !plistFiles[plistName] && !G.Pkg.vars.Defined("ALTERNATIVES_SRC") {
+                               if plistName != implementation {
+                                       line.Errorf("Alternative implementation %q must appear in the PLIST as %q.", implementation, plistName)
+                               } else {
+                                       line.Errorf("Alternative implementation %q must appear in the PLIST.", implementation)
+                               }
+                       }
+
+                       fix := line.Autofix()
+                       fix.Notef("@PREFIX@/ can be omitted from the file name.")
+                       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)
+                       Explain(
+                               "Run \"" + confMake + " help topic=alternatives\" for more information.")
+               }
+       }
+}
Index: pkgsrc/pkgtools/pkglint/files/alternatives_test.go
diff -u /dev/null pkgsrc/pkgtools/pkglint/files/alternatives_test.go:1.1
--- /dev/null   Sat May 19 12:58:25 2018
+++ pkgsrc/pkgtools/pkglint/files/alternatives_test.go  Sat May 19 12:58:25 2018
@@ -0,0 +1,27 @@
+package main
+
+import "gopkg.in/check.v1"
+
+func (s *Suite) Test_Alternatives_PLIST(c *check.C) {
+       t := s.Init(c)
+
+       t.SetupFileLines("ALTERNATIVES",
+               "sbin/sendmail @PREFIX@/sbin/sendmail.postfix@POSTFIXVER@",
+               "sbin/sendmail @PREFIX@/sbin/sendmail.exim@EXIMVER@",
+               "bin/echo bin/gnu-echo",
+               "bin/editor bin/vim -e")
+
+       G.Pkg = NewPackage("")
+       G.Pkg.PlistFiles["bin/echo"] = true
+       G.Pkg.PlistFiles["bin/vim"] = true
+       G.Pkg.PlistFiles["sbin/sendmail.exim${EXIMVER}"] = true
+
+       CheckfileAlternatives(t.TempFilename("ALTERNATIVES"), G.Pkg.PlistFiles)
+
+       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 file name.",
+               "NOTE: ~/ALTERNATIVES:2: @PREFIX@/ can be omitted from the file name.",
+               "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.")
+}



Home | Main Index | Thread Index | Old Index