[csw-devel] SF.net SVN: gar:[17094] csw/mgar/pkg/cpan/makemake

dmichelsen at users.sourceforge.net dmichelsen at users.sourceforge.net
Mon Feb 20 17:53:39 CET 2012


Revision: 17094
          http://gar.svn.sourceforge.net/gar/?rev=17094&view=rev
Author:   dmichelsen
Date:     2012-02-20 16:53:39 +0000 (Mon, 20 Feb 2012)
Log Message:
-----------
cpan/makemake: Add patch from Claudio

Modified Paths:
--------------
    csw/mgar/pkg/cpan/makemake

Modified: csw/mgar/pkg/cpan/makemake
===================================================================
--- csw/mgar/pkg/cpan/makemake	2012-02-20 16:31:51 UTC (rev 17093)
+++ csw/mgar/pkg/cpan/makemake	2012-02-20 16:53:39 UTC (rev 17094)
@@ -2,18 +2,16 @@
 
 use strict;
 use warnings;
-
-use File::chdir;
+use feature ':5.10';
+use Cwd; # was use File::chdir;
 use CPAN;
 use YAML qw(LoadFile);
 use File::Path;
 use File::Temp qw(:POSIX);
 use Module::Version 'get_version';
-use version 0.77; # get latest bug-fixes and API
+use version 0.77;   # get latest bug-fixes and API
 use Data::Dumper;
-
-# For online retreival of catalogname for package
-use LWP::UserAgent;
+use LWP::UserAgent; # For online retreival of catalogname for package
 use JSON;
 
 # TBD:
@@ -30,146 +28,26 @@
 # completes successfuly, the log file is thrown away.  If the command fails,
 # the log file is printed along with an error message by calling fail.
 
-our ($verbose, $logfile, $pgm);
-sub logoutput {
-        if( ! $verbose ) {
-                $logfile = tmpnam();
-                open( OLDOUT, '>&STDOUT' );
-                open( OLDERR, '>&STDERR' );
-                open( STDOUT, "> $logfile" );
-                open( STDERR, "> $logfile" );
-        }
-}
 
-sub endlog {
-        if( ! $verbose ) {
-                # Reference fh to silence warning
-                select( OLDERR ); select( OLDOUT );
+### Variables ###
+my ( $verbose, $logfile, $pgm );
+my $cpandir = getcwd;
 
-                # Restore output.
-                select( STDOUT);
-                close( STDOUT );
-                open( STDOUT, ">&OLDOUT" );
-                close( STDERR );
-                open( STDERR, ">&OLDERR" );
 
-                rmtree( $logfile );
-        }
+### User input ###
+my $modname = shift(@ARGV);
+if ( !defined $modname ) {
+	say STDERR "Please supply the module name as a parameter.\nBaling out...";
+	exit(1);
 }
 
-sub fail {
-        close( STDOUT );
-        open( STDOUT, ">&OLDOUT" );
-        close( STDERR );
-        open( STDERR, ">&OLDERR" );
-        open( LOG, "< $logfile" ) or
-        	die "$pgm: Error, @_ - can't open log\n";
-        print STDERR foreach <LOG>;
-        close( LOG );
-        rmtree( $logfile );
-        die "\n$pgm: Error, @_\n";
-}
+### Main ###
 
-sub guess_name_from_module {
-  my $modname = shift @_;
-  my $mod = (CPAN::Shell->expand("Module", $modname))[0];
-  if( !$mod ) {
-    print STDERR "ERROR: Can not find module $modname/n";
-    return;
-  }
-  my $filename = $mod->distribution->base_id;
-  my ($name, $fileversion) = ($filename =~ /^(\D+)-(\d+(?:\.\d+)*)/);
-  my $dirname = $name;
-  my $pkgname = lc( $name );
-  $pkgname = "CSWpm-" . $pkgname;
-  return ($pkgname, $dirname);
-}
+logoutput(); # Start logging
+my $mod = ( CPAN::Shell->expand( "Module", $modname ) )[0]
+	or die "can not locate CPAN module $modname";
+endlog();    # End logging
 
-sub path2pkg {
-  my @pathes = @_;
-
-  return () if( @pathes == 0 );
-
-  my %pkgs;
-  open P, "/home/dam/mgar/gar/v2/bin/pkgdb show filename " . join( " ", @pathes ) . " |" or die "Cannot open gar/bin/pkgdb";
-  while( <P> ) {
-    my $path = shift @pathes;
-    $pkgs{$path} = [ split( /\s+/, $_ ) ];
-  }
-  close P;
-
-  return %pkgs;
-}
-
-sub mod2pkg {
-  my $modname = shift @_;
-  my @result;
-  my $path = `/opt/csw/bin/perl -S /opt/csw/bin/pmpath $modname 2>&1`;
-  chomp $path;
-  if( $path =~ /Can't locate/ ) {
-    print STDERR "$modname is missing\n";
-    return;
-  }
-
-  my %pkgs = path2pkg( $path );
-  return (map { @{$pkgs{$_} or ["undef $_"]} } keys %pkgs);
-}
-
-sub dep_pkgs {
-  my $req = shift @_;
-  my @result;
-  foreach my $modname (keys %$req) {
-    my $version = version->parse( $req->{$modname} );
-    if( $modname eq "perl" ) {
-      if( version->parse($^V) < $version ) {
-        die "requires perl version $version";
-      }
-      next;
-    }
-    if( $version > version->parse( get_version($modname) ) ) {
-      print STDERR "Version of $modname is too old. Required is $version, installed is ",
-        (get_version($modname) or "nothing"), "\n";
-    }
-
-    my @pkgs = mod2pkg( $modname );
-    if( @pkgs > 1 ) {
-      print STDERR "ERROR: More than one package for module '$modname' found: @pkgs\n";
-    }
-    my $pkg = shift @pkgs;
-    if( $pkg ) {
-      print STDERR "Packages for module '$modname': $pkg\n";
-      next if( $pkg eq 'CSWperl' );
-    } else {
-      print STDERR "MISSING package for '$modname'\n";
-      # Guess name of missing module
-      my $dirname;
-      ($pkg, $dirname) = guess_name_from_module( $modname );
-      if( $pkg ) {
-        if( ! -d $dirname ) {
-          print STDERR "MISSING $pkg directory '$dirname', to build please invoke   makemake $modname\n";
-        } else {
-          print STDERR "MISSING $pkg Please build and install module in $dirname\n";
-        }
-      }
-    }
-    push @result, $pkg if( $pkg );
-  }
-
-  return @result;
-}
-
-
-
-my $modname = shift @ARGV;
-
-my $cpandir = $CWD;
-
-logoutput();
-my $mod = (CPAN::Shell->expand("Module", $modname))[0];
-endlog();
-
-die "can not locate CPAN module $modname" unless( $mod );
-
 # We need this so dependencies can be retreived
 #logoutput();
 #close( STDIN );
@@ -177,18 +55,18 @@
 #endlog();
 # print "Make done\n";
 
-
 my $filename = $mod->cpan_file;
-my $author = (split(/\//, $filename))[2];
-my $author1 = substr($author,0,1);
-my $author2 = substr($author,0,2);
-print STDERR "WARNING: Strange username, CPAN lists " . $mod->userid . " but module is stored for $author\n" if( $author ne $mod->userid );
+my $author   = ( split( /\//, $filename ) )[2];
+my $author1  = substr( $author, 0, 1 );
+my $author2  = substr( $author, 0, 2 );
+print STDERR "WARNING: Strange username, CPAN lists " . $mod->userid . " but module is stored for $author\n"
+	if ( $author ne $mod->userid );
 
-my ($notstandard, $fileonly) = ($filename =~ m,^${author1}/${author2}/${author}/(.*/)?([^/]+)$,);
+my ( $notstandard, $fileonly ) = ( $filename =~ m,^${author1}/${author2}/${author}/(.*/)?([^/]+)$, );
 
 # That is the version of the module which may be different than the one from the file
 # my $version = $mod->cpan_version;
-my ($name, $fileversion) = ($fileonly =~ /^(\D+)-(\d+(?:\.\d+)*)/);
+my ( $name, $fileversion ) = ( $fileonly =~ /^(\D+)-(\d+(?:\.\d+)*)/ );
 
 #print "filename: $filename\n";
 #print "notstandard: $notstandard\n";
@@ -197,151 +75,289 @@
 #print "fileversion: $fileversion\n";
 #print "author: $author\n";
 
-my $cswpkg = lc( $modname );
+my $cswpkg = lc($modname);
 $cswpkg =~ s/::/-/g;
 $cswpkg = "CSWpm-" . $cswpkg;
 
-my $cswcatalog = lc( $modname );
+my $cswcatalog = lc($modname);
 $cswcatalog =~ s/::/_/g;
 $cswcatalog = "pm_" . $cswcatalog;
 
 
 # print "DSLIP: ", Dumper( $mod->dslip_status() );
-my $dslip = $mod->dslip_status;
-my $archall = (!defined $dslip->{L} ? 2 :
-               $dslip->{L} eq 'p'   ? 1 :
-                                      0);
+my $dslip   = $mod->dslip_status;
+my $archall = (
+	  !defined $dslip->{L} ? 2
+	: $dslip->{L} eq 'p' ? 1
+	: 0
+);
 
 logoutput();
 $mod->distribution->get;
 endlog();
+
 #$mod->distribution->make;
 my $distdir = $mod->distribution->dir;
 
-my (@build_dep_pkgs, @runtime_dep_pkgs);
+my ( @build_dep_pkgs, @runtime_dep_pkgs );
 
 my $description;
-if( -f "$distdir/META.yml" ) {
-  my $meta = LoadFile( "$distdir/META.yml" );
-  $description = $meta->{abstract} if( exists $meta->{abstract} );
-  my $req = $meta->{requires};
-  my $recommends = $meta->{recommends};
-  my $build_requires = $meta->{build_requires};
+if ( -f "$distdir/META.yml" ) {
+	my $meta = LoadFile("$distdir/META.yml");
+	$description = $meta->{abstract} if ( exists $meta->{abstract} );
+	my $req            = $meta->{requires};
+	my $recommends     = $meta->{recommends};
+	my $build_requires = $meta->{build_requires};
 
-  @build_dep_pkgs = dep_pkgs( $build_requires );
-  @runtime_dep_pkgs = dep_pkgs( $req );
+	@build_dep_pkgs   = dep_pkgs($build_requires);
+	@runtime_dep_pkgs = dep_pkgs($req);
 }
 
-$description ||= $mod->description;
-$description ||= $mod->manpage_headline;
-$description ||= $mod->distribution->as_glimpse;
-$description ||= "";
-$description = ucfirst( $description );
-chomp( $description );
+$description //= $mod->description; # Changed to defined from false or
+$description //= $mod->manpage_headline;
+$description //= $mod->distribution->as_glimpse;
+$description //= "";
+$description = ucfirst($description);
+chomp($description);
 
 # Come back from cpan module build directory to GAR cpan/
-$CWD = $cpandir;
+chdir($cpandir) or die($!);
 
-if( ! -d $name ) {
-  system( "pwd; gmake newpkg-$name" );
+if ( !-d $name ) {
+	system("pwd; gmake newpkg-$name");
 }
 
-open( MF, ">$name/trunk/Makefile" ) or die "Couldn't write to $name/trunk/Makefile";
+open( my $mf_fh, '>', "$name/trunk/Makefile" ) or die "Couldn't write to $name/trunk/Makefile";
 
-print MF "NAME = $name\n";
-print MF "VERSION = $fileversion\n";
-print MF "CATEGORIES = cpan\n";
-print MF "AUTHOR = $author\n";
-print MF "\n";
-print MF "DESCRIPTION = $description\n";
-print MF "define BLURB\n";
-print MF "endef\n";
-print MF "\n";
+say {$mf_fh} "NAME = $name";
+say {$mf_fh} "VERSION = $fileversion";
+say {$mf_fh} 'CATEGORIES = cpan';
+say {$mf_fh} "AUTHOR = $author";
+say {$mf_fh} "";
+say {$mf_fh} "DESCRIPTION = $description";
+say {$mf_fh} "define BLURB";
+say {$mf_fh} "endef";
+say {$mf_fh} "";
 
 my $upstreaminfo = 0;
-if( $notstandard ) {
-  print MF "MASTER_SITES = \$(addsuffix ${notstandard},\$(CPAN_MIRRORS))\n";
-  $upstreaminfo = 1;
+if ($notstandard) {
+	say {$mf_fh} "MASTER_SITES = \$(addsuffix ${notstandard},\$(CPAN_MIRRORS))";
+	$upstreaminfo = 1;
 }
-if( $fileonly ne "${name}-${fileversion}.tar.gz" ) {
-  print MF "MODDIST = $fileonly\n";
-  $upstreaminfo = 1;
+if ( $fileonly ne "${name}-${fileversion}.tar.gz" ) {
+	say {$mf_fh} "MODDIST = $fileonly";
+	$upstreaminfo = 1;
 }
-print MF "\n" if( $upstreaminfo );
+say {$mf_fh} "" if ($upstreaminfo);
 
-if( @build_dep_pkgs ) {
-  foreach my $p (@build_dep_pkgs) {
-    print MF "BUILD_DEP_PKGS += $p\n";
-  }
-  print MF "\n";
+if (@build_dep_pkgs) {
+	foreach my $p (@build_dep_pkgs) {
+		say {$mf_fh} "BUILD_DEP_PKGS += $p";
+	}
+	say {$mf_fh} "";
 }
 
-print MF "CATALOG_RELEASE = unstable\n";
-print MF "\n";
+say {$mf_fh} "CATALOG_RELEASE = unstable";
+say {$mf_fh} "";
 
-foreach (qw(LICENSE LICENSE.LGPL COPYING Copying COPYRIGHT Artistic ARTISTIC GPL)) {
-  if( -f "$distdir/$_" ) {
-    print MF "LICENSE = $_\n\n";
-    last;
-  }
+foreach my $file (qw(LICENSE LICENSE.LGPL COPYING Copying COPYRIGHT Artistic ARTISTIC GPL)) {
+	if ( -f "$distdir/$file" ) {
+		say {$mf_fh} "LICENSE = $file\n";
+		last;
+	}
 }
 
-print MF "PACKAGES += $cswpkg\n";
-print MF "CATALOGNAME_$cswpkg = $cswcatalog\n";
-print MF "SPKG_DESC_$cswpkg = $description\n";
+say {$mf_fh} "PACKAGES += $cswpkg";
+say {$mf_fh} "CATALOGNAME_$cswpkg = $cswcatalog";
+say {$mf_fh} "SPKG_DESC_$cswpkg = $description";
 
 # Do we have the package in the catalog and has it the same name?
 # dam at login [login]:/home/dam >  curl -s http://buildfarm.opencsw.org/pkgdb/rest/catalogs/current/sparc/SunOS5.9/pkgnames/CSWvim/
-# {"maintainer_full_name": "Dagobert Michelsen", "version_string": "7.3.055,REV=2010.11.25", "basename": "vim-7.3.055,REV=2010.11.25-SunOS5.9-sparc-CSW.pkg.gz", "maintainer_email": "dam at opencsw.org", "mtime": "2010-11-27 05:31:11", "file_basename": "vim-7.3.055,REV=2010.11.25-SunOS5.9-sparc-CSW.pkg.gz", "arch": "sparc", "osrel": "SunOS5.9", "size": 1026296, "md5_sum": "96bda1535071daa08372ceee7787b17b", "pkgname": "CSWvim", "rev": "2010.11.25", "filename_arch": "sparc", "version": "7.3.055,REV=2010.11.25", "cadam at login [login]:/home/dam > 
+# {"maintainer_full_name": "Dagobert Michelsen", "version_string": "7.3.055,REV=2010.11.25", "basename": "vim-7.3.055,REV=2010.11.25-SunOS5.9-sparc-CSW.pkg.gz", "maintainer_email": "dam at opencsw.org", "mtime": "2010-11-27 05:31:11", "file_basename": "vim-7.3.055,REV=2010.11.25-SunOS5.9-sparc-CSW.pkg.gz", "arch": "sparc", "osrel": "SunOS5.9", "size": 1026296, "md5_sum": "96bda1535071daa08372ceee7787b17b", "pkgname": "CSWvim", "rev": "2010.11.25", "filename_arch": "sparc", "version": "7.3.055,REV=2010.11.25", "cadam at login [login]:/home/dam >
 # Or does it need to be obsoleted?
 
-print MF "# There was no information if this is pure Perl or not. Please remove if necessary.\n" if( $archall == 2 );
-print MF "ARCHALL_$cswpkg = 1\n" if( $archall );
+say {$mf_fh} "# There was no information if this is pure Perl or not. Please remove if necessary." if ( $archall == 2 );
+say {$mf_fh} "ARCHALL_$cswpkg = 1" if ($archall);
 
 foreach my $p (@runtime_dep_pkgs) {
-  print MF "RUNTIME_DEP_PKGS_$cswpkg += $p\n";
+	say {$mf_fh} "RUNTIME_DEP_PKGS_$cswpkg += $p";
 }
 
 # Is this an obsoletion for an old package?
-my @oldpkgs = mod2pkg( $modname );
-if( @oldpkgs > 1 ) {
-  print STDERR "ERROR: More than one package for module '$modname' found: @oldpkgs\n";
+my @oldpkgs = mod2pkg($modname);
+if ( @oldpkgs > 1 ) {
+	say STDERR "ERROR: More than one package for module '$modname' found: @oldpkgs";
 }
 my $oldpkg = shift @oldpkgs;
-if( $oldpkg ne $cswpkg ) {
-  print MF "OBSOLETED_BY_$cswpkg += $oldpkg\n";
+if ( $oldpkg ne $cswpkg ) {
+	say {$mf_fh} "OBSOLETED_BY_$cswpkg += $oldpkg";
 
-  my $ua = LWP::UserAgent->new;
-  $ua->timeout(300);
-  $ua->proxy(['http', 'ftp'], 'http://proxy:3128' );
+	my $ua = LWP::UserAgent->new;
+	$ua->timeout(300);
+	$ua->proxy( [ 'http', 'ftp' ], 'http://proxy:3128' );
 
-  my $catalog = "unstable";
-  my $arch = "sparc";
-  my $rel = "SunOS5.10";
-  
-  my $url = "http://buildfarm.opencsw.org/pkgdb/rest/catalogs/$catalog/$arch/$rel/pkgnames/$oldpkg/";
+	my $catalog = "unstable";
+	my $arch    = "sparc";
+	my $rel     = "SunOS5.10";
 
-  my $response = $ua->get( $url );
+	my $url = "http://buildfarm.opencsw.org/pkgdb/rest/catalogs/$catalog/$arch/$rel/pkgnames/$oldpkg/";
 
-  if ($response->is_success) {
-    my $json_string = $response->decoded_content;  # or whatever
-    if( $json_string eq "null" ) {
-      print "Couldn't find package $oldpkg in $catalog:$arch:$rel\n";
-    } else {
-      my $data = decode_json $json_string;
-      my $cname = $data->{catalogname};
-      print MF "CATALOGNAME_$oldpkg = ${cname}_stub\n";
-    }
-  } else {
-    print "Error getting $url\n" . $response->status_line;
-  }
+	my $response = $ua->get($url);
 
+	if ( $response->is_success ) {
+		my $json_string = $response->decoded_content; # or whatever
+		if ( $json_string eq "null" ) {
+			say "Couldn't find package $oldpkg in $catalog:$arch:$rel";
+		} else {
+			my $data  = decode_json $json_string;
+			my $cname = $data->{catalogname};
+			say {$mf_fh} "CATALOGNAME_$oldpkg = ${cname}_stub";
+		}
+	} else {
+		print "Error getting $url\n" . $response->status_line;
+	}
+
 }
 
-print MF "\n";
+say {$mf_fh} "";
+say {$mf_fh} "include gar/category.mk";
 
-print MF "include gar/category.mk\n";
+close($mf_fh) or warn($!);
+chdir("$name/trunk") or die($!);
+system('mgar', 'makesum') == 0 or die($!);
+system('mgar', 'package') == 0 or die($!);
 
-close( MF );
+say 'Done.';
 
-system( "cd $name/trunk; mgar makesum; mgar package ");
+### Subroutines ###
+
+sub dep_pkgs {
+	my $req = shift @_;
+	my @result;
+	foreach my $modname ( keys %$req ) {
+		my $version = version->parse( $req->{$modname} );
+		if ( $modname eq "perl" ) {
+			if ( version->parse($^V) < $version ) {
+				die "requires perl version $version";
+			}
+			next;
+		}
+		if ( $version > version->parse( get_version($modname) ) ) {
+			print STDERR "Version of $modname is too old. Required is $version, installed is ",
+				( get_version($modname) or "nothing" ), "\n";
+		}
+
+		my @pkgs = mod2pkg($modname);
+		if ( @pkgs > 1 ) {
+			print STDERR "ERROR: More than one package for module '$modname' found: @pkgs\n";
+		}
+		my $pkg = shift @pkgs;
+		if ($pkg) {
+			print STDERR "Packages for module '$modname': $pkg\n";
+			next if ( $pkg eq 'CSWperl' );
+		} else {
+			print STDERR "MISSING package for '$modname'\n";
+
+			# Guess name of missing module
+			my $dirname;
+			( $pkg, $dirname ) = guess_name_from_module($modname);
+			if ($pkg) {
+				if ( !-d $dirname ) {
+					print STDERR "MISSING $pkg directory '$dirname', to build please invoke   makemake $modname\n";
+				} else {
+					print STDERR "MISSING $pkg Please build and install module in $dirname\n";
+				}
+			}
+		}
+		push @result, $pkg if ($pkg);
+	}
+
+	return @result;
+}
+
+sub endlog {
+	if ( !$verbose ) {
+
+		# Reference fh to silence warning
+		select(OLDERR); select(OLDOUT);
+
+		# Restore output.
+		select(STDOUT);
+		close(STDOUT);
+		open( STDOUT, ">&OLDOUT" );
+		close(STDERR);
+		open( STDERR, ">&OLDERR" );
+
+		rmtree($logfile);
+	}
+}
+
+sub fail {
+	close(STDOUT);
+	open( STDOUT, ">&OLDOUT" );
+	close(STDERR);
+	open( STDERR, ">&OLDERR" );
+	open( LOG,    "< $logfile" )
+		or die "$pgm: Error, @_ - can't open log\n";
+	print STDERR foreach <LOG>;
+	close(LOG);
+	rmtree($logfile);
+	die "\n$pgm: Error, @_\n";
+}
+
+sub guess_name_from_module {
+	my $modname = shift @_;
+	my $mod = ( CPAN::Shell->expand( "Module", $modname ) )[0];
+	if ( !$mod ) {
+		print STDERR "ERROR: Can not find module $modname/n";
+		return;
+	}
+	my $filename = $mod->distribution->base_id;
+	my ( $name, $fileversion ) = ( $filename =~ /^(\D+)-(\d+(?:\.\d+)*)/ );
+	my $dirname = $name;
+	my $pkgname = lc($name);
+	$pkgname = "CSWpm-" . $pkgname;
+	return ( $pkgname, $dirname );
+}
+
+sub logoutput {
+	if ( !$verbose ) {
+		$logfile = tmpnam();
+		open( OLDOUT, '>&STDOUT' );
+		open( OLDERR, '>&STDERR' );
+		open( STDOUT, "> $logfile" );
+		open( STDERR, "> $logfile" );
+	}
+}
+
+sub mod2pkg {
+	my $modname = shift @_;
+	my @result;
+	my $path = `/opt/csw/bin/perl -S /opt/csw/bin/pmpath $modname 2>&1`;
+	chomp $path;
+	if ( $path =~ /Can't locate/ ) {
+		print STDERR "$modname is missing\n";
+		return;
+	}
+
+	my %pkgs = path2pkg($path);
+	return ( map { @{ $pkgs{$_} or ["undef $_"] } } keys %pkgs );
+}
+
+
+sub path2pkg {
+	my @pathes = @_;
+
+	return () if ( @pathes == 0 );
+
+	my %pkgs;
+	open P, "/home/dam/mgar/gar/v2/bin/pkgdb show filename " . join( " ", @pathes ) . " |"
+		or die "Cannot open gar/bin/pkgdb";
+	while (<P>) {
+		my $path = shift @pathes;
+		$pkgs{$path} = [ split( /\s+/, $_ ) ];
+	}
+	close P;
+
+	return %pkgs;
+}

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list