Date: Thu, 26 Jun 2008 20:27:09 GMT From: "Philip M. Gollucci" <pgollucci@p6m7g8.com> To: FreeBSD-gnats-submit@FreeBSD.org Cc: edwin@FreeBSD.org Subject: ports/125025: [PATCH] Tools/scripts: Some cleanups, additions to bump_version.pl Message-ID: <200806262027.m5QKR9ng016753@riderwayinc.com> Resent-Message-ID: <200806262030.m5QKU6Yv081204@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 125025 >Category: ports >Synopsis: [PATCH] Tools/scripts: Some cleanups, additions to bump_version.pl >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Thu Jun 26 20:30:06 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Philip M. Gollucci >Release: FreeBSD 7.0-RELEASE amd64 >Organization: Riderway Inc. >Environment: System: FreeBSD riderwayinc.com 7.0-RELEASE FreeBSD 7.0-RELEASE #2: Thu Feb 28 21:20:48 UTC 2008 >Description: - added -c, doesn't change anything - added -n, deal with an already checkouted tree - removed negative logic in favor of 'unless' - switch to 3 arg form of open() - don't use globs for filehandles, this is been obsolete since at least 5.6.1 - handle possible errors in close() - allow CVSROOT to be overriden in the ENV Generated with FreeBSD Port Tools 0.77 >How-To-Repeat: >Fix: --- .patch begins here --- Index: bump_revision.pl =================================================================== RCS file: /home/ncvs/ports/Tools/scripts/bump_revision.pl,v retrieving revision 1.2 diff -u -u -r1.2 bump_revision.pl --- bump_revision.pl 6 Jun 2008 05:52:57 -0000 1.2 +++ bump_revision.pl 26 Jun 2008 20:24:12 -0000 @@ -10,15 +10,18 @@ use strict; use Cwd; use Data::Dumper; +use File::Basename; -use vars qw/$opt_i $opt_u/; +use vars qw/$opt_c $opt_n $opt_i $opt_u/; sub usage { print <<EOF; Usage: $0 [options] [<category>/]<portname> - -u <username> - Your freebsd.org username. Defaults to \$ENV{USER}. - -i <filename> - Use this for INDEX name. Defaults to /usr/ports/INDEX. + -c - Just check + -n - No tmpdir, just use dirname(INDEX) + -u <username> - Your freebsd.org username. Defaults to \$ENV{USER}. + -i <filename> - Use this for INDEX name. Defaults to /usr/ports/INDEX. Questions, suggestions etc -> edwin\@freebsd.org EOF @@ -30,16 +33,16 @@ { $opt_i = ""; $opt_u = ""; - getopts("i:u:"); + getopts("cni:u:"); $INDEX = $opt_i if ($opt_i); $USER = $opt_u if ($opt_u); - die "$INDEX doesn't seem to exist. Please check the value supplied with -i or use -i." if (! -f $INDEX); + die "$INDEX doesn't seem to exist. Please check the value supplied with -i or use -i." unless(-f $INDEX); } my $PORT = $ARGV[0]; -usage() if (!$PORT); +usage() unless($PORT); -my $CVSROOT = ":ext:$USER\@pcvs.freebsd.org:/home/pcvs"; +my $CVSROOT = $ENV{CVSROOT} // ':ext:$USER\@pcvs.freebsd.org:/home/pcvs'; # # Read the index, save some interesting keys @@ -47,10 +50,10 @@ my %index = (); { print "Reading $INDEX\n"; - open(FIN, "$INDEX") or die "Cannot open $INDEX for reading."; - my @lines = <FIN>; + open(my $fin, '<', "$INDEX") or die "Cannot open $INDEX for reading."; + my @lines = <$fin>; chomp(@lines); - close(FIN); + close($fin); foreach my $line (@lines) { my @a = split(/\|/, $line); @@ -80,9 +83,7 @@ # If specified as category/portname, that should be enough. # If specified as portname, check all indexes for existence or duplicates. # -if (defined $index{$PORT}) { - # all okay -} else { +unless (defined $index{$PORT}) { my $count = 0; my $n = ""; foreach my $p (keys(%index)) { @@ -126,13 +127,15 @@ # Create a temp directory and cvs checkout the ports # (don't do error checking, too complicated right now) # -my $TMPDIR = getcwd()."/.tmpdir.$$"; -{ - mkdir($TMPDIR, 0755); - chdir($TMPDIR); - `cvs -d $CVSROOT co -T $ports`; + +my $TMPDIR = File::Basename::dirname($INDEX); +unless ($opt_n) { + $TMPDIR = getcwd() . "/.tmpdir.$$"; + mkdir($TMPDIR, 0755); + chdir($TMPDIR); + system "cvs -d $CVSROOT co -T $ports"; + chdir($TMPDIR); } -chdir($TMPDIR); # # Bump portrevisions @@ -143,13 +146,15 @@ my $makefile = "ports/$p/Makefile"; print "- Updating Makefile of $p\n"; + next if $opt_c; - if (!open(FIN, $makefile)) { + my $fin; + unless(open($fin, $makefile)) { print "-- Cannot open Makefile of $p, ignored.\n"; next; } - my @lines = <FIN>; - close(FIN); + my @lines = <$fin>; + close($fin) or die "Can't close $makefile b/c $!"; chomp(@lines); my $revision = 1; @@ -160,28 +165,28 @@ } my $printedrev = 0; - open(FOUT, ">$makefile"); + open(my $fout, '>', "$makefile"); foreach my $line (@lines) { if (!$printedrev) { if ($line =~ /^CATEGORIES??=/ || $line =~ /^PORTEPOCH??=/) { - print FOUT "PORTREVISION= $revision\n"; + print $fout "PORTREVISION= $revision\n"; $printedrev = 1; # Fall through! } if ($line =~ /^PORTREVISION\?=/) { - print FOUT "PORTREVISION?= $revision\n"; + print $fout "PORTREVISION?= $revision\n"; $printedrev = 1; next; } if ($line =~ /^PORTREVISION=/) { - print FOUT "PORTREVISION= $revision\n"; + print $fout "PORTREVISION= $revision\n"; $printedrev = 1; next; } } - print FOUT "$line\n"; + print $fout "$line\n"; } - close(FOUT); + close($fout) or die "Can't close $makefile b/c $!"; } } --- .patch ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806262027.m5QKR9ng016753>