diff options
author | rillig <rillig@pkgsrc.org> | 2020-07-23 18:40:41 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2020-07-23 18:40:41 +0000 |
commit | 5522883bd05453d86a5b773a7aaac9f188f3d0a6 (patch) | |
tree | 4344eb818c3ea2b4d44569cf24796a1c39df385d /pkgtools | |
parent | c3e0cf1ef01ce080f1a6c93d37d381e2cff479cc (diff) | |
download | pkgsrc-5522883bd05453d86a5b773a7aaac9f188f3d0a6.tar.gz |
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 (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkglint/Makefile | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/patches.go | 29 | ||||
-rw-r--r-- | pkgtools/pkglint/files/patches_test.go | 60 |
3 files changed, 89 insertions, 4 deletions
diff --git a/pkgtools/pkglint/Makefile b/pkgtools/pkglint/Makefile index 43440a26843..bbe465252d1 100644 --- a/pkgtools/pkglint/Makefile +++ b/pkgtools/pkglint/Makefile @@ -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 --git a/pkgtools/pkglint/files/patches.go b/pkgtools/pkglint/files/patches.go index 853feef21ce..8239756ef54 100644 --- a/pkgtools/pkglint/files/patches.go +++ b/pkgtools/pkglint/files/patches.go @@ -148,20 +148,26 @@ func (ck *PatchChecker) checkUnifiedDiff(patchedFile Path) { // 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 @@ func (ck *PatchChecker) checkConfigure(addedText string, isConfigure bool) { "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 --git a/pkgtools/pkglint/files/patches_test.go b/pkgtools/pkglint/files/patches_test.go index 3822d36e2d9..86967364e7e 100644 --- a/pkgtools/pkglint/files/patches_test.go +++ b/pkgtools/pkglint/files/patches_test.go @@ -778,6 +778,66 @@ func (s *Suite) Test_PatchChecker_checkConfigure__configure_ac(c *check.C) { "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) |