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.21
details: https://anonhg.NetBSD.org/pkgsrc/rev/600472c1e897
branches: trunk
changeset: 400077:600472c1e897
user: rillig <rillig%pkgsrc.org@localhost>
date: Wed Aug 21 16:45:16 2019 +0000
description:
pkgtools/pkglint: update to 5.7.21
Changes since 5.7.20:
* PKG_OPTIONS that are handled using patterns are correctly identified.
* Simple R packages should follow the canonical variable order.
* Fixed some edge cases for aligning variable assignments.
* Improved detection of allowed values for USE_LANGUAGES.
diffstat:
pkgtools/pkglint/Makefile | 4 +-
pkgtools/pkglint/files/check_test.go | 12 +
pkgtools/pkglint/files/mkline_test.go | 7 +-
pkgtools/pkglint/files/mklinechecker.go | 11 +-
pkgtools/pkglint/files/mklinechecker_test.go | 5 +-
pkgtools/pkglint/files/mkshparser.go | 6 +-
pkgtools/pkglint/files/mkshparser_test.go | 39 ++++-
pkgtools/pkglint/files/mktypes.go | 8 +-
pkgtools/pkglint/files/options.go | 30 ++-
pkgtools/pkglint/files/options_test.go | 63 ++++++
pkgtools/pkglint/files/package.go | 2 +
pkgtools/pkglint/files/package_test.go | 17 +-
pkgtools/pkglint/files/varalignblock.go | 33 +--
pkgtools/pkglint/files/varalignblock_test.go | 254 ++++++++++++++++++++++++++-
pkgtools/pkglint/files/vardefs.go | 29 ++-
pkgtools/pkglint/files/vardefs_test.go | 38 +++-
pkgtools/pkglint/files/vartype.go | 4 +
pkgtools/pkglint/files/vartypecheck.go | 67 +++++-
pkgtools/pkglint/files/vartypecheck_test.go | 63 +++++-
19 files changed, 604 insertions(+), 88 deletions(-)
diffs (truncated from 1133 to 300 lines):
diff -r 7ac38845cdb9 -r 600472c1e897 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Wed Aug 21 16:31:18 2019 +0000
+++ b/pkgtools/pkglint/Makefile Wed Aug 21 16:45:16 2019 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.593 2019/08/16 21:00:17 rillig Exp $
+# $NetBSD: Makefile,v 1.594 2019/08/21 16:45:16 rillig Exp $
-PKGNAME= pkglint-5.7.20
+PKGNAME= pkglint-5.7.21
CATEGORIES= pkgtools
DISTNAME= tools
MASTER_SITES= ${MASTER_SITE_GITHUB:=golang/}
diff -r 7ac38845cdb9 -r 600472c1e897 pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go Wed Aug 21 16:31:18 2019 +0000
+++ b/pkgtools/pkglint/files/check_test.go Wed Aug 21 16:45:16 2019 +0000
@@ -309,6 +309,18 @@
t.CreateFileLines("mk/bsd.fast.prefs.mk",
MkCvsID)
+ // This file is used for initializing the allowed values for
+ // USE_LANGUAGES; see VarTypeRegistry.compilerLanguages.
+ t.CreateFileLines("mk/compiler.mk",
+ "_CXX_STD_VERSIONS=\tc++ c++14",
+ ".if ${USE_LANGUAGES:Mada} || \\",
+ " ${USE_LANGUAGES:Mc} || \\",
+ " ${USE_LANGUAGES:Mc99} || \\",
+ " ${USE_LANGUAGES:Mobjc} || \\",
+ " ${USE_LANGUAGES:Mfortran} || \\",
+ " ${USE_LANGUAGES:Mfortran77}",
+ ".endif")
+
// Category Makefiles require this file for the common definitions.
t.CreateFileLines("mk/misc/category.mk")
diff -r 7ac38845cdb9 -r 600472c1e897 pkgtools/pkglint/files/mkline_test.go
--- a/pkgtools/pkglint/files/mkline_test.go Wed Aug 21 16:31:18 2019 +0000
+++ b/pkgtools/pkglint/files/mkline_test.go Wed Aug 21 16:45:16 2019 +0000
@@ -457,9 +457,10 @@
"\tvalue",
true)
- // In commented multilines, the continuation lines may or may not start
- // with a comment character. Bmake doesn't care, but for human readers
- // it is confusing to omit the leading comment character.
+ // In commented multilines, bmake doesn't care whether the
+ // continuation lines does or doesn't start with a comment character.
+ // For human readers though, it is confusing to omit the leading
+ // comment character.
//
// For determining whether a multiline is aligned, the initial comment
// character is ignored.
diff -r 7ac38845cdb9 -r 600472c1e897 pkgtools/pkglint/files/mklinechecker.go
--- a/pkgtools/pkglint/files/mklinechecker.go Wed Aug 21 16:31:18 2019 +0000
+++ b/pkgtools/pkglint/files/mklinechecker.go Wed Aug 21 16:45:16 2019 +0000
@@ -599,7 +599,7 @@
if len(mods) == 3 {
if m, _, from, to, options := mods[0].MatchSubst(); m && from == "^" && matches(to, `^\w+$`) && options == "1" {
magic := to
- if m, positive, pattern := mods[1].MatchMatch(); m && positive && pattern == magic+"*" {
+ if m, positive, pattern, _ := mods[1].MatchMatch(); m && positive && pattern == magic+"*" {
if m, _, from, to, options = mods[2].MatchSubst(); m && from == "^"+magic && to == "" && options == "" {
fix := ck.MkLine.Autofix()
fix.Notef("The modifier %q can be written as %q.", varuse.Mod(), ":[1]")
@@ -1583,7 +1583,8 @@
pattern +
condStr(fromEmpty, ")", "}")
- to := "${" + varname + "} " + op + " " + pattern
+ quote := condStr(matches(pattern, `[^\-/0-9@A-Za-z]`), "\"", "")
+ to := "${" + varname + "} " + op + " " + quote + pattern + quote
// TODO: Check in more cases whether the parentheses are really necessary.
// In a !!${VAR} expression, parentheses are necessary.
@@ -1599,11 +1600,11 @@
modifiers := varuse.modifiers
for _, modifier := range modifiers {
- if m, positive, pattern := modifier.MatchMatch(); m && (positive || len(modifiers) == 1) {
+ if m, positive, pattern, exact := modifier.MatchMatch(); m && (positive || len(modifiers) == 1) {
ck.checkVartype(varname, opUseMatch, pattern, "")
vartype := G.Pkgsrc.VariableType(ck.MkLines, varname)
- if matches(pattern, `^[\w-/]+$`) && vartype != nil && !vartype.List() {
+ if exact && matches(pattern, `^[\w-/]+$`) && vartype != nil && !vartype.List() {
fix := ck.MkLine.Autofix()
fix.Notef("%s should be compared using %s instead of matching against %q.",
@@ -1649,7 +1650,7 @@
ck.checkCompareVarStr(varname, op, str)
case 1:
- if m, _, pattern := varmods[0].MatchMatch(); m {
+ if m, _, pattern, _ := varmods[0].MatchMatch(); m {
ck.checkVartype(varname, opUseMatch, pattern, "")
// After applying the :M or :N modifier, every expression may end up empty,
diff -r 7ac38845cdb9 -r 600472c1e897 pkgtools/pkglint/files/mklinechecker_test.go
--- a/pkgtools/pkglint/files/mklinechecker_test.go Wed Aug 21 16:31:18 2019 +0000
+++ b/pkgtools/pkglint/files/mklinechecker_test.go Wed Aug 21 16:45:16 2019 +0000
@@ -2184,6 +2184,9 @@
mklines := t.SetUpFileMkLines("options.mk",
MkCvsID,
"GOPATH=\t${WRKDIR}",
+ "",
+ "CONFIGURE_ENV+=\tNAME=${R_PKGNAME} VER=${R_PKGVER}",
+ "",
"do-build:",
"\tcd ${WRKSRC} && GOPATH=${GOPATH} PATH=${PATH} :")
@@ -2197,7 +2200,7 @@
// of pkgsrc, and these may contain special characters.
t.CheckOutputLines(
- "WARN: ~/options.mk:4: The variable PATH should be quoted as part of a shell word.")
+ "WARN: ~/options.mk:7: The variable PATH should be quoted as part of a shell word.")
}
func (s *Suite) Test_MkLineChecker_checkVarUseQuoting__mstar(c *check.C) {
diff -r 7ac38845cdb9 -r 600472c1e897 pkgtools/pkglint/files/mkshparser.go
--- a/pkgtools/pkglint/files/mkshparser.go Wed Aug 21 16:31:18 2019 +0000
+++ b/pkgtools/pkglint/files/mkshparser.go Wed Aug 21 16:45:16 2019 +0000
@@ -11,12 +11,12 @@
lexer := NewShellLexer(tokens, rest)
parser := shyyParserImpl{}
- succeeded := parser.Parse(lexer)
+ zeroMeansSuccess := parser.Parse(lexer)
switch {
- case succeeded == 0 && lexer.error == "":
+ case zeroMeansSuccess == 0 && lexer.error == "":
return lexer.result, nil
- case succeeded == 0:
+ case zeroMeansSuccess == 0:
return nil, fmt.Errorf("splitIntoShellTokens couldn't parse %q", rest)
default:
return nil, &ParseError{append([]string{lexer.current}, lexer.remaining...)}
diff -r 7ac38845cdb9 -r 600472c1e897 pkgtools/pkglint/files/mkshparser_test.go
--- a/pkgtools/pkglint/files/mkshparser_test.go Wed Aug 21 16:31:18 2019 +0000
+++ b/pkgtools/pkglint/files/mkshparser_test.go Wed Aug 21 16:45:16 2019 +0000
@@ -19,6 +19,7 @@
t.CheckEquals(err, expError)
} else {
t.CheckDeepEquals(err, expError)
+ t.CheckDeepEquals(err.Error(), expError.Error()) // Just for code coverage
t.CheckDeepEquals(program, expProgram)
}
@@ -48,6 +49,12 @@
nil,
nil,
nil...)
+
+ test(
+ "case ;;",
+ nil,
+ &ParseError{[]string{";;"}},
+ nil...)
}
type ShSuite struct {
@@ -396,11 +403,17 @@
b.Words("*"),
b.List(), sepNone))))
- // The default case may be omitted if PATTERNS can never be empty.
+ // The default case may even be omitted.
s.test("case $$expr in ${PATTERNS:@p@ (${p}) action ;; @} esac",
b.List().AddCommand(b.Case(
b.Token("$$expr"),
b.CaseItemVar("${PATTERNS:@p@ (${p}) action ;; @}"))))
+
+ // Only variables that end with a :@ modifier may be used in this
+ // construct. All others are tokenized as normal words and lead
+ // to a syntax error in the shell parser.
+ s.testFail("case $$expr in ${PATTERNS} esac",
+ []string{}...)
}
func (s *ShSuite) Test_ShellParser__if_clause(c *check.C) {
@@ -589,6 +602,21 @@
}
}
+func (s *ShSuite) testFail(program string, expectedRemaining ...string) {
+ t := s.t
+
+ tokens, rest := splitIntoShellTokens(dummyLine, program)
+ t.CheckEquals(rest, "")
+ lexer := ShellLexer{remaining: tokens, atCommandStart: true}
+ parser := shyyParserImpl{}
+
+ zeroMeansSuccess := parser.Parse(&lexer)
+
+ if t.CheckEquals(zeroMeansSuccess, 1) && t.Check(lexer.error, check.Not(check.Equals), "") {
+ t.CheckDeepEquals(lexer.remaining, expectedRemaining)
+ }
+}
+
func (s *ShSuite) Test_ShellLexer_Lex__redirects(c *check.C) {
t := s.t
@@ -708,6 +736,15 @@
tkIN,
tkWORD,
tkESAC)
+
+ test(
+ "case $$expr in ${PATTERNS:Mpattern} esac",
+
+ tkCASE,
+ tkWORD,
+ tkIN,
+ tkWORD,
+ tkWORD) // No tkESAC since there is no :@ modifier.
}
type MkShBuilder struct {
diff -r 7ac38845cdb9 -r 600472c1e897 pkgtools/pkglint/files/mktypes.go
--- a/pkgtools/pkglint/files/mktypes.go Wed Aug 21 16:31:18 2019 +0000
+++ b/pkgtools/pkglint/files/mktypes.go Wed Aug 21 16:45:16 2019 +0000
@@ -92,11 +92,13 @@
// :Mpattern => true, true, "pattern"
// :Npattern => true, false, "pattern"
// :X => false
-func (m MkVarUseModifier) MatchMatch() (ok bool, positive bool, pattern string) {
+func (m MkVarUseModifier) MatchMatch() (ok bool, positive bool, pattern string, exact bool) {
if hasPrefix(m.Text, "M") || hasPrefix(m.Text, "N") {
- return true, m.Text[0] == 'M', m.Text[1:]
+ // See devel/bmake/files/str.c:^Str_Match
+ exact := !strings.ContainsAny(m.Text[1:], "*?[\\")
+ return true, m.Text[0] == 'M', m.Text[1:], exact
}
- return false, false, ""
+ return false, false, "", false
}
func (m MkVarUseModifier) IsToLower() bool { return m.Text == "tl" }
diff -r 7ac38845cdb9 -r 600472c1e897 pkgtools/pkglint/files/options.go
--- a/pkgtools/pkglint/files/options.go Wed Aug 21 16:31:18 2019 +0000
+++ b/pkgtools/pkglint/files/options.go Wed Aug 21 16:45:16 2019 +0000
@@ -1,5 +1,7 @@
package pkglint
+import "path"
+
func CheckLinesOptionsMk(mklines *MkLines) {
ck := OptionsLinesChecker{
mklines,
@@ -125,13 +127,27 @@
func (ck *OptionsLinesChecker) handleLowerCondition(mkline *MkLine, cond *MkCond) {
recordUsedOption := func(varuse *MkVarUse) {
- if varuse.varname == "PKG_OPTIONS" && len(varuse.modifiers) == 1 {
- if m, positive, pattern := varuse.modifiers[0].MatchMatch(); m && positive {
- option := pattern
- if !containsVarRef(option) {
- ck.handledOptions[option] = mkline
- ck.optionsInDeclarationOrder = append(ck.optionsInDeclarationOrder, option)
- }
+ if varuse.varname != "PKG_OPTIONS" || len(varuse.modifiers) != 1 {
+ return
+ }
+
+ m, positive, pattern, exact := varuse.modifiers[0].MatchMatch()
+ if !m || !positive || containsVarRef(pattern) {
+ return
+ }
+
+ if exact {
+ option := pattern
+ ck.handledOptions[option] = mkline
+ ck.optionsInDeclarationOrder = append(ck.optionsInDeclarationOrder, option)
+ return
+ }
+
+ 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)
}
}
}
diff -r 7ac38845cdb9 -r 600472c1e897 pkgtools/pkglint/files/options_test.go
--- a/pkgtools/pkglint/files/options_test.go Wed Aug 21 16:31:18 2019 +0000
+++ b/pkgtools/pkglint/files/options_test.go Wed Aug 21 16:45:16 2019 +0000
@@ -324,3 +324,66 @@
". endif",
".endif")
}
+
+// A few packages (such as www/w3m) define several options that are
+// handled by a single .if block in the lower part.
+func (s *Suite) Test_CheckLinesOptionsMk__combined_option_handling(c *check.C) {
+ t := s.Init(c)
+
+ t.SetUpOption("opt-variant1", "")
+ t.SetUpOption("opt-variant2", "")
+ t.SetUpOption("other", "")
Home |
Main Index |
Thread Index |
Old Index