summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2005-08-06 22:20:10 +0000
committerrillig <rillig@pkgsrc.org>2005-08-06 22:20:10 +0000
commit49fa8bb914a1e387b03dc6db0d43878dae8f3af2 (patch)
tree2f3fc938ddad277cfa402ca0f5bc921e5dd70cb9 /pkgtools
parentff58c1b6cb6d72091c3a3c8a349fe14a70c9403a (diff)
downloadpkgsrc-49fa8bb914a1e387b03dc6db0d43878dae8f3af2.tar.gz
The check_category subroutine has been converted to a one-pass checker.
The new code, which is not as nice as the old code, will hopefully allow the --autofix option to be implemented really easily. If that will not become true, I will probably revert to the old code. There's an indentation FIXME in the code to keep this patch small. I will remove that FIXME in a minute.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkglint/files/pkglint.pl91
1 files changed, 57 insertions, 34 deletions
diff --git a/pkgtools/pkglint/files/pkglint.pl b/pkgtools/pkglint/files/pkglint.pl
index 6e3a5468960..bd04db3fb08 100644
--- a/pkgtools/pkglint/files/pkglint.pl
+++ b/pkgtools/pkglint/files/pkglint.pl
@@ -11,7 +11,7 @@
# Freely redistributable. Absolutely no warranty.
#
# From Id: portlint.pl,v 1.64 1998/02/28 02:34:05 itojun Exp
-# $NetBSD: pkglint.pl,v 1.232 2005/08/06 21:08:05 rillig Exp $
+# $NetBSD: pkglint.pl,v 1.233 2005/08/06 22:20:10 rillig Exp $
#
# This version contains lots of changes necessary for NetBSD packages
# done by:
@@ -645,6 +645,21 @@ sub is_committed($) {
return false;
}
+sub get_subdirs($) {
+ my ($dir) = @_;
+ my (@result) = ();
+
+ if (opendir(DIR, $dir)) {
+ foreach my $subdir (readdir(DIR)) {
+ if ($subdir ne "." && $subdir ne ".." && $subdir ne "CVS" && -d "${dir}/${subdir}") {
+ push(@result, $subdir);
+ }
+ }
+ closedir(DIR);
+ }
+ return @result;
+}
+
#
# Subroutines common to all checking routines
#
@@ -2026,8 +2041,6 @@ sub check_category($) {
my ($dir) = @_;
my $fname = "${dir}/Makefile";
my ($lines);
- my (@makefile_subdirs) = ();
- my (@filesys_subdirs) = ();
my ($is_wip);
if (!($lines = load_file($fname))) {
@@ -2065,7 +2078,19 @@ sub check_category($) {
}
my ($last_subdir) = (undef);
- for my $line (@{$lines}[5 .. $#{$lines} - 2]) {
+
+ my @filesys_subdirs = sort(get_subdirs($dir));
+ my ($filesys_index, $filesys_atend) = (0, false);
+ my ($lines_index, $lines_atend) = (5, false);
+ my ($fetch_next_line) = true;
+
+ while (!$lines_atend || !$filesys_atend) {
+ my $line = $lines->[$lines_index];
+
+ if (!$lines_atend && $fetch_next_line) {
+ $fetch_next_line = false;
+
+# FIXME: <indent +1>
if ($line->text =~ qr"^(#?)SUBDIR\+=(\s*)(\S+)\s*(?:#\s*(.*?)\s*|)$") {
my ($comment_flag, $indentation, $subdir, $comment) = ($1, $2, $3, $4);
@@ -2084,47 +2109,45 @@ sub check_category($) {
}
$last_subdir = $subdir;
- push(@makefile_subdirs, $subdir);
-
- } else {
+ } elsif ($is_wip && $line->text eq "") {
# ignore the special case "wip", which defines its own "index" target.
- if ($is_wip && $line->text eq "") {
- last;
- }
+ $lines_atend = true;
+ } else {
$line->log_error("SUBDIR+= line expected.");
}
- }
+# FIXME: </indent>
- if (@{$lines} > 7 && $lines->[-2]->text ne "") {
- $lines->[-2]->log_error("Empty line expected.");
- }
- if (@{$lines} > 7 && $lines->[-1]->text ne ".include \"../mk/bsd.pkg.subdir.mk\"") {
- $lines->[-1]->log_error("Expected this: .include \"../mk/bsd.pkg.subdir.mk\"");
- }
+ $lines_index++;
+ }
- @filesys_subdirs = grep { ($_ = substr($_, length($dir) + 1, -1)) ne "CVS"; } glob("${dir}/*/");
+ my $f = ($filesys_atend) ? undef : $filesys_subdirs[$filesys_index];
+ my $m = ($lines_atend) ? undef : $last_subdir;
- @filesys_subdirs = sort(@filesys_subdirs);
- @makefile_subdirs = sort(@makefile_subdirs);
- my ($findex, $mindex) = (0, 0);
- my ($fmax, $mmax) = (scalar(@filesys_subdirs), scalar(@makefile_subdirs));
- while ($findex < $fmax || $mindex < $mmax) {
- my $f = ($findex < $fmax) ? $filesys_subdirs[$findex] : undef;
- my $m = ($mindex < $mmax) ? $makefile_subdirs[$mindex] : undef;
+ if (!$filesys_atend && ($lines_atend || $f lt $m)) {
+ $line->log_error("${f} exists in the file system, but not in the Makefile.");
+ $filesys_index++;
- if ($findex < $fmax && ($mindex == $mmax || $f lt $m)) {
- log_error($fname, NO_LINE_NUMBER, "$f exists in the file system, but not in the Makefile.");
- $findex++;
+ } elsif (!$lines_atend && ($filesys_atend || $m lt $f)) {
+ $line->log_error("${m} exists in the Makefile, but not in the file system.");
+ $fetch_next_line = true;
- } elsif ($mindex < $mmax && ($findex == $fmax || $m lt $f)) {
- log_error($fname, NO_LINE_NUMBER, "$m exists in the Makefile, but not in the file system.");
- $mindex++;
+ } else { # $f eq $m
+ $filesys_index++;
+ $fetch_next_line = true;
+ }
- } else { # $findex < $fmax && $mindex < $mmax && $f eq $m
- $findex++;
- $mindex++;
+ if ($lines_index == $#{$lines} - 1) {
+ $lines_atend = true;
}
+ $filesys_atend = ($filesys_index == @filesys_subdirs);
+ }
+
+ if (@{$lines} > 7 && $lines->[-2]->text ne "") {
+ $lines->[-2]->log_error("Empty line expected.");
+ }
+ if (@{$lines} > 7 && $lines->[-1]->text ne ".include \"../mk/bsd.pkg.subdir.mk\"") {
+ $lines->[-1]->log_error("Expected this: .include \"../mk/bsd.pkg.subdir.mk\"");
}
}