summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2018-05-19 12:58:24 +0000
committerrillig <rillig@pkgsrc.org>2018-05-19 12:58:24 +0000
commit10e31a77f5bedd47a23b18f14b89784be2bd2a72 (patch)
tree8060e5c513bcdb506c0997a82514d210c729fd5d /pkgtools
parent7cdb46ad2faac9332036fadbd8ef15ca6bebfd7e (diff)
downloadpkgsrc-10e31a77f5bedd47a23b18f14b89784be2bd2a72.tar.gz
pkgtools/pkglint: update to 5.5.12
Changes since 5.5.11: * Improve support for TEST_DEPENDS and USE_TOOLS+= *:test (thanks @leot) * Add checks for ALTERNATIVES files
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkglint/Makefile4
-rw-r--r--pkgtools/pkglint/files/alternatives.go42
-rw-r--r--pkgtools/pkglint/files/alternatives_test.go27
-rw-r--r--pkgtools/pkglint/files/distinfo.go7
-rw-r--r--pkgtools/pkglint/files/distinfo_test.go2
-rw-r--r--pkgtools/pkglint/files/licenses.go9
-rw-r--r--pkgtools/pkglint/files/line.go4
-rw-r--r--pkgtools/pkglint/files/package.go11
-rw-r--r--pkgtools/pkglint/files/pkglint.go3
-rw-r--r--pkgtools/pkglint/files/pkgsrc.go7
-rw-r--r--pkgtools/pkglint/files/plist.go4
-rw-r--r--pkgtools/pkglint/files/toplevel.go4
-rw-r--r--pkgtools/pkglint/files/vartypecheck.go4
-rw-r--r--pkgtools/pkglint/files/vartypecheck_test.go4
14 files changed, 108 insertions, 24 deletions
diff --git a/pkgtools/pkglint/Makefile b/pkgtools/pkglint/Makefile
index 190686db191..e09c8d62005 100644
--- a/pkgtools/pkglint/Makefile
+++ b/pkgtools/pkglint/Makefile
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.538 2018/05/14 20:25:48 rillig Exp $
+# $NetBSD: Makefile,v 1.539 2018/05/19 12:58:24 rillig Exp $
-PKGNAME= pkglint-5.5.11
+PKGNAME= pkglint-5.5.12
DISTFILES= # none
CATEGORIES= pkgtools
diff --git a/pkgtools/pkglint/files/alternatives.go b/pkgtools/pkglint/files/alternatives.go
new file mode 100644
index 00000000000..cb803b9252c
--- /dev/null
+++ b/pkgtools/pkglint/files/alternatives.go
@@ -0,0 +1,42 @@
+package main
+
+import (
+ "netbsd.org/pkglint/regex"
+ "strings"
+)
+
+func CheckfileAlternatives(filename string, plistFiles map[string]bool) {
+ lines, err := readLines(filename, false)
+ if err != nil {
+ return
+ }
+
+ for _, line := range lines {
+ if m, wrapper, space, implementation := match3(line.Text, `^(\S+)([ \t]+)(\S+)`); m {
+ if plistFiles[wrapper] {
+ line.Errorf("Alternative wrapper %q must not appear in the PLIST.", wrapper)
+ }
+
+ relImplementation := strings.Replace(implementation, "@PREFIX@/", "", 1)
+ plistName := regex.Compile(`@(\w+)@`).ReplaceAllString(relImplementation, "${$1}")
+ if !plistFiles[plistName] && !G.Pkg.vars.Defined("ALTERNATIVES_SRC") {
+ if plistName != implementation {
+ line.Errorf("Alternative implementation %q must appear in the PLIST as %q.", implementation, plistName)
+ } else {
+ line.Errorf("Alternative implementation %q must appear in the PLIST.", implementation)
+ }
+ }
+
+ fix := line.Autofix()
+ fix.Notef("@PREFIX@/ can be omitted from the file name.")
+ fix.Explain(
+ "The alternative implementation is always interpreted relative to ${PREFIX}.")
+ fix.ReplaceAfter(space, "@PREFIX@/", "")
+ fix.Apply()
+ } else {
+ line.Errorf("Invalid ALTERNATIVES line %q.", line.Text)
+ Explain(
+ "Run \"" + confMake + " help topic=alternatives\" for more information.")
+ }
+ }
+}
diff --git a/pkgtools/pkglint/files/alternatives_test.go b/pkgtools/pkglint/files/alternatives_test.go
new file mode 100644
index 00000000000..6a678a8f808
--- /dev/null
+++ b/pkgtools/pkglint/files/alternatives_test.go
@@ -0,0 +1,27 @@
+package main
+
+import "gopkg.in/check.v1"
+
+func (s *Suite) Test_Alternatives_PLIST(c *check.C) {
+ t := s.Init(c)
+
+ t.SetupFileLines("ALTERNATIVES",
+ "sbin/sendmail @PREFIX@/sbin/sendmail.postfix@POSTFIXVER@",
+ "sbin/sendmail @PREFIX@/sbin/sendmail.exim@EXIMVER@",
+ "bin/echo bin/gnu-echo",
+ "bin/editor bin/vim -e")
+
+ G.Pkg = NewPackage("")
+ G.Pkg.PlistFiles["bin/echo"] = true
+ G.Pkg.PlistFiles["bin/vim"] = true
+ G.Pkg.PlistFiles["sbin/sendmail.exim${EXIMVER}"] = true
+
+ CheckfileAlternatives(t.TempFilename("ALTERNATIVES"), G.Pkg.PlistFiles)
+
+ t.CheckOutputLines(
+ "ERROR: ~/ALTERNATIVES:1: Alternative implementation \"@PREFIX@/sbin/sendmail.postfix@POSTFIXVER@\" must appear in the PLIST as \"sbin/sendmail.postfix${POSTFIXVER}\".",
+ "NOTE: ~/ALTERNATIVES:1: @PREFIX@/ can be omitted from the file name.",
+ "NOTE: ~/ALTERNATIVES:2: @PREFIX@/ can be omitted from the file name.",
+ "ERROR: ~/ALTERNATIVES:3: Alternative wrapper \"bin/echo\" must not appear in the PLIST.",
+ "ERROR: ~/ALTERNATIVES:3: Alternative implementation \"bin/gnu-echo\" must appear in the PLIST.")
+}
diff --git a/pkgtools/pkglint/files/distinfo.go b/pkgtools/pkglint/files/distinfo.go
index c293516b74f..41e17e2a98e 100644
--- a/pkgtools/pkglint/files/distinfo.go
+++ b/pkgtools/pkglint/files/distinfo.go
@@ -157,16 +157,17 @@ func (ck *distinfoLinesChecker) checkUnrecordedPatches() {
// Inter-package check for differing distfile checksums.
func (ck *distinfoLinesChecker) checkGlobalMismatch(line Line, fname, alg, hash string) {
- if G.Hash != nil && !hasPrefix(fname, "patch-") { // Intentionally checking the filename instead of ck.isPatch
+ hashes := G.Pkgsrc.Hashes
+ if hashes != nil && !hasPrefix(fname, "patch-") { // Intentionally checking the filename instead of ck.isPatch
key := alg + ":" + fname
- otherHash := G.Hash[key]
+ otherHash := hashes[key]
if otherHash != nil {
if otherHash.hash != hash {
line.Errorf("The hash %s for %s is %s, which differs from %s in %s.",
alg, fname, hash, otherHash.hash, otherHash.line.ReferenceFrom(line))
}
} else {
- G.Hash[key] = &Hash{hash, line}
+ hashes[key] = &Hash{hash, line}
}
}
}
diff --git a/pkgtools/pkglint/files/distinfo_test.go b/pkgtools/pkglint/files/distinfo_test.go
index 66d6729f464..7290e469fbf 100644
--- a/pkgtools/pkglint/files/distinfo_test.go
+++ b/pkgtools/pkglint/files/distinfo_test.go
@@ -32,7 +32,7 @@ func (s *Suite) Test_ChecklinesDistinfo_global_hash_mismatch(c *check.C) {
t := s.Init(c)
otherLine := t.NewLine("other/distinfo", 7, "dummy")
- G.Hash = map[string]*Hash{"SHA512:pkgname-1.0.tar.gz": {"Some-512-bit-hash", otherLine}}
+ G.Pkgsrc.Hashes = map[string]*Hash{"SHA512:pkgname-1.0.tar.gz": {"Some-512-bit-hash", otherLine}}
lines := t.NewLines("distinfo",
RcsID,
"",
diff --git a/pkgtools/pkglint/files/licenses.go b/pkgtools/pkglint/files/licenses.go
index 16bb2519a42..8d63fe21b80 100644
--- a/pkgtools/pkglint/files/licenses.go
+++ b/pkgtools/pkglint/files/licenses.go
@@ -6,7 +6,8 @@ import (
)
func checkToplevelUnusedLicenses() {
- if G.UsedLicenses == nil {
+ usedLicenses := G.Pkgsrc.UsedLicenses
+ if usedLicenses == nil {
return
}
@@ -16,7 +17,7 @@ func checkToplevelUnusedLicenses() {
licensename := licensefile.Name()
licensepath := licensedir + "/" + licensename
if fileExists(licensepath) {
- if !G.UsedLicenses[licensename] {
+ if !usedLicenses[licensename] {
NewLineWhole(licensepath).Warnf("This license seems to be unused.")
}
}
@@ -52,8 +53,8 @@ func (lc *LicenseChecker) checkLicenseName(license string) {
}
if licenseFile == "" {
licenseFile = G.Pkgsrc.File("licenses/" + license)
- if G.UsedLicenses != nil {
- G.UsedLicenses[license] = true
+ if G.Pkgsrc.UsedLicenses != nil {
+ G.Pkgsrc.UsedLicenses[license] = true
}
}
diff --git a/pkgtools/pkglint/files/line.go b/pkgtools/pkglint/files/line.go
index 18d0583455f..022274b2775 100644
--- a/pkgtools/pkglint/files/line.go
+++ b/pkgtools/pkglint/files/line.go
@@ -162,7 +162,7 @@ func (line *LineImpl) String() string {
// Usage:
//
-// fix := mkline.Line.Autofix()
+// fix := line.Autofix()
//
// fix.Errorf("Must not be ...")
// fix.Warnf("Should not be ...")
@@ -174,7 +174,7 @@ func (line *LineImpl) String() string {
//
// fix.Replace("from", "to")
// fix.ReplaceAfter("prefix", "from", "to")
-// fix.ReplaceRegex(`\s+`, "space", "from", "to")
+// fix.ReplaceRegex(`\s+`, "space", -1)
// fix.InsertBefore("new line")
// fix.InsertAfter("new line")
// fix.Delete()
diff --git a/pkgtools/pkglint/files/package.go b/pkgtools/pkglint/files/package.go
index cc79fdf70a4..f0a9e7e495e 100644
--- a/pkgtools/pkglint/files/package.go
+++ b/pkgtools/pkglint/files/package.go
@@ -26,6 +26,7 @@ type Package struct {
EffectivePkgnameLine MkLine // The origin of the three effective_* values
SeenBsdPrefsMk bool // Has bsd.prefs.mk already been included?
PlistDirs map[string]bool // Directories mentioned in the PLIST files
+ PlistFiles map[string]bool // Regular files mentioned in the PLIST files
vars Scope
bl3 map[string]Line // buildlink3.mk name => line; contains only buildlink3.mk files that are directly included.
@@ -42,6 +43,7 @@ func NewPackage(pkgpath string) *Package {
pkg := &Package{
Pkgpath: pkgpath,
PlistDirs: make(map[string]bool),
+ PlistFiles: make(map[string]bool),
vars: NewScope(),
bl3: make(map[string]Line),
plistSubstCond: make(map[string]bool),
@@ -216,6 +218,14 @@ func (pkglint *Pkglint) checkdirPackage(pkgpath string) {
}
}
+ if G.opts.CheckAlternatives {
+ for _, fname := range files {
+ if path.Base(fname) == "ALTERNATIVES" {
+ CheckfileAlternatives(fname, pkg.PlistFiles)
+ }
+ }
+ }
+
if !isEmptyDir(G.CurrentDir + "/scripts") {
NewLineWhole(G.CurrentDir + "/scripts").Warnf("This directory and its contents are deprecated! Please call the script(s) explicitly from the corresponding target(s) in the pkg's Makefile.")
}
@@ -934,6 +944,7 @@ func (pkg *Package) loadPlistDirs(plistFilename string) {
for _, line := range lines {
text := line.Text
+ pkg.PlistFiles[text] = true // XXX: ignores PLIST conditionals for now
// Keep in sync with PlistChecker.collectFilesAndDirs
if !contains(text, "$") && !contains(text, "@") {
for dir := path.Dir(text); dir != "."; dir = path.Dir(dir) {
diff --git a/pkgtools/pkglint/files/pkglint.go b/pkgtools/pkglint/files/pkglint.go
index 220a14d5bab..318e4130b94 100644
--- a/pkgtools/pkglint/files/pkglint.go
+++ b/pkgtools/pkglint/files/pkglint.go
@@ -41,9 +41,6 @@ type Pkglint struct {
CvsEntriesDir string // Cached to avoid I/O
CvsEntriesLines []Line
- Hash map[string]*Hash // Maps "alg:fname" => hash (inter-package check).
- UsedLicenses map[string]bool // Maps "license name" => true (inter-package check).
-
errors int
warnings int
explainNext bool
diff --git a/pkgtools/pkglint/files/pkgsrc.go b/pkgtools/pkglint/files/pkgsrc.go
index ea4ed936de1..6960e226646 100644
--- a/pkgtools/pkglint/files/pkgsrc.go
+++ b/pkgtools/pkglint/files/pkgsrc.go
@@ -35,6 +35,9 @@ type Pkgsrc struct {
UserDefinedVars map[string]MkLine // varname => line; used for checking BUILD_DEFS
Deprecated map[string]string //
vartypes map[string]*Vartype // varcanon => type
+
+ Hashes map[string]*Hash // Maps "alg:fname" => hash (inter-package check).
+ UsedLicenses map[string]bool // Maps "license name" => true (inter-package check).
}
func NewPkgsrc(dir string) *Pkgsrc {
@@ -51,7 +54,9 @@ func NewPkgsrc(dir string) *Pkgsrc {
make(map[string]string),
make(map[string]MkLine),
make(map[string]string),
- make(map[string]*Vartype)}
+ make(map[string]*Vartype),
+ nil, // Only initialized when pkglint is run for a whole pkgsrc installation
+ nil}
// Some user-defined variables do not influence the binary
// package at all and therefore do not have to be added to
diff --git a/pkgtools/pkglint/files/plist.go b/pkgtools/pkglint/files/plist.go
index 4e9f681ab3e..f375e8193de 100644
--- a/pkgtools/pkglint/files/plist.go
+++ b/pkgtools/pkglint/files/plist.go
@@ -402,8 +402,8 @@ func (pline *PlistLine) CheckDirective(cmd, arg string) {
line := pline.line
if cmd == "unexec" {
- if m, arg := match1(arg, `^(?:rmdir|\$\{RMDIR\} \%D/)(.*)`); m {
- if !contains(arg, "true") && !contains(arg, "${TRUE}") {
+ if m, dir := match1(arg, `^(?:rmdir|\$\{RMDIR\} \%D/)(.*)`); m {
+ if !contains(dir, "true") && !contains(dir, "${TRUE}") {
pline.line.Warnf("Please remove this line. It is no longer necessary.")
}
}
diff --git a/pkgtools/pkglint/files/toplevel.go b/pkgtools/pkglint/files/toplevel.go
index 9305eadd865..3b0e875d5eb 100644
--- a/pkgtools/pkglint/files/toplevel.go
+++ b/pkgtools/pkglint/files/toplevel.go
@@ -32,8 +32,8 @@ func CheckdirToplevel() {
if G.opts.Recursive {
if G.opts.CheckGlobal {
- G.UsedLicenses = make(map[string]bool)
- G.Hash = make(map[string]*Hash)
+ G.Pkgsrc.UsedLicenses = make(map[string]bool)
+ G.Pkgsrc.Hashes = make(map[string]*Hash)
}
G.Todo = append(append([]string(nil), ctx.subdirs...), G.Todo...)
}
diff --git a/pkgtools/pkglint/files/vartypecheck.go b/pkgtools/pkglint/files/vartypecheck.go
index cb6a0b98d04..a767047c8fa 100644
--- a/pkgtools/pkglint/files/vartypecheck.go
+++ b/pkgtools/pkglint/files/vartypecheck.go
@@ -950,9 +950,9 @@ func (cv *VartypeCheck) Tool() {
cv.Line.Errorf("Unknown tool %q.", toolname)
}
switch tooldep {
- case "", "bootstrap", "build", "pkgsrc", "run":
+ case "", "bootstrap", "build", "pkgsrc", "run", "test":
default:
- cv.Line.Errorf("Unknown tool dependency %q. Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\".", tooldep)
+ cv.Line.Errorf("Unknown tool dependency %q. Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\" or \"test\".", tooldep)
}
} else if cv.Op != opUseMatch {
cv.Line.Errorf("Invalid tool syntax: %q.", cv.Value)
diff --git a/pkgtools/pkglint/files/vartypecheck_test.go b/pkgtools/pkglint/files/vartypecheck_test.go
index 9953659e679..1926c05b6dc 100644
--- a/pkgtools/pkglint/files/vartypecheck_test.go
+++ b/pkgtools/pkglint/files/vartypecheck_test.go
@@ -554,7 +554,7 @@ func (s *Suite) Test_VartypeCheck_Tool(c *check.C) {
t.CheckOutputLines(
"ERROR: fname:2: Unknown tool dependency \"unknown\". " +
- "Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\".")
+ "Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\" or \"test\".")
runVartypeChecks(t, "USE_TOOLS.NetBSD", opAssignAppend, (*VartypeCheck).Tool,
"tool3:run",
@@ -562,7 +562,7 @@ func (s *Suite) Test_VartypeCheck_Tool(c *check.C) {
t.CheckOutputLines(
"ERROR: fname:2: Unknown tool dependency \"unknown\". " +
- "Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\".")
+ "Use one of \"bootstrap\", \"build\", \"pkgsrc\" or \"run\" or \"test\".")
}
func (s *Suite) Test_VartypeCheck_VariableName(c *check.C) {