pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint Updated pkglint to 5.4.1.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/cac2d857bcba
branches:  trunk
changeset: 348240:cac2d857bcba
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Jun 10 19:42:41 2016 +0000

description:
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.

diffstat:

 pkgtools/pkglint/Makefile                   |   4 +-
 pkgtools/pkglint/files/globaldata.go        |   1 -
 pkgtools/pkglint/files/mkline.go            |  77 ++++++++++++++++++++++++++--
 pkgtools/pkglint/files/mklines.go           |   9 ++-
 pkgtools/pkglint/files/mklines_test.go      |  14 +++++
 pkgtools/pkglint/files/vardefs.go           |  15 +++--
 pkgtools/pkglint/files/vartype.go           |   1 +
 pkgtools/pkglint/files/vartypecheck.go      |   7 ++
 pkgtools/pkglint/files/vartypecheck_test.go |  10 +++
 9 files changed, 119 insertions(+), 19 deletions(-)

diffs (truncated from 309 to 300 lines):

diff -r 39e593df3ae0 -r cac2d857bcba pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Fri Jun 10 15:24:22 2016 +0000
+++ b/pkgtools/pkglint/Makefile Fri Jun 10 19:42:41 2016 +0000
@@ -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
 
diff -r 39e593df3ae0 -r cac2d857bcba pkgtools/pkglint/files/globaldata.go
--- a/pkgtools/pkglint/files/globaldata.go      Fri Jun 10 15:24:22 2016 +0000
+++ b/pkgtools/pkglint/files/globaldata.go      Fri Jun 10 19:42:41 2016 +0000
@@ -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.",
diff -r 39e593df3ae0 -r cac2d857bcba pkgtools/pkglint/files/mkline.go
--- a/pkgtools/pkglint/files/mkline.go  Fri Jun 10 15:24:22 2016 +0000
+++ b/pkgtools/pkglint/files/mkline.go  Fri Jun 10 19:42:41 2016 +0000
@@ -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,6 +1229,34 @@
                        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) {
@@ -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.depth)
+}
+
+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) Len() int        { return len(ind.data) }
-func (ind *Indentation) Depth() int      { return ind.data[len(ind.data)-1] }
-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) 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
+}
diff -r 39e593df3ae0 -r cac2d857bcba pkgtools/pkglint/files/mklines.go
--- a/pkgtools/pkglint/files/mklines.go Fri Jun 10 15:24:22 2016 +0000
+++ b/pkgtools/pkglint/files/mklines.go Fri Jun 10 19:42:41 2016 +0000
@@ -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)
diff -r 39e593df3ae0 -r cac2d857bcba pkgtools/pkglint/files/mklines_test.go
--- a/pkgtools/pkglint/files/mklines_test.go    Fri Jun 10 15:24:22 2016 +0000
+++ b/pkgtools/pkglint/files/mklines_test.go    Fri Jun 10 19:42:41 2016 +0000
@@ -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")
+}
diff -r 39e593df3ae0 -r cac2d857bcba pkgtools/pkglint/files/vardefs.go
--- a/pkgtools/pkglint/files/vardefs.go Fri Jun 10 15:24:22 2016 +0000
+++ b/pkgtools/pkglint/files/vardefs.go Fri Jun 10 19:42:41 2016 +0000
@@ -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)
diff -r 39e593df3ae0 -r cac2d857bcba pkgtools/pkglint/files/vartype.go
--- a/pkgtools/pkglint/files/vartype.go Fri Jun 10 15:24:22 2016 +0000
+++ b/pkgtools/pkglint/files/vartype.go Fri Jun 10 19:42:41 2016 +0000
@@ -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}
diff -r 39e593df3ae0 -r cac2d857bcba pkgtools/pkglint/files/vartypecheck.go
--- a/pkgtools/pkglint/files/vartypecheck.go    Fri Jun 10 15:24:22 2016 +0000
+++ b/pkgtools/pkglint/files/vartypecheck.go    Fri Jun 10 19:42:41 2016 +0000
@@ -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)
diff -r 39e593df3ae0 -r cac2d857bcba pkgtools/pkglint/files/vartypecheck_test.go
--- a/pkgtools/pkglint/files/vartypecheck_test.go       Fri Jun 10 15:24:22 2016 +0000
+++ b/pkgtools/pkglint/files/vartypecheck_test.go       Fri Jun 10 19:42:41 2016 +0000
@@ -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}",



Home | Main Index | Thread Index | Old Index