diff options
author | rillig <rillig@pkgsrc.org> | 2020-02-17 20:22:21 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2020-02-17 20:22:21 +0000 |
commit | ba9bf95207b57a665124f9fbc69ad860a2bccac8 (patch) | |
tree | d1f53e159c648e0df27589487729adfaf6d4fab0 /pkgtools | |
parent | 05a761e0d167bb7d61e7b50fd400ce0b566fb915 (diff) | |
download | pkgsrc-ba9bf95207b57a665124f9fbc69ad860a2bccac8.tar.gz |
pkgtools/pkglint: update to 19.4.9
Changes since 19.4.8:
Packages that include omf-scrollkeeper.mk even though their PLIST doesn't
contain any .omf files will generate an error message, suggesting that
the .include line be removed.
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkglint/Makefile | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/autofix.go | 2 | ||||
-rw-r--r-- | pkgtools/pkglint/files/package.go | 11 | ||||
-rw-r--r-- | pkgtools/pkglint/files/package_test.go | 6 | ||||
-rw-r--r-- | pkgtools/pkglint/files/pkgsrc_test.go | 18 | ||||
-rw-r--r-- | pkgtools/pkglint/files/plist.go | 24 | ||||
-rw-r--r-- | pkgtools/pkglint/files/plist_test.go | 52 | ||||
-rw-r--r-- | pkgtools/pkglint/files/varalignblock_test.go | 58 |
8 files changed, 158 insertions, 17 deletions
diff --git a/pkgtools/pkglint/Makefile b/pkgtools/pkglint/Makefile index 4eb31686afc..b09a3c9283e 100644 --- a/pkgtools/pkglint/Makefile +++ b/pkgtools/pkglint/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.631 2020/02/15 13:48:40 rillig Exp $ +# $NetBSD: Makefile,v 1.632 2020/02/17 20:22:21 rillig Exp $ -PKGNAME= pkglint-19.4.8 +PKGNAME= pkglint-19.4.9 CATEGORIES= pkgtools DISTNAME= tools MASTER_SITES= ${MASTER_SITE_GITHUB:=golang/} diff --git a/pkgtools/pkglint/files/autofix.go b/pkgtools/pkglint/files/autofix.go index 9fed2574f19..a43d5dc1353 100644 --- a/pkgtools/pkglint/files/autofix.go +++ b/pkgtools/pkglint/files/autofix.go @@ -219,7 +219,7 @@ func (fix *Autofix) Delete() { // and if so, call Describef to describe the actual fix. // // If autofix is false, the fix should be applied, as far as only -// in-memory data structures are effected, and these are not written +// in-memory data structures are affected, and these are not written // back to disk. No externally observable modification must be done. // For example, changing the text of Line.raw is appropriate, // but changing files in the file system is not. diff --git a/pkgtools/pkglint/files/package.go b/pkgtools/pkglint/files/package.go index 5a53dc20785..370adf6345c 100644 --- a/pkgtools/pkglint/files/package.go +++ b/pkgtools/pkglint/files/package.go @@ -651,7 +651,7 @@ func (pkg *Package) checkfilePackageMakefile(filename CurrPath, mklines *MkLines // This check is experimental because it's not yet clear how to // classify the various Python packages and whether all Python // packages really need the prefix. - if G.Experimental && pkg.EffectivePkgname != "" && pkg.Includes("../../lang/python/extension.mk") { + if G.Experimental && pkg.EffectivePkgname != "" && pkg.Includes("../../lang/python/extension.mk") != nil { pkg.EffectivePkgnameLine.Warnf("The PKGNAME of Python extensions should start with ${PYPKGPREFIX}.") } @@ -1529,9 +1529,12 @@ func (pkg *Package) Rel(filename CurrPath) PackagePath { // Returns whether the given file (relative to the package directory) // is included somewhere in the package, either directly or indirectly. -func (pkg *Package) Includes(filename PackagePath) bool { - return pkg.unconditionalIncludes[filename] != nil || - pkg.conditionalIncludes[filename] != nil +func (pkg *Package) Includes(filename PackagePath) *MkLine { + mkline := pkg.unconditionalIncludes[filename] + if mkline == nil { + mkline = pkg.conditionalIncludes[filename] + } + return mkline } // PlistContent lists the directories and files that appear in the diff --git a/pkgtools/pkglint/files/package_test.go b/pkgtools/pkglint/files/package_test.go index 9c74f1cf11b..1b61b598290 100644 --- a/pkgtools/pkglint/files/package_test.go +++ b/pkgtools/pkglint/files/package_test.go @@ -3525,9 +3525,9 @@ func (s *Suite) Test_Package_Includes(c *check.C) { pkg.load() - t.CheckEquals(pkg.Includes("unconditionally.mk"), true) - t.CheckEquals(pkg.Includes("conditionally.mk"), true) - t.CheckEquals(pkg.Includes("other.mk"), false) + t.CheckEquals(pkg.Includes("unconditionally.mk") != nil, true) + t.CheckEquals(pkg.Includes("conditionally.mk") != nil, true) + t.CheckEquals(pkg.Includes("other.mk") != nil, false) // The file never.mk is in conditionalIncludes since pkglint only // analyzes on the syntactical level. It doesn't evaluate the diff --git a/pkgtools/pkglint/files/pkgsrc_test.go b/pkgtools/pkglint/files/pkgsrc_test.go index ea730aecf3f..9773186b872 100644 --- a/pkgtools/pkglint/files/pkgsrc_test.go +++ b/pkgtools/pkglint/files/pkgsrc_test.go @@ -1407,6 +1407,24 @@ func (s *Suite) Test_Pkgsrc_File(c *check.C) { test("filename", "filename") } +func (s *Suite) Test_Pkgsrc_FilePkg(c *check.C) { + t := s.Init(c) + + t.Chdir(".") + + test := func(rel PackagePath, abs CurrPath) { + actual := G.Pkgsrc.FilePkg(rel) + t.CheckEquals(actual, abs) + } + + test("", "") + test("category/package", "") + test("../package", "") + test("../../category", "") + test("../../category/package", "category/package") + test("../../../something", "") +} + func (s *Suite) Test_Change_Version(c *check.C) { t := s.Init(c) diff --git a/pkgtools/pkglint/files/plist.go b/pkgtools/pkglint/files/plist.go index 69ae77fd5b3..bad22f7f4f3 100644 --- a/pkgtools/pkglint/files/plist.go +++ b/pkgtools/pkglint/files/plist.go @@ -72,6 +72,7 @@ func (ck *PlistChecker) Check(plainLines *Lines) { ck.checkLine(pline) pline.CheckTrailingWhitespace() } + ck.checkOmf(plines) CheckLinesTrailingEmptyLines(plainLines) sorter := NewPlistLineSorter(plines) @@ -498,6 +499,29 @@ func (ck *PlistChecker) checkCond(pline *PlistLine, cond string) { cond) } +func (ck *PlistChecker) checkOmf(plines []*PlistLine) { + if ck.pkg == nil { + return + } + mkline := ck.pkg.Includes("../../mk/omf-scrollkeeper.mk") + if mkline == nil { + return + } + + for _, pline := range plines { + if hasSuffix(pline.text, ".omf") { + return + } + } + + fix := mkline.Autofix() + fix.Errorf("Only packages that have .omf files in their PLIST may include omf-scrollkeeper.mk.") + if !mkline.HasRationale() { + fix.Delete() + } + fix.Apply() +} + type PlistLine struct { *Line conditions []string // e.g. PLIST.docs diff --git a/pkgtools/pkglint/files/plist_test.go b/pkgtools/pkglint/files/plist_test.go index 1d476398c8c..756c3cad403 100644 --- a/pkgtools/pkglint/files/plist_test.go +++ b/pkgtools/pkglint/files/plist_test.go @@ -1106,6 +1106,58 @@ func (s *Suite) Test_PlistChecker_checkCond__hacks_mk(c *check.C) { "in the package Makefile.") } +func (s *Suite) Test_PlistChecker_checkOmf__autofix(c *check.C) { + t := s.Init(c) + + t.CreateFileLines("mk/omf-scrollkeeper.mk", + MkCvsID) + t.SetUpPackage("category/package", + ".include \"../../mk/omf-scrollkeeper.mk\"") + t.Chdir("category/package") + t.FinishSetUp() + + t.ExpectDiagnosticsAutofix( + func(bool) { G.checkdirPackage(".") }, + "ERROR: Makefile:20: Only packages that have .omf files in "+ + "their PLIST may include omf-scrollkeeper.mk.", + "AUTOFIX: Makefile:20: Deleting this line.") +} + +func (s *Suite) Test_PlistChecker_checkOmf__rationale(c *check.C) { + t := s.Init(c) + + t.CreateFileLines("mk/omf-scrollkeeper.mk", + MkCvsID) + t.SetUpPackage("category/package", + ".include \"../../mk/omf-scrollkeeper.mk\" # needs to stay") + t.Chdir("category/package") + t.FinishSetUp() + + t.ExpectDiagnosticsAutofix( + func(bool) { G.checkdirPackage(".") }, + "ERROR: Makefile:20: Only packages that have .omf files in "+ + "their PLIST may include omf-scrollkeeper.mk.") +} + +func (s *Suite) Test_PlistChecker_checkOmf__ok(c *check.C) { + t := s.Init(c) + + t.CreateFileLines("mk/omf-scrollkeeper.mk", + MkCvsID) + t.SetUpPackage("category/package", + ".include \"../../mk/omf-scrollkeeper.mk\" # needs to stay") + t.Chdir("category/package") + t.CreateFileLines("PLIST", + PlistCvsID, + "bin/program", + "share/omf/documentation.omf") + t.FinishSetUp() + + t.ExpectDiagnosticsAutofix( + func(bool) { G.checkdirPackage(".") }, + nil...) +} + func (s *Suite) Test_PlistLine_Path(c *check.C) { t := s.Init(c) diff --git a/pkgtools/pkglint/files/varalignblock_test.go b/pkgtools/pkglint/files/varalignblock_test.go index 42dc1049393..adaff884274 100644 --- a/pkgtools/pkglint/files/varalignblock_test.go +++ b/pkgtools/pkglint/files/varalignblock_test.go @@ -3134,11 +3134,28 @@ func (s *Suite) Test_VaralignBlock_Finish__continuation_beyond_right_margin(c *c } func (s *Suite) Test_varalignLine_realignDetails(c *check.C) { - t := s.Init(c) - - // FIXME + vt := NewVaralignTester(s, c) - t.CheckOutputEmpty() + // Just a random example to exercise some of the code paths, + // with no particular intention. + vt.Input( + "VAR=\t\tvalue", + "VAR= \\", + "\t\t ..24 \\", + "\t..12") + vt.Diagnostics( + "NOTE: Makefile:2: This variable value should be aligned "+ + "with tabs, not spaces, to column 17 instead of 6.", + "NOTE: Makefile:3: This continuation line should be indented with \"\\t\\t\".") + vt.Autofixes( + "AUTOFIX: Makefile:2: Replacing \" \" with \"\\t\\t\".", + "AUTOFIX: Makefile:3: Replacing \"\\t\\t \" with \"\\t\\t\".") + vt.Fixed( + "VAR= value", + "VAR= \\", + " ..24 \\", + " ..12") + vt.Run() } func (s *Suite) Test_VaralignSplitter_split(c *check.C) { @@ -4391,15 +4408,42 @@ func (s *Suite) Test_varalignLine_alignContinuation(c *check.C) { func (s *Suite) Test_varalignLine_replaceSpaceBeforeValue(c *check.C) { t := s.Init(c) - // FIXME + t.SetUpCommandLine("--autofix", "--show-autofix") + mklines := t.NewMkLines("filename.mk", + "VAR= \t value") + line := mklines.lines.Lines[0] + parts := NewVaralignSplitter().split(line.RawText(0), true) + info := varalignLine{line, 0, false, parts} + fix := line.Autofix() + fix.Warnf("Warning.") + + info.replaceSpaceBeforeValue(fix, "\t\t") + fix.Apply() - t.CheckOutputEmpty() + t.CheckOutputLines( + "WARN: filename.mk:1: Warning.", + "AUTOFIX: filename.mk:1: Replacing \" \\t \" with \"\\t\\t\".") } func (s *Suite) Test_varalignLine_replaceSpaceBeforeContinuationSilently(c *check.C) { t := s.Init(c) - // FIXME + t.SetUpCommandLine("--autofix", "--show-autofix") + mklines := t.NewMkLines("filename.mk", + "VAR= \t value \\", + "\\tend") + line := mklines.lines.Lines[0] + parts := NewVaralignSplitter().split(line.RawText(0), true) + info := varalignLine{line, 0, false, parts} + fix := line.Autofix() + fix.Warnf("Warning.") + + info.replaceSpaceBeforeContinuationSilently(fix, 32) + fix.Apply() + + t.CheckOutputLines( + "WARN: filename.mk:1: Warning.", + "AUTOFIX: filename.mk:1: Replacing \" \\\\\" with \"\\t\\t\\t\\\\\".") t.CheckOutputEmpty() } |