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.7.12



details:   https://anonhg.NetBSD.org/pkgsrc/rev/39d259f53c1d
branches:  trunk
changeset: 334390:39d259f53c1d
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sun May 26 14:05:57 2019 +0000

description:
pkgtools/pkglint: update to 5.7.12

Changes since 5.7.11:

* Fixed an alignment bug when pkglint replaced SUBST_SED with
  SUBST_VARS.

* Added many test cases.

diffstat:

 pkgtools/pkglint/Makefile                    |    4 +-
 pkgtools/pkglint/files/autofix.go            |   28 +
 pkgtools/pkglint/files/autofix_test.go       |   48 ++
 pkgtools/pkglint/files/mkline_test.go        |   22 +-
 pkgtools/pkglint/files/mklinechecker.go      |    6 +-
 pkgtools/pkglint/files/mklinechecker_test.go |    2 +-
 pkgtools/pkglint/files/mklines.go            |    5 +-
 pkgtools/pkglint/files/pkgsrc.go             |   77 ++--
 pkgtools/pkglint/files/redundantscope.go     |   18 +-
 pkgtools/pkglint/files/shell.go              |    6 +-
 pkgtools/pkglint/files/shell_test.go         |   14 +
 pkgtools/pkglint/files/substcontext.go       |   27 +-
 pkgtools/pkglint/files/substcontext_test.go  |  451 ++++++++++++++++++++++++--
 pkgtools/pkglint/files/tools.go              |    2 +-
 pkgtools/pkglint/files/util.go               |   21 +-
 pkgtools/pkglint/files/util_test.go          |   76 ++++
 pkgtools/pkglint/files/var_test.go           |   23 +
 pkgtools/pkglint/files/vardefs.go            |    8 +-
 pkgtools/pkglint/files/vardefs_test.go       |   17 +-
 pkgtools/pkglint/files/vartype.go            |   20 +-
 pkgtools/pkglint/files/vartype_test.go       |    4 +-
 pkgtools/pkglint/files/vartypecheck_test.go  |    9 +-
 22 files changed, 748 insertions(+), 140 deletions(-)

diffs (truncated from 1492 to 300 lines):

diff -r 3cd12eef6a79 -r 39d259f53c1d pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sun May 26 13:52:14 2019 +0000
+++ b/pkgtools/pkglint/Makefile Sun May 26 14:05:57 2019 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.582 2019/05/26 13:52:14 rillig Exp $
+# $NetBSD: Makefile,v 1.583 2019/05/26 14:06:42 rillig Exp $
 
-PKGNAME=       pkglint-5.7.11
+PKGNAME=       pkglint-5.7.12
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 3cd12eef6a79 -r 39d259f53c1d pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Sun May 26 13:52:14 2019 +0000
+++ b/pkgtools/pkglint/files/autofix.go Sun May 26 14:05:57 2019 +0000
@@ -100,6 +100,15 @@
                if replaced != rawLine.textnl {
                        if G.Logger.IsAutofix() {
                                rawLine.textnl = replaced
+
+                               // Fix the parsed text as well.
+                               // This is only approximate and won't work in some edge cases
+                               // that involve escaped comments or replacements across line breaks.
+                               //
+                               // TODO: Do this properly by parsing the whole line again,
+                               //  and ideally everything that depends on the parsed line.
+                               //  This probably requires a generic notification mechanism.
+                               fix.line.Text = strings.Replace(fix.line.Text, prefix+from, prefix+to, 1)
                        }
                        fix.Describef(rawLine.Lineno, "Replacing %q with %q.", from, to)
                        return
@@ -141,6 +150,25 @@
                        }
                }
        }
+
+       // Fix the parsed text as well.
+       // This is only approximate and won't work in some edge cases
+       // that involve escaped comments or replacements across line breaks.
+       //
+       // TODO: Do this properly by parsing the whole line again,
+       //  and ideally everything that depends on the parsed line.
+       //  This probably requires a generic notification mechanism.
+       done = 0
+       fix.line.Text = replaceAllFunc(
+               fix.line.Text,
+               from,
+               func(fromText string) string {
+                       if howOften >= 0 && done >= howOften {
+                               return fromText
+                       }
+                       done++
+                       return toText
+               })
 }
 
 // Custom runs a custom fix action, unless the fix is skipped anyway
diff -r 3cd12eef6a79 -r 39d259f53c1d pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Sun May 26 13:52:14 2019 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Sun May 26 14:05:57 2019 +0000
@@ -965,6 +965,54 @@
                "+\ttext again")
 }
 
+// After fixing part of a line, the whole line needs to be parsed again.
+//
+// As of May 2019, this is not done yet.
+func (s *Suite) Test_Autofix_Apply__text_after_replacing_string(c *check.C) {
+       t := s.Init(c)
+
+       t.SetUpCommandLine("-Wall", "--autofix")
+       mkline := t.NewMkLine("filename.mk", 123, "VAR=\tvalue")
+
+       fix := mkline.Autofix()
+       fix.Notef("Just a demo.")
+       fix.Replace("value", "new value")
+       fix.Apply()
+
+       t.CheckOutputLines(
+               "AUTOFIX: filename.mk:123: Replacing \"value\" with \"new value\".")
+
+       t.Check(mkline.raw[0].textnl, equals, "VAR=\tnew value\n")
+       t.Check(mkline.raw[0].orignl, equals, "VAR=\tvalue\n")
+       t.Check(mkline.Text, equals, "VAR=\tnew value")
+       // FIXME: should be updated as well.
+       t.Check(mkline.Value(), equals, "value")
+}
+
+// After fixing part of a line, the whole line needs to be parsed again.
+//
+// As of May 2019, this is not done yet.
+func (s *Suite) Test_Autofix_Apply__text_after_replacing_regex(c *check.C) {
+       t := s.Init(c)
+
+       t.SetUpCommandLine("-Wall", "--autofix")
+       mkline := t.NewMkLine("filename.mk", 123, "VAR=\tvalue")
+
+       fix := mkline.Autofix()
+       fix.Notef("Just a demo.")
+       fix.ReplaceRegex(`va...`, "new value", -1)
+       fix.Apply()
+
+       t.CheckOutputLines(
+               "AUTOFIX: filename.mk:123: Replacing \"value\" with \"new value\".")
+
+       t.Check(mkline.raw[0].textnl, equals, "VAR=\tnew value\n")
+       t.Check(mkline.raw[0].orignl, equals, "VAR=\tvalue\n")
+       t.Check(mkline.Text, equals, "VAR=\tnew value")
+       // FIXME: should be updated as well.
+       t.Check(mkline.Value(), equals, "value")
+}
+
 func (s *Suite) Test_Autofix_Realign__wrong_line_type(c *check.C) {
        t := s.Init(c)
 
diff -r 3cd12eef6a79 -r 39d259f53c1d pkgtools/pkglint/files/mkline_test.go
--- a/pkgtools/pkglint/files/mkline_test.go     Sun May 26 13:52:14 2019 +0000
+++ b/pkgtools/pkglint/files/mkline_test.go     Sun May 26 14:05:57 2019 +0000
@@ -564,11 +564,6 @@
 }
 
 // No quoting is necessary when lists of options are appended to each other.
-// PKG_OPTIONS are declared as "lkShell" although they are processed
-// using make's .for loop, which splits them at whitespace and usually
-// requires the variable to be declared as "lkSpace".
-// In this case it doesn't matter though since each option is an identifier,
-// and these do not pose any quoting or escaping problems.
 func (s *Suite) Test_MkLine_VariableNeedsQuoting__package_options(c *check.C) {
        t := s.Init(c)
 
@@ -1159,6 +1154,23 @@
                "WARN: Makefile:1: Missing closing \"}\" for \"UNFINISHED\".")
 }
 
+func (s *Suite) Test_MkLine_ValueTokens__parse_error(c *check.C) {
+       t := s.Init(c)
+
+       mkline := t.NewMkLine("filename.mk", 123, "VAR=\t$")
+
+       tokens, rest := mkline.ValueTokens()
+
+       t.Check(tokens, check.IsNil)
+       t.Check(rest, equals, "$")
+
+       // Returns the same values, this time from the cache.
+       tokens, rest = mkline.ValueTokens()
+
+       t.Check(tokens, check.IsNil)
+       t.Check(rest, equals, "$")
+}
+
 func (s *Suite) Test_MkLine_ValueTokens__caching(c *check.C) {
        t := s.Init(c)
 
diff -r 3cd12eef6a79 -r 39d259f53c1d pkgtools/pkglint/files/mklinechecker.go
--- a/pkgtools/pkglint/files/mklinechecker.go   Sun May 26 13:52:14 2019 +0000
+++ b/pkgtools/pkglint/files/mklinechecker.go   Sun May 26 14:05:57 2019 +0000
@@ -224,8 +224,8 @@
                // The guessed flag could also be determined more correctly. As of November 2018,
                // running pkglint over the whole pkgsrc tree did not produce any different result
                // whether guessed was true or false.
-               forLoopType := Vartype{btForLoop, List, []ACLEntry{{"*", aclpAllRead}}}
-               forLoopContext := VarUseContext{&forLoopType, vucTimeParse, VucQuotPlain, false}
+               forLoopType := NewVartype(btForLoop, List, NewACLEntry("*", aclpAllRead))
+               forLoopContext := VarUseContext{forLoopType, vucTimeParse, VucQuotPlain, false}
                mkline.ForEachUsed(func(varUse *MkVarUse, time vucTime) {
                        ck.CheckVaruse(varUse, &forLoopContext)
                })
@@ -1002,7 +1002,7 @@
 
        ck.checkTextVarUse(
                ck.MkLine.Varname(),
-               &Vartype{BtVariableName, NoVartypeOptions, []ACLEntry{{"*", aclpAll}}},
+               NewVartype(BtVariableName, NoVartypeOptions, NewACLEntry("*", aclpAll)),
                vucTimeParse)
 }
 
diff -r 3cd12eef6a79 -r 39d259f53c1d pkgtools/pkglint/files/mklinechecker_test.go
--- a/pkgtools/pkglint/files/mklinechecker_test.go      Sun May 26 13:52:14 2019 +0000
+++ b/pkgtools/pkglint/files/mklinechecker_test.go      Sun May 26 14:05:57 2019 +0000
@@ -1218,7 +1218,7 @@
        // This combination of BtUnknown and all permissions is typical for
        // otherwise unknown variables from the pkgsrc infrastructure.
        G.Pkgsrc.vartypes.Define("INFRA", BtUnknown, NoVartypeOptions,
-               ACLEntry{"*", aclpAll})
+               NewACLEntry("*", aclpAll))
        G.Pkgsrc.vartypes.DefineParse("VAR", BtUnknown, NoVartypeOptions,
                "buildlink3.mk: none",
                "*: use")
diff -r 3cd12eef6a79 -r 39d259f53c1d pkgtools/pkglint/files/mklines.go
--- a/pkgtools/pkglint/files/mklines.go Sun May 26 13:52:14 2019 +0000
+++ b/pkgtools/pkglint/files/mklines.go Sun May 26 14:05:57 2019 +0000
@@ -130,15 +130,13 @@
 
                varalign.Process(mkline)
                mklines.Tools.ParseToolLine(mklines, mkline, false, false)
+               substContext.Process(mkline)
 
                switch {
-               case mkline.IsEmpty():
-                       substContext.Finish(mkline)
 
                case mkline.IsVarassign():
                        mklines.target = ""
                        mkline.Tokenize(mkline.Value(), true) // Just for the side-effect of the warnings.
-                       substContext.Varassign(mkline)
 
                        mklines.checkVarassignPlist(mkline)
 
@@ -150,7 +148,6 @@
 
                case mkline.IsDirective():
                        ck.checkDirective(mklines.forVars, mklines.indentation)
-                       substContext.Directive(mkline)
 
                case mkline.IsDependency():
                        ck.checkDependencyRule(allowedTargets)
diff -r 3cd12eef6a79 -r 39d259f53c1d pkgtools/pkglint/files/pkgsrc.go
--- a/pkgtools/pkglint/files/pkgsrc.go  Sun May 26 13:52:14 2019 +0000
+++ b/pkgtools/pkglint/files/pkgsrc.go  Sun May 26 14:05:57 2019 +0000
@@ -347,7 +347,7 @@
 func (src *Pkgsrc) loadUntypedVars() {
 
        // Setting guessed to false prevents the vartype.guessed case in MkLineChecker.CheckVaruse.
-       unknownType := Vartype{BtUnknown, NoVartypeOptions, []ACLEntry{{"*", aclpAll}}}
+       unknownType := NewVartype(BtUnknown, NoVartypeOptions, NewACLEntry("*", aclpAll))
 
        define := func(varcanon string, mkline MkLine) {
                switch {
@@ -371,7 +371,7 @@
                        if trace.Tracing {
                                trace.Stepf("Untyped variable %q in %s", varcanon, mkline)
                        }
-                       src.vartypes.DefineType(varcanon, &unknownType)
+                       src.vartypes.DefineType(varcanon, unknownType)
                }
        }
 
@@ -922,75 +922,84 @@
                if tool.Validity == AfterPrefsMk && mklines.Tools.SeenPrefs {
                        perms |= aclpUseLoadtime
                }
-               return &Vartype{BtShellCommand, NoVartypeOptions, []ACLEntry{{"*", perms}}}
+               return NewVartype(BtShellCommand, NoVartypeOptions, NewACLEntry("*", perms))
        }
 
        if m, toolVarname := match1(varname, `^TOOLS_(.*)`); m {
                if tool := G.ToolByVarname(mklines, toolVarname); tool != nil {
-                       return &Vartype{BtPathname, NoVartypeOptions, []ACLEntry{{"*", aclpUse}}}
+                       return NewVartype(BtPathname, NoVartypeOptions, NewACLEntry("*", aclpUse))
                }
        }
 
        return src.guessVariableType(varname)
 }
 
+// guessVariableType guesses the data type of the variable based on naming conventions.
 func (src *Pkgsrc) guessVariableType(varname string) (vartype *Vartype) {
-       allowAll := []ACLEntry{{"*", aclpAll}}
-       allowRuntime := []ACLEntry{{"*", aclpAllRuntime}}
+       plainType := func(basicType *BasicType, permissions ACLPermissions) *Vartype {
+               gtype := NewVartype(basicType, Guessed, NewACLEntry("*", permissions))
+               trace.Step2("The guessed type of %q is %q.", varname, gtype.String())
+               return gtype
+       }
+       listType := func(basicType *BasicType, permissions ACLPermissions) *Vartype {
+               gtype := NewVartype(basicType, List|Guessed, NewACLEntry("*", permissions))
+               trace.Step2("The guessed type of %q is %q.", varname, gtype.String())
+               return gtype
+       }
 
-       // Guess the data type of the variable based on naming conventions.
        varbase := varnameBase(varname)
-       var gtype *Vartype
        switch {
        case hasSuffix(varbase, "DIRS"):
-               gtype = &Vartype{BtPathmask, List | Guessed, allowRuntime}
+               return listType(BtPathmask, aclpAllRuntime)
        case hasSuffix(varbase, "DIR") && !hasSuffix(varbase, "DESTDIR"), hasSuffix(varname, "_HOME"):
                // TODO: hasSuffix(varbase, "BASE")
-               gtype = &Vartype{BtPathname, Guessed, allowRuntime}
+               return plainType(BtPathname, aclpAllRuntime)
        case hasSuffix(varbase, "FILES"):
-               gtype = &Vartype{BtPathmask, List | Guessed, allowRuntime}
+               return listType(BtPathmask, aclpAllRuntime)
        case hasSuffix(varbase, "FILE"):
-               gtype = &Vartype{BtPathname, Guessed, allowRuntime}
+               return plainType(BtPathname, aclpAllRuntime)
        case hasSuffix(varbase, "PATH"):
-               gtype = &Vartype{BtPathlist, Guessed, allowRuntime}
+               return plainType(BtPathlist, aclpAllRuntime)
        case hasSuffix(varbase, "PATHS"):
-               gtype = &Vartype{BtPathname, List | Guessed, allowRuntime}
+               return listType(BtPathname, aclpAllRuntime)
        case hasSuffix(varbase, "_USER"):
-               gtype = &Vartype{BtUserGroupName, Guessed, allowAll}
+               return plainType(BtUserGroupName, aclpAll)
        case hasSuffix(varbase, "_GROUP"):
-               gtype = &Vartype{BtUserGroupName, Guessed, allowAll}
+               return plainType(BtUserGroupName, aclpAll)



Home | Main Index | Thread Index | Old Index