diff options
author | rillig <rillig@pkgsrc.org> | 2020-06-12 19:14:45 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2020-06-12 19:14:45 +0000 |
commit | b46b346d68dde0d5086b9aa40f0c2606fb23bc56 (patch) | |
tree | 1476ced4958a05e8a7a7c8f597b14314591274ea | |
parent | 80a8092fe8148dfb170afdc8ee571bf94dbe555e (diff) | |
download | pkgsrc-b46b346d68dde0d5086b9aa40f0c2606fb23bc56.tar.gz |
pkgtools/pkglint: update to 20.1.16
Changes since 20.1.15:
When a package adds an additional version requirement for another
package, it must do so using BUILDLINK_API_DEPENDS instead of
BUILDLINK_ABI_DEPENDS. Most packages already do this.
When a values is appended to an undefined variable using the += operator,
bmake does not add a space before, and pkglint caught up to do the same.
This change has no practical consequences though.
As always, a bit of refactoring. The method names of MkAssignChecker
contained the redundant word "varassign".
-rw-r--r-- | pkgtools/pkglint/Makefile | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/buildlink3_test.go | 1 | ||||
-rw-r--r-- | pkgtools/pkglint/files/homepage_test.go | 12 | ||||
-rw-r--r-- | pkgtools/pkglint/files/mkassignchecker.go | 117 | ||||
-rw-r--r-- | pkgtools/pkglint/files/mkassignchecker_test.go | 117 | ||||
-rw-r--r-- | pkgtools/pkglint/files/mkline_test.go | 16 | ||||
-rw-r--r-- | pkgtools/pkglint/files/mklinechecker.go | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/mklines_test.go | 24 | ||||
-rw-r--r-- | pkgtools/pkglint/files/mkvarusechecker.go | 2 | ||||
-rw-r--r-- | pkgtools/pkglint/files/mkvarusechecker_test.go | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/package.go | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/redundantscope_test.go | 1 | ||||
-rw-r--r-- | pkgtools/pkglint/files/shell_test.go | 2 | ||||
-rw-r--r-- | pkgtools/pkglint/files/util.go | 92 | ||||
-rw-r--r-- | pkgtools/pkglint/files/util_test.go | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/var.go | 7 | ||||
-rw-r--r-- | pkgtools/pkglint/files/var_test.go | 4 | ||||
-rw-r--r-- | pkgtools/pkglint/files/vartypecheck_test.go | 22 |
18 files changed, 282 insertions, 155 deletions
diff --git a/pkgtools/pkglint/Makefile b/pkgtools/pkglint/Makefile index 9966cc774a4..513a2a18e2c 100644 --- a/pkgtools/pkglint/Makefile +++ b/pkgtools/pkglint/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.654 2020/06/07 15:49:23 rillig Exp $ +# $NetBSD: Makefile,v 1.655 2020/06/12 19:14:45 rillig Exp $ -PKGNAME= pkglint-20.1.15 +PKGNAME= pkglint-20.1.16 CATEGORIES= pkgtools DISTNAME= tools MASTER_SITES= ${MASTER_SITE_GITHUB:=golang/} diff --git a/pkgtools/pkglint/files/buildlink3_test.go b/pkgtools/pkglint/files/buildlink3_test.go index c5b374951aa..38989b159a6 100644 --- a/pkgtools/pkglint/files/buildlink3_test.go +++ b/pkgtools/pkglint/files/buildlink3_test.go @@ -305,6 +305,7 @@ func (s *Suite) Test_CheckLinesBuildlink3Mk__name_mismatch_abi_api(c *check.C) { CheckLinesBuildlink3Mk(mklines) t.CheckOutputLines( + "ERROR: buildlink3.mk:10: Packages must only require API versions, not ABI versions of dependencies.", "WARN: buildlink3.mk:9: Package name mismatch between ABI \"hs-X12\" and API \"hs-X11\" (from line 8).", "WARN: buildlink3.mk:10: Only buildlink variables for \"hs-X11\", not \"hs-X12\" may be set in this file.") } diff --git a/pkgtools/pkglint/files/homepage_test.go b/pkgtools/pkglint/files/homepage_test.go index ca7ae4f9efc..6566461e15f 100644 --- a/pkgtools/pkglint/files/homepage_test.go +++ b/pkgtools/pkglint/files/homepage_test.go @@ -64,8 +64,8 @@ func (s *Suite) Test_HomepageChecker_checkBasedOnMasterSites(c *check.C) { vt.Output( "WARN: filename.mk:11: HOMEPAGE should not be defined in terms of MASTER_SITEs.") - pkg.vars.v("MASTER_SITES").firstDef = nil - pkg.vars.v("MASTER_SITES").lastDef = nil + pkg.vars.create("MASTER_SITES").firstDef = nil + pkg.vars.create("MASTER_SITES").lastDef = nil pkg.vars.Define("MASTER_SITES", t.NewMkLine(pkg.File("Makefile"), 5, "MASTER_SITES=\thttps://cdn.NetBSD.org/pub/pkgsrc/distfiles/")) @@ -76,8 +76,8 @@ func (s *Suite) Test_HomepageChecker_checkBasedOnMasterSites(c *check.C) { "WARN: filename.mk:21: HOMEPAGE should not be defined in terms of MASTER_SITEs. " + "Use https://cdn.NetBSD.org/pub/pkgsrc/distfiles/ directly.") - pkg.vars.v("MASTER_SITES").firstDef = nil - pkg.vars.v("MASTER_SITES").lastDef = nil + pkg.vars.create("MASTER_SITES").firstDef = nil + pkg.vars.create("MASTER_SITES").lastDef = nil pkg.vars.Define("MASTER_SITES", t.NewMkLine(pkg.File("Makefile"), 5, "MASTER_SITES=\t${MASTER_SITE_GITHUB}")) @@ -89,8 +89,8 @@ func (s *Suite) Test_HomepageChecker_checkBasedOnMasterSites(c *check.C) { vt.Output( "WARN: filename.mk:31: HOMEPAGE should not be defined in terms of MASTER_SITEs.") - pkg.vars.v("MASTER_SITES").firstDef = nil - pkg.vars.v("MASTER_SITES").lastDef = nil + pkg.vars.create("MASTER_SITES").firstDef = nil + pkg.vars.create("MASTER_SITES").lastDef = nil pkg.vars.Define("MASTER_SITES", t.NewMkLine(pkg.File("Makefile"), 5, "MASTER_SITES=\t# none")) diff --git a/pkgtools/pkglint/files/mkassignchecker.go b/pkgtools/pkglint/files/mkassignchecker.go index 417c1b295c2..e2b074ce5f7 100644 --- a/pkgtools/pkglint/files/mkassignchecker.go +++ b/pkgtools/pkglint/files/mkassignchecker.go @@ -15,26 +15,27 @@ func NewMkAssignChecker(mkLine *MkLine, mkLines *MkLines) *MkAssignChecker { return &MkAssignChecker{MkLine: mkLine, MkLines: mkLines} } -func (ck *MkAssignChecker) checkVarassign() { - ck.checkVarassignLeft() - ck.checkVarassignOp() - ck.checkVarassignRight() +func (ck *MkAssignChecker) check() { + ck.checkLeft() + ck.checkOp() + ck.checkRight() } -// checkVarassignLeft checks everything to the left of the assignment operator. -func (ck *MkAssignChecker) checkVarassignLeft() { +// checkLeft checks everything to the left of the assignment operator. +func (ck *MkAssignChecker) checkLeft() { varname := ck.MkLine.Varname() if hasPrefix(varname, "_") && !G.Infrastructure && G.Pkgsrc.vartypes.Canon(varname) == nil { ck.MkLine.Warnf("Variable names starting with an underscore (%s) are reserved for internal pkgsrc use.", varname) } - ck.checkVarassignLeftNotUsed() - ck.checkVarassignLeftDeprecated() - ck.checkVarassignLeftBsdPrefs() - if !ck.checkVarassignLeftUserSettable() { - ck.checkVarassignLeftPermissions() + ck.checkLeftNotUsed() + ck.checkLeftDeprecated() + ck.checkLeftBsdPrefs() + if !ck.checkLeftUserSettable() { + ck.checkLeftPermissions() + ck.checkLeftAbiDepends() } - ck.checkVarassignLeftRationale() + ck.checkLeftRationale() NewMkLineChecker(ck.MkLines, ck.MkLine).checkTextVarUse( ck.MkLine.Varname(), @@ -42,10 +43,10 @@ func (ck *MkAssignChecker) checkVarassignLeft() { VucLoadTime) } -// checkVarassignLeftNotUsed checks whether the left-hand side of a variable +// checkLeftNotUsed checks whether the left-hand side of a variable // assignment is not used. If it is unused and also doesn't have a predefined // data type, it may be a spelling mistake. -func (ck *MkAssignChecker) checkVarassignLeftNotUsed() { +func (ck *MkAssignChecker) checkLeftNotUsed() { varname := ck.MkLine.Varname() varcanon := varnameCanon(varname) @@ -90,7 +91,7 @@ func (ck *MkAssignChecker) checkVarassignLeftNotUsed() { "see mk/subst.mk for an example of such a documentation comment.") } -func (ck *MkAssignChecker) checkVarassignLeftDeprecated() { +func (ck *MkAssignChecker) checkLeftDeprecated() { varname := ck.MkLine.Varname() if fix := G.Pkgsrc.Deprecated[varname]; fix != "" { ck.MkLine.Warnf("Definition of %s is deprecated. %s", varname, fix) @@ -99,7 +100,7 @@ func (ck *MkAssignChecker) checkVarassignLeftDeprecated() { } } -func (ck *MkAssignChecker) checkVarassignLeftBsdPrefs() { +func (ck *MkAssignChecker) checkLeftBsdPrefs() { mkline := ck.MkLine switch mkline.Varcanon() { @@ -147,10 +148,10 @@ func (ck *MkAssignChecker) checkVarassignLeftBsdPrefs() { "bsd.prefs.mk file, which will take care of everything.") } -// checkVarassignLeftUserSettable checks whether a package defines a +// checkLeftUserSettable checks whether a package defines a // variable that is marked as user-settable since it is defined in // mk/defaults/mk.conf. -func (ck *MkAssignChecker) checkVarassignLeftUserSettable() bool { +func (ck *MkAssignChecker) checkLeftUserSettable() bool { mkline := ck.MkLine varname := mkline.Varname() @@ -198,11 +199,11 @@ func (ck *MkAssignChecker) checkVarassignLeftUserSettable() bool { return true } -// checkVarassignLeftPermissions checks the permissions for the left-hand side +// checkLeftPermissions checks the permissions for the left-hand side // of a variable assignment line. // // See checkPermissions. -func (ck *MkAssignChecker) checkVarassignLeftPermissions() { +func (ck *MkAssignChecker) checkLeftPermissions() { if !G.WarnPerm { return } @@ -273,7 +274,43 @@ func (ck *MkAssignChecker) checkVarassignLeftPermissions() { } } -func (ck *MkAssignChecker) checkVarassignLeftRationale() { +func (ck *MkAssignChecker) checkLeftAbiDepends() { + mkline := ck.MkLine + + varname := mkline.Varname() + if !hasPrefix(varname, "BUILDLINK_ABI_DEPENDS.") { + return + } + + basename := mkline.Basename + if basename == "buildlink3.mk" { + varparam := varnameParam(varname) + bl3id := "" + for _, bl3line := range ck.MkLines.mklines { + if bl3line.IsVarassign() && bl3line.Varname() == "BUILDLINK_TREE" { + bl3id = bl3line.Value() + break + } + } + if varparam == bl3id { + return + } + } + + fix := mkline.Autofix() + fix.Errorf("Packages must only require API versions, not ABI versions of dependencies.") + fix.Explain( + "When building a package from the sources,", + "the version of the installed package does not matter.", + "That version is specified by BUILDLINK_ABI_VERSION.", + "", + "The only version that matters is the API of the dependency,", + "which is selected by specifying BUILDLINK_API_DEPENDS.") + fix.Replace("BUILDLINK_ABI_DEPENDS", "BUILDLINK_API_DEPENDS") + fix.Apply() +} + +func (ck *MkAssignChecker) checkLeftRationale() { if !G.WarnExtra { return } @@ -305,11 +342,11 @@ func (ck *MkAssignChecker) checkVarassignLeftRationale() { "* has it been reported upstream?") } -func (ck *MkAssignChecker) checkVarassignOp() { - ck.checkVarassignOpShell() +func (ck *MkAssignChecker) checkOp() { + ck.checkOpShell() } -func (ck *MkAssignChecker) checkVarassignOpShell() { +func (ck *MkAssignChecker) checkOpShell() { mkline := ck.MkLine switch { @@ -356,8 +393,8 @@ func (ck *MkAssignChecker) checkVarassignOpShell() { "or .for directive.") } -// checkVarassignLeft checks everything to the right of the assignment operator. -func (ck *MkAssignChecker) checkVarassignRight() { +// checkLeft checks everything to the right of the assignment operator. +func (ck *MkAssignChecker) checkRight() { mkline := ck.MkLine varname := mkline.Varname() op := mkline.Op() @@ -372,12 +409,12 @@ func (ck *MkAssignChecker) checkVarassignRight() { mkLineChecker.checkText(value) mkLineChecker.checkVartype(varname, op, value, comment) - ck.checkVarassignMisc() + ck.checkMisc() - ck.checkVarassignRightVaruse() + ck.checkRightVaruse() } -func (ck *MkAssignChecker) checkVarassignRightCategory() { +func (ck *MkAssignChecker) checkRightCategory() { mkline := ck.MkLine if mkline.Op() != opAssign && mkline.Op() != opAssignDefault { return @@ -403,7 +440,7 @@ func (ck *MkAssignChecker) checkVarassignRightCategory() { fix.Apply() } -func (ck *MkAssignChecker) checkVarassignMisc() { +func (ck *MkAssignChecker) checkMisc() { mkline := ck.MkLine varname := mkline.Varname() value := mkline.Value() @@ -413,7 +450,7 @@ func (ck *MkAssignChecker) checkVarassignMisc() { } if varname == "PYTHON_VERSIONS_ACCEPTED" { - ck.checkVarassignDecreasingVersions() + ck.checkDecreasingVersions() } if mkline.Comment() == " defined" && !hasSuffix(varname, "_MK") && !hasSuffix(varname, "_COMMON") { @@ -444,14 +481,16 @@ func (ck *MkAssignChecker) checkVarassignMisc() { if varname == "PKG_SKIP_REASON" && ck.MkLines.indentation.DependsOn("OPSYS") { // TODO: Provide autofix for simple cases, like ".if ${OPSYS} == SunOS". + // This needs support for high-level refactoring tools though. + // As of June 2020, refactoring is limited to text replacements in single lines. mkline.Notef("Consider setting NOT_FOR_PLATFORM instead of " + "PKG_SKIP_REASON depending on ${OPSYS}.") } - ck.checkVarassignMiscRedundantInstallationDirs() + ck.checkMiscRedundantInstallationDirs() } -func (ck *MkAssignChecker) checkVarassignDecreasingVersions() { +func (ck *MkAssignChecker) checkDecreasingVersions() { mkline := ck.MkLine strVersions := mkline.Fields() intVersions := make([]int, len(strVersions)) @@ -475,7 +514,7 @@ func (ck *MkAssignChecker) checkVarassignDecreasingVersions() { } } -func (ck *MkAssignChecker) checkVarassignMiscRedundantInstallationDirs() { +func (ck *MkAssignChecker) checkMiscRedundantInstallationDirs() { mkline := ck.MkLine varname := mkline.Varname() pkg := ck.MkLines.pkg @@ -502,10 +541,10 @@ func (ck *MkAssignChecker) checkVarassignMiscRedundantInstallationDirs() { } } -// checkVarassignRightVaruse checks that in a variable assignment, +// checkRightVaruse checks that in a variable assignment, // each variable used on the right-hand side of the assignment operator // has the correct data type and quoting. -func (ck *MkAssignChecker) checkVarassignRightVaruse() { +func (ck *MkAssignChecker) checkRightVaruse() { if trace.Tracing { defer trace.Call0()() } @@ -524,16 +563,16 @@ func (ck *MkAssignChecker) checkVarassignRightVaruse() { } if vartype != nil && vartype.IsShell() { - ck.checkVarassignVaruseShell(vartype, time) + ck.checkVaruseShell(vartype, time) } else { mkLineChecker := NewMkLineChecker(ck.MkLines, ck.MkLine) mkLineChecker.checkTextVarUse(ck.MkLine.Value(), vartype, time) } } -// checkVarassignVaruseShell is very similar to checkVarassignRightVaruse, they just differ +// checkVaruseShell is very similar to checkRightVaruse, they just differ // in the way they determine isWordPart. -func (ck *MkAssignChecker) checkVarassignVaruseShell(vartype *Vartype, time VucTime) { +func (ck *MkAssignChecker) checkVaruseShell(vartype *Vartype, time VucTime) { if trace.Tracing { defer trace.Call(vartype, time)() } diff --git a/pkgtools/pkglint/files/mkassignchecker_test.go b/pkgtools/pkglint/files/mkassignchecker_test.go index 7164f4ae625..3bf22bb2902 100644 --- a/pkgtools/pkglint/files/mkassignchecker_test.go +++ b/pkgtools/pkglint/files/mkassignchecker_test.go @@ -10,14 +10,14 @@ func (s *Suite) Test_NewMkAssignChecker(c *check.C) { ck := NewMkAssignChecker(mklines.mklines[0], mklines) - ck.checkVarassign() + ck.check() t.CheckOutputLines( "WARN: filename.mk:1: VAR is defined but not used.", "WARN: filename.mk:1: OTHER is used but not defined.") } -func (s *Suite) Test_MkAssignChecker_checkVarassign(c *check.C) { +func (s *Suite) Test_MkAssignChecker_check(c *check.C) { t := s.Init(c) t.SetUpVartypes() @@ -34,7 +34,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassign(c *check.C) { // Pkglint once interpreted all lists as consisting of shell tokens, // splitting this URL at the ampersand. -func (s *Suite) Test_MkAssignChecker_checkVarassign__URL_with_shell_special_characters(c *check.C) { +func (s *Suite) Test_MkAssignChecker_check__URL_with_shell_special_characters(c *check.C) { t := s.Init(c) pkg := NewPackage(t.File("graphics/gimp-fix-ca")) @@ -48,7 +48,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassign__URL_with_shell_special_char t.CheckOutputEmpty() } -func (s *Suite) Test_MkAssignChecker_checkVarassign__list(c *check.C) { +func (s *Suite) Test_MkAssignChecker_check__list(c *check.C) { t := s.Init(c) t.SetUpMasterSite("MASTER_SITE_GITHUB", "https://github.com/") @@ -82,7 +82,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassign__list(c *check.C) { "") } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeft(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeft(c *check.C) { t := s.Init(c) mklines := t.NewMkLines("module.mk", @@ -100,7 +100,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeft(c *check.C) { // Files from the pkgsrc infrastructure may define and use variables // whose name starts with an underscore. -func (s *Suite) Test_MkAssignChecker_checkVarassignLeft__infrastructure(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeft__infrastructure(c *check.C) { t := s.Init(c) t.SetUpPkgsrc() @@ -116,7 +116,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeft__infrastructure(c *check "WARN: ~/mk/infra.mk:2: _VARNAME is defined but not used.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeft__documented_underscore(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeft__documented_underscore(c *check.C) { t := s.Init(c) t.SetUpPkgsrc() @@ -130,7 +130,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeft__documented_underscore(c t.CheckOutputEmpty() } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftNotUsed__procedure_call(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftNotUsed__procedure_call(c *check.C) { t := s.Init(c) t.CreateFileLines("mk/pkg-build-options.mk") @@ -156,7 +156,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftNotUsed__procedure_call(c "WARN: ~/category/package/filename.mk:6: VAR is defined but not used.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftNotUsed__procedure_call_no_tracing(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftNotUsed__procedure_call_no_tracing(c *check.C) { t := s.Init(c) t.DisableTracing() // Just for code coverage @@ -172,7 +172,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftNotUsed__procedure_call_n t.CheckOutputEmpty() } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftNotUsed__infra(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftNotUsed__infra(c *check.C) { t := s.Init(c) t.CreateFileLines("mk/infra.mk", @@ -200,7 +200,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftNotUsed__infra(c *check.C "WARN: ~/category/package/Makefile:22: UNDOCUMENTED is used but not defined.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftDeprecated(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftDeprecated(c *check.C) { t := s.Init(c) t.SetUpPkgsrc() @@ -211,7 +211,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftDeprecated(c *check.C) { varname+"=\t# none") ck := NewMkAssignChecker(mklines.mklines[0], mklines) - ck.checkVarassignLeftDeprecated() + ck.checkLeftDeprecated() t.CheckOutput(diagnostics) } @@ -224,7 +224,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftDeprecated(c *check.C) { nil...) } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftBsdPrefs(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftBsdPrefs(c *check.C) { t := s.Init(c) t.SetUpCommandLine("-Wall", "--only", "bsd.prefs.mk") @@ -257,7 +257,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftBsdPrefs(c *check.C) { // Up to 2019-12-03, pkglint didn't issue a warning if a default assignment // to a package-settable variable appeared before one to a user-settable // variable. This was a mistake. -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftBsdPrefs__first_time(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftBsdPrefs__first_time(c *check.C) { t := s.Init(c) t.SetUpVartypes() @@ -276,7 +276,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftBsdPrefs__first_time(c *c "be given a default value by any package.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftBsdPrefs__vartype_nil(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftBsdPrefs__vartype_nil(c *check.C) { t := s.Init(c) mklines := t.NewMkLines("builtin.mk", @@ -290,7 +290,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftBsdPrefs__vartype_nil(c * "WARN: builtin.mk:2: Please include \"../../mk/bsd.prefs.mk\" before using \"?=\".") } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftUserSettable(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftUserSettable(c *check.C) { t := s.Init(c) // TODO: Allow CreateFileLines before SetUpPackage, since it matches @@ -335,7 +335,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftUserSettable(c *check.C) "which differs from the default value \"default\" from mk/defaults/mk.conf.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftUserSettable__before_prefs(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftUserSettable__before_prefs(c *check.C) { t := s.Init(c) t.SetUpCommandLine("-Wall", "--explain") @@ -358,7 +358,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftUserSettable__before_pref "") } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftUserSettable__after_prefs(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftUserSettable__after_prefs(c *check.C) { t := s.Init(c) t.SetUpCommandLine("-Wall", "--explain") @@ -377,7 +377,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftUserSettable__after_prefs "NOTE: Makefile:21: Redundant definition for AFTER from mk/defaults/mk.conf.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftUserSettable__vartype_nil(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftUserSettable__vartype_nil(c *check.C) { t := s.Init(c) t.CreateFileLines("category/package/allVars.mk", @@ -405,7 +405,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftUserSettable__vartype_nil "WARN: Makefile:20: USER_SETTABLE is defined but not used.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftPermissions__hacks_mk(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftPermissions__hacks_mk(c *check.C) { t := s.Init(c) t.SetUpVartypes() @@ -422,7 +422,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftPermissions__hacks_mk(c * t.CheckOutputEmpty() } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftPermissions(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftPermissions(c *check.C) { t := s.Init(c) t.SetUpVartypes() @@ -466,7 +466,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftPermissions(c *check.C) { "but not options.mk.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftPermissions__no_tracing(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftPermissions__no_tracing(c *check.C) { t := s.Init(c) t.SetUpVartypes() @@ -483,7 +483,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftPermissions__no_tracing(c // languages like Perl or Python that suggest certain licenses. // // The default license is typically set in a Makefile.common or module.mk. -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftPermissions__license_default(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftPermissions__license_default(c *check.C) { t := s.Init(c) t.SetUpPkgsrc() @@ -502,7 +502,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftPermissions__license_defa } // Don't check the permissions for infrastructure files since they have their own rules. -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftPermissions__infrastructure(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkLeftPermissions__infrastructure(c *check.C) { t := s.Init(c) t.SetUpVartypes() @@ -517,7 +517,26 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftPermissions__infrastructu t.CheckOutputEmpty() } -func (s *Suite) Test_MkAssignChecker_checkVarassignLeftRationale(c *check.C) { +// Seen in x11/gtkmm3 before 2020-06-07. +func (s *Suite) Test_MkAssignChecker_checkLeftAbiDepends(c *check.C) { + t := s.Init(c) + + t.SetUpPackage("category/package", + "BUILDLINK_ABI_DEPENDS.lib+=\tlib>=1.0") + t.Chdir("category/package") + t.FinishSetUp() + + G.Check(".") + + // It may be a good idea to not only check the buildlink identifier + // for ${BUILDLINK_PREFIX.*} but also for appending to + // BUILDLINK_API_DEPENDS and BUILDLINK_ABI_DEPENDS. + t.CheckOutputLines( + "ERROR: Makefile:20: Packages must only require API versions, " + + "not ABI versions of dependencies.") +} + +func (s *Suite) Test_MkAssignChecker_checkLeftRationale(c *check.C) { t := s.Init(c) t.SetUpVartypes() @@ -608,7 +627,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignLeftRationale(c *check.C) { nil...) } -func (s *Suite) Test_MkAssignChecker_checkVarassignOp(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkOp(c *check.C) { t := s.Init(c) t.SetUpTool("uname", "UNAME", AfterPrefsMk) @@ -630,7 +649,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignOp(c *check.C) { "bsd.prefs.mk has to be included before.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignOpShell(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkOpShell(c *check.C) { t := s.Init(c) t.SetUpTool("uname", "UNAME", AfterPrefsMk) @@ -706,7 +725,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignOpShell(c *check.C) { "WARN: ~/category/package/standalone.mk:15: Please use \"${ECHO}\" instead of \"echo\".") } -func (s *Suite) Test_MkAssignChecker_checkVarassignRight(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRight(c *check.C) { t := s.Init(c) t.SetUpVartypes() @@ -715,7 +734,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRight(c *check.C) { mklines.ForEach(func(mkline *MkLine) { ck := NewMkAssignChecker(mkline, mklines) - ck.checkVarassignRight() + ck.checkRight() }) // No warning about the UNKNOWN variable on the left-hand side, @@ -726,7 +745,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRight(c *check.C) { "WARN: filename.mk:1: Unknown shell command \"make\".") } -func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__none(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRightCategory__none(c *check.C) { t := s.Init(c) t.SetUpPackage("obscure/package", @@ -738,7 +757,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__none(c *check. t.CheckOutputEmpty() } -func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__indirect(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRightCategory__indirect(c *check.C) { t := s.Init(c) t.SetUpPackage("obscure/package", @@ -756,7 +775,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__indirect(c *ch "Invalid category \"${PKGPATH:C,/.*,,}\".") } -func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__wrong(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRightCategory__wrong(c *check.C) { t := s.Init(c) t.SetUpPackage("obscure/package", @@ -769,7 +788,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__wrong(c *check "WARN: ~/obscure/package/Makefile:5: The primary category should be \"obscure\", not \"perl5\".") } -func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__wrong_in_package_directory(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRightCategory__wrong_in_package_directory(c *check.C) { t := s.Init(c) t.SetUpPackage("obscure/package", @@ -785,7 +804,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__wrong_in_packa // Allow any primary category in "packages" from regress/*. // These packages won't be installed in a regular pkgsrc installation anyway. -func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__regress(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRightCategory__regress(c *check.C) { t := s.Init(c) t.SetUpPackage("regress/regress-package", @@ -802,7 +821,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__regress(c *che t.CheckOutputEmpty() } -func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__append(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRightCategory__append(c *check.C) { t := s.Init(c) t.SetUpPackage("obscure/package", @@ -817,7 +836,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__append(c *chec t.CheckOutputEmpty() } -func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__default(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRightCategory__default(c *check.C) { t := s.Init(c) t.SetUpPackage("obscure/package", @@ -831,7 +850,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__default(c *che "WARN: ~/obscure/package/Makefile:5: The primary category should be \"obscure\", not \"perl5\".") } -func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__autofix(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRightCategory__autofix(c *check.C) { t := s.Init(c) t.SetUpCommandLine("-Wall", "--autofix") @@ -846,7 +865,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__autofix(c *che "Replacing \"perl5 obscure\" with \"obscure perl5\".") } -func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__third(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRightCategory__third(c *check.C) { t := s.Init(c) t.SetUpPackage("obscure/package", @@ -865,7 +884,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__third(c *check t.CheckOutputEmpty() } -func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__other_file(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRightCategory__other_file(c *check.C) { t := s.Init(c) t.SetUpPackage("obscure/package", @@ -885,7 +904,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRightCategory__other_file(c * "The primary category should be \"obscure\", not \"perl5\".") } -func (s *Suite) Test_MkAssignChecker_checkVarassignMisc(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkMisc(c *check.C) { t := s.Init(c) t.SetUpPkgsrc() @@ -946,7 +965,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignMisc(c *check.C) { "as it includes the PKGREVISION. Please use PKGVERSION_NOREV instead.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignMisc__multiple_inclusion_guards(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkMisc__multiple_inclusion_guards(c *check.C) { t := s.Init(c) t.SetUpPkgsrc() @@ -977,7 +996,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignMisc__multiple_inclusion_guar "instead of \"# defined\".") } -func (s *Suite) Test_MkAssignChecker_checkVarassignDecreasingVersions(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkDecreasingVersions(c *check.C) { t := s.Init(c) t.SetUpVartypes() @@ -996,7 +1015,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignDecreasingVersions(c *check.C mklines.Check() // Half of these warnings are from VartypeCheck.Enum, - // the other half are from checkVarassignDecreasingVersions. + // the other half are from checkDecreasingVersions. // Strictly speaking some of them are redundant, but that's ok. // They all need to be fixed in the end. t.CheckOutputLines( @@ -1016,7 +1035,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignDecreasingVersions(c *check.C "Use one of { 27 36 37 38 } instead.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignMiscRedundantInstallationDirs__AUTO_MKDIRS_yes(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkMiscRedundantInstallationDirs__AUTO_MKDIRS_yes(c *check.C) { t := s.Init(c) t.SetUpPackage("category/package", @@ -1037,7 +1056,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignMiscRedundantInstallationDirs "The directory \"man\" is redundant in INSTALLATION_DIRS.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignMiscRedundantInstallationDirs__AUTO_MKDIRS_no(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkMiscRedundantInstallationDirs__AUTO_MKDIRS_no(c *check.C) { t := s.Init(c) t.SetUpPackage("category/package", @@ -1054,7 +1073,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignMiscRedundantInstallationDirs t.CheckOutputEmpty() } -func (s *Suite) Test_MkAssignChecker_checkVarassignMiscRedundantInstallationDirs__absolute(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkMiscRedundantInstallationDirs__absolute(c *check.C) { t := s.Init(c) t.SetUpPackage("category/package", @@ -1074,7 +1093,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignMiscRedundantInstallationDirs "must be relative to ${PREFIX}.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignRightVaruse(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkRightVaruse(c *check.C) { t := s.Init(c) t.SetUpVartypes() @@ -1090,7 +1109,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignRightVaruse(c *check.C) { "NOTE: module.mk:2: The :Q modifier isn't necessary for ${LOCALBASE} here.") } -func (s *Suite) Test_MkAssignChecker_checkVarassignVaruseShell(c *check.C) { +func (s *Suite) Test_MkAssignChecker_checkVaruseShell(c *check.C) { t := s.Init(c) mklines := t.NewMkLines("filename.mk", @@ -1098,7 +1117,7 @@ func (s *Suite) Test_MkAssignChecker_checkVarassignVaruseShell(c *check.C) { mklines.ForEach(func(mkline *MkLine) { ck := NewMkAssignChecker(mkline, mklines) - ck.checkVarassignRight() + ck.checkRight() }) t.CheckOutputLines( diff --git a/pkgtools/pkglint/files/mkline_test.go b/pkgtools/pkglint/files/mkline_test.go index a4510c4a4d2..2e77fae2dc0 100644 --- a/pkgtools/pkglint/files/mkline_test.go +++ b/pkgtools/pkglint/files/mkline_test.go @@ -634,7 +634,7 @@ func (s *Suite) Test_MkLine_VariableNeedsQuoting__append_URL_to_list_of_URLs(c * t.CheckEquals(nq, no) - NewMkAssignChecker(mkline, mklines).checkVarassign() + NewMkAssignChecker(mkline, mklines).check() t.CheckOutputEmpty() // Up to version 5.3.6, pkglint warned about a missing :Q here, which was wrong. } @@ -648,7 +648,7 @@ func (s *Suite) Test_MkLine_VariableNeedsQuoting__append_list_to_list(c *check.C MkCvsID, "MASTER_SITES=\t${MASTER_SITE_SOURCEFORGE:=squirrel-sql/}") - NewMkAssignChecker(mklines.mklines[1], mklines).checkVarassign() + NewMkAssignChecker(mklines.mklines[1], mklines).check() // Assigning lists to lists is ok. t.CheckOutputEmpty() @@ -669,7 +669,7 @@ func (s *Suite) Test_MkLine_VariableNeedsQuoting__eval_shell(c *check.C) { mklines.ForEach(func(mkline *MkLine) { if mkline.IsVarassign() { - NewMkAssignChecker(mkline, mklines).checkVarassign() + NewMkAssignChecker(mkline, mklines).check() } }) @@ -685,7 +685,7 @@ func (s *Suite) Test_MkLine_VariableNeedsQuoting__command_in_single_quotes(c *ch MkCvsID, "SUBST_SED.hpath=\t-e 's|^\\(INSTALL[\t:]*=\\).*|\\1${INSTALL}|'") - NewMkAssignChecker(mklines.mklines[1], mklines).checkVarassign() + NewMkAssignChecker(mklines.mklines[1], mklines).check() t.CheckOutputLines( "WARN: Makefile:2: Please use ${INSTALL:Q} instead of ${INSTALL} " + @@ -933,7 +933,7 @@ func (s *Suite) Test_MkLine_VariableNeedsQuoting__PKGNAME_and_URL_list_in_URL_li MkCvsID, "MASTER_SITES=\tftp://ftp.gtk.org/${PKGNAME}/ ${MASTER_SITE_GNOME:=subdir/}") - NewMkAssignChecker(mklines.mklines[1], mklines).checkVarassignRightVaruse() + NewMkAssignChecker(mklines.mklines[1], mklines).checkRightVaruse() t.CheckOutputEmpty() // Don't warn about missing :Q modifiers. } @@ -948,7 +948,7 @@ func (s *Suite) Test_MkLine_VariableNeedsQuoting__tool_in_CONFIGURE_ENV(c *check "", "CONFIGURE_ENV+=\tSYS_TAR_COMMAND_PATH=${TOOLS_TAR:Q}") - NewMkAssignChecker(mklines.mklines[2], mklines).checkVarassignRightVaruse() + NewMkAssignChecker(mklines.mklines[2], mklines).checkRightVaruse() // The TOOLS_* variables only contain the path to the tool, // without any additional arguments that might be necessary @@ -969,8 +969,8 @@ func (s *Suite) Test_MkLine_VariableNeedsQuoting__backticks(c *check.C) { "COMPILE_CMD=\tcc `${CAT} ${WRKDIR}/compileflags`", "COMMENT_CMD=\techo `echo ${COMMENT}`") - NewMkAssignChecker(mklines.mklines[2], mklines).checkVarassignRightVaruse() - NewMkAssignChecker(mklines.mklines[3], mklines).checkVarassignRightVaruse() + NewMkAssignChecker(mklines.mklines[2], mklines).checkRightVaruse() + NewMkAssignChecker(mklines.mklines[3], mklines).checkRightVaruse() // Both CAT and WRKDIR are safe from quoting, therefore no warnings. // But COMMENT may contain arbitrary characters and therefore must diff --git a/pkgtools/pkglint/files/mklinechecker.go b/pkgtools/pkglint/files/mklinechecker.go index 5c2fbd24699..082a019549f 100644 --- a/pkgtools/pkglint/files/mklinechecker.go +++ b/pkgtools/pkglint/files/mklinechecker.go @@ -24,7 +24,7 @@ func (ck MkLineChecker) Check() { switch { case mkline.IsVarassign(): - NewMkAssignChecker(mkline, ck.MkLines).checkVarassign() + NewMkAssignChecker(mkline, ck.MkLines).check() case mkline.IsShellCommand(): ck.checkShellCommand() @@ -171,7 +171,7 @@ func (ck MkLineChecker) checkVartype(varname string, op MkOperator, value, comme } if vartype.basicType == BtCategory { mkAssignChecker := NewMkAssignChecker(mkline, ck.MkLines) - mkAssignChecker.checkVarassignRightCategory() + mkAssignChecker.checkRightCategory() } for _, word := range words { ck.CheckVartypeBasic(varname, vartype.basicType, op, word, comment, vartype.IsGuessed()) diff --git a/pkgtools/pkglint/files/mklines_test.go b/pkgtools/pkglint/files/mklines_test.go index cfc0d4040e1..1e00933262f 100644 --- a/pkgtools/pkglint/files/mklines_test.go +++ b/pkgtools/pkglint/files/mklines_test.go @@ -222,6 +222,28 @@ func (s *Suite) Test_MkLines_Check__PKG_SKIP_REASON_depending_on_OPSYS(c *check. "NOTE: Makefile:7: Consider setting NOT_FOR_PLATFORM instead of PKG_SKIP_REASON depending on ${OPSYS}.") } +func (s *Suite) Test_MkLines_Check__PKG_SKIP_REASON_depending_on_OPSYS_and_others(c *check.C) { + t := s.Init(c) + + t.SetUpPkgsrc() + t.Chdir("category/package") + t.FinishSetUp() + mklines := t.NewMkLines("Makefile", + MkCvsID, + "", + ".include \"../../mk/bsd.prefs.mk\"", + "", + "PKG_SKIP_REASON+=\t\"Fails everywhere\"", + ".if ${OPSYS} == \"Cygwin\" && ${MACHINE_ARCH} == i386", + "PKG_SKIP_REASON+=\t\"Fails on Cygwin i386\"", + ".endif") + + mklines.Check() + + t.CheckOutputLines( + "NOTE: Makefile:7: Consider setting NOT_FOR_PLATFORM instead of PKG_SKIP_REASON depending on ${OPSYS}.") +} + func (s *Suite) Test_MkLines_Check__use_list_variable_as_part_of_word(c *check.C) { t := s.Init(c) @@ -495,7 +517,7 @@ func (s *Suite) Test_MkLines_collectUsedVariables__simple(c *check.C) { mklines.collectUsedVariables() t.Check(mklines.allVars.vs, check.HasLen, 1) - t.CheckEquals(mklines.allVars.v("VAR").used, mkline) + t.CheckEquals(mklines.allVars.create("VAR").used, mkline) t.CheckEquals(mklines.allVars.FirstUse("VAR"), mkline) } diff --git a/pkgtools/pkglint/files/mkvarusechecker.go b/pkgtools/pkglint/files/mkvarusechecker.go index 30c244b4b0f..4a3c79aedad 100644 --- a/pkgtools/pkglint/files/mkvarusechecker.go +++ b/pkgtools/pkglint/files/mkvarusechecker.go @@ -194,7 +194,7 @@ func (ck *MkVarUseChecker) checkVarnameBuildlink(varname string) { // be it in a variable assignment, in a shell command, a conditional, or // somewhere else. // -// See checkVarassignLeftPermissions. +// See MkAssignChecker.checkLeftPermissions. func (ck *MkVarUseChecker) checkPermissions(vuc *VarUseContext) { if !G.WarnPerm { return diff --git a/pkgtools/pkglint/files/mkvarusechecker_test.go b/pkgtools/pkglint/files/mkvarusechecker_test.go index fcd2dbbd83f..b56a2bd2f89 100644 --- a/pkgtools/pkglint/files/mkvarusechecker_test.go +++ b/pkgtools/pkglint/files/mkvarusechecker_test.go @@ -1083,7 +1083,7 @@ func (s *Suite) Test_MkVarUseChecker_checkAssignable(c *check.C) { mklines.ForEach(func(mkline *MkLine) { ck := NewMkAssignChecker(mkline, mklines) - ck.checkVarassignRight() + ck.checkRight() }) t.CheckOutputLines( @@ -1117,7 +1117,7 @@ func (s *Suite) Test_MkVarUseChecker_checkAssignable__shell_command_to_pathname( mklines.ForEach(func(mkline *MkLine) { ck := NewMkAssignChecker(mkline, mklines) - ck.checkVarassignRight() + ck.checkRight() }) t.CheckOutputLines( diff --git a/pkgtools/pkglint/files/package.go b/pkgtools/pkglint/files/package.go index aa2e32fe68f..ddc6a463a51 100644 --- a/pkgtools/pkglint/files/package.go +++ b/pkgtools/pkglint/files/package.go @@ -118,7 +118,7 @@ func NewPackage(dir CurrPath) *Package { conditionalIncludes: make(map[PackagePath]*MkLine), unconditionalIncludes: make(map[PackagePath]*MkLine), } - pkg.vars.DefineAll(G.Pkgsrc.UserDefinedVars) + pkg.vars.DefineAll(&G.Pkgsrc.UserDefinedVars) pkg.vars.Fallback("PKGDIR", ".") pkg.vars.Fallback("DISTINFO_FILE", "${PKGDIR}/distinfo") @@ -157,7 +157,7 @@ func (pkg *Package) load() ([]CurrPath, *MkLines, *MkLines) { files = append(files, pkg.File(pkg.Pkgdir).ReadPaths()...) } files = append(files, pkg.File(pkg.Patchdir).ReadPaths()...) - if pkg.DistinfoFile != NewPackagePathString(pkg.vars.v("DISTINFO_FILE").fallback) { + if pkg.DistinfoFile != NewPackagePathString(pkg.vars.create("DISTINFO_FILE").fallback) { files = append(files, pkg.File(pkg.DistinfoFile)) } diff --git a/pkgtools/pkglint/files/redundantscope_test.go b/pkgtools/pkglint/files/redundantscope_test.go index a919fbdf667..e7b7e3c50bd 100644 --- a/pkgtools/pkglint/files/redundantscope_test.go +++ b/pkgtools/pkglint/files/redundantscope_test.go @@ -428,6 +428,7 @@ func (s *Suite) Test_RedundantScope__before_including_same_value(c *check.C) { "NOTE: including.mk:2: Default assignment of VAR.def.asg has no effect because of included.mk:2.", "NOTE: including.mk:4: Definition of VAR.asg.def is redundant because of included.mk:4.", "NOTE: including.mk:5: Definition of VAR.asg.asg is redundant because of included.mk:5.", + "NOTE: including.mk:7: Definition of VAR.app.def is redundant because of included.mk:7.", "WARN: including.mk:8: Variable VAR.app.asg is overwritten in included.mk:8.") } diff --git a/pkgtools/pkglint/files/shell_test.go b/pkgtools/pkglint/files/shell_test.go index e4d25b9785f..b6ff89b4aba 100644 --- a/pkgtools/pkglint/files/shell_test.go +++ b/pkgtools/pkglint/files/shell_test.go @@ -1393,7 +1393,7 @@ func (s *Suite) Test_ShellLineChecker_CheckWord(c *check.C) { t.SetUpVartypes() test := func(shellWord string, checkQuoting bool, diagnostics ...string) { - // See checkVaruseUndefined and checkVarassignLeftNotUsed. + // See MkVarUseChecker.checkUndefined and MkAssignChecker.checkLeftNotUsed. ck := t.NewShellLineChecker("\t echo " + shellWord) ck.CheckWord(shellWord, checkQuoting, RunTime) t.CheckOutput(diagnostics) diff --git a/pkgtools/pkglint/files/util.go b/pkgtools/pkglint/files/util.go index 823df9cbe02..ee44ceb9bfc 100644 --- a/pkgtools/pkglint/files/util.go +++ b/pkgtools/pkglint/files/util.go @@ -617,7 +617,8 @@ func (o *Once) check(key uint64) bool { // // See also RedundantScope. type Scope struct { - vs map[string]*scopeVar + vs map[string]*scopeVar + names []string } type scopeVar struct { @@ -631,15 +632,30 @@ type scopeVar struct { } func NewScope() Scope { - return Scope{make(map[string]*scopeVar)} + return Scope{make(map[string]*scopeVar), nil} } -func (s *Scope) v(varname string) *scopeVar { - if v, found := s.vs[varname]; found { +func (s *Scope) varnames() []string { + if len(s.names) == 0 && len(s.vs) > 0 { + varnames := make([]string, len(s.vs)) + i := 0 + for varname := range s.vs { + varnames[i] = varname + i++ + } + sort.Strings(varnames) + s.names = varnames + } + return s.names +} + +func (s *Scope) create(varname string) *scopeVar { + if v := s.vs[varname]; v != nil { return v } var sv scopeVar s.vs[varname] = &sv + s.names = nil return &sv } @@ -653,7 +669,7 @@ func (s *Scope) Define(varname string, mkline *MkLine) { } func (s *Scope) def(name string, mkline *MkLine) { - v := s.v(name) + v := s.create(name) if v.firstDef == nil { v.firstDef = mkline if trace.Tracing { @@ -694,13 +710,13 @@ func (s *Scope) def(name string, mkline *MkLine) { } func (s *Scope) Fallback(varname string, value string) { - s.v(varname).fallback = value + s.create(varname).fallback = value } // Use marks the variable and its canonicalized form as used. func (s *Scope) Use(varname string, line *MkLine, time VucTime) { use := func(name string) { - v := s.v(name) + v := s.create(name) if v.used == nil { v.used = line if trace.Tracing { @@ -721,7 +737,10 @@ func (s *Scope) Use(varname string, line *MkLine, time VucTime) { // - mentioned in a commented variable assignment, // - mentioned in a documentation comment. func (s *Scope) Mentioned(varname string) *MkLine { - return s.v(varname).firstDef + if v := s.vs[varname]; v != nil { + return v.firstDef + } + return nil } // IsDefined tests whether the variable is defined. @@ -730,7 +749,7 @@ func (s *Scope) Mentioned(varname string) *MkLine { // Even if IsDefined returns true, FirstDefinition doesn't necessarily return true // since the latter ignores the default definitions from vardefs.go, keyword dummyVardefMkline. func (s *Scope) IsDefined(varname string) bool { - mkline := s.v(varname).firstDef + mkline := s.Mentioned(varname) return mkline != nil && mkline.IsVarassign() } @@ -756,21 +775,19 @@ func (s *Scope) IsDefinedSimilar(varname string) bool { // IsUsed tests whether the variable is used. // It does NOT test the canonicalized variable name. func (s *Scope) IsUsed(varname string) bool { - return s.v(varname).used != nil + return s.FirstUse(varname) != nil } // IsUsedSimilar tests whether the variable or its canonicalized form is used. func (s *Scope) IsUsedSimilar(varname string) bool { - if s.v(varname).used != nil { - return true - } - return s.v(varnameCanon(varname)).used != nil + return s.FirstUse(varname) != nil || s.FirstUse(varnameCanon(varname)) != nil } // IsUsedAtLoadTime returns true if the variable is used at load time // somewhere. func (s *Scope) IsUsedAtLoadTime(varname string) bool { - return s.v(varname).usedAtLoadTime + v := s.vs[varname] + return v != nil && v.usedAtLoadTime } // FirstDefinition returns the line in which the variable has been defined first. @@ -782,7 +799,12 @@ func (s *Scope) IsUsedAtLoadTime(varname string) bool { // round: the including file sets a value first, and the included file then // assigns a default value using ?=. func (s *Scope) FirstDefinition(varname string) *MkLine { - mkline := s.v(varname).firstDef + v := s.vs[varname] + if v == nil { + return nil + } + + mkline := v.firstDef if mkline != nil && mkline.IsVarassign() { lastLine := s.LastDefinition(varname) if trace.Tracing && lastLine != mkline { @@ -803,7 +825,12 @@ func (s *Scope) FirstDefinition(varname string) *MkLine { // round: the including file sets a value first, and the included file then // assigns a default value using ?=. func (s *Scope) LastDefinition(varname string) *MkLine { - mkline := s.v(varname).lastDef + v := s.vs[varname] + if v == nil { + return nil + } + + mkline := v.lastDef if mkline != nil && mkline.IsVarassign() { return mkline } @@ -814,12 +841,17 @@ func (s *Scope) LastDefinition(varname string) *MkLine { // variable assignments. These are ignored by bmake but used heavily in // mk/defaults/mk.conf for documentation. func (s *Scope) Commented(varname string) *MkLine { - var mklines []*MkLine - if first := s.v(varname).firstDef; first != nil { - mklines = append(mklines, first) + v := s.vs[varname] + if v == nil { + return nil } - if last := s.v(varname).lastDef; last != nil { - mklines = append(mklines, last) + + mklines := make([]*MkLine, 0, 2) + if v.firstDef != nil { + mklines = append(mklines, v.firstDef) + } + if v.lastDef != nil { + mklines = append(mklines, v.lastDef) } for _, mkline := range mklines { @@ -838,7 +870,11 @@ func (s *Scope) Commented(varname string) *MkLine { } func (s *Scope) FirstUse(varname string) *MkLine { - return s.v(varname).used + v := s.vs[varname] + if v == nil { + return nil + } + return v.used } // LastValue returns the value from the last variable definition. @@ -868,14 +904,8 @@ func (s *Scope) LastValueFound(varname string) (value string, found bool, indete return v.fallback, v.fallback != "", v.indeterminate } -func (s *Scope) DefineAll(other Scope) { - var varnames []string - for varname := range other.vs { - varnames = append(varnames, varname) - } - sort.Strings(varnames) - - for _, varname := range varnames { +func (s *Scope) DefineAll(other *Scope) { + for _, varname := range other.varnames() { v := other.vs[varname] if v.firstDef != nil { s.Define(varname, v.firstDef) diff --git a/pkgtools/pkglint/files/util_test.go b/pkgtools/pkglint/files/util_test.go index f161a532232..9d178fafd52 100644 --- a/pkgtools/pkglint/files/util_test.go +++ b/pkgtools/pkglint/files/util_test.go @@ -737,12 +737,12 @@ func (s *Suite) Test_Scope_DefineAll(c *check.C) { src := NewScope() dst := NewScope() - dst.DefineAll(src) + dst.DefineAll(&src) c.Check(dst.vs, check.HasLen, 0) src.Define("VAR", t.NewMkLine("file.mk", 1, "VAR=value")) - dst.DefineAll(src) + dst.DefineAll(&src) t.CheckEquals(dst.IsDefined("VAR"), true) } diff --git a/pkgtools/pkglint/files/var.go b/pkgtools/pkglint/files/var.go index 0fd9319fae4..b0b6857497e 100644 --- a/pkgtools/pkglint/files/var.go +++ b/pkgtools/pkglint/files/var.go @@ -267,12 +267,15 @@ func (v *Var) updateConstantValue(mkline *MkLine) { } case opAssignAppend: - v.constantValue += " " + value + if v.constantState != 0 { + v.constantValue += " " + } + v.constantValue += value default: v.constantState = 3 v.constantValue = "" } - v.constantState = [...]uint8{1, 1, 3, 3}[v.constantState] + v.constantState |= 1 } diff --git a/pkgtools/pkglint/files/var_test.go b/pkgtools/pkglint/files/var_test.go index 5d27f882575..418a3a21589 100644 --- a/pkgtools/pkglint/files/var_test.go +++ b/pkgtools/pkglint/files/var_test.go @@ -137,11 +137,11 @@ func (s *Suite) Test_Var_ConstantValue__append(c *check.C) { v.Write(t.NewMkLine("write.mk", 123, "VARNAME+=\tvalue"), false) - t.CheckEquals(v.ConstantValue(), " value") + t.CheckEquals(v.ConstantValue(), "value") v.Write(t.NewMkLine("write.mk", 124, "VARNAME+=\tappended"), false) - t.CheckEquals(v.ConstantValue(), " value appended") + t.CheckEquals(v.ConstantValue(), "value appended") } func (s *Suite) Test_Var_ConstantValue__eval(c *check.C) { diff --git a/pkgtools/pkglint/files/vartypecheck_test.go b/pkgtools/pkglint/files/vartypecheck_test.go index f429a2940d2..8c316ee1793 100644 --- a/pkgtools/pkglint/files/vartypecheck_test.go +++ b/pkgtools/pkglint/files/vartypecheck_test.go @@ -503,6 +503,8 @@ func (s *Suite) Test_VartypeCheck_DependencyPattern__smaller_version(c *check.C) t.CheckOutputLines( "NOTE: Makefile:21: The requirement >=1.0pkg is already guaranteed "+ "by the >=1.3api from ../../category/lib/buildlink3.mk:12.", + "ERROR: Makefile:22: Packages must only require API versions, "+ + "not ABI versions of dependencies.", "NOTE: Makefile:22: The requirement >=1.1pkg is already guaranteed "+ "by the >=1.4abi from ../../category/lib/buildlink3.mk:13.") } @@ -526,6 +528,8 @@ func (s *Suite) Test_VartypeCheck_DependencyPattern__different_operators(c *chec t.CheckOutputLines( "NOTE: Makefile:21: The requirement >=1.0pkg is already guaranteed "+ "by the >1.3api from ../../category/lib/buildlink3.mk:12.", + "ERROR: Makefile:22: Packages must only require API versions, "+ + "not ABI versions of dependencies.", "NOTE: Makefile:22: The requirement >=1.1pkg is already guaranteed "+ "by the >1.4abi from ../../category/lib/buildlink3.mk:13.") } @@ -549,6 +553,8 @@ func (s *Suite) Test_VartypeCheck_DependencyPattern__additional_greater(c *check t.CheckOutputLines( "NOTE: Makefile:21: The requirement >1.0pkg is already guaranteed "+ "by the >=1.3api from ../../category/lib/buildlink3.mk:12.", + "ERROR: Makefile:22: Packages must only require API versions, "+ + "not ABI versions of dependencies.", "NOTE: Makefile:22: The requirement >1.1pkg is already guaranteed "+ "by the >=1.4abi from ../../category/lib/buildlink3.mk:13.") } @@ -570,8 +576,10 @@ func (s *Suite) Test_VartypeCheck_DependencyPattern__upper_limit(c *check.C) { G.checkdirPackage(".") // If the additional constraint doesn't have a lower bound, - // there is nothing to compare and warn about. - t.CheckOutputEmpty() + // there are no version numbers to compare and warn about. + t.CheckOutputLines( + "ERROR: Makefile:22: Packages must only require API versions, " + + "not ABI versions of dependencies.") } // Having an upper bound for a library dependency is unusual. @@ -593,8 +601,10 @@ func (s *Suite) Test_VartypeCheck_DependencyPattern__upper_limit_in_buildlink3(c G.checkdirPackage(".") // If the additional constraint doesn't have a lower bound, - // there is nothing to compare and warn about. - t.CheckOutputEmpty() + // there are no version numbers to compare and warn about. + t.CheckOutputLines( + "ERROR: Makefile:22: Packages must only require API versions, " + + "not ABI versions of dependencies.") } func (s *Suite) Test_VartypeCheck_DependencyPattern__API_ABI(c *check.C) { @@ -628,7 +638,9 @@ func (s *Suite) Test_VartypeCheck_DependencyPattern__ABI_API(c *check.C) { G.checkdirPackage(".") - t.CheckOutputEmpty() + t.CheckOutputLines( + "ERROR: Makefile:21: Packages must only require API versions, " + + "not ABI versions of dependencies.") } func (s *Suite) Test_VartypeCheck_DependencyWithPath(c *check.C) { |