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.6.4
details: https://anonhg.NetBSD.org/pkgsrc/rev/b89957b4ef64
branches: trunk
changeset: 313786:b89957b4ef64
user: rillig <rillig%pkgsrc.org@localhost>
date: Tue Oct 09 19:12:13 2018 +0000
description:
pkgtools/pkglint: update to 5.6.4
Changes since 5.6.3:
* Allow += for COMMENT
* Sync variable type definitions with reality
* Fix check for "used but not defined" variables. This check had been
broken since pkgtools/pkglint/files/pkglint.pl r1.776 from 2008-10-18
(3cd071958e63), which missed its 10-year anniversary by just 9 days.
After fixing this check, pkglint produces about 800 new warnings
spread all over pkgsrc, most of which are real typos.
* Detect used variables also in .if and .elif conditions. This is
closely related to the above fix and reduces the number of "defined
but not used" variables, while at the same time producing new warnings
because these variables are used at load time, where some of these
variables are not yet defined.
* Detect variables for which pkglint doesn't know the exact data type
by scanning all files under mk/ at startup. Currently there are about
470 of these variables. No "used but not defined" warnings are issued
for these variables anymore.
* To speed up pkglint when checking the whole pkgsrc tree at once, the
most often needed files are cached to reduce IO load. The checks for
USE_TOOLS are optimized now since they were a major bottleneck.
Together with other performance improvements this makes pkglint about
50% faster when checking the whole pkgsrc tree including pkgsrc-wip.
diffstat:
pkgtools/pkglint/Makefile | 4 +-
pkgtools/pkglint/files/alternatives_test.go | 4 -
pkgtools/pkglint/files/autofix.go | 3 +-
pkgtools/pkglint/files/buildlink3_test.go | 1 +
pkgtools/pkglint/files/check_test.go | 18 +-
pkgtools/pkglint/files/files.go | 4 +-
pkgtools/pkglint/files/getopt/getopt.go | 40 ++-
pkgtools/pkglint/files/getopt/getopt_test.go | 98 ++++++++
pkgtools/pkglint/files/licenses/licenses.go | 4 +-
pkgtools/pkglint/files/licenses/licenses_test.go | 28 ++
pkgtools/pkglint/files/mkline.go | 247 +++++++++++----------
pkgtools/pkglint/files/mkline_test.go | 143 ++++++++++--
pkgtools/pkglint/files/mklinechecker.go | 78 +++---
pkgtools/pkglint/files/mklinechecker_test.go | 56 ++++-
pkgtools/pkglint/files/mklines.go | 80 ++++--
pkgtools/pkglint/files/mklines_test.go | 131 +++++++++-
pkgtools/pkglint/files/mkparser.go | 31 ++-
pkgtools/pkglint/files/mkparser_test.go | 62 +++++-
pkgtools/pkglint/files/options.go | 4 +-
pkgtools/pkglint/files/options_test.go | 1 +
pkgtools/pkglint/files/package.go | 34 +-
pkgtools/pkglint/files/package_test.go | 6 +-
pkgtools/pkglint/files/patches_test.go | 8 +-
pkgtools/pkglint/files/pkglint.go | 80 ++----
pkgtools/pkglint/files/pkglint_test.go | 48 ++--
pkgtools/pkglint/files/pkgsrc.go | 125 ++++++++--
pkgtools/pkglint/files/pkgsrc_test.go | 34 +-
pkgtools/pkglint/files/plist.go | 6 +-
pkgtools/pkglint/files/shell.go | 18 +-
pkgtools/pkglint/files/shell_test.go | 69 ++---
pkgtools/pkglint/files/shtokenizer_test.go | 2 +-
pkgtools/pkglint/files/substcontext.go | 2 +-
pkgtools/pkglint/files/textproc/prefixreplacer.go | 18 +-
pkgtools/pkglint/files/tools.go | 208 ++++++++---------
pkgtools/pkglint/files/tools_test.go | 196 ++++++++++++-----
pkgtools/pkglint/files/trace/tracing_test.go | 52 ++++
pkgtools/pkglint/files/util.go | 142 ++++++------
pkgtools/pkglint/files/util_test.go | 7 -
pkgtools/pkglint/files/vardefs.go | 129 ++++++++--
pkgtools/pkglint/files/vardefs_test.go | 14 +
pkgtools/pkglint/files/vartype.go | 6 +-
pkgtools/pkglint/files/vartype_test.go | 17 +-
pkgtools/pkglint/files/vartypecheck.go | 16 +-
pkgtools/pkglint/files/vartypecheck_test.go | 6 +-
44 files changed, 1497 insertions(+), 783 deletions(-)
diffs (truncated from 4699 to 300 lines):
diff -r 9dfdd4c267cf -r b89957b4ef64 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Tue Oct 09 17:07:07 2018 +0000
+++ b/pkgtools/pkglint/Makefile Tue Oct 09 19:12:13 2018 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.549 2018/10/03 22:27:53 rillig Exp $
+# $NetBSD: Makefile,v 1.550 2018/10/09 19:12:13 rillig Exp $
-PKGNAME= pkglint-5.6.3
+PKGNAME= pkglint-5.6.4
DISTFILES= # none
CATEGORIES= pkgtools
diff -r 9dfdd4c267cf -r b89957b4ef64 pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go Tue Oct 09 17:07:07 2018 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go Tue Oct 09 19:12:13 2018 +0000
@@ -21,11 +21,7 @@
G.CheckDirent(".")
- // TODO: Remove redundant diagnostics.
t.CheckOutputLines(
- "NOTE: ALTERNATIVES:1: @PREFIX@/ can be omitted from the file name.",
- "NOTE: ALTERNATIVES:2: @PREFIX@/ can be omitted from the file name.",
- "ERROR: ALTERNATIVES:5: Invalid ALTERNATIVES line \"invalid\".",
"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.",
diff -r 9dfdd4c267cf -r b89957b4ef64 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Tue Oct 09 17:07:07 2018 +0000
+++ b/pkgtools/pkglint/files/autofix.go Tue Oct 09 19:12:13 2018 +0000
@@ -128,7 +128,8 @@
{
// Interpreting the continuation marker as variable value
// is cheating, but works well.
- m, _, _, _, _, valueAlign, value, _, _ := MatchVarassign(mkline.raw[0].orignl)
+ text := strings.TrimSuffix(mkline.raw[0].orignl, "\n")
+ m, _, _, _, _, valueAlign, value, _, _ := MatchVarassign(text)
if m && value != "\\" {
oldWidth = tabWidth(valueAlign)
}
diff -r 9dfdd4c267cf -r b89957b4ef64 pkgtools/pkglint/files/buildlink3_test.go
--- a/pkgtools/pkglint/files/buildlink3_test.go Tue Oct 09 17:07:07 2018 +0000
+++ b/pkgtools/pkglint/files/buildlink3_test.go Tue Oct 09 19:12:13 2018 +0000
@@ -343,6 +343,7 @@
// No warning about the indentation of the .include lines.
t.CheckOutputLines(
+ "WARN: ~/buildlink3.mk:3: VAAPI_AVAILABLE is used but not defined.",
"ERROR: ~/buildlink3.mk:11: \"multimedia/libva\" does not exist.",
"ERROR: ~/buildlink3.mk:11: There is no package in \"multimedia/libva\".",
"ERROR: ~/buildlink3.mk:13: \"x11/libX11/buildlink3.mk\" does not exist.",
diff -r 9dfdd4c267cf -r b89957b4ef64 pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go Tue Oct 09 17:07:07 2018 +0000
+++ b/pkgtools/pkglint/files/check_test.go Tue Oct 09 19:12:13 2018 +0000
@@ -161,17 +161,8 @@
G.Pkgsrc.PkgOptions[name] = description
}
-func (t *Tester) SetupTool(name, varname string) *Tool {
- tools := G.Pkgsrc.Tools
- return tools.Define(name, varname, dummyMkLine)
-}
-
-// SetupToolUsable registers a tool and immediately makes it usable,
-// as if the tool were predefined globally in pkgsrc.
-func (t *Tester) SetupToolUsable(name, varname string) *Tool {
- tool := t.SetupTool(name, varname)
- tool.SetValidity(AtRunTime, G.Pkgsrc.Tools.TraceName)
- return tool
+func (t *Tester) SetupTool(name, varname string, validity Validity) *Tool {
+ return G.Pkgsrc.Tools.defTool(name, varname, false, validity)
}
// SetupFileLines creates a temporary file and writes the given lines to it.
@@ -247,8 +238,9 @@
}
}
-// SetupPackage sets up all files for a package so that it does not produce
-// any warnings.
+// SetupPackage sets up all files for a package (including the pkgsrc
+// infrastructure) so that it does not produce any warnings. After calling
+// this method, individual files can be overwritten as necessary.
//
// The given makefileLines start in line 20. Except if they are variable
// definitions for already existing variables, then they replace that line.
diff -r 9dfdd4c267cf -r b89957b4ef64 pkgtools/pkglint/files/files.go
--- a/pkgtools/pkglint/files/files.go Tue Oct 09 17:07:07 2018 +0000
+++ b/pkgtools/pkglint/files/files.go Tue Oct 09 19:12:13 2018 +0000
@@ -48,7 +48,9 @@
}
result := convertToLogicalLines(fileName, rawText, options&Makefile != 0)
- G.fileCache.Put(fileName, options, result)
+ if hasSuffix(fileName, ".mk") {
+ G.fileCache.Put(fileName, options, result)
+ }
return result
}
diff -r 9dfdd4c267cf -r b89957b4ef64 pkgtools/pkglint/files/getopt/getopt.go
--- a/pkgtools/pkglint/files/getopt/getopt.go Tue Oct 09 17:07:07 2018 +0000
+++ b/pkgtools/pkglint/files/getopt/getopt.go Tue Oct 09 19:12:13 2018 +0000
@@ -18,6 +18,14 @@
return new(Options)
}
+// AddFlagGroup adds an option that takes multiple flag values.
+//
+// Example:
+// var extra bool
+//
+// opts := NewOptions()
+// warnings := opts.AddFlagGroup('W', "warnings", "warning,...", "Enable the given warnings")
+// warnings.AddFlagVar("extra", &extra, false, "Print extra warnings")
func (o *Options) AddFlagGroup(shortName rune, longName, argDescription, description string) *FlagGroup {
grp := new(FlagGroup)
opt := &option{shortName, longName, argDescription, description, grp}
@@ -37,6 +45,8 @@
o.options = append(o.options, opt)
}
+// Parse extracts the command line options from the given arguments.
+// args[0] is the program name, as in os.Args.
func (o *Options) Parse(args []string) (remainingArgs []string, err error) {
var skip int
for i := 1; i < len(args) && err == nil; i++ {
@@ -108,20 +118,24 @@
}
return 0, nil
case *[]string:
- if argval != nil {
+ switch {
+ case argval != nil:
*data = append(*data, *argval)
return 0, nil
- } else if i+1 < len(args) {
+ case i+1 < len(args):
*data = append(*data, args[i+1])
return 1, nil
- } else {
+ default:
return 0, optErr("option requires an argument: --" + opt.longName)
}
case *FlagGroup:
- if argval == nil {
+ switch {
+ case argval != nil:
+ return 0, data.parse("--"+opt.longName+"=", *argval)
+ case i+1 < len(args):
return 1, data.parse("--"+opt.longName+"=", args[i+1])
- } else {
- return 0, data.parse("--"+opt.longName+"=", *argval)
+ default:
+ return 0, optErr("option requires an argument: --" + opt.longName)
}
}
panic("getopt: unknown option type")
@@ -139,23 +153,25 @@
case *[]string:
argarg := optchars[ai+utf8.RuneLen(optchar):]
- if argarg != "" {
+ switch {
+ case argarg != "":
*data = append(*data, argarg)
return 0, nil
- } else if i+1 < len(args) {
+ case i+1 < len(args):
*data = append(*data, args[i+1])
return 1, nil
- } else {
+ default:
return 0, optErr("option requires an argument: -" + string([]rune{optchar}))
}
case *FlagGroup:
argarg := optchars[ai+utf8.RuneLen(optchar):]
- if argarg != "" {
+ switch {
+ case argarg != "":
return 0, data.parse(string([]rune{'-', optchar}), argarg)
- } else if i+1 < len(args) {
+ case i+1 < len(args):
return 1, data.parse(string([]rune{'-', optchar}), args[i+1])
- } else {
+ default:
return 0, optErr("option requires an argument: -" + string([]rune{optchar}))
}
}
diff -r 9dfdd4c267cf -r b89957b4ef64 pkgtools/pkglint/files/getopt/getopt_test.go
--- a/pkgtools/pkglint/files/getopt/getopt_test.go Tue Oct 09 17:07:07 2018 +0000
+++ b/pkgtools/pkglint/files/getopt/getopt_test.go Tue Oct 09 19:12:13 2018 +0000
@@ -2,6 +2,7 @@
import (
"gopkg.in/check.v1"
+ "strings"
"testing"
)
@@ -177,3 +178,100 @@
c.Check(iflag, check.Equals, true)
c.Check(err, check.ErrorMatches, `^progname: invalid argument for option --jflag$`)
}
+
+func (s *Suite) Test_Options_handleLongOption__flag_group_without_argument(c *check.C) {
+ var extra bool
+
+ opts := NewOptions()
+ group := opts.AddFlagGroup('W', "warnings", "warning,...", "Print selected warnings")
+ group.AddFlagVar("extra", &extra, false, "Print extra warnings")
+
+ args, err := opts.Parse([]string{"progname", "--warnings"})
+
+ c.Check(args, check.IsNil)
+ c.Check(err.Error(), check.Equals, "progname: option requires an argument: --warnings")
+ c.Check(extra, check.Equals, false)
+}
+
+func (s *Suite) Test_Options_handleLongOption__flag_group_separate_argument(c *check.C) {
+ var extra bool
+
+ opts := NewOptions()
+ group := opts.AddFlagGroup('W', "warnings", "warning,...", "Print selected warnings")
+ group.AddFlagVar("extra", &extra, false, "Print extra warnings")
+
+ args, err := opts.Parse([]string{"progname", "--warnings", "extra,unknown"})
+
+ c.Check(args, check.IsNil)
+ c.Check(err.Error(), check.Equals, "progname: unknown option: --warnings=unknown")
+ c.Check(extra, check.Equals, true)
+}
+
+func (s *Suite) Test_Options_handleLongOption__flag_group_negated(c *check.C) {
+ var extra bool
+
+ opts := NewOptions()
+ group := opts.AddFlagGroup('W', "warnings", "warning,...", "Print selected warnings")
+ group.AddFlagVar("extra", &extra, true, "Print extra warnings")
+
+ args, err := opts.Parse([]string{"progname", "--warnings", "all,no-extra"})
+
+ c.Check(args, check.IsNil)
+ c.Check(err, check.IsNil)
+ c.Check(extra, check.Equals, false)
+}
+
+func (s *Suite) Test_Options_handleLongOption__internal_error(c *check.C) {
+ var extra bool
+
+ opts := NewOptions()
+ group := opts.AddFlagGroup('W', "warnings", "warning,...", "Print selected warnings")
+ group.AddFlagVar("extra", &extra, false, "Print extra warnings")
+ opts.options[0].data = "unexpected value"
+
+ c.Check(
+ func() { _, _ = opts.Parse([]string{"progname", "--warnings"}) },
+ check.Panics,
+ "getopt: unknown option type")
+}
+
+func (s *Suite) Test_Options_parseShortOptions__flag_group_separate_argument(c *check.C) {
+ var extra bool
+
+ opts := NewOptions()
+ group := opts.AddFlagGroup('W', "warnings", "warning,...", "Print selected warnings")
+ group.AddFlagVar("extra", &extra, false, "Print extra warnings")
+
+ args, err := opts.Parse([]string{"progname", "-W", "extra,unknown"})
+
+ c.Check(args, check.IsNil)
+ c.Check(err.Error(), check.Equals, "progname: unknown option: -Wunknown")
+ c.Check(extra, check.Equals, true)
+}
+
+func (s *Suite) Test_Options_Help(c *check.C) {
+ var verbose, basic, extra bool
+
+ opts := NewOptions()
+ opts.AddFlagVar('v', "verbose", &verbose, false, "Print a detailed log")
+ group := opts.AddFlagGroup('W', "warnings", "warning,...", "Print selected warnings")
+ group.AddFlagVar("basic", &basic, true, "Print basic warnings")
+ group.AddFlagVar("extra", &extra, false, "Print extra warnings")
+
+ var out strings.Builder
+ opts.Help(&out, "progname [options] args")
+
+ c.Check(out.String(), check.Equals, ""+
+ "usage: progname [options] args\n"+
+ "\n"+
+ " -v, --verbose Print a detailed log\n"+
+ " -W, --warnings=warning,... Print selected warnings\n"+
+ "\n"+
+ " Flags for -W, --warnings:\n"+
+ " all all of the following\n"+
+ " none none of the following\n"+
+ " basic Print basic warnings (enabled)\n"+
+ " extra Print extra warnings (disabled)\n"+
+ "\n"+
Home |
Main Index |
Thread Index |
Old Index