diff options
-rw-r--r-- | pkgtools/pkglint/Makefile | 5 | ||||
-rw-r--r-- | pkgtools/pkglint/files/distinfo.go | 22 | ||||
-rw-r--r-- | pkgtools/pkglint/files/distinfo_test.go | 81 | ||||
-rw-r--r-- | pkgtools/pkglint/files/package_test.go | 10 | ||||
-rw-r--r-- | pkgtools/pkglint/files/pkglint.go | 3 | ||||
-rw-r--r-- | pkgtools/pkglint/files/pkgsrc_test.go | 8 | ||||
-rw-r--r-- | pkgtools/pkglint/files/redundantscope_test.go | 23 | ||||
-rw-r--r-- | pkgtools/pkglint/files/vardefs.go | 1 | ||||
-rw-r--r-- | pkgtools/pkglint/files/vartypecheck.go | 6 | ||||
-rw-r--r-- | pkgtools/pkglint/files/vartypecheck_test.go | 14 |
10 files changed, 107 insertions, 66 deletions
diff --git a/pkgtools/pkglint/Makefile b/pkgtools/pkglint/Makefile index 86df89953bf..d5c16f2dbba 100644 --- a/pkgtools/pkglint/Makefile +++ b/pkgtools/pkglint/Makefile @@ -1,7 +1,6 @@ -# $NetBSD: Makefile,v 1.699 2021/10/08 18:55:08 bsiegert Exp $ +# $NetBSD: Makefile,v 1.700 2021/10/09 08:33:09 rillig Exp $ -PKGNAME= pkglint-21.3.0 -PKGREVISION= 1 +PKGNAME= pkglint-21.3.1 CATEGORIES= pkgtools DISTNAME= tools MASTER_SITES= ${MASTER_SITE_GITHUB:=golang/} diff --git a/pkgtools/pkglint/files/distinfo.go b/pkgtools/pkglint/files/distinfo.go index 0803c281716..90bb58c7c54 100644 --- a/pkgtools/pkglint/files/distinfo.go +++ b/pkgtools/pkglint/files/distinfo.go @@ -146,9 +146,10 @@ func (ck *distinfoLinesChecker) checkAlgorithms(info distinfoFileInfo) { switch { case algorithms == "SHA1" && isPatch != no: return - - case algorithms == "SHA1, RMD160, SHA512, Size" && isPatch != yes: + case algorithms == "RMD160, SHA512, Size" && isPatch != yes: return + case algorithms == "SHA1, RMD160, SHA512, Size" && isPatch != yes: + return // TODO: remove as of 2021Q3 } switch { @@ -159,7 +160,7 @@ func (ck *distinfoLinesChecker) checkAlgorithms(info distinfoFileInfo) { line.Errorf("Wrong checksum algorithms %s for %s.", algorithms, filename) line.Explain( "Distfiles that are downloaded from external sources must have the", - "checksum algorithms SHA1, RMD160, SHA512, Size.", + "checksum algorithms RMD160, SHA512, Size.", "", "Patch files from pkgsrc must have only the SHA1 hash.") @@ -190,9 +191,10 @@ func (ck *distinfoLinesChecker) checkAlgorithms(info distinfoFileInfo) { // added to the distinfo file via an autofix. func (ck *distinfoLinesChecker) checkAlgorithmsDistfile(info distinfoFileInfo) { line := info.line() - line.Errorf("Expected SHA1, RMD160, SHA512, Size checksums for %q, got %s.", info.filename(), info.algorithms()) + line.Errorf("Expected RMD160, SHA512, Size checksums for %q, got %s.", + info.filename(), info.algorithms()) - algorithms := [...]string{"SHA1", "RMD160", "SHA512", "Size"} + algorithms := [...]string{"RMD160", "SHA512", "Size"} missing := map[string]bool{} for _, alg := range algorithms { @@ -445,11 +447,17 @@ func (info *distinfoFileInfo) algorithms() string { func (info *distinfoFileInfo) hasDistfileAlgorithms() bool { h := info.hashes - return len(h) == 4 && + if len(h) == 4 && // TODO: remove as of 2021Q3 h[0].algorithm == "SHA1" && h[1].algorithm == "RMD160" && h[2].algorithm == "SHA512" && - h[3].algorithm == "Size" + h[3].algorithm == "Size" { + return true + } + return len(h) == 3 && + h[0].algorithm == "RMD160" && + h[1].algorithm == "SHA512" && + h[2].algorithm == "Size" } type distinfoHash struct { diff --git a/pkgtools/pkglint/files/distinfo_test.go b/pkgtools/pkglint/files/distinfo_test.go index dfe065458ab..a8a835715d9 100644 --- a/pkgtools/pkglint/files/distinfo_test.go +++ b/pkgtools/pkglint/files/distinfo_test.go @@ -31,7 +31,7 @@ func (s *Suite) Test_CheckLinesDistinfo__parse_errors(c *check.C) { "ERROR: distinfo:1: Invalid line: should be the CVS ID", "ERROR: distinfo:2: Invalid line: should be empty", "ERROR: distinfo:8: Invalid line: Another invalid line", - "ERROR: distinfo:3: Expected SHA1, RMD160, SHA512, Size checksums for \"distfile-1.0.tar.gz\", got MD5, SHA1.", + "ERROR: distinfo:3: Expected RMD160, SHA512, Size checksums for \"distfile-1.0.tar.gz\", got MD5, SHA1.", "ERROR: distinfo:5: Expected SHA1 hash for patch-aa, got SHA1, Size.", "WARN: distinfo:9: Patch file \"patch-nonexistent\" does not exist in directory \"patches\".") } @@ -283,7 +283,7 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithms__nonexistent_distfile_ // a patch, it is a normal distfile because it has other hash algorithms // than exactly SHA1. t.CheckOutputLines( - "ERROR: distinfo:3: Expected SHA1, RMD160, SHA512, Size checksums " + + "ERROR: distinfo:3: Expected RMD160, SHA512, Size checksums " + "for \"patch-5.3.tar.gz\", got MD5, SHA1.") } @@ -300,7 +300,7 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithms__wrong_distfile_algori CheckLinesDistinfo(nil, lines) t.CheckOutputLines( - "ERROR: distinfo:3: Expected SHA1, RMD160, SHA512, Size checksums " + + "ERROR: distinfo:3: Expected RMD160, SHA512, Size checksums " + "for \"distfile.tar.gz\", got MD5, SHA1.") } @@ -326,7 +326,7 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithms__ambiguous_distfile(c "ERROR: distinfo:3: Wrong checksum algorithms MD5 for patch-4.2.tar.gz.", "", "\tDistfiles that are downloaded from external sources must have the", - "\tchecksum algorithms SHA1, RMD160, SHA512, Size.", + "\tchecksum algorithms RMD160, SHA512, Size.", "", "\tPatch files from pkgsrc must have only the SHA1 hash.", "") @@ -422,7 +422,7 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithms__missing_patch_with_wr // therefore it requires the usual distfile checksum algorithms here. t.CheckOutputLines( "ERROR: ~/category/package/distinfo:3: " + - "Expected SHA1, RMD160, SHA512, Size checksums for \"patch-aa\", got RMD160.") + "Expected RMD160, SHA512, Size checksums for \"patch-aa\", got RMD160.") } // When there is at least one correct hash for a distfile and the distfile @@ -449,9 +449,8 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__add_missing_h t.CheckOutputLines( "ERROR: ~/category/package/distinfo:3: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+ + "Expected RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+ "got RMD160, Size, CRC32.", - "ERROR: ~/category/package/distinfo:3: Missing SHA1 hash for package-1.0.txt.", "ERROR: ~/category/package/distinfo:3: Missing SHA512 hash for package-1.0.txt.") t.SetUpCommandLine("-Wall", "--autofix", "--show-autofix", "--source") @@ -462,20 +461,11 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__add_missing_h // hash right away. It also adds the missing hashes since this file is // not a patch file. t.CheckOutputLines( - "ERROR: ~/category/package/distinfo:3: Missing SHA1 hash for package-1.0.txt.", - "AUTOFIX: ~/category/package/distinfo:3: "+ - "Inserting a line \"SHA1 (package-1.0.txt) "+ - "= cd50d19784897085a8d0e3e413f8612b097c03f1\" "+ - "above this line.", - "+\tSHA1 (package-1.0.txt) = cd50d19784897085a8d0e3e413f8612b097c03f1", - ">\tRMD160 (package-1.0.txt) = 1a88147a0344137404c63f3b695366eab869a98a", - "", "ERROR: ~/category/package/distinfo:3: Missing SHA512 hash for package-1.0.txt.", "AUTOFIX: ~/category/package/distinfo:3: "+ "Inserting a line \"SHA512 (package-1.0.txt) "+ "= f65f341b35981fda842b09b2c8af9bcdb7602a4c2e6fa1f7d41f0974d3e3122f"+ "268fc79d5a4af66358f5133885cd1c165c916f80ab25e5d8d95db46f803c782c\" below this line.", - "+\tSHA1 (package-1.0.txt) = cd50d19784897085a8d0e3e413f8612b097c03f1", ">\tRMD160 (package-1.0.txt) = 1a88147a0344137404c63f3b695366eab869a98a", "+\tSHA512 (package-1.0.txt) = f65f341b35981fda842b09b2c8af9bcdb7602a4c2e6fa1f7d41f0974d3e3122f"+ "268fc79d5a4af66358f5133885cd1c165c916f80ab25e5d8d95db46f803c782c") @@ -486,8 +476,8 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__add_missing_h t.CheckOutputLines( "ERROR: ~/category/package/distinfo:3: " + - "Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", " + - "got SHA1, RMD160, SHA512, Size, CRC32.") + "Expected RMD160, SHA512, Size checksums for \"package-1.0.txt\", " + + "got RMD160, SHA512, Size, CRC32.") } // When some of the hashes for a distfile are missing, pkglint can calculate @@ -513,7 +503,7 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__add_missing_h t.CheckOutputLines( "ERROR: ~/category/package/distinfo:3: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+ + "Expected RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+ "got RMD160, Size, CRC32.", "", "\tTo add the missing lines to the distinfo file, run", @@ -557,7 +547,7 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__wrong_distfil t.CheckOutputLines( "ERROR: ~/category/package/distinfo:3: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+ + "Expected RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+ "got RMD160.", "ERROR: ~/category/package/distinfo:3: "+ "The RMD160 checksum for \"package-1.0.txt\" is 1234wrongHash1234 in distinfo, "+ @@ -580,7 +570,7 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__no_usual_algo t.CheckOutputLines( "ERROR: ~/category/package/distinfo:3: " + - "Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", " + + "Expected RMD160, SHA512, Size checksums for \"package-1.0.txt\", " + "got MD5.") } @@ -602,9 +592,8 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__top_algorithm t.CheckOutputLines( "ERROR: ~/category/package/distinfo:3: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+ + "Expected RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+ "got SHA512, Size.", - "ERROR: ~/category/package/distinfo:3: Missing SHA1 hash for package-1.0.txt.", "ERROR: ~/category/package/distinfo:3: Missing RMD160 hash for package-1.0.txt.") } @@ -625,22 +614,22 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__bottom_algori t.CheckOutputLines( "ERROR: ~/category/package/distinfo:3: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+ + "Expected RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+ "got SHA1, RMD160.", - "ERROR: ~/category/package/distinfo:4: Missing SHA512 hash for package-1.0.txt.", - "ERROR: ~/category/package/distinfo:4: Missing Size hash for package-1.0.txt.") + "ERROR: ~/category/package/distinfo:3: Missing SHA512 hash for package-1.0.txt.", + "ERROR: ~/category/package/distinfo:3: Missing Size hash for package-1.0.txt.") t.SetUpCommandLine("-Wall", "--autofix") G.Check(t.File("category/package")) t.CheckOutputLines( - "AUTOFIX: ~/category/package/distinfo:4: "+ + "AUTOFIX: ~/category/package/distinfo:3: "+ "Inserting a line \"SHA512 (package-1.0.txt) = f65f341b35981fda842b"+ "09b2c8af9bcdb7602a4c2e6fa1f7d41f0974d3e3122f268fc79d5a4af66358f513"+ - "3885cd1c165c916f80ab25e5d8d95db46f803c782c\" below this line.", - "AUTOFIX: ~/category/package/distinfo:4: "+ - "Inserting a line \"Size (package-1.0.txt) = 13 bytes\" below this line.") + "3885cd1c165c916f80ab25e5d8d95db46f803c782c\" above this line.", + "AUTOFIX: ~/category/package/distinfo:3: "+ + "Inserting a line \"Size (package-1.0.txt) = 13 bytes\" above this line.") } func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__algorithms_in_wrong_order(c *check.C) { @@ -651,7 +640,6 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__algorithms_in CvsID, "", "RMD160 (package-1.0.txt) = 1a88147a0344137404c63f3b695366eab869a98a", - "SHA1 (package-1.0.txt) = cd50d19784897085a8d0e3e413f8612b097c03f1", "Size (package-1.0.txt) = 13 bytes", "SHA512 (package-1.0.txt) = f65f341b35981fda842b09b2c8af9bcdb7602a4c2e6fa1f7"+ "d41f0974d3e3122f268fc79d5a4af66358f5133885cd1c165c916f80ab25e5d8d95db46f803c782c") @@ -665,8 +653,8 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__algorithms_in // This case doesn't happen in practice, therefore there's no autofix for it. t.CheckOutputLines( "ERROR: ~/category/package/distinfo:3: " + - "Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", " + - "got RMD160, SHA1, Size, SHA512.") + "Expected RMD160, SHA512, Size checksums for \"package-1.0.txt\", " + + "got RMD160, Size, SHA512.") } func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__some_algorithms_in_wrong_order(c *check.C) { @@ -689,10 +677,9 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__some_algorith // This case doesn't happen in practice, therefore there's no autofix for it. t.CheckOutputLines( - "ERROR: ~/category/package/distinfo:3: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"package-1.0.txt\", "+ - "got RMD160, Size, SHA512.", - "ERROR: ~/category/package/distinfo:3: Missing SHA1 hash for package-1.0.txt.") + "ERROR: ~/category/package/distinfo:3: " + + "Expected RMD160, SHA512, Size checksums for \"package-1.0.txt\", " + + "got RMD160, Size, SHA512.") } func (s *Suite) Test_distinfoLinesChecker_checkUnrecordedPatches(c *check.C) { @@ -764,21 +751,21 @@ func (s *Suite) Test_distinfoLinesChecker_checkGlobalDistfileMismatch(c *check.C t.CheckOutputLines( "ERROR: ~/category/package1/distinfo:3: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"distfile-1.0.tar.gz\", got SHA512.", + "Expected RMD160, SHA512, Size checksums for \"distfile-1.0.tar.gz\", got SHA512.", "ERROR: ~/category/package1/distinfo:4: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"distfile-1.1.tar.gz\", got SHA512.", + "Expected RMD160, SHA512, Size checksums for \"distfile-1.1.tar.gz\", got SHA512.", "ERROR: ~/category/package1/distinfo:5: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"patch-4.2.tar.gz\", got SHA512.", + "Expected RMD160, SHA512, Size checksums for \"patch-4.2.tar.gz\", got SHA512.", "ERROR: ~/category/package2/distinfo:3: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"distfile-1.0.tar.gz\", got SHA512.", + "Expected RMD160, SHA512, Size checksums for \"distfile-1.0.tar.gz\", got SHA512.", "ERROR: ~/category/package2/distinfo:3: "+ "The SHA512 hash for distfile-1.0.tar.gz is 1234567822222222, "+ "which conflicts with 1234567811111111 in ../../category/package1/distinfo:3.", "ERROR: ~/category/package2/distinfo:4: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"distfile-1.1.tar.gz\", got SHA512.", + "Expected RMD160, SHA512, Size checksums for \"distfile-1.1.tar.gz\", got SHA512.", "ERROR: ~/category/package2/distinfo:5: "+ - "Expected SHA1, RMD160, SHA512, Size checksums for \"encoding-error.tar.gz\", got SHA512.", + "Expected RMD160, SHA512, Size checksums for \"encoding-error.tar.gz\", got SHA512.", "ERROR: ~/category/package2/distinfo:5: "+ "The SHA512 hash for encoding-error.tar.gz contains a non-hex character.", @@ -968,13 +955,13 @@ func (s *Suite) Test_distinfoFileInfo_hasDistfileAlgorithms__code_coverage(c *ch G.Check(".") t.CheckOutputLines( - "ERROR: distinfo:3: Expected SHA1, RMD160, SHA512, Size checksums for "+ + "ERROR: distinfo:3: Expected RMD160, SHA512, Size checksums for "+ "\"dist-a.tar.gz\", got other, RMD160, SHA512, Size.", - "ERROR: distinfo:7: Expected SHA1, RMD160, SHA512, Size checksums for "+ + "ERROR: distinfo:7: Expected RMD160, SHA512, Size checksums for "+ "\"dist-b.tar.gz\", got SHA1, other, SHA512, Size.", - "ERROR: distinfo:11: Expected SHA1, RMD160, SHA512, Size checksums for "+ + "ERROR: distinfo:11: Expected RMD160, SHA512, Size checksums for "+ "\"dist-c.tar.gz\", got SHA1, RMD160, other, Size.", - "ERROR: distinfo:15: Expected SHA1, RMD160, SHA512, Size checksums for "+ + "ERROR: distinfo:15: Expected RMD160, SHA512, Size checksums for "+ "\"dist-d.tar.gz\", got SHA1, RMD160, SHA512, other.") } diff --git a/pkgtools/pkglint/files/package_test.go b/pkgtools/pkglint/files/package_test.go index b69d8881123..9bf058483da 100644 --- a/pkgtools/pkglint/files/package_test.go +++ b/pkgtools/pkglint/files/package_test.go @@ -498,6 +498,7 @@ func (s *Suite) Test_Package_load__extra_files(c *check.C) { "ERROR: gnu-style.mk:5: Unknown Makefile line format: \"endif\".", "ERROR: gnu-style.mk:1: Expected \""+MkCvsID+"\".", "WARN: gnu-style.mk:2: IS_GCC is defined but not used.", + "WARN: gnu-style.mk:2: Variable IS_GCC is overwritten in line 4.", // There is no warning about files/gnu-style.mk since pkglint // doesn't even attempt at guessing the file type. Files placed @@ -519,6 +520,7 @@ func (s *Suite) Test_Package_load__extra_files(c *check.C) { "ERROR: ../../category/other/gnu-style.mk:5: Unknown Makefile line format: \"endif\".", "ERROR: ../../category/other/gnu-style.mk:1: Expected \""+MkCvsID+"\".", "WARN: ../../category/other/gnu-style.mk:2: IS_GCC is defined but not used.", + "WARN: ../../category/other/gnu-style.mk:2: Variable IS_GCC is overwritten in line 4.", "ERROR: patches/patch-Makefile.mk: Contains no patch.", "WARN: patches/readme.mk: Patch files should be named \"patch-\", followed by letters, '-', '_', '.', and digits only.") @@ -1869,9 +1871,11 @@ func (s *Suite) Test_Package_checkfilePackageMakefile__redundancy_in_infra(c *ch G.Check("mk/redundant.mk") - // The redundancy check is only performed when a whole package - // is checked. Therefore nothing is reported here. - t.CheckOutputEmpty() + // The redundancy check applies both to package Makefiles and to + // makefile fragments that are given in the command line. + t.CheckOutputLines( + "NOTE: mk/redundant.mk:3: " + + "Definition of INFRA_REDUNDANT is redundant because of line 2.") // If the global checks are enabled, redundancy warnings from the // pkgsrc infrastructure are reported as well. diff --git a/pkgtools/pkglint/files/pkglint.go b/pkgtools/pkglint/files/pkglint.go index 757d6e922d8..6c6636bdf06 100644 --- a/pkgtools/pkglint/files/pkglint.go +++ b/pkgtools/pkglint/files/pkglint.go @@ -542,6 +542,9 @@ func CheckFileMk(filename CurrPath, pkg *Package) { } mklines.Check() + if pkg == nil || pkg.Includes(pkg.Rel(filename)) == nil { + NewRedundantScope().Check(mklines) + } mklines.SaveAutofixChanges() } diff --git a/pkgtools/pkglint/files/pkgsrc_test.go b/pkgtools/pkglint/files/pkgsrc_test.go index c2aa2dd7d82..6a4bb25f9d7 100644 --- a/pkgtools/pkglint/files/pkgsrc_test.go +++ b/pkgtools/pkglint/files/pkgsrc_test.go @@ -1301,7 +1301,7 @@ func (s *Suite) Test_Pkgsrc_guessVariableType__SKIP(c *check.C) { mklines := t.NewMkLines("filename.mk", MkCvsID, - "MY_CHECK_SKIP=\t*.c \"bad*pathname\"", + "MY_CHECK_SKIP=\t*.c \"quoted*pathname\"", "MY_CHECK_SKIP+=\t*.cpp", ".if ${MY_CHECK_SKIP}", ".endif") @@ -1313,16 +1313,14 @@ func (s *Suite) Test_Pkgsrc_guessVariableType__SKIP(c *check.C) { t.CheckEquals(vartype.EffectivePermissions("filename.mk"), aclpAllRuntime) // The permissions for MY_CHECK_SKIP say aclpAllRuntime, which excludes - // aclpUseLoadtime. Therefore there should be a warning about the VarUse in + // aclpUseLoadtime. Therefore, there should be a warning about the VarUse in // the .if line. As of March 2019, pkglint skips the permissions check for // guessed variables since that variable might have an entirely different // meaning; see MkVarUseChecker.checkPermissions. // // There is no warning for the += operator in line 3 since the variable type // (although guessed) is a list of things, and lists may be appended to. - t.CheckOutputLines( - "WARN: filename.mk:2: The pathname pattern \"\\\"bad*pathname\\\"\" " + - "contains the invalid characters \"\\\"\\\"\".") + t.CheckOutputEmpty() } func (s *Suite) Test_Pkgsrc_checkToplevelUnusedLicenses(c *check.C) { diff --git a/pkgtools/pkglint/files/redundantscope_test.go b/pkgtools/pkglint/files/redundantscope_test.go index 598762b7a64..b9a0c815d12 100644 --- a/pkgtools/pkglint/files/redundantscope_test.go +++ b/pkgtools/pkglint/files/redundantscope_test.go @@ -1470,6 +1470,29 @@ func (s *Suite) Test_RedundantScope__is_relevant_for_infrastructure(c *check.C) "Variable PKG_OPTIONS is overwritten in line 3.") } +// All makefile fragments that are not directly or indirectly included by the +// package Makefile need to be checked separately for redundant variable +// assignments since these would otherwise go unnoticed. +// +// See CheckFileMk and Package.checkfilePackageMakefile. +func (s *Suite) Test_RedundantScope__standalone(c *check.C) { + t := s.Init(c) + + t.SetUpPackage("category/package") + t.CreateFileLines("category/package/build.mk", + MkCvsID, + "", + "_PKG_VARS.package=\tPACKAGE_REQD", + "_PKG_VARS.package=\tCONFIGURE_DIRS") + t.FinishSetUp() + + G.Check(t.File("category/package")) + + t.CheckOutputLines( + "WARN: ~/category/package/build.mk:3: " + + "Variable _PKG_VARS.package is overwritten in line 4.") +} + // Branch coverage for info.vari.IsConstant(). The other tests typically // make a variable non-constant by adding conditional assignments between // .if/.endif. But there are other ways. The output of shell commands is diff --git a/pkgtools/pkglint/files/vardefs.go b/pkgtools/pkglint/files/vardefs.go index 012288c071d..948305ea5e1 100644 --- a/pkgtools/pkglint/files/vardefs.go +++ b/pkgtools/pkglint/files/vardefs.go @@ -1381,6 +1381,7 @@ func (reg *VarTypeRegistry) Init(src *Pkgsrc) { reg.pkglist("MESSAGE_SRC", BtPathname) reg.pkglist("MESSAGE_SUBST", BtShellWord) + reg.pkgloadlist("MESON_REQD", BtVersion) reg.pkg("META_PACKAGE", BtYes) reg.syslist("MISSING_FEATURES", BtIdentifierDirect) reg.pkglist("MYSQL_VERSIONS_ACCEPTED", mysqlVersions) diff --git a/pkgtools/pkglint/files/vartypecheck.go b/pkgtools/pkglint/files/vartypecheck.go index 71e41860f25..5fc039e3310 100644 --- a/pkgtools/pkglint/files/vartypecheck.go +++ b/pkgtools/pkglint/files/vartypecheck.go @@ -980,9 +980,13 @@ func (cv *VartypeCheck) Pathlist() { // PathPattern is a shell pattern for pathnames, possibly including slashes. // +// Spaces, backslashes and quotes are rarely needed but still allowed. +// Without these characters, the patterns would need to use '?', which does +// not represent the intended patterns exactly. +// // See FilePattern. func (cv *VartypeCheck) PathPattern() { - invalid := replaceAll(cv.ValueNoVar, `[!%*+,\-./0-9?@A-Z\[\]_a-z~]`, "") + invalid := replaceAll(cv.ValueNoVar, `[ "%'*+,\-./0-9?@A-Z\[\\\]_a-z~]`, "") if invalid == "" { return } diff --git a/pkgtools/pkglint/files/vartypecheck_test.go b/pkgtools/pkglint/files/vartypecheck_test.go index bfc6637c471..0a572ad6dbe 100644 --- a/pkgtools/pkglint/files/vartypecheck_test.go +++ b/pkgtools/pkglint/files/vartypecheck_test.go @@ -2442,6 +2442,20 @@ func (s *Suite) Test_VartypeCheck_WrksrcPathPattern(c *check.C) { vt.Output( "AUTOFIX: filename.mk:12: Replacing \"${WRKSRC}/\" with \"\".") + + t.SetUpCommandLine("-Wall") + + // Seen in devel/meson/Makefile. + vt.Varname("REPLACE_PYTHON") + vt.Op(opAssign) + vt.Values( + "test\\ cases/*/*/*.py", + "test\" \"cases/*/*/*.py", + "test' 'cases/*/*/*.py", + // This matches the single file literally named '*.py'. + "'test cases/*/*/*.py'") + + vt.OutputEmpty() } func (s *Suite) Test_VartypeCheck_WrksrcSubdirectory(c *check.C) { |