pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint/files Internal cleanup: moved some su...
details: https://anonhg.NetBSD.org/pkgsrc/rev/73ac58b59aac
branches: trunk
changeset: 497652:73ac58b59aac
user: rillig <rillig%pkgsrc.org@localhost>
date: Mon Aug 01 17:06:56 2005 +0000
description:
Internal cleanup: moved some subroutines so that fewer forward
references are needed. As the return value of the checkfile_*
subroutines is not needed, it is not provided anymore. Some other small
changes, which all do not affect the actual output or behavior of
pkglint.
diffstat:
pkgtools/pkglint/files/pkglint.pl | 234 +++++++++++++++----------------------
1 files changed, 98 insertions(+), 136 deletions(-)
diffs (truncated from 664 to 300 lines):
diff -r 61fd397494f3 -r 73ac58b59aac pkgtools/pkglint/files/pkglint.pl
--- a/pkgtools/pkglint/files/pkglint.pl Mon Aug 01 15:40:19 2005 +0000
+++ b/pkgtools/pkglint/files/pkglint.pl Mon Aug 01 17:06:56 2005 +0000
@@ -1,4 +1,4 @@
-#!@PERL@ -w
+#! @PERL@ -w
#
# pkglint - lint for package directory
#
@@ -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.219 2005/07/30 23:39:33 rillig Exp $
+# $NetBSD: pkglint.pl,v 1.220 2005/08/01 17:06:56 rillig Exp $
#
# This version contains lots of changes necessary for NetBSD packages
# done by:
@@ -47,15 +47,15 @@
{
my ($out, $table) = @_;
my (@width) = ();
- foreach my $row (@$table) {
- foreach my $i (0..(scalar(@$row)-1)) {
+ foreach my $row (@{$table}) {
+ foreach my $i (0..$#{$row}) {
if (!defined($width[$i]) || length($row->[$i]) > $width[$i]) {
$width[$i] = length($row->[$i]);
}
}
}
- foreach my $row (@$table) {
- my ($max) = (scalar(@$row) - 1);
+ foreach my $row (@{$table}) {
+ my ($max) = ($#{$row});
foreach my $i (0..$max) {
if ($i != 0) {
print $out (" ");
@@ -67,7 +67,6 @@
}
print $out ("\n");
}
- return 1;
}
#== End of PkgLint::Util ==================================================
@@ -208,14 +207,10 @@
my ($class, $file, $lineno, $text) = @_;
my ($self) = ({});
bless($self, $class);
- $self->_init($file, $lineno, $text);
- return $self;
- }
- sub _init($$$$) {
- my ($self, $file, $lineno, $text) = @_;
$self->{"file"} = $file;
$self->{"lineno"} = $lineno;
$self->{"text"} = $text;
+ return $self;
}
sub file($) {
return shift(@_)->{"file"};
@@ -265,7 +260,7 @@
while (defined($line = <F>)) {
$lineno++;
$seen_newline = ($line =~ s/\n$//);
- push(@$result, PkgLint::FileUtil::Line->new($fname, $lineno, $line));
+ push(@{$result}, PkgLint::FileUtil::Line->new($fname, $lineno, $line));
}
if (!$seen_newline) {
$result->[-1]->log_error("File must end with a newline.");
@@ -378,8 +373,6 @@
my $seen_Makefile_common;
my $pkgname;
-# these subroutines return C<true> if the checking succeeded (that includes
-# errors in the file) and C<false> if the file could not be checked.
sub checkfile_DESCR($$);
sub checkfile_distinfo($$);
sub checkfile_extra($$);
@@ -398,17 +391,6 @@
sub checkearlier($@);
sub check_predefined_sites($$);
-sub init_global_vars() {
- $pkgdir = ".";
- $filesdir = "files";
- $patchdir = "patches";
- $distinfo_file = "distinfo";
- $scriptdir = "scripts";
- $seen_USE_PKGLOCALEDIR = false;
- $seen_Makefile_common = false;
- $pkgname = undef;
-}
-
sub help($$$) {
my ($out, $exitval, $show_all) = @_;
my ($prog) = (basename($0));
@@ -477,7 +459,6 @@
}
}
}
- return true;
}
sub parse_command_line() {
@@ -503,7 +484,6 @@
help(*STDERR, 1, false);
}
}
- return true;
}
sub load_make_vars_typemap() {
@@ -514,7 +494,7 @@
}
$vartypes = {};
- foreach my $line (@$lines) {
+ foreach my $line (@{$lines}) {
if ($line->text =~ qr"^(?:#.*|\s*)$") {
# ignore empty and comment lines
@@ -571,46 +551,24 @@
return $predefined_sites;
}
-sub check_directory($) {
- my ($dir) = @_;
-
- if (-f "${dir}/../mk/bsd.pkg.mk") {
- log_info(NO_FILE, NO_LINE_NUMBER, "Checking category Makefile.");
- check_category($dir);
-
- } elsif (-f "${dir}/../../mk/bsd.pkg.mk") {
- load_predefined_sites("${dir}/../..");
- check_package($dir);
-
- } else {
- log_error($dir, NO_LINE_NUMBER, "Neither a package nor a category.");
- }
-}
-
-sub main() {
- parse_command_line();
-
- if (@ARGV) {
- foreach my $dir (@ARGV) {
- check_directory($dir);
- }
- } else {
- check_directory(".");
- }
- print_summary_and_exit($opt_quiet);
-}
-
sub check_package($) {
my ($dir) = @_;
my ($whole, $lines);
- init_global_vars();
+ $pkgdir = ".";
+ $filesdir = "files";
+ $patchdir = "patches";
+ $distinfo_file = "distinfo";
+ $scriptdir = "scripts";
+ $seen_USE_PKGLOCALEDIR = false;
+ $seen_Makefile_common = false;
+ $pkgname = undef;
# we need to handle the Makefile first to get some variables
if (!load_package_Makefile($dir, "${dir}/Makefile", \$whole, \$lines)) {
log_error("${dir}/Makefile", NO_LINE_NUMBER, "Cannot be read.");
- return false;
+ return;
}
my @files = <${dir}/*>;
@@ -673,8 +631,7 @@
if (grep { $_ !~ qr"/CVS$" } <$dir/scripts/*>) {
log_warning("$dir/scripts", NO_LINE_NUMBER, "This directory and its contents are deprecated! Please call the script(s) explicitly from the corresponding target(s) in the pkg's
Makefile.");
}
- return true;
-} # check_package
+}
sub is_committed($) {
my ($fname) = @_;
@@ -703,7 +660,6 @@
if (length($line->text) > $maxlength) {
$line->log_warning("Line too long (should be no more than $maxlength characters).");
}
- return true;
}
sub checkline_valid_characters($$) {
@@ -715,7 +671,6 @@
my @chars = map { $_ = sprintf("0x%02x", ord($_)); } split(//, $rest);
$line->log_warning(sprintf("Line contains invalid characters (%s).", join(", ", @chars)));
}
- return true;
}
sub checkline_trailing_whitespace($) {
@@ -723,7 +678,6 @@
if ($line->text =~ /\s+$/) {
$line->log_warning("Trailing white-space.");
}
- return true;
}
sub checkline_rcsid_regex($$$) {
@@ -732,12 +686,11 @@
if ($line->text !~ qr"^${prefix_regex}${regex_rcsidstr}$") {
$line->log_error("\"${prefix}\$${conf_rcsidstr}\$\" expected.");
}
- return true;
}
sub checkline_rcsid($$) {
my ($line, $prefix) = @_;
- return checkline_rcsid_regex($line, quotemeta($prefix), $prefix);
+ checkline_rcsid_regex($line, quotemeta($prefix), $prefix);
}
sub checklines_trailing_empty_lines($) {
@@ -751,7 +704,6 @@
if ($last != $max) {
$lines->[$last]->log_warning("Trailing empty lines.");
}
- return true;
}
#
@@ -766,27 +718,25 @@
log_subinfo("checkfile_DESCR", $fname, NO_LINE_NUMBER, undef);
checkperms($fname);
- if (!defined($descr = load_file($fname))) {
+ if (!($descr = load_file($fname))) {
log_error($fname, NO_LINE_NUMBER, "Cannot be read.");
- return false;
+ return;
}
- if (scalar(@{$descr}) == 0) {
+ if (@{$descr} == 0) {
log_error($fname, NO_LINE_NUMBER, "Must not be empty.");
- return true;
+ return;
}
- foreach my $line (@$descr) {
+ foreach my $line (@{$descr}) {
checkline_length($line, $maxchars);
checkline_trailing_whitespace($line);
checkline_valid_characters($line, $regex_validchars);
}
checklines_trailing_empty_lines($descr);
- if (scalar(@$descr) > $maxlines) {
+ if (@{$descr} > $maxlines) {
log_warning($fname, NO_LINE_NUMBER, "File too long (should be no more than $maxlines lines).");
}
-
- return true;
}
sub checkfile_distinfo($$) {
@@ -796,19 +746,19 @@
log_subinfo("checkfile_distinfo", $fname, NO_LINE_NUMBER, undef);
checkperms($fname);
- if (!defined($distinfo = load_file($fname))) {
+ if (!($distinfo = load_file($fname))) {
log_error($fname, NO_LINE_NUMBER, "Cannot be read.");
- return false;
+ return;
}
- if (scalar(@$distinfo) == 0) {
+ if (@{$distinfo} == 0) {
log_error($fname, NO_LINE_NUMBER, "Must not be empty.");
- return true;
+ return;
}
checkline_rcsid($distinfo->[0], "");
- foreach my $line (@$distinfo[1 .. scalar(@$distinfo)-1]) {
+ foreach my $line (@{$distinfo}) {
next unless $line->text =~ /^(MD5|SHA1|RMD160) \(([^)]+)\) = (.*)$/;
my ($alg, $patch, $sum) = ($1, $2, $3);
@@ -833,7 +783,6 @@
log_error($fname, NO_LINE_NUMBER, "$patch is not recorded. Rerun '$conf_make makepatchsum'.");
}
}
- return true;
}
Home |
Main Index |
Thread Index |
Old Index