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.2.3



details:   https://anonhg.NetBSD.org/pkgsrc/rev/aaec18cbb223
branches:  trunk
changeset: 436026:aaec18cbb223
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Jul 23 18:40:41 2020 +0000

description:
pkgtools/pkglint: update to 20.2.3

Changes since 20.2.2:

Complain about patches that add a hard-coded interpreter.  Even if that
interpreter is /bin/sh, which is available on most platforms, it is still
inappropriate on old Solaris installations.  Other popular paths start
with /usr/pkg or /usr/local, and these are not controlled by pkgsrc either.

diffstat:

 pkgtools/pkglint/Makefile              |   4 +-
 pkgtools/pkglint/files/patches.go      |  29 +++++++++++++++-
 pkgtools/pkglint/files/patches_test.go |  60 ++++++++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+), 4 deletions(-)

diffs (147 lines):

diff -r 6f319d087554 -r aaec18cbb223 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Thu Jul 23 18:39:31 2020 +0000
+++ b/pkgtools/pkglint/Makefile Thu Jul 23 18:40:41 2020 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.663 2020/07/22 19:26:29 rillig Exp $
+# $NetBSD: Makefile,v 1.664 2020/07/23 18:40:41 rillig Exp $
 
-PKGNAME=       pkglint-20.2.2
+PKGNAME=       pkglint-20.2.3
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 6f319d087554 -r aaec18cbb223 pkgtools/pkglint/files/patches.go
--- a/pkgtools/pkglint/files/patches.go Thu Jul 23 18:39:31 2020 +0000
+++ b/pkgtools/pkglint/files/patches.go Thu Jul 23 18:40:41 2020 +0000
@@ -148,20 +148,26 @@
                                // all the patch programs can handle this situation.
                                linesToDel--
                                linesToAdd--
+                               linenoDel++
+                               linenoAdd++
 
                        case hasPrefix(text, " "), hasPrefix(text, "\t"):
                                linesToDel--
                                linesToAdd--
+                               linenoDel++
+                               linenoAdd++
                                ck.checktextCvsID(text)
 
                        case hasPrefix(text, "-"):
                                linesToDel--
+                               linenoDel++
 
                        case hasPrefix(text, "+"):
                                linesToAdd--
                                ck.checktextCvsID(text)
                                ck.checkConfigure(text[1:], isConfigure)
-                               ck.checkAddedLine(text[1:])
+                               ck.checkAddedLine(text[1:], linenoAdd)
+                               linenoAdd++
 
                        case hasPrefix(text, "\\"):
                                // \ No newline at end of file (or a translation of that message)
@@ -248,13 +254,32 @@
                "mk/configure/gnu-configure.mk.")
 }
 
-func (ck *PatchChecker) checkAddedLine(addedText string) {
+func (ck *PatchChecker) checkAddedLine(addedText string, lineno int) {
        dirs := regcomp(`(?:^|[^.@)}])(/usr/pkg|/var|/etc)([^\w-]|$)`)
        for _, m := range dirs.FindAllStringSubmatchIndex(addedText, -1) {
                before := addedText[:m[2]]
                dir := NewPath(addedText[m[2]:m[3]])
                ck.checkAddedAbsPath(before, dir, addedText[m[4]:])
        }
+       if lineno == 1 {
+               if m, interp := match1(addedText, `^#!\s*(/\S+)`); m {
+                       line := ck.llex.PreviousLine()
+                       line.Errorf("Patches must not add a hard-coded interpreter (%s).", interp)
+                       line.Explain(
+                               "If a patch modifies the first line of a script,",
+                               "it should use the established pattern of setting the",
+                               "interpreter to a @PLACEHOLDER@ and later replace this",
+                               "placeholder with the actual path, for example by using",
+                               "REPLACE_INTERPRETER (or its specialized variants",
+                               "REPLACE_BASH, REPLACE_PERL, etc.), or by using the",
+                               "SUBST framework.",
+                               "",
+                               sprintf("For more information, run %q or %q.",
+                                       bmakeHelp("interp"), bmakeHelp("subst")),
+                               seeGuide("The SUBST framework", "fixes.subst"),
+                               "for more information about the @PLACEHOLDER@.")
+               }
+       }
 }
 
 func (ck *PatchChecker) checkAddedAbsPath(before string, dir Path, after string) {
diff -r 6f319d087554 -r aaec18cbb223 pkgtools/pkglint/files/patches_test.go
--- a/pkgtools/pkglint/files/patches_test.go    Thu Jul 23 18:39:31 2020 +0000
+++ b/pkgtools/pkglint/files/patches_test.go    Thu Jul 23 18:40:41 2020 +0000
@@ -778,6 +778,66 @@
                "ERROR: ~/patch-aa:9: This code must not be included in patches.")
 }
 
+func (s *Suite) Test_PatchChecker_checkAddedLine__interpreter(c *check.C) {
+       t := s.Init(c)
+
+       lines := t.NewLines("patch-aa",
+               CvsID,
+               "",
+               "Documentation.",
+               "",
+               "--- a/aa",
+               "+++ b/aa",
+               "@@ -1,1 +1,1 @@",
+               "-old",
+               "+#! /home/my/pkgsrc/pkg/bin/bash")
+
+       CheckLinesPatch(lines, nil)
+
+       t.CheckOutputLines(
+               "ERROR: patch-aa:9: Patches must not add a hard-coded interpreter " +
+                       "(/home/my/pkgsrc/pkg/bin/bash).")
+}
+
+func (s *Suite) Test_PatchChecker_checkAddedLine__interpreter_in_line_2(c *check.C) {
+       t := s.Init(c)
+
+       lines := t.NewLines("patch-aa",
+               CvsID,
+               "",
+               "Documentation.",
+               "",
+               "--- a/aa",
+               "+++ b/aa",
+               "@@ -1,1 +1,2 @@",
+               "-old",
+               "+new",
+               "+#! /home/my/pkgsrc/pkg/bin/bash")
+
+       CheckLinesPatch(lines, nil)
+
+       t.CheckOutputEmpty()
+}
+
+func (s *Suite) Test_PatchChecker_checkAddedLine__interpreter_placeholder(c *check.C) {
+       t := s.Init(c)
+
+       lines := t.NewLines("patch-aa",
+               CvsID,
+               "",
+               "Documentation.",
+               "",
+               "--- a/aa",
+               "+++ b/aa",
+               "@@ -1,1 +1,1 @@",
+               "-old",
+               "+#! @PREFIX@/bin/bash")
+
+       CheckLinesPatch(lines, nil)
+
+       t.CheckOutputEmpty()
+}
+
 func (s *Suite) Test_PatchChecker_checkAddedAbsPath(c *check.C) {
        t := s.Init(c)
 



Home | Main Index | Thread Index | Old Index