Fri Jun 10 19:42:42 2016 UTC ()
Updated pkglint to 5.4.1.

Changes since 5.4.0:

* PKG_SKIP_REASON is no longer marked as deprecated, since it still
  has its value
* When PKG_SKIP_REASON is defined depending on OPSYS, suggest to
  use NOT_FOR_PLATFORM instead.
* Check for ROOT_USER/ROOT_GROUP being used in special file
  permissions; using REAL_ROOT_USER/REAL_ROOT_GROUP is better.


(rillig)
diff -r1.485 -r1.486 pkgsrc/pkgtools/pkglint/Makefile
diff -r1.9 -r1.10 pkgsrc/pkgtools/pkglint/files/globaldata.go
diff -r1.9 -r1.10 pkgsrc/pkgtools/pkglint/files/vartypecheck_test.go
diff -r1.11 -r1.12 pkgsrc/pkgtools/pkglint/files/mkline.go
diff -r1.5 -r1.6 pkgsrc/pkgtools/pkglint/files/mklines.go
diff -r1.4 -r1.5 pkgsrc/pkgtools/pkglint/files/mklines_test.go
diff -r1.8 -r1.9 pkgsrc/pkgtools/pkglint/files/vardefs.go
diff -r1.7 -r1.8 pkgsrc/pkgtools/pkglint/files/vartype.go
diff -r1.13 -r1.14 pkgsrc/pkgtools/pkglint/files/vartypecheck.go

cvs diff -r1.485 -r1.486 pkgsrc/pkgtools/pkglint/Makefile (expand / switch to context diff)
--- pkgsrc/pkgtools/pkglint/Makefile 2016/06/05 11:24:32 1.485
+++ pkgsrc/pkgtools/pkglint/Makefile 2016/06/10 19:42:41 1.486
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.485 2016/06/05 11:24:32 rillig Exp $
+# $NetBSD: Makefile,v 1.486 2016/06/10 19:42:41 rillig Exp $
 
-PKGNAME=	pkglint-5.4.0
+PKGNAME=	pkglint-5.4.1
 DISTFILES=	# none
 CATEGORIES=	pkgtools
 

cvs diff -r1.9 -r1.10 pkgsrc/pkgtools/pkglint/files/Attic/globaldata.go (expand / switch to context diff)
--- pkgsrc/pkgtools/pkglint/files/Attic/globaldata.go 2016/06/05 11:24:32 1.9
+++ pkgsrc/pkgtools/pkglint/files/Attic/globaldata.go 2016/06/10 19:42:42 1.10
@@ -478,7 +478,6 @@
 
 		// November 2006
 		"SKIP_PORTABILITY_CHECK": "Use CHECK_PORTABILITY_SKIP (a list of patterns) instead.",
-		"PKG_SKIP_REASON":        "Use PKG_FAIL_REASON instead.",
 
 		// January 2007
 		"BUILDLINK_TRANSFORM.*": "Use BUILDLINK_FNAME_TRANSFORM.* instead.",

cvs diff -r1.9 -r1.10 pkgsrc/pkgtools/pkglint/files/Attic/vartypecheck_test.go (expand / switch to context diff)
--- pkgsrc/pkgtools/pkglint/files/Attic/vartypecheck_test.go 2016/06/05 11:24:32 1.9
+++ pkgsrc/pkgtools/pkglint/files/Attic/vartypecheck_test.go 2016/06/10 19:42:42 1.10
@@ -277,6 +277,16 @@
 	c.Check(s.Output(), equals, "WARN: fname:1: All components of PATH (in this case \".\") should be absolute paths.\n")
 }
 
+func (s *Suite) Test_VartypeCheck_Perms(c *check.C) {
+	runVartypeChecks("CONF_FILES_PERMS", opAssignAppend, (*VartypeCheck).Perms,
+		"root",
+		"${ROOT_USER}",
+		"ROOT_USER",
+		"${REAL_ROOT_USER}")
+
+	c.Check(s.Output(), equals, "ERROR: fname:2: ROOT_USER must not be used in permission definitions. Use REAL_ROOT_USER instead.\n")
+}
+
 func (s *Suite) TestVartypeCheck_PkgOptionsVar(c *check.C) {
 	runVartypeChecks("PKG_OPTIONS_VAR.screen", opAssign, (*VartypeCheck).PkgOptionsVar,
 		"PKG_OPTIONS.${PKGBASE}")

cvs diff -r1.11 -r1.12 pkgsrc/pkgtools/pkglint/files/Attic/mkline.go (expand / switch to context diff)
--- pkgsrc/pkgtools/pkglint/files/Attic/mkline.go 2016/06/05 11:24:32 1.11
+++ pkgsrc/pkgtools/pkglint/files/Attic/mkline.go 2016/06/10 19:42:42 1.12
@@ -216,8 +216,9 @@
 	}
 }
 
-func (mkline *MkLine) checkCond(indentation *Indentation, forVars map[string]bool) {
+func (mkline *MkLine) checkCond(forVars map[string]bool) {
 	indent, directive, args := mkline.Indent(), mkline.Directive(), mkline.Args()
+	indentation := &G.Mk.indentation
 
 	switch directive {
 	case "endif", "endfor", "elif", "else":
@@ -943,6 +944,10 @@
 	if hasPrefix(varname, "SITES_") {
 		mkline.Warn0("SITES_* is deprecated. Please use SITES.* instead.")
 	}
+
+	if varname == "PKG_SKIP_REASON" && G.Mk.indentation.DependsOn("OPSYS") {
+		mkline.Note0("Consider defining NOT_FOR_PLATFORM instead of setting PKG_SKIP_REASON depending on ${OPSYS}.")
+	}
 }
 
 func (mkline *MkLine) checkVarassignBsdPrefs() {
@@ -1224,8 +1229,36 @@
 			mkline.CheckVartype(varname, opUseMatch, value, "")
 		}
 	})
+
+	mkline.rememberUsedVariables(cond)
 }
 
+func (mkline *MkLine) rememberUsedVariables(cond *Tree) {
+	if G.Mk == nil {
+		return
+	}
+
+	indentation := &G.Mk.indentation
+	arg0varname := func(node *Tree) {
+		varname := node.args[0].(string)
+		indentation.AddVar(varname)
+	}
+	arg0varuse := func(node *Tree) {
+		varuse := node.args[0].(MkVarUse)
+		indentation.AddVar(varuse.varname)
+	}
+	arg2varuse := func(node *Tree) {
+		varuse := node.args[2].(MkVarUse)
+		indentation.AddVar(varuse.varname)
+	}
+	cond.Visit("defined", arg0varname)
+	cond.Visit("empty", arg0varuse)
+	cond.Visit("compareVarNum", arg0varuse)
+	cond.Visit("compareVarStr", arg0varuse)
+	cond.Visit("compareVarVar", arg0varuse)
+	cond.Visit("compareVarVar", arg2varuse)
+}
+
 func (mkline *MkLine) CheckValidCharactersInValue(reValid string) {
 	rest := regcomp(reValid).ReplaceAllString(mkline.Value(), "")
 	if rest != "" {
@@ -1679,10 +1712,42 @@
 }
 
 type Indentation struct {
-	data []int
+	depth         []int             // Number of space characters; always a multiple of 2
+	conditionVars []map[string]bool // Variables on which the current path depends
 }
 
-func (ind *Indentation) Len() int        { return len(ind.data) }
+func (ind *Indentation) Len() int {
-func (ind *Indentation) Depth() int      { return ind.data[len(ind.data)-1] }
+	return len(ind.depth)
-func (ind *Indentation) Pop()            { ind.data = ind.data[:len(ind.data)-1] }
+}
-func (ind *Indentation) Push(indent int) { ind.data = append(ind.data, indent) }
+
+func (ind *Indentation) Depth() int {
+	return ind.depth[len(ind.depth)-1]
+}
+
+func (ind *Indentation) Pop() {
+	newlen := ind.Len() - 1
+	ind.depth = ind.depth[:newlen]
+	ind.conditionVars = ind.conditionVars[:newlen]
+}
+
+func (ind *Indentation) Push(indent int) {
+	ind.depth = append(ind.depth, indent)
+	ind.conditionVars = append(ind.conditionVars, nil)
+}
+
+func (ind *Indentation) AddVar(varname string) {
+	level := ind.Len() - 1
+	if ind.conditionVars[level] == nil {
+		ind.conditionVars[level] = make(map[string]bool)
+	}
+	ind.conditionVars[level][varname] = true
+}
+
+func (ind *Indentation) DependsOn(varname string) bool {
+	for _, vars := range ind.conditionVars {
+		if vars[varname] {
+			return true
+		}
+	}
+	return false
+}

cvs diff -r1.5 -r1.6 pkgsrc/pkgtools/pkglint/files/Attic/mklines.go (expand / switch to context diff)
--- pkgsrc/pkgtools/pkglint/files/Attic/mklines.go 2016/06/05 11:24:32 1.5
+++ pkgsrc/pkgtools/pkglint/files/Attic/mklines.go 2016/06/10 19:42:42 1.6
@@ -17,6 +17,7 @@
 	plistVars      map[string]bool    // Variables that are registered in PLIST_VARS, to ensure that all user-defined variables are added to it.
 	tools          map[string]bool    // Set of tools that are declared to be used.
 	SeenBsdPrefsMk bool
+	indentation    Indentation // Indentation depth of preprocessing directives
 }
 
 func NewMkLines(lines []*Line) *MkLines {
@@ -41,7 +42,8 @@
 		make(map[string]bool),
 		make(map[string]bool),
 		tools,
-		false}
+		false,
+		Indentation{}}
 }
 
 func (mklines *MkLines) DefineVar(mkline *MkLine, varname string) {
@@ -99,7 +101,8 @@
 
 	var substcontext SubstContext
 	var varalign VaralignBlock
-	indentation := Indentation{[]int{0}} // Indentation depth of preprocessing directives
+	indentation := &mklines.indentation
+	indentation.Push(0)
 	for _, mkline := range mklines.mklines {
 		mkline.Check()
 		varalign.Check(mkline)
@@ -120,7 +123,7 @@
 			}
 
 		case mkline.IsCond():
-			mkline.checkCond(&indentation, mklines.forVars)
+			mkline.checkCond(mklines.forVars)
 
 		case mkline.IsDependency():
 			mkline.checkDependencyRule(allowedTargets)

cvs diff -r1.4 -r1.5 pkgsrc/pkgtools/pkglint/files/Attic/mklines_test.go (expand / switch to context diff)
--- pkgsrc/pkgtools/pkglint/files/Attic/mklines_test.go 2016/06/05 11:24:32 1.4
+++ pkgsrc/pkgtools/pkglint/files/Attic/mklines_test.go 2016/06/10 19:42:42 1.5
@@ -244,3 +244,17 @@
 		"WARN: chat/xchat/Makefile:4: Unknown shell command \"${GCONF_SCHEMAS:@.s.@"+
 		"${INSTALL_DATA} ${WRKSRC}/src/common/dbus/${.s.} ${DESTDIR}${GCONF_SCHEMAS_DIR}/@}\".\n")
 }
+
+func (s *Suite) Test_MkLines_Indentation_DependsOn(c *check.C) {
+	G.globalData.InitVartypes()
+	mklines := s.NewMkLines("Makefile",
+		"# $"+"NetBSD$",
+		"PKG_SKIP_REASON+=\t\"Fails everywhere\"",
+		".if ${OPSYS} == \"Cygwin\"",
+		"PKG_SKIP_REASON+=\t\"Fails on Cygwin\"",
+		".endif")
+
+	mklines.Check()
+
+	c.Check(s.Output(), equals, "NOTE: Makefile:4: Consider defining NOT_FOR_PLATFORM instead of setting PKG_SKIP_REASON depending on ${OPSYS}.\n")
+}

cvs diff -r1.8 -r1.9 pkgsrc/pkgtools/pkglint/files/Attic/vardefs.go (expand / switch to context diff)
--- pkgsrc/pkgtools/pkglint/files/Attic/vardefs.go 2016/06/05 11:24:32 1.8
+++ pkgsrc/pkgtools/pkglint/files/Attic/vardefs.go 2016/06/10 19:42:42 1.9
@@ -206,7 +206,7 @@
 	pkglist("CONFLICTS", lkSpace, CheckvarDependency)
 	pkglist("CONF_FILES", lkShell, CheckvarShellWord)
 	pkg("CONF_FILES_MODE", lkNone, enum("0644 0640 0600 0400"))
-	pkglist("CONF_FILES_PERMS", lkShell, CheckvarShellWord)
+	pkglist("CONF_FILES_PERMS", lkShell, CheckvarPerms)
 	sys("COPY", lkNone, enum("-c")) // The flag that tells ${INSTALL} to copy a file
 	sys("CPP", lkNone, CheckvarShellCommand)
 	pkglist("CPPFLAGS*", lkShell, CheckvarCFlag)
@@ -400,7 +400,7 @@
 	pkglist("MAKEFLAGS", lkShell, CheckvarShellWord)
 	acl("MAKEVARS", lkShell, CheckvarVarname, "builtin.mk: append; buildlink3.mk: append; hacks.mk: append")
 	pkglist("MAKE_DIRS", lkShell, CheckvarPathname)
-	pkglist("MAKE_DIRS_PERMS", lkShell, CheckvarShellWord)
+	pkglist("MAKE_DIRS_PERMS", lkShell, CheckvarPerms)
 	acl("MAKE_ENV", lkShell, CheckvarShellWord, "Makefile: append, set, use; Makefile.common: append, set, use; buildlink3.mk: append; builtin.mk: append; *.mk: append, use")
 	pkg("MAKE_FILE", lkNone, CheckvarPathname)
 	pkglist("MAKE_FLAGS", lkShell, CheckvarShellWord)
@@ -477,7 +477,7 @@
 	pkg("OVERRIDE_GNU_CONFIG_SCRIPTS", lkNone, CheckvarYes)
 	acl("OWNER", lkNone, CheckvarMailAddress, "Makefile: set; Makefile.common: default")
 	pkglist("OWN_DIRS", lkShell, CheckvarPathname)
-	pkglist("OWN_DIRS_PERMS", lkShell, CheckvarShellWord)
+	pkglist("OWN_DIRS_PERMS", lkShell, CheckvarPerms)
 	sys("PAMBASE", lkNone, CheckvarPathname)
 	usr("PAM_DEFAULT", lkNone, enum("linux-pam openpam solaris-pam"))
 	acl("PATCHDIR", lkNone, CheckvarRelativePkgPath, "Makefile: set; Makefile.common: default, set")
@@ -564,7 +564,7 @@
 	acl("PKG_SUGGESTED_OPTIONS", lkShell, CheckvarOption, "options.mk: set, append; Makefile: set, append; Makefile.common: set")
 	acl("PKG_SUPPORTED_OPTIONS", lkShell, CheckvarOption, "options.mk: set, append, use; Makefile: set, append; Makefile.common: set")
 	pkg("PKG_SYSCONFDIR*", lkNone, CheckvarPathname)
-	pkglist("PKG_SYSCONFDIR_PERMS", lkShell, CheckvarShellWord)
+	pkglist("PKG_SYSCONFDIR_PERMS", lkShell, CheckvarPerms)
 	sys("PKG_SYSCONFBASEDIR", lkNone, CheckvarPathname)
 	pkg("PKG_SYSCONFSUBDIR", lkNone, CheckvarPathname)
 	acl("PKG_SYSCONFVAR", lkNone, CheckvarIdentifier, "") // FIXME: name/type mismatch.
@@ -614,10 +614,10 @@
 	pkglist("REPLACE_PYTHON", lkShell, CheckvarPathmask)
 	pkglist("REPLACE_SH", lkShell, CheckvarPathmask)
 	pkglist("REQD_DIRS", lkShell, CheckvarPathname)
-	pkglist("REQD_DIRS_PERMS", lkShell, CheckvarShellWord)
+	pkglist("REQD_DIRS_PERMS", lkShell, CheckvarPerms)
 	pkglist("REQD_FILES", lkShell, CheckvarPathname)
 	pkg("REQD_FILES_MODE", lkNone, enum("0644 0640 0600 0400"))
-	pkglist("REQD_FILES_PERMS", lkShell, CheckvarShellWord)
+	pkglist("REQD_FILES_PERMS", lkShell, CheckvarPerms)
 	pkg("RESTRICTED", lkNone, CheckvarMessage)
 	usr("ROOT_USER", lkNone, CheckvarUserGroupName)
 	usr("ROOT_GROUP", lkNone, CheckvarUserGroupName)
@@ -634,7 +634,7 @@
 	acl("SHLIBTOOL", lkNone, CheckvarShellCommand, "Makefile: use")
 	acl("SHLIBTOOL_OVERRIDE", lkShell, CheckvarPathmask, "Makefile: set, append; Makefile.common: append")
 	acl("SITES.*", lkShell, CheckvarFetchURL, "Makefile, Makefile.common, options.mk: set, append, use")
-	pkglist("SPECIAL_PERMS", lkShell, CheckvarShellWord)
+	pkglist("SPECIAL_PERMS", lkShell, CheckvarPerms)
 	sys("STEP_MSG", lkNone, CheckvarShellCommand)
 	acl("SUBDIR", lkShell, CheckvarFilename, "Makefile: append; *:")
 	acl("SUBST_CLASSES", lkShell, CheckvarIdentifier, "Makefile: set, append; *: append")
@@ -672,6 +672,7 @@
 	acl("USE_BUILTIN.*", lkNone, CheckvarYesNoIndirectly, "builtin.mk: set")
 	pkg("USE_CMAKE", lkNone, CheckvarYes)
 	acl("USE_CROSSBASE", lkNone, CheckvarYes, "Makefile: set")
+	usr("USE_DESTDIR", lkNone, CheckvarYes)
 	pkg("USE_FEATURES", lkShell, CheckvarIdentifier)
 	pkg("USE_GCC_RUNTIME", lkNone, CheckvarYesNo)
 	pkg("USE_GNU_CONFIGURE_HOST", lkNone, CheckvarYesNo)

cvs diff -r1.7 -r1.8 pkgsrc/pkgtools/pkglint/files/Attic/vartype.go (expand / switch to context diff)
--- pkgsrc/pkgtools/pkglint/files/Attic/vartype.go 2016/06/05 11:24:32 1.7
+++ pkgsrc/pkgtools/pkglint/files/Attic/vartype.go 2016/06/10 19:42:42 1.8
@@ -236,6 +236,7 @@
 	CheckvarPathmask               = &VarChecker{"Pathmask", (*VartypeCheck).Pathmask}
 	CheckvarPathname               = &VarChecker{"Pathname", (*VartypeCheck).Pathname}
 	CheckvarPerl5Packlist          = &VarChecker{"Perl5Packlist", (*VartypeCheck).Perl5Packlist}
+	CheckvarPerms                  = &VarChecker{"Perms", (*VartypeCheck).Perms}
 	CheckvarPkgName                = &VarChecker{"PkgName", (*VartypeCheck).PkgName}
 	CheckvarPkgPath                = &VarChecker{"PkgPath", (*VartypeCheck).PkgPath}
 	CheckvarPkgOptionsVar          = &VarChecker{"PkgOptionsVar", (*VartypeCheck).PkgOptionsVar}

cvs diff -r1.13 -r1.14 pkgsrc/pkgtools/pkglint/files/Attic/vartypecheck.go (expand / switch to context diff)
--- pkgsrc/pkgtools/pkglint/files/Attic/vartypecheck.go 2016/06/05 11:24:32 1.13
+++ pkgsrc/pkgtools/pkglint/files/Attic/vartypecheck.go 2016/06/10 19:42:42 1.14
@@ -662,6 +662,13 @@
 	}
 }
 
+func (cv *VartypeCheck) Perms() {
+	if cv.value == "${ROOT_USER}" || cv.value == "${ROOT_GROUP}" {
+		valuename := cv.value[2 : len(cv.value)-1]
+		cv.line.Error1("%s must not be used in permission definitions. Use REAL_%[1]s instead.", valuename)
+	}
+}
+
 func (cv *VartypeCheck) PkgName() {
 	if cv.op != opUseMatch && cv.value == cv.valueNovar && !matches(cv.value, rePkgname) {
 		cv.line.Warn1("%q is not a valid package name. A valid package name has the form packagename-version, where version consists only of digits, letters and dots.", cv.value)