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:           Thu Mar  2 08:58:29 UTC 2023

Modified Files:
        pkgsrc/pkgtools/pkglint: Makefile
        pkgsrc/pkgtools/pkglint/files: check_test.go files.go
            mkassignchecker.go mkcondchecker.go mkcondchecker_test.go mkline.go
            mkline_test.go mklinechecker.go mklineparser.go mklines.go
            mkparser_test.go mkvarusechecker.go package_test.go patches.go
            pkglint.go pkglint_test.go pkgsrc.go var.go vardefs_test.go

Log Message:
pkgtools/pkglint: Update to 22.4.1

Changes since 22.4.0:

Allow pkglint to be run outside the pkgsrc top directory, in order to
allow individual makefiles to be formatted and checked as well. The many
pkgsrc-specific checks don't apply in this case. This mode is
experimental, there are still crashes to be expected.

Fix a crash for syntactically invalid conditions in '.if'.

Fix parsing of dependency lines that contain an escaped '#', which is
used for switching to another shell using a '.SHELL: ...' line.


To generate a diff of this commit:
cvs rdiff -u -r1.739 -r1.740 pkgsrc/pkgtools/pkglint/Makefile
cvs rdiff -u -r1.81 -r1.82 pkgsrc/pkgtools/pkglint/files/check_test.go
cvs rdiff -u -r1.32 -r1.33 pkgsrc/pkgtools/pkglint/files/files.go
cvs rdiff -u -r1.16 -r1.17 pkgsrc/pkgtools/pkglint/files/mkassignchecker.go
cvs rdiff -u -r1.15 -r1.16 pkgsrc/pkgtools/pkglint/files/mkcondchecker.go
cvs rdiff -u -r1.14 -r1.15 \
    pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go \
    pkgsrc/pkgtools/pkglint/files/mklineparser.go \
    pkgsrc/pkgtools/pkglint/files/mkvarusechecker.go
cvs rdiff -u -r1.86 -r1.87 pkgsrc/pkgtools/pkglint/files/mkline.go
cvs rdiff -u -r1.85 -r1.86 pkgsrc/pkgtools/pkglint/files/mkline_test.go
cvs rdiff -u -r1.71 -r1.72 pkgsrc/pkgtools/pkglint/files/mklinechecker.go
cvs rdiff -u -r1.76 -r1.77 pkgsrc/pkgtools/pkglint/files/mklines.go
cvs rdiff -u -r1.43 -r1.44 pkgsrc/pkgtools/pkglint/files/mkparser_test.go
cvs rdiff -u -r1.93 -r1.94 pkgsrc/pkgtools/pkglint/files/package_test.go
cvs rdiff -u -r1.47 -r1.48 pkgsrc/pkgtools/pkglint/files/patches.go
cvs rdiff -u -r1.87 -r1.88 pkgsrc/pkgtools/pkglint/files/pkglint.go
cvs rdiff -u -r1.73 -r1.74 pkgsrc/pkgtools/pkglint/files/pkglint_test.go
cvs rdiff -u -r1.69 -r1.70 pkgsrc/pkgtools/pkglint/files/pkgsrc.go
cvs rdiff -u -r1.10 -r1.11 pkgsrc/pkgtools/pkglint/files/var.go
cvs rdiff -u -r1.29 -r1.30 pkgsrc/pkgtools/pkglint/files/vardefs_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.739 pkgsrc/pkgtools/pkglint/Makefile:1.740
--- pkgsrc/pkgtools/pkglint/Makefile:1.739      Thu Feb 16 15:02:04 2023
+++ pkgsrc/pkgtools/pkglint/Makefile    Thu Mar  2 08:58:28 2023
@@ -1,7 +1,6 @@
-# $NetBSD: Makefile,v 1.739 2023/02/16 15:02:04 bsiegert Exp $
+# $NetBSD: Makefile,v 1.740 2023/03/02 08:58:28 rillig Exp $
 
-PKGNAME=       pkglint-22.4.0
-PKGREVISION=   1
+PKGNAME=       pkglint-22.4.1
 CATEGORIES=    pkgtools
 
 MAINTAINER=    rillig%NetBSD.org@localhost

Index: pkgsrc/pkgtools/pkglint/files/check_test.go
diff -u pkgsrc/pkgtools/pkglint/files/check_test.go:1.81 pkgsrc/pkgtools/pkglint/files/check_test.go:1.82
--- pkgsrc/pkgtools/pkglint/files/check_test.go:1.81    Sun Jan 29 13:36:31 2023
+++ pkgsrc/pkgtools/pkglint/files/check_test.go Thu Mar  2 08:58:29 2023
@@ -157,10 +157,13 @@ func Test__qa(t *testing.T) {
        ck.Configure("*", "*", "", -intqa.EMissingTest)
 
        // The Suite type is used for testing all parts of pkglint.
-       // Therefore its test methods may be everywhere.
+       // Therefore, its test methods may be everywhere.
        ck.Configure("*.go", "Suite", "*", -intqa.EMethodsSameFile)
        ck.Configure("*.go", "Tester", "*", -intqa.EMethodsSameFile)
 
+       // When running gobco, it inserts the function 'GobcoCover'.
+       ck.Configure("*", "", "GobcoCover", -intqa.EMissingTest)
+
        ck.Check()
 }
 
@@ -228,7 +231,7 @@ func (t *Tester) SetUpCommandLine(args .
 //
 // See SetUpTool for registering tools like echo, awk, perl.
 func (t *Tester) SetUpVartypes() {
-       G.Pkgsrc.vartypes.Init(&G.Pkgsrc)
+       G.Pkgsrc.vartypes.Init(G.Pkgsrc)
 }
 
 func (t *Tester) SetUpMasterSite(varname string, urls ...string) {
@@ -1098,12 +1101,14 @@ func (t *Tester) NewMkLinesPkg(filename 
                basename.HasSuffixText(".mk") || basename == "Makefile" || basename.HasPrefixText("Makefile."),
                "filename %q must be realistic, otherwise the variable permissions are wrong", filename)
 
-       var rawText strings.Builder
+       var sb strings.Builder
        for _, line := range lines {
-               rawText.WriteString(line)
-               rawText.WriteString("\n")
+               sb.WriteString(line)
+               sb.WriteString("\n")
        }
-       return NewMkLines(convertToLogicalLines(filename, rawText.String(), true), pkg, nil)
+       rawText := sb.String()
+       logicalLines := convertToLogicalLines(filename, rawText, true)
+       return NewMkLines(logicalLines, pkg, nil)
 }
 
 // Returns and consumes the output from both stdout and stderr.

Index: pkgsrc/pkgtools/pkglint/files/files.go
diff -u pkgsrc/pkgtools/pkglint/files/files.go:1.32 pkgsrc/pkgtools/pkglint/files/files.go:1.33
--- pkgsrc/pkgtools/pkglint/files/files.go:1.32 Sat Feb 15 13:48:40 2020
+++ pkgsrc/pkgtools/pkglint/files/files.go      Thu Mar  2 08:58:29 2023
@@ -59,6 +59,9 @@ func Load(filename CurrPath, options Loa
        return result
 }
 
+// convertToLogicalLines splits the raw text into lines.
+// If joinBackslashes is true, lines that end with an odd number of backslashes
+// are joined with the following line.
 func convertToLogicalLines(filename CurrPath, rawText string, joinBackslashLines bool) *Lines {
        var rawLines []*RawLine
        for _, rawLine := range strings.SplitAfter(rawText, "\n") {

Index: pkgsrc/pkgtools/pkglint/files/mkassignchecker.go
diff -u pkgsrc/pkgtools/pkglint/files/mkassignchecker.go:1.16 pkgsrc/pkgtools/pkglint/files/mkassignchecker.go:1.17
--- pkgsrc/pkgtools/pkglint/files/mkassignchecker.go:1.16       Fri Aug 19 17:35:43 2022
+++ pkgsrc/pkgtools/pkglint/files/mkassignchecker.go    Thu Mar  2 08:58:29 2023
@@ -29,6 +29,9 @@ func (ck *MkAssignChecker) checkLeft() {
                ck.MkLine.Warnf("Variable names starting with an underscore (%s) are reserved for internal pkgsrc use.", varname)
        }
 
+       if G.Pkgsrc == nil {
+               goto checkVarUse
+       }
        ck.checkLeftNotUsed()
        ck.checkLeftOpsys()
        ck.checkLeftDeprecated()
@@ -39,6 +42,7 @@ func (ck *MkAssignChecker) checkLeft() {
        }
        ck.checkLeftRationale()
 
+checkVarUse:
        NewMkLineChecker(ck.MkLines, ck.MkLine).checkTextVarUse(
                varname,
                NewVartype(BtVariableName, NoVartypeOptions, NewACLEntry("*", aclpAll)),
@@ -699,7 +703,7 @@ func (ck *MkAssignChecker) mayBeDefined(
        if G.Infrastructure {
                return true
        }
-       if G.Pkgsrc.vartypes.Canon(varname) != nil {
+       if G.Pkgsrc == nil || G.Pkgsrc.vartypes.Canon(varname) != nil {
                return true
        }
 

Index: pkgsrc/pkgtools/pkglint/files/mkcondchecker.go
diff -u pkgsrc/pkgtools/pkglint/files/mkcondchecker.go:1.15 pkgsrc/pkgtools/pkglint/files/mkcondchecker.go:1.16
--- pkgsrc/pkgtools/pkglint/files/mkcondchecker.go:1.15 Mon Nov 28 23:33:28 2022
+++ pkgsrc/pkgtools/pkglint/files/mkcondchecker.go      Thu Mar  2 08:58:29 2023
@@ -25,7 +25,7 @@ func (ck *MkCondChecker) Check() {
 
        p := NewMkParser(nil, mkline.Args()) // No emitWarnings here, see the code below.
        cond := p.MkCond()
-       if !p.EOF() {
+       if !p.EOF() || cond == nil {
                mkline.Warnf("Invalid condition, unrecognized part: %q.", p.Rest())
                return
        }
@@ -165,7 +165,7 @@ var mkCondModifierPatternLiteral = textp
 func (ck *MkCondChecker) checkCompare(left *MkCondTerm, op string, right *MkCondTerm) {
        switch {
        case right.Num != "":
-               ck.checkCompareVarNum(left, op, right.Num)
+               ck.checkCompareWithNum(left, op, right.Num)
        case left.Var != nil && right.Var == nil:
                ck.checkCompareVarStr(left.Var, op, right.Str)
        }
@@ -209,12 +209,12 @@ func (ck *MkCondChecker) checkCompareVar
        }
 }
 
-func (ck *MkCondChecker) checkCompareVarNum(left *MkCondTerm, op string, num string) {
-       ck.checkCompareVarNumVersion(op, num)
-       ck.checkCompareVarNumPython(left, op, num)
+func (ck *MkCondChecker) checkCompareWithNum(left *MkCondTerm, op string, num string) {
+       ck.checkCompareWithNumVersion(op, num)
+       ck.checkCompareWithNumPython(left, op, num)
 }
 
-func (ck *MkCondChecker) checkCompareVarNumVersion(op string, num string) {
+func (ck *MkCondChecker) checkCompareWithNumVersion(op string, num string) {
        if !contains(num, ".") {
                return
        }
@@ -236,7 +236,7 @@ func (ck *MkCondChecker) checkCompareVar
                "the version number 1.11 would also match, which is not intended.")
 }
 
-func (ck *MkCondChecker) checkCompareVarNumPython(left *MkCondTerm, op string, num string) {
+func (ck *MkCondChecker) checkCompareWithNumPython(left *MkCondTerm, op string, num string) {
        if left.Var != nil && left.Var.varname == "_PYTHON_VERSION" &&
                op != "==" && op != "!=" &&
                matches(num, `^\d+$`) {
@@ -289,6 +289,9 @@ func (ck *MkCondChecker) checkContradict
 
        byVarname := make(map[string][]VarFact)
        levels := ck.MkLines.indentation.levels
+       if len(levels) == 0 {
+               goto skip // For .elif outside .if
+       }
        for _, level := range levels[:len(levels)-1] {
                if !level.mkline.NeedsCond() {
                        continue
@@ -300,6 +303,7 @@ func (ck *MkCondChecker) checkContradict
                }
        }
 
+skip:
        facts := ck.collectFacts(mkline)
        for _, curr := range facts {
                varname := curr.Varname

Index: pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go
diff -u pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go:1.14 pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go:1.15
--- pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go:1.14    Mon Nov 28 23:33:28 2022
+++ pkgsrc/pkgtools/pkglint/files/mkcondchecker_test.go Thu Mar  2 08:58:29 2023
@@ -129,6 +129,13 @@ func (s *Suite) Test_MkCondChecker_Check
                "WARN: filename.mk:4: Invalid variable modifier \"//*\" for \"MASTER_SITES\".",
                "WARN: filename.mk:4: \"ftp\" is not a valid URL.",
                "WARN: filename.mk:4: MASTER_SITES should not be used at load time in any file.")
+
+       test(".if !",
+               "WARN: filename.mk:4: Invalid condition, unrecognized part: \"\".")
+
+       // TODO: There should be another error for the '.elif' outside '.if'.
+       test(".elif 0",
+               "ERROR: filename.mk:5: Unmatched .endif.")
 }
 
 func (s *Suite) Test_MkCondChecker_Check__tracing(c *check.C) {
@@ -599,7 +606,7 @@ func (s *Suite) Test_MkCondChecker_check
        t.CheckOutputEmpty()
 }
 
-func (s *Suite) Test_MkCondChecker_checkCompareVarNum(c *check.C) {
+func (s *Suite) Test_MkCondChecker_checkCompareWithNum(c *check.C) {
        t := s.Init(c)
 
        mklines := t.NewMkLines("filename.mk",
@@ -617,7 +624,7 @@ func (s *Suite) Test_MkCondChecker_check
                "WARN: filename.mk:4: _PYTHON_VERSION is used but not defined.")
 }
 
-func (s *Suite) Test_MkCondChecker_checkCompareVarNumVersion(c *check.C) {
+func (s *Suite) Test_MkCondChecker_checkCompareWithNumVersion(c *check.C) {
        t := s.Init(c)
 
        mklines := t.NewMkLines("filename.mk",
@@ -638,7 +645,7 @@ func (s *Suite) Test_MkCondChecker_check
                "WARN: filename.mk:8: Numeric comparison == 6.5.")
 }
 
-func (s *Suite) Test_MkCondChecker_checkCompareVarNumPython(c *check.C) {
+func (s *Suite) Test_MkCondChecker_checkCompareWithNumPython(c *check.C) {
        t := s.Init(c)
 
        mklines := t.NewMkLines("filename.mk",
@@ -647,9 +654,8 @@ func (s *Suite) Test_MkCondChecker_check
                "_PYTHON_VERSION=\tnone",
                "",
                ".if ${_PYTHON_VERSION} < 38",
-               ".endif",
-               "",
-               ".if ${_PYTHON_VERSION} < 310",
+               ".elif ${_PYTHON_VERSION} < 310",
+               ".elif \"\" < 310",
                ".endif")
 
        mklines.Check()
@@ -661,7 +667,7 @@ func (s *Suite) Test_MkCondChecker_check
                        "for internal pkgsrc use.",
                "ERROR: filename.mk:5: "+
                        "The Python version must not be compared numerically.",
-               "ERROR: filename.mk:8: "+
+               "ERROR: filename.mk:6: "+
                        "The Python version must not be compared numerically.")
 }
 
Index: pkgsrc/pkgtools/pkglint/files/mklineparser.go
diff -u pkgsrc/pkgtools/pkglint/files/mklineparser.go:1.14 pkgsrc/pkgtools/pkglint/files/mklineparser.go:1.15
--- pkgsrc/pkgtools/pkglint/files/mklineparser.go:1.14  Sat Jun  6 20:42:56 2020
+++ pkgsrc/pkgtools/pkglint/files/mklineparser.go       Thu Mar  2 08:58:29 2023
@@ -260,7 +260,7 @@ func (p MkLineParser) parseSysinclude(li
 func (p MkLineParser) parseDependency(line *Line, splitResult mkLineSplitResult) *MkLine {
        // XXX: Replace this regular expression with proper parsing.
        // There might be a ${VAR:M*.c} in these variables, which the below regular expression cannot handle.
-       m, targets, whitespace, sources := match3(line.Text, `^([^\t :]+(?:[\t ]*[^\t :]+)*)([\t ]*):[\t ]*([^#]*?)(?:[\t ]*#.*)?$`)
+       m, targets, whitespace, sources := match3(splitResult.main, `^([^\t :]+(?:[\t ]*[^\t :]+)*)([\t ]*):[\t ]*(.*)$`)
        if !m {
                return nil
        }
Index: pkgsrc/pkgtools/pkglint/files/mkvarusechecker.go
diff -u pkgsrc/pkgtools/pkglint/files/mkvarusechecker.go:1.14 pkgsrc/pkgtools/pkglint/files/mkvarusechecker.go:1.15
--- pkgsrc/pkgtools/pkglint/files/mkvarusechecker.go:1.14       Sun Jun  6 07:41:34 2021
+++ pkgsrc/pkgtools/pkglint/files/mkvarusechecker.go    Thu Mar  2 08:58:29 2023
@@ -33,11 +33,15 @@ func (ck *MkVarUseChecker) Check(vuc *Va
        ck.checkAssignable(vuc)
        ck.checkQuoting(vuc)
 
+       if G.Pkgsrc == nil {
+               goto checkVarUse
+       }
        ck.checkToolsPlatform()
        ck.checkBuildDefs()
        ck.checkDeprecated()
        ck.checkPkgBuildOptions()
 
+checkVarUse:
        NewMkLineChecker(ck.MkLines, ck.MkLine).
                checkTextVarUse(ck.use.varname, ck.vartype, vuc.time)
 }

Index: pkgsrc/pkgtools/pkglint/files/mkline.go
diff -u pkgsrc/pkgtools/pkglint/files/mkline.go:1.86 pkgsrc/pkgtools/pkglint/files/mkline.go:1.87
--- pkgsrc/pkgtools/pkglint/files/mkline.go:1.86        Sun Jan 29 13:36:31 2023
+++ pkgsrc/pkgtools/pkglint/files/mkline.go     Thu Mar  2 08:58:29 2023
@@ -1305,6 +1305,9 @@ func (ind *Indentation) TrackAfter(mklin
 
                ind.RememberUsedVariables(cond)
 
+               if G.Pkgsrc == nil {
+                       break
+               }
                cond.Walk(&MkCondCallback{
                        Call: func(name string, arg string) {
                                if name == "exists" && !NewPath(arg).IsAbs() {

Index: pkgsrc/pkgtools/pkglint/files/mkline_test.go
diff -u pkgsrc/pkgtools/pkglint/files/mkline_test.go:1.85 pkgsrc/pkgtools/pkglint/files/mkline_test.go:1.86
--- pkgsrc/pkgtools/pkglint/files/mkline_test.go:1.85   Sun Jan 29 13:36:31 2023
+++ pkgsrc/pkgtools/pkglint/files/mkline_test.go        Thu Mar  2 08:58:29 2023
@@ -333,6 +333,20 @@ func (s *Suite) Test_MkLine_ValueFields_
        // Most probably, the shell will complain about it when it is executed.
 }
 
+func (s *Suite) Test_MkLine_ValueFields__escaped_number_sign(c *check.C) {
+       t := s.Init(c)
+       mklines := t.NewMkLines("filename.mk",
+               ".SHELL: \\",
+               "\tname=sh \\",
+               "\tpath=${.SHELL} \\",
+               "\tquiet=\"\\# .echoOff\"")
+       mkline := mklines.mklines[0]
+
+       words := mkline.ValueFields(mkline.Sources())
+
+       t.CheckDeepEquals(words, []string{"name=sh", "path=${.SHELL}", "quiet=\"# .echoOff\""})
+}
+
 func (s *Suite) Test_MkLine_ValueTokens(c *check.C) {
        t := s.Init(c)
        b := NewMkTokenBuilder()
@@ -639,7 +653,7 @@ func (s *Suite) Test_MkLine_VariableNeed
        t.CheckOutputEmpty() // Up to version 5.3.6, pkglint warned about a missing :Q here, which was wrong.
 }
 
-func (s *Suite) Test_MkLine_VariableNeedsQuoting__append_list_to_list(c *check.C) {
+func (s *Suite) Test_MkLine_VariableNeedsQuoting__assign_list_to_list(c *check.C) {
        t := s.Init(c)
 
        t.SetUpVartypes()

Index: pkgsrc/pkgtools/pkglint/files/mklinechecker.go
diff -u pkgsrc/pkgtools/pkglint/files/mklinechecker.go:1.71 pkgsrc/pkgtools/pkglint/files/mklinechecker.go:1.72
--- pkgsrc/pkgtools/pkglint/files/mklinechecker.go:1.71 Sun Jan 29 13:36:31 2023
+++ pkgsrc/pkgtools/pkglint/files/mklinechecker.go      Thu Mar  2 08:58:29 2023
@@ -247,6 +247,9 @@ func (ck MkLineChecker) checkInclude() {
        if trace.Tracing {
                trace.Stepf("includingFile=%s includedFile=%s", mkline.Filename(), includedFile)
        }
+       if G.Pkgsrc == nil {
+               return
+       }
        ck.CheckRelativePath(NewPackagePath(includedFile), includedFile, mustExist)
 
        switch {

Index: pkgsrc/pkgtools/pkglint/files/mklines.go
diff -u pkgsrc/pkgtools/pkglint/files/mklines.go:1.76 pkgsrc/pkgtools/pkglint/files/mklines.go:1.77
--- pkgsrc/pkgtools/pkglint/files/mklines.go:1.76       Sun Oct  2 15:11:19 2022
+++ pkgsrc/pkgtools/pkglint/files/mklines.go    Thu Mar  2 08:58:29 2023
@@ -62,7 +62,9 @@ func NewMkLines(lines *Lines, pkg *Packa
        }
 
        tools := NewTools()
-       tools.Fallback(G.Pkgsrc.Tools)
+       if G.Pkgsrc != nil {
+               tools.Fallback(G.Pkgsrc.Tools)
+       }
 
        return &MkLines{
                mklines,

Index: pkgsrc/pkgtools/pkglint/files/mkparser_test.go
diff -u pkgsrc/pkgtools/pkglint/files/mkparser_test.go:1.43 pkgsrc/pkgtools/pkglint/files/mkparser_test.go:1.44
--- pkgsrc/pkgtools/pkglint/files/mkparser_test.go:1.43 Sat Jul  9 06:40:55 2022
+++ pkgsrc/pkgtools/pkglint/files/mkparser_test.go      Thu Mar  2 08:58:29 2023
@@ -302,6 +302,11 @@ func (s *Suite) Test_MkParser_MkCond(c *
        testRest("unknown(arg)",
                nil,
                "unknown(arg)")
+
+       // The '!' is consumed by the parser.
+       testRest("!",
+               nil,
+               "")
 }
 
 func (s *Suite) Test_MkParser_mkCondCompare(c *check.C) {

Index: pkgsrc/pkgtools/pkglint/files/package_test.go
diff -u pkgsrc/pkgtools/pkglint/files/package_test.go:1.93 pkgsrc/pkgtools/pkglint/files/package_test.go:1.94
--- pkgsrc/pkgtools/pkglint/files/package_test.go:1.93  Sun Jan 29 13:36:31 2023
+++ pkgsrc/pkgtools/pkglint/files/package_test.go       Thu Mar  2 08:58:29 2023
@@ -3153,7 +3153,7 @@ func (s *Suite) Test_Package_checkPossib
 
        t.CreateFileLines("doc/CHANGES-2018",
                "\tUpdated category/pkgbase to 1.8 [committer 2018-01-05]")
-       G.Pkgsrc.changes.load(&G.Pkgsrc)
+       G.Pkgsrc.changes.load(G.Pkgsrc)
 
        t.Chdir("category/pkgbase")
        pkg := NewPackage(".")

Index: pkgsrc/pkgtools/pkglint/files/patches.go
diff -u pkgsrc/pkgtools/pkglint/files/patches.go:1.47 pkgsrc/pkgtools/pkglint/files/patches.go:1.48
--- pkgsrc/pkgtools/pkglint/files/patches.go:1.47       Wed Jul  6 06:14:24 2022
+++ pkgsrc/pkgtools/pkglint/files/patches.go    Thu Mar  2 08:58:29 2023
@@ -183,8 +183,9 @@ func (ck *PatchChecker) checkUnifiedDiff
                // this by looking only at the patch file.
                if linesToAdd != linesToDel {
                        line := ck.llex.PreviousLine()
-                       line.Warnf("Premature end of patch hunk (expected %d lines to be deleted and %d lines to be added).",
-                               linesToDel, linesToAdd)
+                       line.Warnf("Premature end of patch hunk (expected %d %s to be deleted and %d %s to be added).",
+                               linesToDel, condStr(linesToDel != 1, "lines", "line"),
+                               linesToAdd, condStr(linesToAdd != 1, "lines", "line"))
                }
        }
 

Index: pkgsrc/pkgtools/pkglint/files/pkglint.go
diff -u pkgsrc/pkgtools/pkglint/files/pkglint.go:1.87 pkgsrc/pkgtools/pkglint/files/pkglint.go:1.88
--- pkgsrc/pkgtools/pkglint/files/pkglint.go:1.87       Sun Jan 29 13:36:31 2023
+++ pkgsrc/pkgtools/pkglint/files/pkglint.go    Thu Mar  2 08:58:29 2023
@@ -32,7 +32,7 @@ type Pkglint struct {
        Network,
        Recursive bool
 
-       Pkgsrc Pkgsrc // Global data, mostly extracted from mk/*.
+       Pkgsrc *Pkgsrc // Global data, mostly extracted from mk/*.
 
        Todo CurrPathQueue // The files or directories that still need to be checked.
 
@@ -190,23 +190,27 @@ func (p *Pkglint) setUpProfiling() func(
 
 func (p *Pkglint) prepareMainLoop() {
        firstDir := p.Todo.Front()
-       if firstDir.IsFile() {
+       isFile := firstDir.IsFile()
+       if isFile {
                firstDir = firstDir.Dir()
        }
 
        relTopdir := p.findPkgsrcTopdir(firstDir)
        if relTopdir.IsEmpty() {
                // If the first argument to pkglint is not inside a pkgsrc tree,
-               // pkglint doesn't know where to load the infrastructure files from,
-               // Since virtually every single check needs these files,
-               // the only sensible thing to do is to quit immediately.
-               G.Logger.TechFatalf(firstDir, "Must be inside a pkgsrc tree.")
+               // pkglint doesn't know where to load the infrastructure files from.
+               if isFile {
+                       // Allow this mode nevertheless, for checking the basic syntax
+                       // and for formatting individual makefiles outside pkgsrc.
+               } else {
+                       G.Logger.TechFatalf(firstDir, "Must be inside a pkgsrc tree.")
+               }
+       } else {
+               p.Pkgsrc = NewPkgsrc(firstDir.JoinNoClean(relTopdir))
+               p.Wip = p.Pkgsrc.IsWip(firstDir) // See Pkglint.checkMode.
+               p.Pkgsrc.LoadInfrastructure()
        }
 
-       p.Pkgsrc = NewPkgsrc(firstDir.JoinNoClean(relTopdir))
-       p.Wip = p.Pkgsrc.IsWip(firstDir) // See Pkglint.checkMode.
-       p.Pkgsrc.LoadInfrastructure()
-
        currentUser, err := user.Current()
        assertNil(err, "user.Current")
        // On Windows, this is `Computername\Username`.
@@ -308,6 +312,11 @@ func (p *Pkglint) checkMode(dirent CurrP
                dir = dirent.Dir()
        }
 
+       if isReg && p.Pkgsrc == nil {
+               CheckFileMk(dirent, nil)
+               return
+       }
+
        pkgsrcRel := p.Pkgsrc.Rel(dirent)
 
        p.Wip = pkgsrcRel.HasPrefixPath("wip")

Index: pkgsrc/pkgtools/pkglint/files/pkglint_test.go
diff -u pkgsrc/pkgtools/pkglint/files/pkglint_test.go:1.73 pkgsrc/pkgtools/pkglint/files/pkglint_test.go:1.74
--- pkgsrc/pkgtools/pkglint/files/pkglint_test.go:1.73  Sun Jan 29 13:36:31 2023
+++ pkgsrc/pkgtools/pkglint/files/pkglint_test.go       Thu Mar  2 08:58:29 2023
@@ -244,7 +244,7 @@ func (s *Suite) Test_Pkglint_Main__compl
                "ERROR: ~/sysutils/checkperms/distinfo:6: SHA1 hash of patches/patch-checkperms.c differs "+
                        "(distinfo has asdfasdf, patch file has bcfb79696cb6bf4d2222a6d78a530e11bf1c0cea).",
                "WARN: ~/sysutils/checkperms/patches/patch-checkperms.c:12: Premature end of patch hunk "+
-                       "(expected 1 lines to be deleted and 0 lines to be added).",
+                       "(expected 1 line to be deleted and 0 lines to be added).",
                "3 errors, 2 warnings and 1 note found.",
                t.Shquote("(Run \"pkglint -e -Wall -Call %s\" to show explanations.)", "sysutils/checkperms"),
                t.Shquote("(Run \"pkglint -fs -Wall -Call %s\" to show what can be fixed automatically.)", "sysutils/checkperms"),

Index: pkgsrc/pkgtools/pkglint/files/pkgsrc.go
diff -u pkgsrc/pkgtools/pkglint/files/pkgsrc.go:1.69 pkgsrc/pkgtools/pkglint/files/pkgsrc.go:1.70
--- pkgsrc/pkgtools/pkglint/files/pkgsrc.go:1.69        Sun Jan 29 13:36:31 2023
+++ pkgsrc/pkgtools/pkglint/files/pkgsrc.go     Thu Mar  2 08:58:29 2023
@@ -47,8 +47,8 @@ type Pkgsrc struct {
        vartypes   VarTypeRegistry
 }
 
-func NewPkgsrc(dir CurrPath) Pkgsrc {
-       return Pkgsrc{
+func NewPkgsrc(dir CurrPath) *Pkgsrc {
+       return &Pkgsrc{
                dir,
                make(map[string]bool),
                NewTools(),
@@ -736,6 +736,9 @@ func (src *Pkgsrc) ListVersions(category
 // (possibly guessed based on the variable name),
 // or nil if the type cannot even be guessed.
 func (src *Pkgsrc) VariableType(mklines *MkLines, varname string) (vartype *Vartype) {
+       if src == nil {
+               return nil
+       }
        if trace.Tracing {
                defer trace.Call(varname, trace.Result(&vartype))()
        }

Index: pkgsrc/pkgtools/pkglint/files/var.go
diff -u pkgsrc/pkgtools/pkglint/files/var.go:1.10 pkgsrc/pkgtools/pkglint/files/var.go:1.11
--- pkgsrc/pkgtools/pkglint/files/var.go:1.10   Sun Jan 29 13:36:31 2023
+++ pkgsrc/pkgtools/pkglint/files/var.go        Thu Mar  2 08:58:29 2023
@@ -187,7 +187,7 @@ func (v *Var) Write(mkline *MkLine, cond
        v.refs.AddAll(conditionVarnames)
 
        v.update(mkline, &v.valueInfra)
-       if !G.Pkgsrc.IsInfra(mkline.Line.Filename()) {
+       if G.Pkgsrc != nil && !G.Pkgsrc.IsInfra(mkline.Line.Filename()) {
                v.update(mkline, &v.value)
        }
 

Index: pkgsrc/pkgtools/pkglint/files/vardefs_test.go
diff -u pkgsrc/pkgtools/pkglint/files/vardefs_test.go:1.29 pkgsrc/pkgtools/pkglint/files/vardefs_test.go:1.30
--- pkgsrc/pkgtools/pkglint/files/vardefs_test.go:1.29  Sun Jun  7 15:49:23 2020
+++ pkgsrc/pkgtools/pkglint/files/vardefs_test.go       Thu Mar  2 08:58:29 2023
@@ -41,7 +41,7 @@ func (s *Suite) Test_VarTypeRegistry_com
                ".endif")
        reg := NewVarTypeRegistry()
 
-       compilerLanguages := reg.compilerLanguages(&G.Pkgsrc)
+       compilerLanguages := reg.compilerLanguages(G.Pkgsrc)
 
        enumValues := compilerLanguages.AllowedEnums()
        t.CheckEquals(enumValues, "empty-lang expr-lang gnu++14")
@@ -101,9 +101,9 @@ func (s *Suite) Test_VarTypeRegistry_enu
        reg := NewVarTypeRegistry()
        t.DisableTracing()
 
-       existingType := reg.enumFrom(&G.Pkgsrc, "mk/existing.mk", "defval", "VAR")
-       noAssignmentsType := reg.enumFrom(&G.Pkgsrc, "mk/existing.mk", "defval", "OTHER_VAR")
-       nonexistentType := reg.enumFrom(&G.Pkgsrc, "mk/nonexistent.mk", "defval", "VAR")
+       existingType := reg.enumFrom(G.Pkgsrc, "mk/existing.mk", "defval", "VAR")
+       noAssignmentsType := reg.enumFrom(G.Pkgsrc, "mk/existing.mk", "defval", "OTHER_VAR")
+       nonexistentType := reg.enumFrom(G.Pkgsrc, "mk/nonexistent.mk", "defval", "VAR")
 
        t.CheckEquals(existingType.AllowedEnums(), "first second")
        t.CheckEquals(noAssignmentsType.AllowedEnums(), "defval")
@@ -162,7 +162,7 @@ func (s *Suite) Test_VarTypeRegistry_enu
        t.ExpectFatal(
                func() {
                        G.Pkgsrc.vartypes.enumFromDirs(
-                               &G.Pkgsrc, "category", `^pack.*`, "$0", "default")
+                               G.Pkgsrc, "category", `^pack.*`, "$0", "default")
                },
                "FATAL: ~/category: Must contain at least 1 "+
                        "subdirectory matching \"^pack.*\".")
@@ -193,7 +193,7 @@ func (s *Suite) Test_VarTypeRegistry_enu
 
        t.ExpectFatal(
                func() {
-                       G.Pkgsrc.vartypes.enumFromFiles(&G.Pkgsrc,
+                       G.Pkgsrc.vartypes.enumFromFiles(G.Pkgsrc,
                                "mk/platform", `^(\w+)\.mk$`, "$1", "default")
                },
                "FATAL: ~/mk/platform: Must contain at least 1 "+
@@ -216,7 +216,7 @@ func (s *Suite) Test_VarTypeRegistry_Ini
        t := s.Init(c)
 
        src := NewPkgsrc(t.File("."))
-       src.vartypes.Init(&src)
+       src.vartypes.Init(src)
 
        t.CheckEquals(src.vartypes.Canon("BSD_MAKE_ENV").basicType.name, "ShellWord")
        t.CheckEquals(src.vartypes.Canon("USE_BUILTIN.*").basicType.name, "YesNoIndirectly")



Home | Main Index | Thread Index | Old Index