pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint/files - Added experimental support fo...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/de2e61a3f94a
branches:  trunk
changeset: 508099:de2e61a3f94a
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Tue Feb 14 22:03:19 2006 +0000

description:
- Added experimental support for detecting defined, but unused variables.
  The main task is now to filter out the false positives (that is, all
  system-defined variables) and add them to makevars.map.

diffstat:

 pkgtools/pkglint/files/makevars.map |  23 +++++++++++++++++++-
 pkgtools/pkglint/files/pkglint.pl   |  41 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 2 deletions(-)

diffs (228 lines):

diff -r 314c5a858d6d -r de2e61a3f94a pkgtools/pkglint/files/makevars.map
--- a/pkgtools/pkglint/files/makevars.map       Tue Feb 14 21:57:44 2006 +0000
+++ b/pkgtools/pkglint/files/makevars.map       Tue Feb 14 22:03:19 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: makevars.map,v 1.58 2006/01/20 13:03:10 rillig Exp $
+# $NetBSD: makevars.map,v 1.59 2006/02/14 22:03:19 rillig Exp $
 #
 
 # This file contains the guessed type of some variables, according to
@@ -37,6 +37,7 @@
 ALL_ENV                        List+ of ShellWord
 ALTERNATIVES_FILE      Filename
 APACHE_MODULE          Yes
+AUTOCONF_REQD          List+
 BDB185_DEFAULT         Userdefined
 BDBBASE                        Readonly
 BDB_ACCEPTED           List of { db1 db2 db3 db4 }
@@ -52,6 +53,7 @@
 BUILDLINK_INCDIRS      List of Pathname
 BUILDLINK_LIBDIRS      List of Pathname
 BUILDLINK_PACKAGES     BuildlinkPackages
+BUILDLINK_PASSTHRU_DIRS        List+ of Pathname
 BUILDLINK_PKGSRCDIR    RelativePkgDir
 BUILDLINK_RECOMMENDED  List!+ of Dependency
 BUILDLINK_RPATHDIRS    List of Pathname
@@ -78,12 +80,16 @@
 CONFIGURE_DIRS         List of WrksrcSubdirectory
 CONFIGURE_ENV          List+ of ShellWord
 CONFIGURE_SCRIPT       Pathname
+CONFIG_GUESS_OVERRIDE  List+ of Pathmask
+CONFIS_STATUS_OVERRIDE List+ of Pathmask
+CONFIG_SUB_OVERRIDE    List+ of Pathmask
 CONFLICTS              List of Dependency
 CONF_FILES             List of ShellWord
 CONF_FILES_PERMS       List of ShellWord
 CPPFLAGS               List+ of CFlag
 CXX                    Readonly
 CXXFLAGS               List+ of CFlag
+DEINSTALL_EXTRA_TMPL   List+ of Pathname
 DEPENDS                        List!+ of DependencyWithPath
 DISTFILES              List of Filename
 DISTINFO_FILE          RelativePkgPath
@@ -98,8 +104,10 @@
 EMACS_TYPE             Userdefined
 EMACS_USE_LEIM         Yes
 EMACS_VERSIONS_ACCEPTED        List of { emacs21 emacs21nox emacs20 xemacs215 xemacs214 }
+EXTRACT_CMD            List of ShellWord
 EXTRACT_ELEMENTS       List of Pathmask
 EXTRACT_ONLY           List of Pathname
+EXTRACT_OPTS_ZIP       List of ShellWord
 EXTRACT_SUFX           DistSuffix
 EXTRACT_USING          { gtar nbtar pax }
 FAMBASE                        Readonly
@@ -116,6 +124,8 @@
 INFO_FILES             List of Pathmask
 INSTALLATION_DIRS      List of Pathname
 INSTALL_DIRS           List of WrksrcSubdirectory
+INSTALL_EXTRA_TMPL     List+ of Pathname
+INSTALL_MAKE_FLAGS     List+ of ShellWord
 INSTALL_SCRIPTS_ENV    List+ of ShellWord
 INSTALL_TARGET         List of Identifier
 INSTALL_UNSTRIPPED     YesNo
@@ -148,6 +158,7 @@
 NO_BUILD               Yes
 NO_CHECKSUM            Yes
 NO_CONFIGURE           Yes
+NO_INSTALL_MANPAGES    Yes
 NO_MTREE               Yes
 NO_PKGTOOLS_REQD_CHECK Yes
 NO_PKG_REGISTER                Yes
@@ -162,6 +173,7 @@
 PAM_TYPE               Readonly
 PATCHDIR               RelativePkgPath
 PATCHFILES             List of Filename
+PATCH_DIST_STRIP       List of ShellWord
 PATCH_SITES            List of URL
 PERL5_PACKLIST         Perl5Packlist
 PGSQL_VERSIONS_ACCEPTED        List of { 73 74 80 }
@@ -206,6 +218,7 @@
 PKG_SUFX               Userdefined
 PKG_SUGGESTED_OPTIONS  List of Option
 PKG_SUPPORTED_OPTIONS  List of Option
+PKG_SYSCONFSUBDIR      Pathname
 PKG_USERS              List of ShellWord
 PLIST_SRC              List of RelativePkgPath
 PLIST_SUBST            List+ of ShellWord
@@ -214,21 +227,27 @@
 PTHREAD_AUTO_VARS      YesNo
 PTHREAD_OPTS           List+ of { native optional require }
 PTHREAD_TYPE           Readonly
+RCD_SCRIPTS            List of Filename
 REPLACE_EMACS          List+ of Pathmask
 REPLACE_PERL           List+ of Pathmask
+REQD_DIRS              List+ of Pathname
 RESTRICTED             Message
 SCRIPTS_ENV            List+ of ShellWord
 SPECIAL_PERMS          List of ShellWord
 SHLIBTOOL_OVERRIDE     List+ of Pathmask
 SUBST_CLASSES          List+
 SUBST_FILES            List of Pathmask
+SUBST_FILTER_CMD       List of ShellWord
+# ^^ more appropriately, a Shellcommand
 SUBST_MESSAGE          SubstMessage
 SUBST_SED              List of ShellWord
 # ^^ This may be changed to a List+ later.
 SUBST_STAGE            Stage
 SVR4_PKGNAME           SVR4PkgName
+TEST_DIRS              List of WrksrcSubdirectory
 TEST_ENV               List+ of ShellWord
 TEST_TARGET            List of Identifier
+TEX_ACCEPTED           List of { teTeX1 teTeX2 teTeX3 }
 TOOLS_ALIASES          List+ of Filename
 TOOLS_BROKEN           List+ of Tool
 TOOLS_CREATE           List+ of Tool
@@ -237,6 +256,7 @@
 TOOLS_PATH             Pathname
 UNLIMIT_RESOURCES      List of { datasize stacksize memorysize }
 USE_BUILTIN            YesNoFromCommand
+USE_DIRS               List of PkgName
 USE_IMAKE              Yes
 USE_JAVA               { run yes }
 USE_JAVA2              { YES yes 1.4 1.5 }
@@ -248,6 +268,7 @@
 USE_PKGSRC_GCC         Userdefined
 USE_TOOLS              List+ of Tool
 USE_X11                        Yes
+USE_X11BASE            Yes
 WRKSRC                 WrkdirSubdirectory
 X11_PKGSRCDIR          Readonly
 X11_TYPE               Userdefined
diff -r 314c5a858d6d -r de2e61a3f94a pkgtools/pkglint/files/pkglint.pl
--- a/pkgtools/pkglint/files/pkglint.pl Tue Feb 14 21:57:44 2006 +0000
+++ b/pkgtools/pkglint/files/pkglint.pl Tue Feb 14 22:03:19 2006 +0000
@@ -1,5 +1,5 @@
 #! @PERL@
-# $NetBSD: pkglint.pl,v 1.515 2006/02/13 17:50:40 rillig Exp $
+# $NetBSD: pkglint.pl,v 1.516 2006/02/14 22:03:19 rillig Exp $
 #
 
 # pkglint - static analyzer and checker for pkgsrc packages
@@ -1276,6 +1276,7 @@
 my $seen_bsd_prefs_mk;         # Has bsd.prefs.mk already been included?
 
 my $makevar;                   # Table of variables and values
+my $varuse;                    # Table of used variables
 my $seen_Makefile_common;      # Does the package have any .includes?
 
 my @todo_items;                        # The list of directory entries that still need
@@ -1923,6 +1924,21 @@
        }
 }
 
+sub determine_used_variables($) {
+       my ($lines) = @_;
+       my ($rest);
+
+       foreach my $line (@{$lines}) {
+               $line->log_debug(".");
+               $rest = $line->text;
+               while ($rest =~ s/(?:\$\{|defined\(|empty\()([0-9.A-Z_a-z]+)[:})]//) {
+                       my ($varname) = ($1);
+                       $varuse->{$varname} = $line;
+                       $line->log_debug("Variable ${varname} is used.");
+               }
+       }
+}      
+
 #
 # Loading package-specific data from files.
 #
@@ -2033,6 +2049,8 @@
                }
        }
 
+       determine_used_variables($all_lines);
+
        # HACK
        if ($whole =~ qr"\nPHPEXT_MK" && $whole !~ qr"\nUSE_PHP_EXT_PATCHES") {
                log_info($fname, NO_LINE_NUMBER, "[hack] USE_PHP_EXT_PATCHES");
@@ -3201,6 +3219,15 @@
        checkline_mk_text($line, $value);
        checkline_mk_vartype($line, $varname, $op, $value, $comment);
 
+       # If the variable is not used and is untyped, it may be a
+       # spelling mistake.
+       if (defined($varuse) && !exists($varuse->{$varname})) {
+               my $vt = get_vartypes_map();
+               if (!exists($vt->{$varname}) && !exists($vt->{$varbase})) {
+                       $line->log_warning("[experimental] ${varname} is defined, but not used.");
+               }
+       }
+
        if (!$is_internal && $varname =~ qr"^_") {
                $line->log_warning("Variable names starting with an underscore are reserved for internal pkgsrc use.");
        }
@@ -4427,6 +4454,7 @@
 
        # Initialize global variables
        $makevar = {};
+       $varuse = {};
        $seen_bsd_prefs_mk = false;
        $seen_Makefile_common = false;
 
@@ -4449,6 +4477,16 @@
        }
        $have_distinfo = false;
        $have_patches = false;
+
+       # Determine the used variables before checking any of the
+       # Makefile fragments.
+       foreach my $fname (@files) {
+               if ($fname =~ qr"\.mk$"
+               && (defined(my $lines = load_lines($fname, true)))) {
+                       determine_used_variables($lines);
+               }
+       }
+
        foreach my $fname (@files) {
                if ($fname eq "${current_dir}/Makefile") {
                        $opt_check_Makefile and checkfile_package_Makefile($fname, $whole, $lines);
@@ -4499,6 +4537,7 @@
        $patchdir               = "patches";
        $distinfo_file          = "distinfo";
        $makevar                = undef;
+       $varuse                 = undef;
        $seen_Makefile_common   = undef;
        $pkgname                = undef;
        $hack_php_patches       = false;



Home | Main Index | Thread Index | Old Index