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 5.5.16



details:   https://anonhg.NetBSD.org/pkgsrc/rev/f8ed77ca4869
branches:  trunk
changeset: 383776:f8ed77ca4869
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Aug 09 20:08:12 2018 +0000

description:
pkgtools/pkglint: Update to 5.5.16

Changes since 5.5.15:

* Add checks for options.mk files

* Treat redundant variable definitions as notes, not as warnings

* Check doc/CHANGES-* for typos in the dates (only for 2018 and later)

* Lots of cleanup in the test code

diffstat:

 pkgtools/pkglint/Makefile                       |    4 +-
 pkgtools/pkglint/files/autofix_test.go          |    4 +-
 pkgtools/pkglint/files/check_test.go            |    5 +-
 pkgtools/pkglint/files/expecter.go              |   38 ++++++++
 pkgtools/pkglint/files/files_test.go            |   12 ++-
 pkgtools/pkglint/files/mkline_test.go           |    3 +-
 pkgtools/pkglint/files/mklinechecker_test.go    |    9 +-
 pkgtools/pkglint/files/mklines_test.go          |   12 ++
 pkgtools/pkglint/files/mklines_varalign_test.go |    7 +-
 pkgtools/pkglint/files/options.go               |  106 ++++++++++++++++++++++++
 pkgtools/pkglint/files/options_test.go          |   78 +++++++++++++++++
 pkgtools/pkglint/files/package_test.go          |    7 +-
 pkgtools/pkglint/files/pkglint.go               |    9 ++
 pkgtools/pkglint/files/pkglint_test.go          |    1 +
 pkgtools/pkglint/files/pkgsrc.go                |   24 +++++
 pkgtools/pkglint/files/pkgsrc_test.go           |   34 ++++---
 pkgtools/pkglint/files/shell_test.go            |    4 +-
 pkgtools/pkglint/files/util.go                  |    5 +-
 18 files changed, 319 insertions(+), 43 deletions(-)

diffs (truncated from 638 to 300 lines):

diff -r f418f09a6308 -r f8ed77ca4869 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Thu Aug 09 19:10:06 2018 +0000
+++ b/pkgtools/pkglint/Makefile Thu Aug 09 20:08:12 2018 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.543 2018/07/28 18:31:23 rillig Exp $
+# $NetBSD: Makefile,v 1.544 2018/08/09 20:08:12 rillig Exp $
 
-PKGNAME=       pkglint-5.5.15
+PKGNAME=       pkglint-5.5.16
 DISTFILES=     # none
 CATEGORIES=    pkgtools
 
diff -r f418f09a6308 -r f8ed77ca4869 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Thu Aug 09 19:10:06 2018 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Thu Aug 09 20:08:12 2018 +0000
@@ -257,12 +257,12 @@
        t := s.Init(c)
 
        t.SetupCommandLine("--show-autofix", "--source")
-       lines := t.SetupFileLinesContinuation("Makefile",
+       mklines := t.SetupFileMkLines("Makefile",
                MkRcsID,
                "before \\",
                "The old song \\",
                "after")
-       line := lines[1]
+       line := mklines.lines[1]
 
        {
                fix := line.Autofix()
diff -r f418f09a6308 -r f8ed77ca4869 pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go      Thu Aug 09 19:10:06 2018 +0000
+++ b/pkgtools/pkglint/files/check_test.go      Thu Aug 09 20:08:12 2018 +0000
@@ -154,9 +154,10 @@
 
 // SetupFileLines creates a temporary file and writes the given lines to it.
 // The file is then read in, handling line continuations for Makefiles.
-func (t *Tester) SetupFileLinesContinuation(relativeFilename string, lines ...string) []Line {
+func (t *Tester) SetupFileMkLines(relativeFilename string, lines ...string) *MkLines {
        filename := t.CreateFileLines(relativeFilename, lines...)
-       return LoadExistingLines(filename, true)
+       plainLines := LoadExistingLines(filename, true)
+       return NewMkLines(plainLines)
 }
 
 func (t *Tester) CreateFileLines(relativeFilename string, lines ...string) (filename string) {
diff -r f418f09a6308 -r f8ed77ca4869 pkgtools/pkglint/files/expecter.go
--- a/pkgtools/pkglint/files/expecter.go        Thu Aug 09 19:10:06 2018 +0000
+++ b/pkgtools/pkglint/files/expecter.go        Thu Aug 09 20:08:12 2018 +0000
@@ -82,6 +82,16 @@
        return !exp.EOF() && exp.lines[exp.index].Text == text && exp.Advance()
 }
 
+func (exp *Expecter) AdvanceWhile(pred func(line Line) bool) {
+       if trace.Tracing {
+               defer trace.Call(exp.CurrentLine().Text)()
+       }
+
+       for !exp.EOF() && !pred(exp.CurrentLine()) {
+               exp.Advance()
+       }
+}
+
 func (exp *Expecter) ExpectEmptyLine(warnSpace bool) bool {
        if exp.AdvanceIfEquals("") {
                return true
@@ -110,3 +120,31 @@
 func (exp *Expecter) SkipToFooter() {
        exp.index = len(exp.lines) - 2
 }
+
+// MkExpecter records the state when checking a list of Makefile lines from top to bottom.
+type MkExpecter struct {
+       mklines *MkLines
+       Expecter
+}
+
+func NewMkExpecter(mklines *MkLines) *MkExpecter {
+       return &MkExpecter{mklines, *NewExpecter(mklines.lines)}
+}
+
+func (exp *MkExpecter) CurrentMkLine() MkLine {
+       return exp.mklines.mklines[exp.index]
+}
+
+func (exp *MkExpecter) PreviousMkLine() MkLine {
+       return exp.mklines.mklines[exp.index-1]
+}
+
+func (exp *MkExpecter) AdvanceWhile(pred func(mkline MkLine) bool) {
+       if trace.Tracing {
+               defer trace.Call(exp.CurrentMkLine().Text)()
+       }
+
+       for !exp.EOF() && pred(exp.CurrentMkLine()) {
+               exp.Advance()
+       }
+}
diff -r f418f09a6308 -r f8ed77ca4869 pkgtools/pkglint/files/files_test.go
--- a/pkgtools/pkglint/files/files_test.go      Thu Aug 09 19:10:06 2018 +0000
+++ b/pkgtools/pkglint/files/files_test.go      Thu Aug 09 20:08:12 2018 +0000
@@ -34,7 +34,7 @@
 func (s *Suite) Test_convertToLogicalLines__comments(c *check.C) {
        t := s.Init(c)
 
-       lines := t.SetupFileLinesContinuation("comment.mk",
+       mklines := t.SetupFileMkLines("comment.mk",
                "# This is a comment",
                "",
                "#\\",
@@ -60,7 +60,7 @@
                "This is no comment")
 
        var texts []string
-       for _, line := range lines {
+       for _, line := range mklines.lines {
                texts = append(texts, line.Text)
        }
 
@@ -83,7 +83,7 @@
                "This is no comment"})
 
        var rawTexts []string
-       for _, line := range lines {
+       for _, line := range mklines.lines {
                for _, rawLine := range line.raw {
                        rawTexts = append(rawTexts, rawLine.textnl)
                }
@@ -113,6 +113,12 @@
                "This is a comment\n",
                "#\\\\\\\\\\\\\n",
                "This is no comment\n"})
+
+       // This is just a side-effect and not relevant for this particular test.
+       t.CheckOutputLines(
+               "ERROR: ~/comment.mk:15: Unknown Makefile line format.",
+               "ERROR: ~/comment.mk:19: Unknown Makefile line format.",
+               "ERROR: ~/comment.mk:23: Unknown Makefile line format.")
 }
 
 func (s *Suite) Test_convertToLogicalLines_continuationInLastLine(c *check.C) {
diff -r f418f09a6308 -r f8ed77ca4869 pkgtools/pkglint/files/mkline_test.go
--- a/pkgtools/pkglint/files/mkline_test.go     Thu Aug 09 19:10:06 2018 +0000
+++ b/pkgtools/pkglint/files/mkline_test.go     Thu Aug 09 20:08:12 2018 +0000
@@ -679,13 +679,12 @@
        t.SetupCommandLine("-Wall", "--autofix")
        t.SetupVartypes()
 
-       lines := t.SetupFileLinesContinuation("Makefile",
+       mklines := t.SetupFileMkLines("Makefile",
                MkRcsID,
                "",
                "demo: .PHONY",
                "\t${ECHO} ${WRKSRC:Q}",
                "\t${ECHO} ${FOODIR:Q}")
-       mklines := NewMkLines(lines)
 
        mklines.Check()
 
diff -r f418f09a6308 -r f8ed77ca4869 pkgtools/pkglint/files/mklinechecker_test.go
--- a/pkgtools/pkglint/files/mklinechecker_test.go      Thu Aug 09 19:10:06 2018 +0000
+++ b/pkgtools/pkglint/files/mklinechecker_test.go      Thu Aug 09 20:08:12 2018 +0000
@@ -330,14 +330,13 @@
 
        t.SetupCommandLine("-Wall", "--autofix")
        t.SetupVartypes()
-       lines := t.SetupFileLinesContinuation("options.mk",
+       mklines := t.SetupFileMkLines("options.mk",
                MkRcsID,
                ".if ${PKGNAME} == pkgname",
                ".if \\",
                "   ${PLATFORM:MNetBSD-4.*}",
                ".endif",
                ".endif")
-       mklines := NewMkLines(lines)
 
        mklines.Check()
 
@@ -359,12 +358,11 @@
 
        t.SetupCommandLine("-Wall")
        t.SetupVartypes()
-       lines := t.SetupFileLinesContinuation("options.mk",
+       mklines := t.SetupFileMkLines("options.mk",
                MkRcsID,
                "GOPATH=\t${WRKDIR}",
                "do-build:",
                "\tcd ${WRKSRC} && GOPATH=${GOPATH} PATH=${PATH} :")
-       mklines := NewMkLines(lines)
 
        mklines.Check()
 
@@ -387,11 +385,10 @@
        t.SetupCommandLine("-Wall")
        t.SetupVartypes()
        t.SetupMasterSite("MASTER_SITE_GITHUB", "https://github.com/";)
-       lines := t.SetupFileLinesContinuation("options.mk",
+       mklines := t.SetupFileMkLines("options.mk",
                MkRcsID,
                "WRKSRC=\t\t${WRKDIR:=/subdir}",
                "MASTER_SITES=\t${MASTER_SITE_GITHUB:=organization/}")
-       mklines := NewMkLines(lines)
 
        mklines.Check()
 
diff -r f418f09a6308 -r f8ed77ca4869 pkgtools/pkglint/files/mklines_test.go
--- a/pkgtools/pkglint/files/mklines_test.go    Thu Aug 09 19:10:06 2018 +0000
+++ b/pkgtools/pkglint/files/mklines_test.go    Thu Aug 09 20:08:12 2018 +0000
@@ -599,6 +599,18 @@
        t.CheckOutputEmpty()
 }
 
+func (s *Suite) Test_MkLines_CheckRedundantVariables__overwrite_same_value(c *check.C) {
+       t := s.Init(c)
+       mklines := t.NewMkLines("module.mk",
+               "VAR=\tvalue ${OTHER}",
+               "VAR=\tvalue ${OTHER}")
+
+       mklines.CheckRedundantVariables()
+
+       t.CheckOutputLines(
+               "NOTE: module.mk:1: Definition of VAR is redundant because of line 2.")
+}
+
 func (s *Suite) Test_MkLines_CheckRedundantVariables__procedure_call(c *check.C) {
        t := s.Init(c)
        mklines := t.NewMkLines("mk/pthread.buildlink3.mk",
diff -r f418f09a6308 -r f8ed77ca4869 pkgtools/pkglint/files/mklines_varalign_test.go
--- a/pkgtools/pkglint/files/mklines_varalign_test.go   Thu Aug 09 19:10:06 2018 +0000
+++ b/pkgtools/pkglint/files/mklines_varalign_test.go   Thu Aug 09 20:08:12 2018 +0000
@@ -52,8 +52,7 @@
        }
        vt.tester.SetupCommandLine(cmdline...)
 
-       lines := vt.tester.SetupFileLinesContinuation("Makefile", vt.input...)
-       mklines := NewMkLines(lines)
+       mklines := vt.tester.SetupFileMkLines("Makefile", vt.input...)
 
        varalign := VaralignBlock{}
        for _, mkline := range mklines.mklines {
@@ -71,9 +70,7 @@
        }
        vt.tester.SetupCommandLine(cmdline...)
 
-       lines := vt.tester.SetupFileLinesContinuation("Makefile", vt.input...)
-
-       mklines := NewMkLines(lines)
+       mklines := vt.tester.SetupFileMkLines("Makefile", vt.input...)
 
        var varalign VaralignBlock
        for _, mkline := range mklines.mklines {
diff -r f418f09a6308 -r f8ed77ca4869 pkgtools/pkglint/files/options.go
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkglint/files/options.go Thu Aug 09 20:08:12 2018 +0000
@@ -0,0 +1,106 @@
+package main
+
+import "netbsd.org/pkglint/trace"
+
+func ChecklinesOptionsMk(mklines *MkLines) {
+       if trace.Tracing {
+               defer trace.Call1(mklines.lines[0].Filename)()
+       }
+
+       mklines.Check()
+
+       exp := NewMkExpecter(mklines)
+       exp.AdvanceWhile(func(mkline MkLine) bool { return mkline.IsComment() || mkline.IsEmpty() })
+
+       if exp.EOF() || !(exp.CurrentMkLine().IsVarassign() && exp.CurrentMkLine().Varname() == "PKG_OPTIONS_VAR") {
+               exp.CurrentLine().Warnf("Expected definition of PKG_OPTIONS_VAR.")
+               Explain(
+                       "The input variables in an options.mk file should always be",
+                       "mentioned in the same order: PKG_OPTIONS_VAR, ",
+                       "PKG_SUPPORTED_OPTIONS, PKG_SUGGESTED_OPTIONS.  This way, the",
+                       "options.mk files have the same structure and are easy to understand.")
+               return
+       }
+       exp.Advance()
+
+       declaredOptions := make(map[string]MkLine)
+       handledOptions := make(map[string]MkLine)
+       var optionsInDeclarationOrder []string
+
+       // The conditionals are typically for OPSYS and MACHINE_ARCH.
+loop:
+       for ; !exp.EOF(); exp.Advance() {
+               mkline := exp.CurrentMkLine()
+               switch {
+               case mkline.IsComment():
+               case mkline.IsEmpty():
+               case mkline.IsVarassign():
+                       varname := mkline.Varname()
+                       if varname == "PKG_SUPPORTED_OPTIONS" || hasPrefix(varname, "PKG_OPTIONS_GROUP.") {
+                               for _, option := range splitOnSpace(mkline.Value()) {
+                                       if option == mkline.WithoutMakeVariables(option) {
+                                               declaredOptions[option] = mkline
+                                               optionsInDeclarationOrder = append(optionsInDeclarationOrder, option)
+                                       }
+                               }



Home | Main Index | Thread Index | Old Index