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.4
details: https://anonhg.NetBSD.org/pkgsrc/rev/c6dfbadaf3aa
branches: trunk
changeset: 416896:c6dfbadaf3aa
user: rillig <rillig%pkgsrc.org@localhost>
date: Fri Nov 01 19:56:52 2019 +0000
description:
pkgtools/pkglint: update to 19.3.4
Changes since 19.3.3:
In cases where the conditions for including buildlink3.mk files differ
between the package itself and its own buildlink3.mk file, explain how
to determine PKG_OPTIONS for dependencies.
Don't issue wrong warnings in options.mk files when the options are
handled in a .for loop.
diffstat:
pkgtools/pkglint/Makefile | 4 +-
pkgtools/pkglint/files/category.go | 2 +-
pkgtools/pkglint/files/category_test.go | 4 +-
pkgtools/pkglint/files/check_test.go | 3 +
pkgtools/pkglint/files/mklinechecker.go | 11 +--
pkgtools/pkglint/files/mktypes.go | 8 +-
pkgtools/pkglint/files/mktypes_test.go | 41 ++++++++++--
pkgtools/pkglint/files/options.go | 80 +++++++++++++++---------
pkgtools/pkglint/files/options_test.go | 98 +++++++++++++++++++++++++++++
pkgtools/pkglint/files/package.go | 24 ++++--
pkgtools/pkglint/files/package_test.go | 105 ++++++++++++++++++++++++++++++++
pkgtools/pkglint/files/pkglint.go | 27 +++----
pkgtools/pkglint/files/toplevel.go | 2 +-
pkgtools/pkglint/files/util.go | 31 +++++++++
pkgtools/pkglint/files/vardefs.go | 46 ++++++++-----
15 files changed, 388 insertions(+), 98 deletions(-)
diffs (truncated from 753 to 300 lines):
diff -r d95670d0dd38 -r c6dfbadaf3aa pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Fri Nov 01 19:42:16 2019 +0000
+++ b/pkgtools/pkglint/Makefile Fri Nov 01 19:56:52 2019 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.603 2019/10/26 11:43:36 rillig Exp $
+# $NetBSD: Makefile,v 1.604 2019/11/01 19:56:52 rillig Exp $
-PKGNAME= pkglint-19.3.3
+PKGNAME= pkglint-19.3.4
CATEGORIES= pkgtools
DISTNAME= tools
MASTER_SITES= ${MASTER_SITE_GITHUB:=golang/}
diff -r d95670d0dd38 -r c6dfbadaf3aa pkgtools/pkglint/files/category.go
--- a/pkgtools/pkglint/files/category.go Fri Nov 01 19:42:16 2019 +0000
+++ b/pkgtools/pkglint/files/category.go Fri Nov 01 19:56:52 2019 +0000
@@ -161,6 +161,6 @@
recurseInto = append(recurseInto, joinPath(dir, msub.name))
}
}
- G.Todo = append(recurseInto, G.Todo...)
+ G.Todo.PushFront(recurseInto...)
}
}
diff -r d95670d0dd38 -r c6dfbadaf3aa pkgtools/pkglint/files/category_test.go
--- a/pkgtools/pkglint/files/category_test.go Fri Nov 01 19:42:16 2019 +0000
+++ b/pkgtools/pkglint/files/category_test.go Fri Nov 01 19:56:52 2019 +0000
@@ -208,12 +208,12 @@
// It is only removed in Pkglint.Main, therefore it stays there even
// after the call to CheckdirCategory. This is a bit unrealistic,
// but close enough for this test.
- t.CheckDeepEquals(G.Todo, []string{"."})
+ t.CheckDeepEquals(G.Todo.entries, []string{"."})
CheckdirCategory(".")
t.CheckOutputEmpty()
- t.CheckDeepEquals(G.Todo, []string{"./package", "."})
+ t.CheckDeepEquals(G.Todo.entries, []string{"./package", "."})
}
// Ensures that a directory in the file system can be added at the very
diff -r d95670d0dd38 -r c6dfbadaf3aa pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go Fri Nov 01 19:42:16 2019 +0000
+++ b/pkgtools/pkglint/files/check_test.go Fri Nov 01 19:56:52 2019 +0000
@@ -69,6 +69,7 @@
t.c = c
t.SetUpCommandLine("-Wall") // To catch duplicate warnings
+ G.Todo.Pop() // The "." was inserted by default.
t.seenSetUpCommandLine = false // This default call doesn't count.
// To improve code coverage and ensure that trace.Result works
@@ -693,6 +694,8 @@
//
// Arguments that name existing files or directories in the temporary test
// directory are transformed to their actual paths.
+//
+// Does not work in combination with SetUpOption.
func (t *Tester) Main(args ...string) int {
if t.seenFinish && !t.seenMain {
t.Errorf("Calling t.FinishSetup() before t.Main() is redundant " +
diff -r d95670d0dd38 -r c6dfbadaf3aa pkgtools/pkglint/files/mklinechecker.go
--- a/pkgtools/pkglint/files/mklinechecker.go Fri Nov 01 19:42:16 2019 +0000
+++ b/pkgtools/pkglint/files/mklinechecker.go Fri Nov 01 19:56:52 2019 +0000
@@ -437,16 +437,9 @@
return
}
- needsRationale := func(mkline *MkLine) bool {
- if !mkline.IsVarassignMaybeCommented() {
- return false
- }
- vartype := G.Pkgsrc.VariableType(ck.MkLines, mkline.Varname())
- return vartype != nil && vartype.NeedsRationale()
- }
-
mkline := ck.MkLine
- if !needsRationale(mkline) {
+ vartype := G.Pkgsrc.VariableType(ck.MkLines, mkline.Varname())
+ if vartype == nil || !vartype.NeedsRationale() {
return
}
diff -r d95670d0dd38 -r c6dfbadaf3aa pkgtools/pkglint/files/mktypes.go
--- a/pkgtools/pkglint/files/mktypes.go Fri Nov 01 19:42:16 2019 +0000
+++ b/pkgtools/pkglint/files/mktypes.go Fri Nov 01 19:56:52 2019 +0000
@@ -89,13 +89,15 @@
// MatchMatch tries to match the modifier to a :M or a :N pattern matching.
// Examples:
-// :Mpattern => true, true, "pattern"
-// :Npattern => true, false, "pattern"
+// :Mpattern => true, true, "pattern", true
+// :M* => true, true, "*", false
+// :M${VAR} => true, true, "${VAR}", false
+// :Npattern => true, false, "pattern", true
// :X => false
func (m MkVarUseModifier) MatchMatch() (ok bool, positive bool, pattern string, exact bool) {
if hasPrefix(m.Text, "M") || hasPrefix(m.Text, "N") {
// See devel/bmake/files/str.c:^Str_Match
- exact := !strings.ContainsAny(m.Text[1:], "*?[\\")
+ exact := !strings.ContainsAny(m.Text[1:], "*?[\\$")
return true, m.Text[0] == 'M', m.Text[1:], exact
}
return false, false, "", false
diff -r d95670d0dd38 -r c6dfbadaf3aa pkgtools/pkglint/files/mktypes_test.go
--- a/pkgtools/pkglint/files/mktypes_test.go Fri Nov 01 19:42:16 2019 +0000
+++ b/pkgtools/pkglint/files/mktypes_test.go Fri Nov 01 19:56:52 2019 +0000
@@ -39,6 +39,16 @@
return &MkVarUse{varname, mods}
}
+// AddCommand adds a command directly to a list of commands,
+// creating all the intermediate nodes for the syntactic representation.
+// As soon as that representation is replaced with a semantic representation,
+// this method should no longer be necessary.
+func (list *MkShList) AddCommand(command *MkShCommand) *MkShList {
+ pipeline := NewMkShPipeline(false, []*MkShCommand{command})
+ andOr := NewMkShAndOr(pipeline)
+ return list.AddAndOr(andOr)
+}
+
func (s *Suite) Test_MkVarUse_Mod(c *check.C) {
t := s.Init(c)
@@ -53,14 +63,29 @@
test("${PATH:ts::Q}", ":ts::Q")
}
-// AddCommand adds a command directly to a list of commands,
-// creating all the intermediate nodes for the syntactic representation.
-// As soon as that representation is replaced with a semantic representation,
-// this method should no longer be necessary.
-func (list *MkShList) AddCommand(command *MkShCommand) *MkShList {
- pipeline := NewMkShPipeline(false, []*MkShCommand{command})
- andOr := NewMkShAndOr(pipeline)
- return list.AddAndOr(andOr)
+func (s *Suite) Test_MkVarUseModifier_MatchMatch(c *check.C) {
+ t := s.Init(c)
+
+ testFail := func(modifier string) {
+ mod := MkVarUseModifier{modifier}
+ ok, _, _, _ := mod.MatchMatch()
+ t.CheckEquals(ok, false)
+ }
+ test := func(modifier string, positive bool, pattern string, exact bool) {
+ mod := MkVarUseModifier{modifier}
+ actualOk, actualPositive, actualPattern, actualExact := mod.MatchMatch()
+ t.CheckDeepEquals(
+ []interface{}{actualOk, actualPositive, actualPattern, actualExact},
+ []interface{}{true, positive, pattern, exact})
+ }
+
+ testFail("")
+ testFail("X")
+
+ test("Mpattern", true, "pattern", true)
+ test("M*", true, "*", false)
+ test("M${VAR}", true, "${VAR}", false)
+ test("Npattern", false, "pattern", true)
}
func (s *Suite) Test_MkVarUseModifier_ChangesWords(c *check.C) {
diff -r d95670d0dd38 -r c6dfbadaf3aa pkgtools/pkglint/files/options.go
--- a/pkgtools/pkglint/files/options.go Fri Nov 01 19:42:16 2019 +0000
+++ b/pkgtools/pkglint/files/options.go Fri Nov 01 19:56:52 2019 +0000
@@ -1,7 +1,5 @@
package pkglint
-import "path"
-
func CheckLinesOptionsMk(mklines *MkLines) {
ck := OptionsLinesChecker{
mklines,
@@ -42,10 +40,13 @@
mlex.Skip()
}
- for !mlex.EOF() {
- ck.handleLowerLine(mlex.CurrentMkLine())
- mlex.Skip()
- }
+ i := 0
+ mklines.ForEach(func(mkline *MkLine) {
+ if i >= mlex.index {
+ ck.handleLowerLine(mkline)
+ }
+ i++
+ })
ck.checkOptionsMismatch()
@@ -81,7 +82,10 @@
case mkline.IsVarassign():
switch mkline.Varcanon() {
- case "PKG_SUPPORTED_OPTIONS", "PKG_OPTIONS_GROUP.*", "PKG_OPTIONS_SET.*":
+ 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
@@ -113,48 +117,64 @@
}
func (ck *OptionsLinesChecker) handleLowerLine(mkline *MkLine) {
- if mkline.IsDirective() {
- directive := mkline.Directive()
- if directive == "if" || directive == "elif" {
- cond := mkline.Cond()
- if cond != nil {
- ck.handleLowerCondition(mkline, cond)
- }
- }
+ if !mkline.IsDirective() {
+ return
+ }
+
+ directive := mkline.Directive()
+ if directive != "if" && directive != "elif" {
+ return
}
+
+ cond := mkline.Cond()
+ if cond == nil {
+ return
+ }
+
+ ck.handleLowerCondition(mkline, cond)
}
func (ck *OptionsLinesChecker) handleLowerCondition(mkline *MkLine, cond *MkCond) {
- recordUsedOption := func(varuse *MkVarUse) {
+ recordOption := func(option string) {
+ if containsVarRef(option) {
+ return
+ }
+
+ ck.handledOptions[option] = mkline
+ ck.optionsInDeclarationOrder = append(ck.optionsInDeclarationOrder, option)
+ }
+
+ recordVarUse := func(varuse *MkVarUse) {
if varuse.varname != "PKG_OPTIONS" || len(varuse.modifiers) != 1 {
return
}
m, positive, pattern, exact := varuse.modifiers[0].MatchMatch()
- if !m || !positive || containsVarRef(pattern) {
+ if !m || !positive {
return
}
- if exact {
- option := pattern
- ck.handledOptions[option] = mkline
- ck.optionsInDeclarationOrder = append(ck.optionsInDeclarationOrder, option)
- return
- }
+ if optionVarUse := ToVarUse(pattern); optionVarUse != nil {
+ for _, option := range ck.mklines.ExpandLoopVar(optionVarUse.varname) {
+ recordOption(option)
+ }
- for declaredOption := range ck.declaredOptions {
- matched, err := path.Match(pattern, declaredOption)
- if err == nil && matched {
- ck.handledOptions[declaredOption] = mkline
- ck.optionsInDeclarationOrder = append(ck.optionsInDeclarationOrder, declaredOption)
+ } else if exact {
+ recordOption(pattern)
+
+ } else {
+ for declaredOption := range ck.declaredOptions {
+ if pathMatches(pattern, declaredOption) {
+ recordOption(declaredOption)
+ }
}
}
}
cond.Walk(&MkCondCallback{
- Empty: recordUsedOption,
- Var: recordUsedOption})
+ Empty: recordVarUse,
+ Var: recordVarUse})
if cond.Empty != nil && cond.Empty.varname == "PKG_OPTIONS" && mkline.HasElseBranch() {
mkline.Notef("The positive branch of the .if/.else should be the one where the option is set.")
diff -r d95670d0dd38 -r c6dfbadaf3aa pkgtools/pkglint/files/options_test.go
--- a/pkgtools/pkglint/files/options_test.go Fri Nov 01 19:42:16 2019 +0000
+++ b/pkgtools/pkglint/files/options_test.go Fri Nov 01 19:56:52 2019 +0000
@@ -387,3 +387,101 @@
t.CheckOutputLines(
"WARN: options.mk:4: Option \"opt-variant\" should be handled below in an .if block.")
}
+
Home |
Main Index |
Thread Index |
Old Index