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.18
details: https://anonhg.NetBSD.org/pkgsrc/rev/5ad4ef5ef7ff
branches: trunk
changeset: 419212:5ad4ef5ef7ff
user: rillig <rillig%pkgsrc.org@localhost>
date: Sat Dec 14 18:04:15 2019 +0000
description:
pkgtools/pkglint: update to 19.3.18
Changes since 19.3.17:
The SUBST check has been completely rewritten. It can handle several
SUBST classes at the same time now. This reduces the number of wrong
warnings.
diffstat:
pkgtools/pkglint/Makefile | 5 +-
pkgtools/pkglint/files/mkcondchecker_test.go | 3 +-
pkgtools/pkglint/files/substcontext.go | 823 +++++++++------
pkgtools/pkglint/files/substcontext_test.go | 1360 ++++++++++++++-----------
pkgtools/pkglint/files/vardefs.go | 4 +-
pkgtools/pkglint/files/vartype.go | 5 -
pkgtools/pkglint/files/vartypecheck.go | 8 +-
pkgtools/pkglint/files/vartypecheck_test.go | 12 +-
8 files changed, 1279 insertions(+), 941 deletions(-)
diffs (truncated from 2768 to 300 lines):
diff -r b3caa5ccfe86 -r 5ad4ef5ef7ff pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sat Dec 14 18:03:10 2019 +0000
+++ b/pkgtools/pkglint/Makefile Sat Dec 14 18:04:15 2019 +0000
@@ -1,7 +1,6 @@
-# $NetBSD: Makefile,v 1.618 2019/12/13 07:44:02 bsiegert Exp $
+# $NetBSD: Makefile,v 1.619 2019/12/14 18:04:15 rillig Exp $
-PKGNAME= pkglint-19.3.17
-PKGREVISION= 1
+PKGNAME= pkglint-19.3.18
CATEGORIES= pkgtools
DISTNAME= tools
MASTER_SITES= ${MASTER_SITE_GITHUB:=golang/}
diff -r b3caa5ccfe86 -r 5ad4ef5ef7ff pkgtools/pkglint/files/mkcondchecker_test.go
--- a/pkgtools/pkglint/files/mkcondchecker_test.go Sat Dec 14 18:03:10 2019 +0000
+++ b/pkgtools/pkglint/files/mkcondchecker_test.go Sat Dec 14 18:04:15 2019 +0000
@@ -73,8 +73,7 @@
test(".if ${MACHINE_PLATFORM:MUnknownOS-*-*} || ${MACHINE_ARCH:Mx86}",
"WARN: filename.mk:4: "+
"The pattern \"UnknownOS\" cannot match any of "+
- "{ AIX BSDOS Bitrig Cygwin Darwin DragonFly FreeBSD FreeMiNT GNUkFreeBSD HPUX Haiku "+
- "IRIX Interix Linux Minix MirBSD NetBSD OSF1 OpenBSD QNX SCO_SV SunOS UnixWare "+
+ "{ Cygwin DragonFly FreeBSD Linux NetBSD SunOS "+
"} for the operating system part of MACHINE_PLATFORM.",
"WARN: filename.mk:4: "+
"The pattern \"x86\" cannot match any of "+
diff -r b3caa5ccfe86 -r 5ad4ef5ef7ff pkgtools/pkglint/files/substcontext.go
--- a/pkgtools/pkglint/files/substcontext.go Sat Dec 14 18:03:10 2019 +0000
+++ b/pkgtools/pkglint/files/substcontext.go Sat Dec 14 18:04:15 2019 +0000
@@ -3,30 +3,25 @@
import "netbsd.org/pkglint/textproc"
// SubstContext records the state of a block of variable assignments
-// that make up a SUBST class (see `mk/subst.mk`).
+// that make up a SUBST class.
+//
+// See mk/subst.mk.
type SubstContext struct {
- queuedIds []string
- id string
- doneIds map[string]bool
+ active *substBlock
- foreignAllowed map[string]struct{}
- foreign []*MkLine
-
- conds []*substCond
+ scopes []*substScope
once Once
}
func NewSubstContext() *SubstContext {
- ctx := SubstContext{}
- ctx.reset()
- return &ctx
+ return &SubstContext{scopes: []*substScope{newSubstScope()}}
}
func (ctx *SubstContext) Process(mkline *MkLine) {
switch {
case mkline.IsEmpty():
- ctx.finishClass(mkline)
+ ctx.emptyLine()
case mkline.IsVarassign():
ctx.varassign(mkline)
case mkline.IsDirective():
@@ -35,8 +30,20 @@
}
func (ctx *SubstContext) Finish(diag Diagnoser) {
- ctx.finishClass(diag)
- ctx.finishFile(diag)
+ // Prevent panics on unbalanced conditionals.
+ for len(ctx.scopes) > 1 {
+ ctx.leave(diag)
+ }
+
+ for _, scope := range ctx.scopes {
+ scope.finish(diag)
+ }
+}
+
+func (ctx *SubstContext) emptyLine() {
+ for _, scope := range ctx.scopes {
+ scope.emptyLine()
+ }
}
func (ctx *SubstContext) varassign(mkline *MkLine) {
@@ -47,8 +54,8 @@
}
if ctx.isForeign(mkline.Varcanon()) {
- if ctx.isActive() {
- ctx.rememberForeign(mkline)
+ if ctx.isActive() && !ctx.block().seenEmpty {
+ ctx.block().rememberForeign(mkline)
}
return
}
@@ -59,115 +66,341 @@
}
}
- if hasPrefix(mkline.Varname(), "SUBST_") && !ctx.isActiveId(mkline.Varparam()) {
+ if hasPrefix(mkline.Varname(), "SUBST_") && mkline.Varparam() != ctx.activeId() {
if !ctx.varassignDifferentClass(mkline) {
return
}
}
+ block := ctx.block()
switch varcanon {
case "SUBST_STAGE.*":
- ctx.varassignStage(mkline)
+ block.varassignStage(mkline)
case "SUBST_MESSAGE.*":
- ctx.varassignMessages(mkline)
+ block.varassignMessages(mkline)
case "SUBST_FILES.*":
- ctx.varassignFiles(mkline)
+ block.varassignFiles(mkline)
case "SUBST_SED.*":
- ctx.varassignSed(mkline)
+ block.varassignSed(mkline)
case "SUBST_VARS.*":
- ctx.varassignVars(mkline)
+ block.varassignVars(mkline)
case "SUBST_FILTER_CMD.*":
- ctx.varassignFilterCmd(mkline)
+ block.varassignFilterCmd(mkline)
}
}
func (ctx *SubstContext) varassignClasses(mkline *MkLine) {
- classes := mkline.ValueFields(mkline.WithoutMakeVariables(mkline.Value()))
- if len(classes) == 0 {
+ ids := mkline.ValueFields(mkline.WithoutMakeVariables(mkline.Value()))
+ if len(ids) == 0 {
return
}
- if len(classes) > 1 {
+ if len(ids) > 1 {
mkline.Notef("Please add only one class at a time to SUBST_CLASSES.")
mkline.Explain(
"This way, each substitution class forms a block in the package Makefile,",
"and to delete this block, it is not necessary to look anywhere else.")
}
- for _, class := range classes {
- ctx.queue(class)
- }
- id := classes[0]
- if ctx.isActive() && !ctx.isActiveId(id) {
- id := ctx.activeId() // since ctx.condEndif may reset it
+ ctx.prepareSubstClasses(mkline)
+ ctx.deactivate(mkline)
- for ctx.isConditional() {
- // This will be confusing for the outer SUBST block,
- // but since that block is assumed to be finished,
- // this doesn't matter.
- ctx.condEndif(mkline)
- }
-
- complete := ctx.isComplete() // since ctx.finishClass will reset it
- ctx.finishClass(mkline)
- if !complete {
- mkline.Warnf("Subst block %q should be finished before adding the next class to SUBST_CLASSES.", id)
+ for _, id := range ids {
+ if ctx.lookup(id) == nil {
+ ctx.scopes[len(ctx.scopes)-1].define(id)
+ } else if mkline.Varparam() == "" {
+ mkline.Errorf("Duplicate SUBST class %q.", id)
}
}
+}
- ctx.setActiveId(id)
-
- return
+func (ctx *SubstContext) prepareSubstClasses(mkline *MkLine) {
+ for _, scope := range ctx.scopes {
+ scope.prepareSubstClasses(mkline)
+ }
}
// varassignOutsideBlock handles variable assignments of SUBST variables that
// appear without a directly corresponding SUBST block.
func (ctx *SubstContext) varassignOutsideBlock(mkline *MkLine) (continueWithNewId bool) {
- varparam := mkline.Varparam()
+ id := mkline.Varparam()
- if ctx.isListCanon(mkline.Varcanon()) && ctx.isDone(varparam) {
+ if id != "" && ctx.isListCanon(mkline.Varcanon()) && ctx.isDone(id) {
if mkline.Op() != opAssignAppend {
mkline.Warnf("Late additions to a SUBST variable should use the += operator.")
}
return
}
- if containsWord(mkline.Rationale(), varparam) {
- return
- }
- if ctx.start(varparam) {
- return true
- }
-
- if ctx.once.FirstTime(varparam) {
- mkline.Warnf("Before defining %s, the SUBST class "+
- "should be declared using \"SUBST_CLASSES+= %s\".",
- mkline.Varname(), varparam)
- }
- return
+ return ctx.activate(mkline, ctx.lookup(id) == nil)
}
func (ctx *SubstContext) varassignDifferentClass(mkline *MkLine) (ok bool) {
varname := mkline.Varname()
- varparam := mkline.Varparam()
+ unknown := ctx.lookup(mkline.Varparam()) == nil
+ if unknown && ctx.isActive() && !ctx.block().isComplete() {
+ mkline.Warnf("Variable %q does not match SUBST class %q.",
+ varname, ctx.activeId())
+ if !ctx.block().seenEmpty {
+ return false
+ }
+ }
+
+ return ctx.activate(mkline, unknown)
+}
+
+func (ctx *SubstContext) directive(mkline *MkLine) {
+ dir := mkline.Directive()
+ switch dir {
+ case "if":
+ ctx.enter()
+ case "elif":
+ ctx.nextBranch(mkline, false)
+ case "else":
+ ctx.nextBranch(mkline, true)
+ case "endif":
+ ctx.leave(mkline)
+ }
+}
- if !ctx.isComplete() {
- mkline.Warnf("Variable %q does not match SUBST class %q.", varname, ctx.activeId())
+func (ctx *SubstContext) enter() {
+ for _, scope := range ctx.scopes {
+ scope.enter()
+ }
+ ctx.scopes = append(ctx.scopes, newSubstScope())
+}
+
+func (ctx *SubstContext) nextBranch(diag Diagnoser, isElse bool) {
+ if ctx.isActive() && !ctx.block().isConditional() {
+ ctx.deactivate(diag)
+ }
+
+ for _, scope := range ctx.scopes {
+ scope.nextBranch(diag, isElse)
+ }
+}
+
+func (ctx *SubstContext) leave(diag Diagnoser) {
+ ctx.deactivate(diag)
+
+ for _, scope := range ctx.scopes {
+ scope.leave(diag)
+ }
+
+ if len(ctx.scopes) > 1 {
+ ctx.scopes = ctx.scopes[:len(ctx.scopes)-1]
+ }
+}
+
+func (ctx *SubstContext) activate(mkline *MkLine, deactivate bool) bool {
+ id := mkline.Varparam()
+ if id == "" {
+ mkline.Errorf("Invalid SUBST class %q in variable name.", id)
return false
}
- ctx.finishClass(mkline)
+ if deactivate {
+ ctx.deactivate(mkline)
+ }
+
+ if block := ctx.lookup(id); block != nil {
+ ctx.active = block
+ return true
+ }
+
+ if ctx.once.FirstTime(id) && !containsWord(mkline.Rationale(), id) {
+ mkline.Warnf("Before defining %s, the SUBST class "+
+ "should be declared using \"SUBST_CLASSES+= %s\".",
+ mkline.Varname(), id)
Home |
Main Index |
Thread Index |
Old Index