summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorrillig <rillig>2006-02-14 22:03:19 +0000
committerrillig <rillig>2006-02-14 22:03:19 +0000
commit1070b67af4188ec25151652b30d068414ed3b765 (patch)
treec7ffa171097b12def58d75afa27d181542544533 /pkgtools
parentdd2584db247d4a32a48a2ed8a6b3a98f37789c20 (diff)
downloadpkgsrc-1070b67af4188ec25151652b30d068414ed3b765.tar.gz
- 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 (limited to 'pkgtools')
-rw-r--r--pkgtools/pkglint/files/makevars.map23
-rw-r--r--pkgtools/pkglint/files/pkglint.pl41
2 files changed, 62 insertions, 2 deletions
diff --git a/pkgtools/pkglint/files/makevars.map b/pkgtools/pkglint/files/makevars.map
index 6f2176522f1..87911539328 100644
--- a/pkgtools/pkglint/files/makevars.map
+++ b/pkgtools/pkglint/files/makevars.map
@@ -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 @@ USE_INET6 YesNo
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_FILES List+ of Pathmask
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_ARGS List+ of ShellWord
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_PKGNAME_PREFIX Readonly
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 @@ INCOMPAT_CURSES List of PlatformTriple
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_BIN_ON_FTP Message
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_DEFAULT Userdefined
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_SKIP_REASON List+ of ShellWord
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 @@ PRINT_PLIST_AWK AwkCommand
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_NOOP List+ of Tool
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_PKGLOCALEDIR YesNo
USE_PKGSRC_GCC Userdefined
USE_TOOLS List+ of Tool
USE_X11 Yes
+USE_X11BASE Yes
WRKSRC WrkdirSubdirectory
X11_PKGSRCDIR Readonly
X11_TYPE Userdefined
diff --git a/pkgtools/pkglint/files/pkglint.pl b/pkgtools/pkglint/files/pkglint.pl
index c07e25345b0..95455c1a467 100644
--- a/pkgtools/pkglint/files/pkglint.pl
+++ b/pkgtools/pkglint/files/pkglint.pl
@@ -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 $hack_php_patches; # Ignore non-existing patches in distinfo
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 backtrace() {
}
}
+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 @@ sub load_package_Makefile($$$) {
}
}
+ 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 @@ sub checkline_mk_varassign($$$$$) {
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 @@ sub checkdir_package() {
# Initialize global variables
$makevar = {};
+ $varuse = {};
$seen_bsd_prefs_mk = false;
$seen_Makefile_common = false;
@@ -4449,6 +4477,16 @@ sub checkdir_package() {
}
$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 @@ sub checkitem($) {
$patchdir = "patches";
$distinfo_file = "distinfo";
$makevar = undef;
+ $varuse = undef;
$seen_Makefile_common = undef;
$pkgname = undef;
$hack_php_patches = false;