Source-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 20.1.17
details: https://anonhg.NetBSD.org/pkgsrc/rev/c7564ff9c4ab
branches: trunk
changeset: 434306:c7564ff9c4ab
user: rillig <rillig%pkgsrc.org@localhost>
date: Sun Jun 14 11:35:54 2020 +0000
description:
pkgtools/pkglint: update to 20.1.17
Changes since 20.1.16:
Conditions that contradict each other in the same file are reported as
errors. Inspired by lang/rust/Makefile r1.174.
diffstat:
pkgtools/pkglint/Makefile | 4 +-
pkgtools/pkglint/PLIST | 7 +-
pkgtools/pkglint/files/check_test.go | 1 +
pkgtools/pkglint/files/makepat/pat.go | 208 +++++++++++++++++
pkgtools/pkglint/files/makepat/pat_test.go | 139 +++++++++++
pkgtools/pkglint/files/mkcondchecker.go | 96 +++++++-
pkgtools/pkglint/files/mkcondchecker_test.go | 192 +++++++++++++++
pkgtools/pkglint/files/mkline.go | 36 +-
pkgtools/pkglint/files/mkparser.go | 4 +
pkgtools/pkglint/files/mkparser_test.go | 7 +-
pkgtools/pkglint/files/scope.go | 326 +++++++++++++++++++++++++++
pkgtools/pkglint/files/scope_test.go | 227 ++++++++++++++++++
pkgtools/pkglint/files/util.go | 323 --------------------------
pkgtools/pkglint/files/util_test.go | 224 ------------------
14 files changed, 1224 insertions(+), 570 deletions(-)
diffs (truncated from 1962 to 300 lines):
diff -r 2f7077515f5f -r c7564ff9c4ab pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sun Jun 14 11:27:41 2020 +0000
+++ b/pkgtools/pkglint/Makefile Sun Jun 14 11:35:54 2020 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.655 2020/06/12 19:14:45 rillig Exp $
+# $NetBSD: Makefile,v 1.656 2020/06/14 11:35:54 rillig Exp $
-PKGNAME= pkglint-20.1.16
+PKGNAME= pkglint-20.1.17
CATEGORIES= pkgtools
DISTNAME= tools
MASTER_SITES= ${MASTER_SITE_GITHUB:=golang/}
diff -r 2f7077515f5f -r c7564ff9c4ab pkgtools/pkglint/PLIST
--- a/pkgtools/pkglint/PLIST Sun Jun 14 11:27:41 2020 +0000
+++ b/pkgtools/pkglint/PLIST Sun Jun 14 11:35:54 2020 +0000
@@ -1,10 +1,11 @@
-@comment $NetBSD: PLIST,v 1.26 2020/01/26 17:12:36 rillig Exp $
+@comment $NetBSD: PLIST,v 1.27 2020/06/14 11:35:54 rillig Exp $
bin/pkglint
gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint.a
gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/getopt.a
gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/histogram.a
gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/intqa.a
gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/licenses.a
+gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/makepat.a
gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/pkgver.a
gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/regex.a
gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/textproc.a
@@ -50,6 +51,8 @@
gopkg/src/netbsd.org/pkglint/lineslexer_test.go
gopkg/src/netbsd.org/pkglint/logging.go
gopkg/src/netbsd.org/pkglint/logging_test.go
+gopkg/src/netbsd.org/pkglint/makepat/pat.go
+gopkg/src/netbsd.org/pkglint/makepat/pat_test.go
gopkg/src/netbsd.org/pkglint/mkassignchecker.go
gopkg/src/netbsd.org/pkglint/mkassignchecker_test.go
gopkg/src/netbsd.org/pkglint/mkcondchecker.go
@@ -101,6 +104,8 @@
gopkg/src/netbsd.org/pkglint/redundantscope.go
gopkg/src/netbsd.org/pkglint/redundantscope_test.go
gopkg/src/netbsd.org/pkglint/regex/regex.go
+gopkg/src/netbsd.org/pkglint/scope.go
+gopkg/src/netbsd.org/pkglint/scope_test.go
gopkg/src/netbsd.org/pkglint/shell.go
gopkg/src/netbsd.org/pkglint/shell.y
gopkg/src/netbsd.org/pkglint/shell_test.go
diff -r 2f7077515f5f -r c7564ff9c4ab pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go Sun Jun 14 11:27:41 2020 +0000
+++ b/pkgtools/pkglint/files/check_test.go Sun Jun 14 11:35:54 2020 +0000
@@ -128,6 +128,7 @@
ck.Configure("pkglint.go", "*", "*", -intqa.EMissingTest) // TODO
ck.Configure("pkgsrc.go", "*", "*", -intqa.EMissingTest) // TODO
ck.Configure("redundantscope.go", "*", "*", -intqa.EMissingTest) // TODO
+ ck.Configure("scope.go", "*", "*", -intqa.EMissingTest) // TODO
ck.Configure("shell.go", "*", "*", -intqa.EMissingTest) // TODO
ck.Configure("shtokenizer.go", "*", "*", -intqa.EMissingTest) // TODO
ck.Configure("shtypes.go", "*", "*", -intqa.EMissingTest) // TODO
diff -r 2f7077515f5f -r c7564ff9c4ab pkgtools/pkglint/files/makepat/pat.go
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkglint/files/makepat/pat.go Sun Jun 14 11:35:54 2020 +0000
@@ -0,0 +1,208 @@
+package makepat
+
+import (
+ "errors"
+ "netbsd.org/pkglint/textproc"
+)
+
+// Pattern is a compiled pattern like "*.c" or "NetBSD-??.[^0-9]".
+// It behaves exactly like in bmake,
+// see devel/bmake/files/str.c, function Str_Match.
+type Pattern struct {
+ states []state
+}
+
+type state struct {
+ transitions []transition
+ end bool
+}
+
+type transition struct {
+ min, max byte
+ to StateID
+}
+
+type StateID uint16
+
+// Compile parses a pattern, including the error checking that is missing
+// from bmake.
+func Compile(pattern string) (*Pattern, error) {
+ var a Pattern
+ s := a.AddState(false)
+
+ var deadEnd StateID
+
+ lex := textproc.NewLexer(pattern)
+ for !lex.EOF() {
+
+ if lex.SkipByte('*') {
+ a.AddTransition(s, 0, 255, s)
+ continue
+ }
+
+ if lex.SkipByte('?') {
+ next := a.AddState(false)
+ a.AddTransition(s, 0, 255, next)
+ s = next
+ continue
+ }
+
+ if lex.SkipByte('\\') {
+ if lex.EOF() {
+ return nil, errors.New("unfinished escape sequence")
+ }
+ ch := lex.NextByte()
+ next := a.AddState(false)
+ a.AddTransition(s, ch, ch, next)
+ s = next
+ continue
+ }
+
+ ch := lex.NextByte()
+ if ch != '[' {
+ next := a.AddState(false)
+ a.AddTransition(s, ch, ch, next)
+ s = next
+ continue
+ }
+
+ negate := lex.SkipByte('^')
+ if negate && deadEnd == 0 {
+ deadEnd = a.AddState(false)
+ }
+ next := a.AddState(false)
+ for {
+ if lex.EOF() {
+ return nil, errors.New("unfinished character class")
+ }
+ ch = lex.NextByte()
+ if ch == ']' {
+ break
+ }
+ max := ch
+ if lex.SkipByte('-') {
+ if lex.EOF() {
+ return nil, errors.New("unfinished character range")
+ }
+ max = lex.NextByte()
+ }
+
+ to := next
+ if negate {
+ to = deadEnd
+ }
+ a.AddTransition(s, bmin(ch, max), bmax(ch, max), to)
+ }
+ if negate {
+ a.AddTransition(s, 0, 255, next)
+ }
+ s = next
+ }
+
+ a.states[s].end = true
+ return &a, nil
+}
+
+func (a *Pattern) AddState(end bool) StateID {
+ a.states = append(a.states, state{nil, end})
+ return StateID(len(a.states) - 1)
+}
+
+func (a *Pattern) AddTransition(from StateID, min, max byte, to StateID) {
+ state := &a.states[from]
+ state.transitions = append(state.transitions, transition{min, max, to})
+}
+
+// Match tests whether a pattern matches the given string.
+func (a *Pattern) Match(s string) bool {
+ state := StateID(0)
+ for _, ch := range []byte(s) {
+ for _, tr := range a.states[state].transitions {
+ if tr.min <= ch && ch <= tr.max {
+ state = tr.to
+ goto nextByte
+ }
+ }
+ return false
+ nextByte:
+ }
+ return a.states[state].end
+}
+
+// Intersect computes a pattern that only matches if both given patterns
+// match at the same time.
+func Intersect(a, b *Pattern) *Pattern {
+ var is Pattern
+ for i := 0; i < len(a.states); i++ {
+ for j := 0; j < len(b.states); j++ {
+ is.AddState(a.states[i].end && b.states[j].end)
+ }
+ }
+
+ for i := 0; i < len(a.states); i++ {
+ for j := 0; j < len(b.states); j++ {
+ for _, at := range a.states[i].transitions {
+ for _, bt := range b.states[j].transitions {
+ min := bmax(at.min, bt.min)
+ max := bmin(at.max, bt.max)
+ if min <= max {
+ from := StateID(i*len(b.states) + j)
+ to := at.to*StateID(len(b.states)) + bt.to
+ is.AddTransition(from, min, max, to)
+ }
+ }
+ }
+ }
+ }
+
+ // TODO: optimize: remove transitions that point to a dead end
+
+ return &is
+}
+
+// CanMatch tests whether the pattern can match some string.
+// Most patterns can do that.
+// Typical counterexamples are:
+// [^]
+// Intersect("*.c", "*.h")
+func (a *Pattern) CanMatch() bool {
+ reachable := make([]bool, len(a.states))
+ reachable[0] = true
+
+again:
+ changed := false
+ for i, s := range a.states {
+ if reachable[i] {
+ for _, t := range s.transitions {
+ if !reachable[t.to] {
+ reachable[t.to] = true
+ changed = true
+ }
+ }
+ }
+ }
+ if changed {
+ goto again
+ }
+
+ for i, s := range a.states {
+ if reachable[i] && s.end {
+ return true
+ }
+ }
+ return false
+}
+
+func bmin(a, b byte) byte {
+ if a < b {
+ return a
+ }
+ return b
+}
+
+func bmax(a, b byte) byte {
+ if a > b {
+ return a
+ }
+ return b
+}
diff -r 2f7077515f5f -r c7564ff9c4ab pkgtools/pkglint/files/makepat/pat_test.go
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pkgtools/pkglint/files/makepat/pat_test.go Sun Jun 14 11:35:54 2020 +0000
@@ -0,0 +1,139 @@
+package makepat
+
+import (
+ "testing"
+)
+
+func Test_Automaton_Match(t *testing.T) {
+ tests := []struct {
+ pattern string
+ str string
+ want bool
+ }{
+ {"a-[0-9]*", "", false},
+ {"a-[0-9]*", "a", false},
+ {"a-[0-9]*", "b", false},
+ {"a-[0-9]*", "a-", false},
+ {"a-[0-9]*", "a-0", true},
+ {"a-[0-9]*", "a-13", true},
+ {"a-[0-9]*", "a-3* matches arbitrary text", true},
+ {"a-[0-9]*", "a+", false},
+ {"a-[0-9]*", "a-x", false},
+ {"\\a", "a", true},
+ {"\\a", "\\a", false},
+ {"\\a", "\u0007", false},
+ {"?", "", false},
+ {"?", "x", true},
+ {"?", "?", true},
Home |
Main Index |
Thread Index |
Old Index