pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint Updated pkglint to 5.4.23.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/51da606eb5c7
branches:  trunk
changeset: 373428:51da606eb5c7
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Mon Jan 01 21:55:36 2018 +0000

description:
Updated pkglint to 5.4.23.

Changes since 5.4.22:
Only autofix PLIST sorting in simple cases. Before this version, pkglint
sorted the PLIST even when it contained unresolved variable references like
${IMAKE_MAN_DIR}, which resulted in strange and unintuitive orders. These
complicated files are left for human inspection.

diffstat:

 pkgtools/pkglint/Makefile            |   4 +-
 pkgtools/pkglint/files/line.go       |   1 +
 pkgtools/pkglint/files/plist.go      |  91 +++++++++++++++++++++++------------
 pkgtools/pkglint/files/plist_test.go |  51 +++++++++++--------
 4 files changed, 93 insertions(+), 54 deletions(-)

diffs (270 lines):

diff -r 1aa9abaec763 -r 51da606eb5c7 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Mon Jan 01 21:29:27 2018 +0000
+++ b/pkgtools/pkglint/Makefile Mon Jan 01 21:55:36 2018 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.519 2018/01/01 18:04:15 rillig Exp $
+# $NetBSD: Makefile,v 1.520 2018/01/01 21:55:36 rillig Exp $
 
-PKGNAME=       pkglint-5.4.22
+PKGNAME=       pkglint-5.4.23
 DISTFILES=     # none
 CATEGORIES=    pkgtools
 
diff -r 1aa9abaec763 -r 51da606eb5c7 pkgtools/pkglint/files/line.go
--- a/pkgtools/pkglint/files/line.go    Mon Jan 01 21:29:27 2018 +0000
+++ b/pkgtools/pkglint/files/line.go    Mon Jan 01 21:55:36 2018 +0000
@@ -65,6 +65,7 @@
        return NewLine(fname, 0, "", nil)
 }
 
+// modifiedLines returns the text after the fixes, including line breaks and newly inserted lines
 func (line *LineImpl) modifiedLines() []string {
        var result []string
        result = append(result, line.before...)
diff -r 1aa9abaec763 -r 51da606eb5c7 pkgtools/pkglint/files/plist.go
--- a/pkgtools/pkglint/files/plist.go   Mon Jan 01 21:29:27 2018 +0000
+++ b/pkgtools/pkglint/files/plist.go   Mon Jan 01 21:55:36 2018 +0000
@@ -83,7 +83,7 @@
        for i, line := range lines {
                conditional, text := "", line.Text
                if hasPrefix(text, "${PLIST.") {
-                       if m, cond, rest := match2(text, `^\$\{(PLIST\.[\w-.]+)\}(.*)`); m {
+                       if m, cond, rest := match2(text, `^(?:\$\{(PLIST\.[\w-.]+)\})+(.*)`); m {
                                conditional, text = cond, rest
                        }
                }
@@ -127,6 +127,10 @@
                pline.CheckDirective(cmd, arg)
        } else if hasPrefix(text, "$") {
                ck.checkpath(pline)
+       } else if text == "" {
+               if !pline.line.AutofixDelete() {
+                       pline.line.Warnf("PLISTs should not contain empty lines.")
+               }
        } else {
                pline.line.Warnf("Unknown line type.")
        }
@@ -143,7 +147,9 @@
                pline.warnImakeMannewsuffix()
        }
        if hasPrefix(text, "${PKGMANDIR}/") {
-               if !line.AutofixReplace("${PKGMANDIR}/", "man/") {
+               if line.AutofixReplace("${PKGMANDIR}/", "man/") {
+                       pline.text = strings.Replace(pline.text, "${PKGMANDIR}/", "man/", 1)
+               } else {
                        line.Notef("PLIST files should mention \"man/\" instead of \"${PKGMANDIR}\".")
                        Explain(
                                "The pkgsrc infrastructure takes care of replacing the correct value",
@@ -479,55 +485,78 @@
 }
 
 type plistLineSorter struct {
-       first     *PlistLine
-       plines    []*PlistLine
-       lines     []Line
-       after     map[*PlistLine][]Line
-       swapped   bool
-       autofixed bool
+       header     []*PlistLine // Does not take part in sorting
+       middle     []*PlistLine // Only this part is sorted
+       footer     []*PlistLine // Does not take part in sorting, typically contains @exec or @pkgdir
+       unsortable Line         // Some lines so difficult to sort that only humans can do that
+       changed    bool         // Whether the sorting actually changed something
+       autofixed  bool         // Whether the newly sorted file has been written to disk
 }
 
 func NewPlistLineSorter(plines []*PlistLine) *plistLineSorter {
-       s := &plistLineSorter{first: plines[0], after: make(map[*PlistLine][]Line)}
-       prev := plines[0]
-       for _, pline := range plines[1:] {
-               if hasPrefix(pline.text, "@") || contains(pline.text, "$") {
-                       s.after[prev] = append(s.after[prev], pline.line)
-               } else {
-                       s.plines = append(s.plines, pline)
-                       s.lines = append(s.lines, pline.line)
-                       prev = pline
+       headerEnd := 0
+       for headerEnd < len(plines) && hasPrefix(plines[headerEnd].text, "@comment") {
+               headerEnd++
+       }
+
+       footerStart := len(plines)
+       for footerStart > headerEnd && hasPrefix(plines[footerStart-1].text, "@") {
+               footerStart--
+       }
+
+       header := plines[0:headerEnd]
+       middle := plines[headerEnd:footerStart]
+       footer := plines[footerStart:]
+       var unsortable Line
+
+       for _, pline := range middle {
+               if unsortable == nil && (hasPrefix(pline.text, "@") || contains(pline.text, "$")) {
+                       unsortable = pline.line
                }
        }
-       return s
+       return &plistLineSorter{header, middle, footer, unsortable, false, false}
 }
 
 func (s *plistLineSorter) Len() int {
-       return len(s.plines)
+       return len(s.middle)
 }
 func (s *plistLineSorter) Less(i, j int) bool {
-       return s.plines[i].text < s.plines[j].text
+       return s.middle[i].text < s.middle[j].text
 }
 func (s *plistLineSorter) Swap(i, j int) {
-       s.swapped = true
-       s.lines[i], s.lines[j] = s.lines[j], s.lines[i]
-       s.plines[i], s.plines[j] = s.plines[j], s.plines[i]
+       s.changed = true
+       s.middle[i], s.middle[j] = s.middle[j], s.middle[i]
 }
 
 func (s *plistLineSorter) Sort() {
-       sort.Stable(s)
-
-       if !s.swapped {
+       if line := s.unsortable; line != nil {
+               if G.opts.PrintAutofix || G.opts.Autofix {
+                       line.Notef("This line prevents pkglint from sorting the PLIST automatically.")
+               }
                return
        }
 
-       firstLine := s.first.line
+       if len(s.middle) == 0 {
+               return
+       }
+       firstLine := s.middle[0].line
+       sort.Stable(s)
+
+       if !s.changed {
+               return
+       }
+
        firstLine.AutofixMark("Sorting the whole file.")
-       lines := []Line{firstLine}
-       lines = append(lines, s.after[s.first]...)
-       for _, pline := range s.plines {
+       var lines []Line
+       for _, pline := range s.header {
+               lines = append(lines, pline.line)
+       }
+       for _, pline := range s.middle {
                lines = append(lines, pline.line)
-               lines = append(lines, s.after[pline]...)
        }
+       for _, pline := range s.footer {
+               lines = append(lines, pline.line)
+       }
+       lines[0].Changed = true // Without this, autofix doesn't know that anything changed
        s.autofixed = SaveAutofixChanges(lines)
 }
diff -r 1aa9abaec763 -r 51da606eb5c7 pkgtools/pkglint/files/plist_test.go
--- a/pkgtools/pkglint/files/plist_test.go      Mon Jan 01 21:29:27 2018 +0000
+++ b/pkgtools/pkglint/files/plist_test.go      Mon Jan 01 21:55:36 2018 +0000
@@ -118,39 +118,48 @@
                "lib/${UNKNOWN}.la",
                "C",
                "ddd",
-               "@exec echo \"after ddd\"",
+               "@exec echo \"after ddd\"", // Makes the PLIST unsortable
                "sbin/program",
                "${PLIST.one}bin/program",
-               "${PKGMANDIR}/man1/program.1",
+               "man/man1/program.1",
                "${PLIST.two}bin/program2",
                "lib/before.la",
+               "${PLIST.linux}${PLIST.x86_64}lib/lib-linux-x86_64.so", // Double conditional, see graphics/graphviz
                "lib/after.la",
                "@exec echo \"after lib/after.la\"")
        ck := &PlistChecker{nil, nil, "", false}
        plines := ck.NewLines(lines)
 
-       NewPlistLineSorter(plines).Sort()
+       sorter1 := NewPlistLineSorter(plines)
+       c.Check(sorter1.unsortable, equals, lines[5])
+
+       cleanedLines := append(append(lines[0:5], lines[6:8]...), lines[9:]...) // Remove ${UNKNOWN} and @exec
+
+       sorter2 := NewPlistLineSorter((&PlistChecker{nil, nil, "", false}).NewLines(cleanedLines))
+
+       c.Check(sorter2.unsortable, check.IsNil)
+
+       sorter2.Sort()
 
        s.CheckOutputLines(
-               "AUTOFIX: ~/PLIST:1: Sorting the whole file.",
+               "AUTOFIX: ~/PLIST:3: Sorting the whole file.",
                "AUTOFIX: ~/PLIST: Has been auto-fixed. Please re-run pkglint.")
        c.Check(s.LoadTmpFile("PLIST"), equals, ""+
                "@comment $"+"NetBSD$\n"+
-               "@comment Do not remove\n"+
+               "@comment Do not remove\n"+ // The header ends here
                "A\n"+
                "C\n"+
                "CCC\n"+
-               "lib/${UNKNOWN}.la\n"+ // Stays below the previous line
                "b\n"+
                "${PLIST.one}bin/program\n"+ // Conditionals are ignored while sorting
-               "${PKGMANDIR}/man1/program.1\n"+ // Stays below the previous line
                "${PLIST.two}bin/program2\n"+
                "ddd\n"+
-               "@exec echo \"after ddd\"\n"+ // Stays below the previous line
                "lib/after.la\n"+
-               "@exec echo \"after lib/after.la\"\n"+
                "lib/before.la\n"+
-               "sbin/program\n")
+               "${PLIST.linux}${PLIST.x86_64}lib/lib-linux-x86_64.so\n"+
+               "man/man1/program.1\n"+
+               "sbin/program\n"+
+               "@exec echo \"after lib/after.la\"\n") // The footer starts here
 }
 
 func (s *Suite) Test_PlistChecker_checkpathShare_Desktop(c *check.C) {
@@ -217,11 +226,11 @@
                "lib/libvirt/lock-driver/lockd.la",
                "${PKGMANDIR}/man1/sh.1",
                "share/augeas/lenses/virtlockd.aug",
-               "share/doc/${PKGNAME}/html/32favicon.png",
-               "share/doc/${PKGNAME}/html/404.html",
-               "share/doc/${PKGNAME}/html/acl.html",
-               "share/doc/${PKGNAME}/html/aclpolkit.html",
-               "share/doc/${PKGNAME}/html/windows.html",
+               "share/doc/pkgname-1.0/html/32favicon.png",
+               "share/doc/pkgname-1.0/html/404.html",
+               "share/doc/pkgname-1.0/html/acl.html",
+               "share/doc/pkgname-1.0/html/aclpolkit.html",
+               "share/doc/pkgname-1.0/html/windows.html",
                "share/examples/libvirt/libvirt.conf",
                "share/locale/zh_CN/LC_MESSAGES/libvirt.mo",
                "share/locale/zh_TW/LC_MESSAGES/libvirt.mo",
@@ -245,7 +254,7 @@
 
        s.CheckOutputLines(
                "AUTOFIX: ~/PLIST:6: Replacing \"${PKGMANDIR}/\" with \"man/\".",
-               "AUTOFIX: ~/PLIST:1: Sorting the whole file.",
+               "AUTOFIX: ~/PLIST:2: Sorting the whole file.",
                "AUTOFIX: ~/PLIST: Has been auto-fixed. Please re-run pkglint.")
        c.Check(len(lines), equals, len(fixedLines))
        c.Check(s.LoadTmpFile("PLIST"), equals, ""+
@@ -256,11 +265,11 @@
                "lib/libvirt/lock-driver/lockd.la\n"+
                "man/man1/sh.1\n"+
                "share/augeas/lenses/virtlockd.aug\n"+
-               "share/doc/${PKGNAME}/html/32favicon.png\n"+
-               "share/doc/${PKGNAME}/html/404.html\n"+
-               "share/doc/${PKGNAME}/html/acl.html\n"+
-               "share/doc/${PKGNAME}/html/aclpolkit.html\n"+
-               "share/doc/${PKGNAME}/html/windows.html\n"+
+               "share/doc/pkgname-1.0/html/32favicon.png\n"+
+               "share/doc/pkgname-1.0/html/404.html\n"+
+               "share/doc/pkgname-1.0/html/acl.html\n"+
+               "share/doc/pkgname-1.0/html/aclpolkit.html\n"+
+               "share/doc/pkgname-1.0/html/windows.html\n"+
                "share/examples/libvirt/libvirt.conf\n"+
                "share/locale/zh_CN/LC_MESSAGES/libvirt.mo\n"+
                "share/locale/zh_TW/LC_MESSAGES/libvirt.mo\n"+



Home | Main Index | Thread Index | Old Index