[BACK]Return to mkvarusechecker.go CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / pkgtools / pkglint / files

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /pkgsrc/pkgtools/pkglint/files/mkvarusechecker.go between version 1.4 and 1.5

version 1.4, 2019/12/30 16:27:13 version 1.5, 2020/01/04 19:53:14
Line 47  func (ck *MkVarUseChecker) checkUndefine
Line 47  func (ck *MkVarUseChecker) checkUndefine
                 vartype != nil && !vartype.IsGuessed(),                  vartype != nil && !vartype.IsGuessed(),
                 // TODO: At load time, check ck.MkLines.loadVars instead of allVars.                  // TODO: At load time, check ck.MkLines.loadVars instead of allVars.
                 ck.MkLines.allVars.IsDefinedSimilar(varname),                  ck.MkLines.allVars.IsDefinedSimilar(varname),
                 ck.MkLines.forVars[varname],                  ck.MkLines.checkAllData.forVars[varname],
                 ck.MkLines.allVars.Mentioned(varname) != nil,                  ck.MkLines.allVars.Mentioned(varname) != nil,
                 G.Pkg != nil && G.Pkg.vars.IsDefinedSimilar(varname),                  ck.MkLines.pkg != nil && ck.MkLines.pkg.vars.IsDefinedSimilar(varname),
                 containsVarRef(varname),                  containsVarUse(varname),
                 G.Pkgsrc.vartypes.IsDefinedCanon(varname),                  G.Pkgsrc.vartypes.IsDefinedCanon(varname),
                 varname == "":                  varname == "":
                 return                  return
Line 200  func (ck *MkVarUseChecker) checkPermissi
Line 200  func (ck *MkVarUseChecker) checkPermissi
   
         effPerms := vartype.EffectivePermissions(basename)          effPerms := vartype.EffectivePermissions(basename)
         if effPerms.Contains(aclpUseLoadtime) {          if effPerms.Contains(aclpUseLoadtime) {
                 ck.checkUseAtLoadTime(vuc.time)                  if vuc.time == VucLoadTime {
                           ck.checkUseAtLoadTime()
                   }
   
                 // Since the variable may be used at load time, it probably                  // Since the variable may be used at load time, it probably
                 // may be used at run time as well. If it weren't, that would                  // may be used at run time as well. If it weren't, that would
Line 285  func (ck *MkVarUseChecker) warnPermissio
Line 287  func (ck *MkVarUseChecker) warnPermissio
         }          }
         alternativeFiles := vartype.AlternativeFiles(needed)          alternativeFiles := vartype.AlternativeFiles(needed)
   
         loadTimeExplanation := func() []string {          loadTimeExplanation := []string{
                 return []string{                  "Many variables, especially lists of something, get their values incrementally.",
                         "Many variables, especially lists of something, get their values incrementally.",                  "Therefore it is generally unsafe to rely on their",
                         "Therefore it is generally unsafe to rely on their",                  "value until it is clear that it will never change again.",
                         "value until it is clear that it will never change again.",                  "This point is reached when the whole package Makefile is loaded and",
                         "This point is reached when the whole package Makefile is loaded and",                  "execution of the shell commands starts; in some cases earlier.",
                         "execution of the shell commands starts; in some cases earlier.",                  "",
                         "",                  "Additionally, when using the \":=\" operator, each $$ is replaced",
                         "Additionally, when using the \":=\" operator, each $$ is replaced",                  "with a single $, so variables that have references to shell",
                         "with a single $, so variables that have references to shell",                  "variables or regular expressions are modified in a subtle way."}
                         "variables or regular expressions are modified in a subtle way."}  
         }  
   
         switch {          switch {
         case alternativeFiles == "" && directly:          case alternativeFiles == "" && directly:
                 mkline.Warnf("%s should not be used at load time in any file.", varname)                  mkline.Warnf("%s should not be used at load time in any file.", varname)
                 ck.explainPermissions(varname, vartype, loadTimeExplanation()...)                  ck.explainPermissions(varname, vartype, loadTimeExplanation...)
   
         case alternativeFiles == "":          case alternativeFiles == "":
                 mkline.Warnf("%s should not be used in any file.", varname)                  mkline.Warnf("%s should not be used in any file.", varname)
                 ck.explainPermissions(varname, vartype, loadTimeExplanation()...)                  ck.explainPermissions(varname, vartype, loadTimeExplanation...)
   
         case directly:          case directly:
                 mkline.Warnf(                  mkline.Warnf(
                         "%s should not be used at load time in this file; "+                          "%s should not be used at load time in this file; "+
                                 "it would be ok in %s.",                                  "it would be ok in %s.",
                         varname, alternativeFiles)                          varname, alternativeFiles)
                 ck.explainPermissions(varname, vartype, loadTimeExplanation()...)                  ck.explainPermissions(varname, vartype, loadTimeExplanation...)
   
         default:          default:
                 mkline.Warnf(                  mkline.Warnf(
Line 364  func (ck *MkVarUseChecker) explainPermis
Line 364  func (ck *MkVarUseChecker) explainPermis
         ck.MkLine.Explain(expl...)          ck.MkLine.Explain(expl...)
 }  }
   
 func (ck *MkVarUseChecker) checkUseAtLoadTime(time VucTime) {  func (ck *MkVarUseChecker) checkUseAtLoadTime() {
         if time != VucLoadTime {  
                 return  
         }  
         if ck.vartype.IsAlwaysInScope() || ck.MkLines.Tools.SeenPrefs {          if ck.vartype.IsAlwaysInScope() || ck.MkLines.Tools.SeenPrefs {
                 return                  return
         }          }
         if G.Pkg != nil && G.Pkg.seenPrefs {          if ck.MkLines.pkg != nil && ck.MkLines.pkg.seenPrefs {
                 return                  return
         }          }
         mkline := ck.MkLine          mkline := ck.MkLine
Line 417  func (ck *MkVarUseChecker) warnToolLoadT
Line 414  func (ck *MkVarUseChecker) warnToolLoadT
         //  to skip the shell and execute the commands via execve, which          //  to skip the shell and execute the commands via execve, which
         //  means that even echo is not a shell-builtin anymore.          //  means that even echo is not a shell-builtin anymore.
   
         // TODO: Replace "parse time" with "load time" everywhere.  
   
         if tool.Validity == AfterPrefsMk {          if tool.Validity == AfterPrefsMk {
                 ck.MkLine.Warnf("To use the tool ${%s} at load time, bsd.prefs.mk has to be included before.", varname)                  ck.MkLine.Warnf("To use the tool ${%s} at load time, bsd.prefs.mk has to be included before.", varname)
                 return                  return
Line 473  func (ck *MkVarUseChecker) checkQuoting(
Line 468  func (ck *MkVarUseChecker) checkQuoting(
         // since the GNU configure scripts cannot handle these space characters.          // since the GNU configure scripts cannot handle these space characters.
         //          //
         // When doing checks outside a package, the :M* modifier is needed for safety.          // When doing checks outside a package, the :M* modifier is needed for safety.
         needMstar := (G.Pkg == nil || G.Pkg.vars.IsDefined("GNU_CONFIGURE")) &&          needMstar := (ck.MkLines.pkg == nil || ck.MkLines.pkg.vars.IsDefined("GNU_CONFIGURE")) &&
                 matches(varUse.varname, `^(?:.*_)?(?:CFLAGS|CPPFLAGS|CXXFLAGS|FFLAGS|LDFLAGS|LIBS)$`)                  matches(varUse.varname, `^(?:.*_)?(?:CFLAGS|CPPFLAGS|CXXFLAGS|FFLAGS|LDFLAGS|LIBS)$`)
   
         mkline := ck.MkLine          mkline := ck.MkLine
Line 502  func (ck *MkVarUseChecker) checkQuotingQ
Line 497  func (ck *MkVarUseChecker) checkQuotingQ
         if correctMod == mod+":Q" && vuc.IsWordPart && !vartype.IsShell() {          if correctMod == mod+":Q" && vuc.IsWordPart && !vartype.IsShell() {
   
                 isSingleWordConstant := func() bool {                  isSingleWordConstant := func() bool {
                         if G.Pkg == nil {                          if ck.MkLines.pkg == nil {
                                 return false                                  return false
                         }                          }
   
                         varinfo := G.Pkg.redundant.vars[varname]                          varinfo := ck.MkLines.pkg.redundant.vars[varname]
                         if varinfo == nil || !varinfo.vari.IsConstant() {                          if varinfo == nil || !varinfo.vari.IsConstant() {
                                 return false                                  return false
                         }                          }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

CVSweb <webmaster@jp.NetBSD.org>