pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/pkglint



Module Name:    pkgsrc
Committed By:   rillig
Date:           Mon Jan  1 21:55:36 UTC 2018

Modified Files:
        pkgsrc/pkgtools/pkglint: Makefile
        pkgsrc/pkgtools/pkglint/files: line.go plist.go plist_test.go

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.519 -r1.520 pkgsrc/pkgtools/pkglint/Makefile
cvs rdiff -u -r1.17 -r1.18 pkgsrc/pkgtools/pkglint/files/line.go
cvs rdiff -u -r1.15 -r1.16 pkgsrc/pkgtools/pkglint/files/plist.go
cvs rdiff -u -r1.14 -r1.15 pkgsrc/pkgtools/pkglint/files/plist_test.go

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/pkglint/Makefile
diff -u pkgsrc/pkgtools/pkglint/Makefile:1.519 pkgsrc/pkgtools/pkglint/Makefile:1.520
--- pkgsrc/pkgtools/pkglint/Makefile:1.519      Mon Jan  1 18:04:15 2018
+++ pkgsrc/pkgtools/pkglint/Makefile    Mon Jan  1 21:55:36 2018
@@ -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
 

Index: pkgsrc/pkgtools/pkglint/files/line.go
diff -u pkgsrc/pkgtools/pkglint/files/line.go:1.17 pkgsrc/pkgtools/pkglint/files/line.go:1.18
--- pkgsrc/pkgtools/pkglint/files/line.go:1.17  Mon Jan  1 18:04:15 2018
+++ pkgsrc/pkgtools/pkglint/files/line.go       Mon Jan  1 21:55:36 2018
@@ -65,6 +65,7 @@ func NewLineWhole(fname string) Line {
        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...)

Index: pkgsrc/pkgtools/pkglint/files/plist.go
diff -u pkgsrc/pkgtools/pkglint/files/plist.go:1.15 pkgsrc/pkgtools/pkglint/files/plist.go:1.16
--- pkgsrc/pkgtools/pkglint/files/plist.go:1.15 Mon Jan  1 18:04:15 2018
+++ pkgsrc/pkgtools/pkglint/files/plist.go      Mon Jan  1 21:55:36 2018
@@ -83,7 +83,7 @@ func (ck *PlistChecker) NewLines(lines [
        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 @@ func (ck *PlistChecker) checkline(pline 
                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 @@ func (ck *PlistChecker) checkpath(pline 
                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 @@ func (pline *PlistLine) warnImakeMannews
 }
 
 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() {
+       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
+       }
+
+       if len(s.middle) == 0 {
+               return
+       }
+       firstLine := s.middle[0].line
        sort.Stable(s)
 
-       if !s.swapped {
+       if !s.changed {
                return
        }
 
-       firstLine := s.first.line
        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)
+       }
+       for _, pline := range s.footer {
                lines = append(lines, pline.line)
-               lines = append(lines, s.after[pline]...)
        }
+       lines[0].Changed = true // Without this, autofix doesn't know that anything changed
        s.autofixed = SaveAutofixChanges(lines)
 }

Index: pkgsrc/pkgtools/pkglint/files/plist_test.go
diff -u pkgsrc/pkgtools/pkglint/files/plist_test.go:1.14 pkgsrc/pkgtools/pkglint/files/plist_test.go:1.15
--- pkgsrc/pkgtools/pkglint/files/plist_test.go:1.14    Sun Oct  8 22:31:13 2017
+++ pkgsrc/pkgtools/pkglint/files/plist_test.go Mon Jan  1 21:55:36 2018
@@ -118,39 +118,48 @@ func (s *Suite) Test_PlistLineSorter_Sor
                "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 @@ func (s *Suite) Test_PlistChecker__autof
                "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 @@ func (s *Suite) Test_PlistChecker__autof
 
        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 @@ func (s *Suite) Test_PlistChecker__autof
                "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