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 19.3.5



details:   https://anonhg.NetBSD.org/pkgsrc/rev/6f4488065a40
branches:  trunk
changeset: 343329:6f4488065a40
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Nov 02 16:37:48 2019 +0000

description:
pkgtools/pkglint: update to 19.3.5

Changes since 19.3.4:

Variable uses in parentheses (such as $(VAR) instead of ${VAR}) are
treated the same. The ones in parentheses had less support before.

Improved the checks for options.mk files, adding support for options
that are defined using .for loops and those referring to other
variables.

Packages that set DISTFILES to an empty list no longer require a
distinfo file.

Patches whose filename contains the word CVE may patch more than one
target file.

diffstat:

 pkgtools/pkglint/Makefile                    |    4 +-
 pkgtools/pkglint/files/check_test.go         |    2 +
 pkgtools/pkglint/files/linelexer.go          |   10 -
 pkgtools/pkglint/files/lines.go              |   10 +-
 pkgtools/pkglint/files/mkline.go             |    8 +-
 pkgtools/pkglint/files/mkline_test.go        |    4 +-
 pkgtools/pkglint/files/mklinechecker.go      |    2 +-
 pkgtools/pkglint/files/mklinechecker_test.go |    8 +
 pkgtools/pkglint/files/mklines.go            |    4 +
 pkgtools/pkglint/files/options.go            |  161 ++++++++++--------
 pkgtools/pkglint/files/options_test.go       |  224 +++++++++++++++++++++++++-
 pkgtools/pkglint/files/package.go            |    7 +-
 pkgtools/pkglint/files/package_test.go       |   42 ++++-
 pkgtools/pkglint/files/patches.go            |    6 +-
 pkgtools/pkglint/files/patches_test.go       |   25 +++
 pkgtools/pkglint/files/pkglint.go            |    4 +-
 pkgtools/pkglint/files/util.go               |    2 +-
 pkgtools/pkglint/files/vardefs.go            |    2 +-
 18 files changed, 406 insertions(+), 119 deletions(-)

diffs (truncated from 856 to 300 lines):

diff -r f7e25170e84f -r 6f4488065a40 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sat Nov 02 16:28:37 2019 +0000
+++ b/pkgtools/pkglint/Makefile Sat Nov 02 16:37:48 2019 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.604 2019/11/01 19:56:52 rillig Exp $
+# $NetBSD: Makefile,v 1.605 2019/11/02 16:37:48 rillig Exp $
 
-PKGNAME=       pkglint-19.3.4
+PKGNAME=       pkglint-19.3.5
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r f7e25170e84f -r 6f4488065a40 pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go      Sat Nov 02 16:28:37 2019 +0000
+++ b/pkgtools/pkglint/files/check_test.go      Sat Nov 02 16:37:48 2019 +0000
@@ -194,6 +194,8 @@
 }
 
 // SetUpOption pretends that the given package option is defined in mk/defaults/options.description.
+//
+// In tests, the description may be left empty.
 func (t *Tester) SetUpOption(name, description string) {
        G.Pkgsrc.PkgOptions[name] = description
 }
diff -r f7e25170e84f -r 6f4488065a40 pkgtools/pkglint/files/linelexer.go
--- a/pkgtools/pkglint/files/linelexer.go       Sat Nov 02 16:28:37 2019 +0000
+++ b/pkgtools/pkglint/files/linelexer.go       Sat Nov 02 16:37:48 2019 +0000
@@ -131,16 +131,6 @@
        return mlex.mklines.mklines[mlex.index]
 }
 
-func (mlex *MkLinesLexer) SkipWhile(pred func(mkline *MkLine) bool) {
-       if trace.Tracing {
-               defer trace.Call(mlex.CurrentMkLine().Text)()
-       }
-
-       for !mlex.EOF() && pred(mlex.CurrentMkLine()) {
-               mlex.Skip()
-       }
-}
-
 func (mlex *MkLinesLexer) SkipIf(pred func(mkline *MkLine) bool) bool {
        if !mlex.EOF() && pred(mlex.CurrentMkLine()) {
                mlex.Skip()
diff -r f7e25170e84f -r 6f4488065a40 pkgtools/pkglint/files/lines.go
--- a/pkgtools/pkglint/files/lines.go   Sat Nov 02 16:28:37 2019 +0000
+++ b/pkgtools/pkglint/files/lines.go   Sat Nov 02 16:37:48 2019 +0000
@@ -21,13 +21,9 @@
 
 func (ls *Lines) EOFLine() *Line { return NewLineMulti(ls.Filename, -1, -1, "", nil) }
 
-func (ls *Lines) Errorf(format string, args ...interface{}) {
-       NewLineWhole(ls.Filename).Errorf(format, args...)
-}
-
-func (ls *Lines) Warnf(format string, args ...interface{}) {
-       NewLineWhole(ls.Filename).Warnf(format, args...)
-}
+// Whole returns a virtual line that can be used for issuing diagnostics
+// and explanations, but not for text replacements.
+func (ls *Lines) Whole() *Line { return NewLineWhole(ls.Filename) }
 
 func (ls *Lines) SaveAutofixChanges() bool {
        return SaveAutofixChanges(ls)
diff -r f7e25170e84f -r 6f4488065a40 pkgtools/pkglint/files/mkline.go
--- a/pkgtools/pkglint/files/mkline.go  Sat Nov 02 16:28:37 2019 +0000
+++ b/pkgtools/pkglint/files/mkline.go  Sat Nov 02 16:37:48 2019 +0000
@@ -279,6 +279,8 @@
 
 func (mkline *MkLine) IncludedFile() string { return mkline.data.(*mkLineInclude).includedFile }
 
+// IncludedFileFull returns the path to the included file, relative to the
+// current working directory.
 func (mkline *MkLine) IncludedFileFull() string {
        return cleanpath(path.Join(path.Dir(mkline.Filename), mkline.IncludedFile()))
 }
@@ -325,7 +327,11 @@
        if mkline.IsVarassignMaybeCommented() && text == mkline.Value() {
                tokens, rest = mkline.ValueTokens()
        } else {
-               p := NewMkParser(mkline.Line, text)
+               var line *Line
+               if warn {
+                       line = mkline.Line
+               }
+               p := NewMkParser(line, text)
                tokens = p.MkTokens()
                rest = p.Rest()
        }
diff -r f7e25170e84f -r 6f4488065a40 pkgtools/pkglint/files/mkline_test.go
--- a/pkgtools/pkglint/files/mkline_test.go     Sat Nov 02 16:28:37 2019 +0000
+++ b/pkgtools/pkglint/files/mkline_test.go     Sat Nov 02 16:37:48 2019 +0000
@@ -1587,9 +1587,7 @@
        test("\"\\", "")
        test("'", "")
 
-       test("\"$(\"", "$(\"",
-               "WARN: filename.mk:1: Missing closing \")\" for \"\\\"\".",
-               "WARN: filename.mk:1: Invalid part \"\\\"\" after variable name \"\".")
+       test("\"$(\"", "$(\"")
 
        test("`", "`")
 
diff -r f7e25170e84f -r 6f4488065a40 pkgtools/pkglint/files/mklinechecker.go
--- a/pkgtools/pkglint/files/mklinechecker.go   Sat Nov 02 16:28:37 2019 +0000
+++ b/pkgtools/pkglint/files/mklinechecker.go   Sat Nov 02 16:37:48 2019 +0000
@@ -1588,7 +1588,7 @@
                        pattern +
                        condStr(fromEmpty, ")", "}")
 
-               quote := condStr(matches(pattern, `[^\-/0-9@A-Za-z]`), "\"", "")
+               quote := condStr(matches(pattern, `[^\-/0-9@A-Z_a-z]`), "\"", "")
                to := "${" + varname + "} " + op + " " + quote + pattern + quote
                return from, to
        }
diff -r f7e25170e84f -r 6f4488065a40 pkgtools/pkglint/files/mklinechecker_test.go
--- a/pkgtools/pkglint/files/mklinechecker_test.go      Sat Nov 02 16:28:37 2019 +0000
+++ b/pkgtools/pkglint/files/mklinechecker_test.go      Sat Nov 02 16:37:48 2019 +0000
@@ -2125,6 +2125,14 @@
                "NOTE: module.mk:2: PKGPATH should be compared using == instead of matching against \":Mtwo\".",
 
                ".if ${PKGPATH:Mone:Mtwo}")
+
+       test(
+               ".if ${MACHINE_ARCH:Mx86_64}",
+
+               "NOTE: module.mk:2: MACHINE_ARCH should be compared using == instead of matching against \":Mx86_64\".",
+               "AUTOFIX: module.mk:2: Replacing \"${MACHINE_ARCH:Mx86_64}\" with \"${MACHINE_ARCH} == x86_64\".",
+
+               ".if ${MACHINE_ARCH} == x86_64")
 }
 
 func (s *Suite) Test_MkLineChecker_checkDirectiveCond__comparing_PKGSRC_COMPILER_with_eqeq(c *check.C) {
diff -r f7e25170e84f -r 6f4488065a40 pkgtools/pkglint/files/mklines.go
--- a/pkgtools/pkglint/files/mklines.go Sat Nov 02 16:28:37 2019 +0000
+++ b/pkgtools/pkglint/files/mklines.go Sat Nov 02 16:37:48 2019 +0000
@@ -70,6 +70,10 @@
 //  ck.AfterLine
 //  ck.Finish
 
+// Whole returns a virtual line that can be used for issuing diagnostics
+// and explanations, but not for text replacements.
+func (mklines *MkLines) Whole() *Line { return mklines.lines.Whole() }
+
 // UseVar remembers that the given variable is used in the given line.
 // This controls the "defined but not used" warning.
 func (mklines *MkLines) UseVar(mkline *MkLine, varname string, time VucTime) {
diff -r f7e25170e84f -r 6f4488065a40 pkgtools/pkglint/files/options.go
--- a/pkgtools/pkglint/files/options.go Sat Nov 02 16:28:37 2019 +0000
+++ b/pkgtools/pkglint/files/options.go Sat Nov 02 16:37:48 2019 +0000
@@ -3,7 +3,9 @@
 func CheckLinesOptionsMk(mklines *MkLines) {
        ck := OptionsLinesChecker{
                mklines,
+               false,
                make(map[string]*MkLine),
+               false,
                make(map[string]*MkLine),
                nil}
 
@@ -16,7 +18,9 @@
 type OptionsLinesChecker struct {
        mklines *MkLines
 
+       declaredArbitrary         bool
        declaredOptions           map[string]*MkLine
+       handledArbitrary          bool
        handledOptions            map[string]*MkLine
        optionsInDeclarationOrder []string
 }
@@ -26,94 +30,91 @@
 
        mklines.Check()
 
-       mlex := NewMkLinesLexer(mklines)
-       mlex.SkipWhile(func(mkline *MkLine) bool { return mkline.IsComment() || mkline.IsEmpty() })
-
-       if !ck.lookingAtPkgOptionsVar(mlex) {
-               return
-       }
-       mlex.Skip()
-
-       upper := true
-       for !mlex.EOF() && upper {
-               upper = ck.handleUpperLine(mlex.CurrentMkLine())
-               mlex.Skip()
-       }
-
-       i := 0
-       mklines.ForEach(func(mkline *MkLine) {
-               if i >= mlex.index {
-                       ck.handleLowerLine(mkline)
-               }
-               i++
-       })
+       ck.collect()
 
        ck.checkOptionsMismatch()
 
        mklines.SaveAutofixChanges()
 }
 
-func (ck *OptionsLinesChecker) lookingAtPkgOptionsVar(mlex *MkLinesLexer) bool {
-       if !mlex.EOF() {
-               mkline := mlex.CurrentMkLine()
-               if mkline.IsVarassign() && mkline.Varname() == "PKG_OPTIONS_VAR" {
-                       return true
+func (ck *OptionsLinesChecker) collect() {
+       seenPkgOptionsVar := false
+       seenInclude := false
+
+       ck.mklines.ForEach(func(mkline *MkLine) {
+               if mkline.IsEmpty() || mkline.IsComment() {
+                       return
                }
+
+               if !seenInclude {
+                       if !seenPkgOptionsVar && mkline.IsVarassign() && mkline.Varname() == "PKG_OPTIONS_VAR" {
+                               seenPkgOptionsVar = true
+                       }
+                       seenInclude = mkline.IsInclude() && mkline.IncludedFile() == "../../mk/bsd.options.mk"
+               }
+
+               if !seenInclude {
+                       ck.handleUpperLine(mkline, seenPkgOptionsVar)
+               } else {
+                       ck.handleLowerLine(mkline)
+               }
+       })
+
+       if !seenPkgOptionsVar {
+               ck.mklines.Whole().Errorf("Each options.mk file must define PKG_OPTIONS_VAR.")
        }
 
-       line := mlex.CurrentLine()
-       line.Warnf("Expected definition of PKG_OPTIONS_VAR.")
-       line.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 false
+       if !seenInclude {
+               file := ck.mklines.Whole()
+               file.Errorf("Each options.mk file must .include \"../../mk/bsd.options.mk\".")
+               file.Explain(
+                       "After defining the input variables (PKG_OPTIONS_VAR, etc.),",
+                       "bsd.options.mk must be included to do the actual processing.")
+       }
 }
 
 // handleUpperLine checks a line from the upper part of an options.mk file,
 // before bsd.options.mk is included.
-func (ck *OptionsLinesChecker) handleUpperLine(mkline *MkLine) bool {
-       switch {
-       case mkline.IsComment():
-               break
-       case mkline.IsEmpty():
-               break
+func (ck *OptionsLinesChecker) handleUpperLine(mkline *MkLine, seenPkgOptionsVar bool) {
+
+       declare := func(option string) {
+               if containsVarRef(option) {
+                       ck.declaredArbitrary = true
+               } else {
+                       ck.declaredOptions[option] = mkline
+                       ck.optionsInDeclarationOrder = append(ck.optionsInDeclarationOrder, option)
+               }
+       }
 
-       case mkline.IsVarassign():
-               switch mkline.Varcanon() {
-               case "PKG_SUPPORTED_OPTIONS",
-                       "PKG_SUPPORTED_OPTIONS.*",
-                       "PKG_OPTIONS_GROUP.*",
-                       "PKG_OPTIONS_SET.*":
-                       for _, option := range mkline.ValueFields(mkline.Value()) {
-                               if !containsVarRef(option) {
-                                       ck.declaredOptions[option] = mkline
-                                       ck.optionsInDeclarationOrder = append(ck.optionsInDeclarationOrder, option)
-                               }
-                       }
+       if !mkline.IsVarassign() {
+               return
+       }
+
+       switch mkline.Varcanon() {
+       case "PKG_SUPPORTED_OPTIONS",
+               "PKG_SUPPORTED_OPTIONS.*",
+               "PKG_OPTIONS_GROUP.*",
+               "PKG_OPTIONS_SET.*":
+               if !seenPkgOptionsVar {
+                       ck.warnVarorder(mkline)
                }
 
-       case mkline.IsDirective():
-               // The conditionals are typically for OPSYS and MACHINE_ARCH.
-
-       case mkline.IsInclude():
-               if mkline.IncludedFile() == "../../mk/bsd.options.mk" {



Home | Main Index | Thread Index | Old Index