pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint Updated pkglint to 5.4.11.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/d1c30511b40d
branches:  trunk
changeset: 354874:d1c30511b40d
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Mon Nov 14 01:08:23 2016 +0000

description:
Updated pkglint to 5.4.11.

Changes since 5.4.10:

* Replaced regular expression with hand-written matching code, since
  it is 30 times as fast.
* Reduced number of syscalls by remembering os.Lstat results and
  CVS/Entries.
* Reduced number of syscalls by querying the current user only once.
* Added warning for comparing ${PKGSRC_COMPILER} == "clang", which
  should rather be ${PKGSRC_COMPILER:Mclang}.
* Added variable definitions for NOT_PAX_ASLR_SAFE and NOT_PAX_MPROTECT_SAFE.

diffstat:

 pkgtools/pkglint/Makefile             |   4 +-
 pkgtools/pkglint/files/globaldata.go  |   2 +-
 pkgtools/pkglint/files/globalvars.go  |  19 ++++++----
 pkgtools/pkglint/files/logging.go     |   2 +-
 pkgtools/pkglint/files/main.go        |   7 +++
 pkgtools/pkglint/files/mkline.go      |  10 +++++-
 pkgtools/pkglint/files/mkline_test.go |  16 ++++++++-
 pkgtools/pkglint/files/package.go     |  21 ++++-------
 pkgtools/pkglint/files/pkglint.go     |  63 +++++++++++++++++++++++++++++++++-
 pkgtools/pkglint/files/plist_test.go  |   2 +-
 pkgtools/pkglint/files/util.go        |  33 +++++++++++------
 pkgtools/pkglint/files/util_test.go   |  58 ++++++++++++++++++++++++++++++++
 pkgtools/pkglint/files/vardefs.go     |   2 +
 13 files changed, 197 insertions(+), 42 deletions(-)

diffs (truncated from 431 to 300 lines):

diff -r 12a4d061c572 -r d1c30511b40d pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sun Nov 13 23:45:42 2016 +0000
+++ b/pkgtools/pkglint/Makefile Mon Nov 14 01:08:23 2016 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.499 2016/11/01 21:40:25 rillig Exp $
+# $NetBSD: Makefile,v 1.500 2016/11/14 01:08:23 rillig Exp $
 
-PKGNAME=       pkglint-5.4.10
+PKGNAME=       pkglint-5.4.11
 DISTFILES=     # none
 CATEGORIES=    pkgtools
 
diff -r 12a4d061c572 -r d1c30511b40d pkgtools/pkglint/files/globaldata.go
--- a/pkgtools/pkglint/files/globaldata.go      Sun Nov 13 23:45:42 2016 +0000
+++ b/pkgtools/pkglint/files/globaldata.go      Mon Nov 14 01:08:23 2016 +0000
@@ -114,7 +114,7 @@
                fname := G.globalData.Pkgsrcdir + "/mk/tools/bsd.tools.mk"
                lines := LoadExistingLines(fname, true)
                for _, line := range lines {
-                       if m, _, _, includefile := match3(line.Text, reMkInclude); m {
+                       if m, _, _, includefile := MatchMkInclude(line.Text); m {
                                if !contains(includefile, "/") {
                                        toolFiles = append(toolFiles, includefile)
                                }
diff -r 12a4d061c572 -r d1c30511b40d pkgtools/pkglint/files/globalvars.go
--- a/pkgtools/pkglint/files/globalvars.go      Sun Nov 13 23:45:42 2016 +0000
+++ b/pkgtools/pkglint/files/globalvars.go      Mon Nov 14 01:08:23 2016 +0000
@@ -11,12 +11,15 @@
        Pkg        *Package   // The package that is currently checked.
        Mk         *MkLines   // The Makefile (or fragment) that is currently checked.
 
-       Todo           []string // The files or directories that still need to be checked.
-       CurrentDir     string   // The currently checked directory, relative to the cwd
-       CurPkgsrcdir   string   // The pkgsrc directory, relative to currentDir
-       Wip            bool     // Is the currently checked directory from pkgsrc-wip?
-       Infrastructure bool     // Is the currently checked item from the pkgsrc infrastructure?
-       Testing        bool     // Is pkglint in self-testing mode (only during development)?
+       Todo            []string // The files or directories that still need to be checked.
+       CurrentDir      string   // The currently checked directory, relative to the cwd
+       CurPkgsrcdir    string   // The pkgsrc directory, relative to currentDir
+       Wip             bool     // Is the currently checked directory from pkgsrc-wip?
+       Infrastructure  bool     // Is the currently checked item from the pkgsrc infrastructure?
+       Testing         bool     // Is pkglint in self-testing mode (only during development)?
+       CurrentUsername string   // For checking against OWNER and MAINTAINER
+       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).
@@ -32,10 +35,10 @@
        logErr                io.Writer
        debugOut              io.Writer
 
-       res       map[string]*regexp.Regexp
+       res       map[string]*regexp.Regexp // Compiled regular expressions
        rematch   *Histogram
        renomatch *Histogram
-       retime    *Histogram
+       retime    *Histogram // Total time taken by matching a regular expression
        loghisto  *Histogram
 }
 
diff -r 12a4d061c572 -r d1c30511b40d pkgtools/pkglint/files/logging.go
--- a/pkgtools/pkglint/files/logging.go Sun Nov 13 23:45:42 2016 +0000
+++ b/pkgtools/pkglint/files/logging.go Mon Nov 14 01:08:23 2016 +0000
@@ -105,7 +105,7 @@
                                print(fmt.Sprintf("Long explanation line (%d): %s\n", l, s))
                        }
                        if m, before := match1(s, `(.+)\. [^ ]`); m {
-                               if !matches(before, `\d$`) {
+                               if !matches(before, `\d$|e\.g`) {
                                        print(fmt.Sprintf("Short space after period: %s\n", s))
                                }
                        }
diff -r 12a4d061c572 -r d1c30511b40d pkgtools/pkglint/files/main.go
--- a/pkgtools/pkglint/files/main.go    Sun Nov 13 23:45:42 2016 +0000
+++ b/pkgtools/pkglint/files/main.go    Mon Nov 14 01:08:23 2016 +0000
@@ -4,6 +4,7 @@
        "fmt"
        "io"
        "os"
+       "os/user"
        "path/filepath"
        "runtime/pprof"
 )
@@ -61,6 +62,12 @@
 
        G.globalData.Initialize()
 
+       currentUser, err := user.Current()
+       if err == nil {
+               // On Windows, this is `Computername\Username`.
+               G.CurrentUsername = regcomp(`^.*\\`).ReplaceAllString(currentUser.Username, "")
+       }
+
        for len(G.Todo) != 0 {
                item := G.Todo[0]
                G.Todo = G.Todo[1:]
diff -r 12a4d061c572 -r d1c30511b40d pkgtools/pkglint/files/mkline.go
--- a/pkgtools/pkglint/files/mkline.go  Sun Nov 13 23:45:42 2016 +0000
+++ b/pkgtools/pkglint/files/mkline.go  Mon Nov 14 01:08:23 2016 +0000
@@ -118,7 +118,7 @@
                return
        }
 
-       if m, indent, directive, includefile := match3(text, reMkInclude); m {
+       if m, indent, directive, includefile := MatchMkInclude(text); m {
                mkline.xtype = 6
                mkline.data = mkLineInclude{directive == "include", indent, includefile, ""}
                return
@@ -1196,6 +1196,14 @@
                value := node.args[2].(string)
                if len(varmods) == 0 {
                        mkline.CheckVartype(varname, opUse, value, "")
+                       if varname == "PKGSRC_COMPILER" {
+                               op := node.args[1].(string)
+                               mkline.Line.Warnf("Use ${PKGSRC_COMPILER:%s%s} instead of the %s operator.", ifelseStr(op == "==", "M", "N"), value, op)
+                               Explain(
+                                       "The PKGSRC_COMPILER can be a list of chained compilers, e.g. \"ccache",
+                                       "distcc clang\".  Therefore, comparing it using == or != leads to",
+                                       "wrong results in these cases.")
+                       }
                } else if len(varmods) == 1 && matches(varmods[0], `^[MN]`) && value != "" {
                        mkline.CheckVartype(varname, opUseMatch, value, "")
                }
diff -r 12a4d061c572 -r d1c30511b40d pkgtools/pkglint/files/mkline_test.go
--- a/pkgtools/pkglint/files/mkline_test.go     Sun Nov 13 23:45:42 2016 +0000
+++ b/pkgtools/pkglint/files/mkline_test.go     Mon Nov 14 01:08:23 2016 +0000
@@ -760,7 +760,21 @@
 
        G.Mk.Check()
 
-       c.Check(s.Output(), equals, "") // Donâ??t warn about unknown shell command "cc".
+       // Donâ??t warn about unknown shell command "cc".
+       c.Check(s.Output(), equals, "WARN: security/openssl/Makefile:2: Use ${PKGSRC_COMPILER:Mgcc} instead of the == operator.\n")
+}
+
+func (s *Suite) Test_MkLine_CheckCond_comparing_PKGSRC_COMPILER_with_eqeq(c *check.C) {
+       s.UseCommandLine(c, "-Wall")
+       G.globalData.InitVartypes()
+       G.Mk = s.NewMkLines("audio/pulseaudio/Makefile",
+               mkrcsid,
+               ".if ${OPSYS} == \"Darwin\" && ${PKGSRC_COMPILER} == \"clang\"",
+               ".endif")
+
+       G.Mk.Check()
+
+       c.Check(s.Output(), equals, "WARN: audio/pulseaudio/Makefile:2: Use ${PKGSRC_COMPILER:Mclang} instead of the == operator.\n")
 }
 
 func (s *Suite) Test_MkLine_Pkgmandir(c *check.C) {
diff -r 12a4d061c572 -r d1c30511b40d pkgtools/pkglint/files/package.go
--- a/pkgtools/pkglint/files/package.go Sun Nov 13 23:45:42 2016 +0000
+++ b/pkgtools/pkglint/files/package.go Mon Nov 14 01:08:23 2016 +0000
@@ -2,7 +2,6 @@
 
 import (
        "fmt"
-       "os/user"
        "path"
        "regexp"
        "strconv"
@@ -329,11 +328,13 @@
                                // current file and in the current working directory.
                                // Pkglint doesnâ??t have an include dir list, like make(1) does.
                                if !fileExists(dirname + "/" + includeFile) {
-                                       dirname = G.CurrentDir
-                               }
-                               if !fileExists(dirname + "/" + includeFile) {
-                                       line.Error1("Cannot read %q.", dirname+"/"+includeFile)
-                                       return false
+                                       if dirname != G.CurrentDir { // Prevent unnecessary syscalls
+                                               dirname = G.CurrentDir
+                                               if !fileExists(dirname + "/" + includeFile) {
+                                                       line.Error1("Cannot read %q.", dirname+"/"+includeFile)
+                                                       return false
+                                               }
+                                       }
                                }
 
                                if G.opts.Debug {
@@ -808,13 +809,7 @@
                return
        }
 
-       user, err := user.Current()
-       if err != nil || user.Username == "" {
-               return
-       }
-       // On Windows, this is `Computername\Username`.
-       username := regcomp(`^.*\\`).ReplaceAllString(user.Username, "")
-
+       username := G.CurrentUsername
        if G.opts.Debug {
                traceStep("user=%q owner=%q maintainer=%q", username, owner, maintainer)
        }
diff -r 12a4d061c572 -r d1c30511b40d pkgtools/pkglint/files/pkglint.go
--- a/pkgtools/pkglint/files/pkglint.go Sun Nov 13 23:45:42 2016 +0000
+++ b/pkgtools/pkglint/files/pkglint.go Mon Nov 14 01:08:23 2016 +0000
@@ -7,8 +7,7 @@
 )
 
 const (
-       reMkInclude = `^\.(\s*)(s?include)\s+\"([^\"]+)\"\s*(?:#.*)?$`
-       rePkgname   = `^([\w\-.+]+)-(\d(?:\w|\.\d)*)$`
+       rePkgname = `^([\w\-.+]+)-(\d(?:\w|\.\d)*)$`
 )
 
 // Returns the pkgsrc top-level directory, relative to the given file or directory.
@@ -386,6 +385,66 @@
        return
 }
 
+func MatchMkInclude(text string) (bool, string, string, string) {
+       goto start
+fail:
+       return false, "", "", ""
+
+start:
+       len := len(text)
+       if len == 0 || text[0] != '.' {
+               goto fail
+       }
+
+       i := 1
+
+       spaceStart := i
+       for i < len && (text[i] == ' ' || text[i] == '\t') {
+               i++
+       }
+       spaceEnd := i
+
+       directiveStart := i
+       if i < len && text[i] == 's' {
+               i++
+       }
+       if !(i+7 < len && text[i] == 'i' && text[i+1] == 'n' && text[i+2] == 'c' && text[i+3] == 'l' && text[i+4] == 'u' && text[i+5] == 'd' && text[i+6] == 'e') {
+               goto fail
+       }
+       i += 7
+       directiveEnd := i
+
+       for i < len && (text[i] == ' ' || text[i] == '\t') {
+               i++
+       }
+       if !(i < len && text[i] == '"') {
+               goto fail
+       }
+       i++
+
+       pathStart := i
+       for i < len && text[i] != '"' {
+               i++
+       }
+       pathEnd := i
+       if !(pathStart < pathEnd) {
+               goto fail
+       }
+
+       if !(i < len && text[i] == '"') {
+               goto fail
+       }
+       i++
+
+       for i < len && (text[i] == ' ' || text[i] == '\t') {
+               i++
+       }
+       if !(i == len || i < len && text[i] == '#') {
+               goto fail
+       }
+       return true, text[spaceStart:spaceEnd], text[directiveStart:directiveEnd], text[pathStart:pathEnd]
+}
+
 type DependencyPattern struct {
        pkgbase  string // "freeciv-client", "{gcc48,gcc48-libs}", "${EMACS_REQD}"
        lowerOp  string // ">=", ">"
diff -r 12a4d061c572 -r d1c30511b40d pkgtools/pkglint/files/plist_test.go
--- a/pkgtools/pkglint/files/plist_test.go      Sun Nov 13 23:45:42 2016 +0000
+++ b/pkgtools/pkglint/files/plist_test.go      Mon Nov 14 01:08:23 2016 +0000
@@ -221,7 +221,7 @@
                "AUTOFIX: ~/PLIST: Has been auto-fixed. Please re-run pkglint.\n")
        c.Check(len(lines), equals, len(fixedLines))
        c.Check(s.LoadTmpFile(c, "PLIST"), equals, ""+
-               "@comment $NetBSD: plist_test.go,v 1.9 2016/11/01 21:40:25 rillig Exp $\n"+
+               "@comment $"+"NetBSD$\n"+
                "${PLIST.xen}lib/libvirt/connection-driver/libvirt_driver_libxl.la\n"+
                "${PLIST.hal}lib/libvirt/connection-driver/libvirt_driver_nodedev.la\n"+
                "lib/libvirt/connection-driver/libvirt_driver_storage.la\n"+
diff -r 12a4d061c572 -r d1c30511b40d pkgtools/pkglint/files/util.go
--- a/pkgtools/pkglint/files/util.go    Sun Nov 13 23:45:42 2016 +0000
+++ b/pkgtools/pkglint/files/util.go    Mon Nov 14 01:08:23 2016 +0000
@@ -71,13 +71,10 @@
 
 // Checks whether a file is already committed to the CVS repository.
 func isCommitted(fname string) bool {
-       basename := path.Base(fname)
-       lines, err := readLines(path.Dir(fname)+"/CVS/Entries", false)
-       if err != nil {
-               return false
-       }



Home | Main Index | Thread Index | Old Index