File cpanspec.patch of Package cpanspec
diff -ruN cpanspec-1.78-orig/cpanspec cpanspec-1.78/cpanspec
--- cpanspec-1.78-orig/cpanspec 2009-01-16 21:35:55.000000000 +0100
+++ cpanspec-1.78/cpanspec 2011-02-01 14:18:48.000000000 +0100
@@ -12,9 +12,6 @@
#
# $Id: cpanspec,v 1.67 2009/01/16 20:35:17 stevenpritchard Exp $
-our $NAME="cpanspec";
-our $VERSION='1.78';
-
=head1 NAME
cpanspec - Generate a spec file for a CPAN module
@@ -191,6 +188,9 @@
use strict;
use warnings;
+our $NAME="cpanspec";
+our $VERSION='1.78.03';
+
use FileHandle;
use Archive::Tar;
use Archive::Zip qw(:ERROR_CODES);
@@ -199,11 +199,12 @@
use Text::Autoformat;
use YAML qw(Load);
use Getopt::Long;
+use Pod::POM;
+use Pod::POM::View::Text;
use Pod::Usage;
use File::Basename;
use LWP::UserAgent;
use Parse::CPAN::Packages;
-use Pod::Simple::TextContent;
# Apparently gets pulled in by another module.
#use Cwd;
@@ -222,8 +223,7 @@
our $buildrpm=0;
our $verbose=0;
our $follow=0;
-our $macros=0;
-our $source;
+our $macros=1;
our $cpan=$ENV{'CPAN'} || "http://www.cpan.org";
our $home=$ENV{'HOME'} || (getpwuid($<))[7];
@@ -241,6 +241,8 @@
our @add_provides;
our @add_buildrequires;
+our ($file,$name,$source,$version,$type);
+our ($content,$summary,$description,$author);
# env. vars and their macro analogues
my @MACROS = (
@@ -252,7 +254,7 @@
# 1 is for the macros.
{
- 'optimize' => '%{optimize}',
+ 'optimize' => '%{optflags}',
'buildroot' => '%{buildroot}',
},
);
@@ -338,6 +340,62 @@
$updated=1;
}
+sub get_file($) {
+ $file=shift;
+ # Look up $file in 02packages.details.txt.
+ update_packages();
+ $packages=Parse::CPAN::Packages->new($pkgdetails)
+ if (!defined($packages));
+ die "Parse::CPAN::Packages->new() failed: $!\n"
+ if (!defined($packages));
+ my ($m,$d);
+ if ($m=$packages->package($file) and $d=$m->distribution()) {
+ $source=$cpan . "/authors/id/" . $d->prefix();
+ $file=basename($d->filename());
+ fetch($source, $file) if (!-f $file);
+ $name=$d->dist();
+ $version=$d->version();
+ $version=~s/^v\.?//;
+ $source=~s/$version/\%{version}/;
+ if ($file =~ /\.(tar)\.(?:gz|bz2)$/i) {
+ $type=$1;
+ } elsif ($file =~ /\.tgz$/i) {
+ $type='tar';
+ } elsif ($file =~ /\.(zip)$/i) {
+ $type=$1;
+ } else {
+ warn "Failed to parse '$file', skipping...\n";
+ next;
+ }
+ } else {
+ warn "Failed to parse '$file' or find a module by that name, skipping...\n";
+ next;
+ }
+}
+
+sub get_source($) {
+ $file=shift;
+
+ # keep things happy if we get "Foo-Bar" instead of "Foo::Bar"
+ $file =~ s/-/::/g;
+
+ # Look up $file in 02packages.details.txt.
+ update_packages();
+ $packages=Parse::CPAN::Packages->new($pkgdetails)
+ if (!defined($packages));
+ die "Parse::CPAN::Packages->new() failed: $!\n"
+ if (!defined($packages));
+ my ($m,$d);
+ if ($m=$packages->package($file) and $d=$m->distribution()) {
+ $source=$cpan . "/authors/id/" . $d->prefix();
+ } else {
+ warn "Failed to parse '$file' or find a module by that name in $pkgdetails, skipping...\n";
+ $source='';
+ return;
+ }
+ $source=~s/$version/\%{version}/;
+}
+
sub build_rpm($) {
my $spec=shift;
my $dir=getcwd();
@@ -387,10 +445,10 @@
}
}
-sub get_description(%) {
+sub get_content(%) {
my %args=@_;
my $pm="";
- my ($summary, $description);
+ my $cont;
my $path=$args{module};
$path=~s,::,/,g;
@@ -415,60 +473,95 @@
last if $pm;
}
- if ($pm) {
- verbose "Trying to fetch description from $pm...";
+ if (my $cont=extract($args{archive}, $args{type}, $pm)) {
+ return $cont;
+ } else {
+ warn "Failed to read $pm from $args{filename}"
+ . ($args{type} eq 'tar'
+ ? (": " . $args{archive}->error()) : "") . "\n";
+ return(undef, undef);
+ }
+}
- if (my $content=extract($args{archive}, $args{type}, $pm)) {
- my $parser=Pod::Simple::TextContent->new()
- or die "Pod::Simple::TextContent->new() failed: $!\n";
- $parser->no_whining(1);
- my $rendered="";
- $parser->output_string(\$rendered);
- $parser->parse_string_document($content);
- if ($parser->content_seen and $rendered) {
- if ($rendered=~/DESCRIPTION\s+(\S.*?)\n\n/s) {
- $description=$1;
- }
- if ($rendered=~/NAME\s*$args{module}\s[-\s]*(\S[^\n]*)/s) {
- if ($1 ne "SYNOPSIS") {
- $summary=$1;
- $summary=~s/[.\s]+$//;
- $summary=~s/^(?:An?|The)\s+//i;
- $summary=ucfirst($summary);
- }
- }
- return($description, $summary) if (defined($description));
- }
- } else {
- warn "Failed to read $pm from $args{filename}"
- . ($args{type} eq 'tar'
- ? (": " . $args{archive}->error()) : "") . "\n";
- }
+sub get_description($) {
+ my $cont = shift;
+ my $parser = Pod::POM->new;
+
+ # extract pod; the file may contain no pod, that's ok
+ my $pom = $parser->parse_text($cont);
+
+ HEAD1:
+ foreach my $head1 ($pom->head1) {
+
+ next HEAD1 unless $head1->title eq 'DESCRIPTION';
+
+ my $pom = $head1->content;
+ $description = $pom->present('Pod::POM::View::Text');
+
+ # limit to 3 paragraphs at the moment
+ #my @paragraphs = (split /\n\n/, $description)[0..2];
+ # no limit
+ my @paragraphs = (split /\n\n/, $description);
+
+ $description = join "\n\n", @paragraphs;
+
+ # autoformat and return...
+ return autoformat $description, { all => 1 };
}
+ return $description='sorry, no description found';
+}
- if (my $readme=(sort {
- length($a) <=> length($b) or $a cmp $b
- } (grep /README/i, @{$args{files}}))[0]) {
- verbose "Trying to fetch description from $readme...";
-
- if (my $content=extract($args{archive}, $args{type},
- "$args{path}/$readme")) {
- $content=~s/\r//g; # Why people use DOS text, I'll never understand.
- for my $string (split "\n\n", $content) {
- $string=~s/^\n+//;
- if ((my @tmp=split "\n", $string) > 2
- and $string !~ /^[#\-=]/) {
- return($string, undef);
- }
- }
- } else {
- warn "Failed to read $readme from $args{filename}"
- . ($args{type} eq 'tar'
- ? (": " . $args{archive}->error()) : "") . "\n";
- }
+sub get_summary($$) {
+ my $cont = shift;
+ my $mod = shift;
+ my $parser = Pod::POM->new;
+
+ # extract pod; the file may contain no pod, that's ok
+ my $pom = $parser->parse_text($cont);
+
+ HEAD1:
+ foreach my $head1 ($pom->head1) {
+
+ next HEAD1 unless $head1->title eq 'NAME';
+
+ my $pom = $head1->content;
+ $pom =~ /^[^-]+ - (.*)$/m;
+
+ # return...
+ return $summary = $1 if $pom;
}
+ return $summary="$mod Perl module";
+}
+
+sub get_author($) {
+ my $cont = shift;
+ my @lines=();
+ my $parser = Pod::POM->new;
+
+ # extract pod; the file may contain no pod, that's ok
+ my $pom = $parser->parse_text($cont);
+
+ HEAD1:
+ foreach my $head1 ($pom->head1) {
+
+ next HEAD1 unless $head1->title eq 'AUTHOR';
+
+ my $pom = $head1->content;
+ $author = $pom->present('Pod::POM::View::Text');
+
+ my @paragraphs = (split /\n/, $author);
+ foreach my $line (@paragraphs){
+ next if $line eq "";
+ $line =~ s/^/ /;
+ push(@lines, $line);
+ }
+
+ $author = join "\n", @lines;
- return(undef, undef);
+ # return...
+ return $author;
+ }
+ return $author='sorry, no author found';
}
sub check_rpm($) {
@@ -554,13 +647,6 @@
$packager=$packager || `rpm --eval '\%packager'`;
-chomp $packager;
-
-if (!$packager or $packager eq "\%packager") {
- die "\%packager not defined in ~/.rpmmacros."
- . " Please add or use --packager option.\n";
-}
-
our %corelist;
my $rpm=new FileHandle "rpm -q --provides perl|"
@@ -577,67 +663,49 @@
my @args=@ARGV;
my @processed=();
-for my $file (@args) {
- my ($name,$version,$type);
+for my $ofile (@args) {
- if ($file =~ /^(?:.*\/)?(.*)-(?:v\.?)?([^-]+)\.(tar)\.(?:gz|bz2)$/) {
+ if ($ofile =~ /^(?:.*\/)?(.*)-(?:v\.?)?([^-]+)\.(tar)\.(?:gz|bz2)$/i) {
+ $file=$ofile;
$name=$1;
$version=$2;
$type=$3;
- } elsif ($file =~ /^(?:.*\/)?(.*)-(?:v\.?)?([^-]+)\.tgz$/) {
+ } elsif ($ofile =~ /^(?:.*\/)?(.*)-(?:v\.?)?([^-]+)\.tgz$/i) {
+ $file=$ofile;
$name=$1;
$version=$2;
$type = 'tar';
- } elsif ($file =~ /^(?:.*\/)?(.*)-(?:v\.?)?([^-]+)\.(zip)$/) {
+ } elsif ($ofile =~ /^(?:.*\/)?(.*)-(?:v\.?)?([^-]+)\.(zip)$/i) {
+ $file=$ofile;
$name=$1;
$version=$2;
$type=$3;
} else {
# keep things happy if we get "Foo-Bar" instead of "Foo::Bar"
- $file =~ s/-/::/g;
+ $ofile =~ s/-/::/g;
# Look up $file in 02packages.details.txt.
- update_packages();
- $packages=Parse::CPAN::Packages->new($pkgdetails)
- if (!defined($packages));
- die "Parse::CPAN::Packages->new() failed: $!\n"
- if (!defined($packages));
- my ($m,$d);
- if ($m=$packages->package($file) and $d=$m->distribution()) {
- $source=$cpan . "/authors/id/" . $d->prefix();
- $file=basename($d->filename());
- fetch($source, $file);
- $name=$d->dist();
- $version=$d->version();
- $version=~s/^v\.?//;
- if ($file =~ /\.(tar)\.gz$/) {
- $type=$1;
- } elsif ($file =~ /\.tgz$/) {
- $type='tar';
- } elsif ($file =~ /\.(zip)$/) {
- $type=$1;
- } else {
- warn "Failed to parse '$file', skipping...\n";
- next;
- }
- } else {
- warn "Failed to parse '$file' or find a module by that name, skipping...\n";
- next;
- }
+ get_file($ofile);
}
my $module=$name;
$module=~s/-/::/g;
+ my $packlist=$name;
+ $packlist=~s/-/\//g;
+
+ my $packlistfile="auto/$packlist/.packlist";
+
my $archive;
my $path;
+ my $ext = '.gz';
if ($type eq 'tar') {
my $f=$file;
if ($file=~/\.bz2$/) {
- eval {
- use IO::Uncompress::Bunzip2;
- };
+ #eval {
+ # use IO::Uncompress::Bunzip2;
+ #};
if ($@) {
warn "Failed to load IO::Uncompress::Bunzip2: $@\n";
@@ -650,12 +718,14 @@
warn "IO::Uncompress::Bunzip2->new() failed on $file: $!\n";
next;
}
+ $ext = '.bz2';
}
$archive=Archive::Tar->new($f, 1)
or die "Archive::Tar->new() failed: $!\n";
} elsif ($type eq 'zip') {
$archive=Archive::Zip->new() or die "Archive::Zip->new() failed: $!\n";
die "Read error on $file\n" unless ($archive->read($file) == AZ_OK);
+ $ext = '.zip';
}
my @files;
@@ -684,12 +754,9 @@
my $url="http://search.cpan.org/dist/$name/";
- $source=$source || "http://www.cpan.org/modules/by-module/"
- . ($module=~/::/ ? (split "::", $module)[0] : (split "-", $name)[0])
- . "/" . basename($file);
- $source=~s/$version/\%{version}/;
+ get_source($name) if(!defined $source);
- my ($description,$summary)=get_description(
+ $content = get_content(
archive => $archive,
type => $type,
filename => $file,
@@ -700,18 +767,13 @@
path => $path,
);
- if (defined($description) and $description) {
- $description=autoformat $description, { "all" => 1,
- "left" => 1,
- "right" => 75,
- "squeeze" => 0,
- };
- $description=~s/\n+$//s;
- } else {
- $description="$module Perl module";
- }
+ get_description($content) if(!defined($description));
+
+ get_summary($content,$module) if (!defined($summary));
+
+ get_author($content) if (!defined($author));
- $summary="$module Perl module" if (!defined($summary));
+ my $authors="Authors:\n--------\n$author";
my @doc=sort { $a cmp $b } grep {
!/\//
@@ -722,6 +784,7 @@
and $_ ne "MANIFEST.SKIP"
and $_ ne "INSTALL"
and $_ ne "SIGNATURE"
+ and $_ ne "META.json"
and $_ ne "META.yml"
and $_ ne "NINJA"
and $_ ne "configure"
@@ -733,6 +796,8 @@
and $_ ne "t"
and $_ ne "inc"
and $_ ne "autobuild.sh"
+ and $_ ne "perlcriticrc"
+ and $_ ne "perltidyrc"
and $_ ne "pm_to_blib"
and $_ ne "install.sh"
} @files;
@@ -947,45 +1012,61 @@
}
print $spec <<END;
+#
+# spec file for package $prefix$name (Version $version)
+#
+# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany.
+#
+# All modifications and additions to the file contributed by third parties
+# remain the property of their copyright owners, unless otherwise agreed
+# upon. The license for this file, and modifications and additions to the
+# file, is the same license as for the pristine package itself (unless the
+# license for the pristine package is not an Open Source License, in which
+# case the license is the MIT License). An "Open Source License" is a
+# license that conforms to the Open Source Definition (Version 1.9)
+# published by the Open Source Initiative.
+
+# Please submit bugfixes or comments via http://bugs.opensuse.org/
+#
+
+END
+
+ print $spec <<END;
Name: $prefix$name
Version: $version
-Release: $release$disttag
+Release: $release
END
print $spec "Epoch: $epoch\n" if (defined($epoch));
print $spec <<END;
-Summary: $summary
License: $license
-Group: Development/Libraries
-URL: $url
-Source0: $source
-BuildRoot: \%{_tmppath}/\%{name}-\%{version}-\%{release}-root-\%(\%{__id_u} -n)
+%define cpan_name $name
+Summary: $summary
+Url: $url
+Group: Development/Libraries/Perl
+#Source: $source
+Source: \%{cpan_name}-\%{version}.tar$ext
END
-
- printf $spec "%-16s%s\n", "BuildArch:", "noarch" if ($noarch);
-
- if (defined($requires{perl})) {
- $build_requires{perl}=$build_requires{perl} || $requires{perl};
- delete $requires{perl};
- }
-
- if (defined($build_requires{perl})) {
- printf $spec "%-16s%s >= %s\n", "BuildRequires:", "perl",
- (($build_requires{perl} lt "5.6.0" ? "0:" : "1:")
- . $build_requires{perl}) if $build_requires{perl};
- delete $build_requires{perl};
+
+ push(@add_buildrequires, "perl");
+ push(@add_buildrequires, "perl-macros");
+ if ($usebuildpl) {
+ push(@add_buildrequires, "perl(Module::Build)");
}
for my $dep (keys(%requires)) {
+ next if ($dep eq 'perl');
$build_requires{$dep}=$build_requires{$dep} || $requires{$dep};
}
+
for my $dep (sort(keys(%build_requires))) {
if (exists($corelist{$dep})) {
next if (!$compat);
} elsif ($follow) {
if ($dep ne $module and !(grep { $_ eq $dep } @processed, @args)) {
+ print "dep: $dep\n";
if (check_dep($dep)) {
verbose("$dep is available, skipping.");
} else {
@@ -1000,11 +1081,12 @@
print $spec "\n";
}
- for my $dep (@add_buildrequires) {
- printf $spec "%-16s%s\n", "BuildRequires:", $dep;
+ for my $dep (sort @add_buildrequires) {
+ printf $spec "%-16s%s\n", "BuildRequires:", $dep if (length($dep));
}
for my $dep (sort(keys(%requires))) {
+ next if ($dep eq 'perl');
next if (!$compat and exists($corelist{$dep}));
printf $spec "%-16s%s", "Requires:", "perl($dep)";
print $spec (" >= " . $requires{$dep}) if ($requires{$dep});
@@ -1015,11 +1097,6 @@
printf $spec "%-16s%s\n", "Requires:", $dep;
}
- if (!$compat) {
- print $spec <<END;
-Requires: perl(:MODULE_COMPAT_\%(eval "`\%{__perl} -V:version`"; echo \$version))
-END
- }
for my $prov (@add_provides) {
printf $spec "%-16s%s\n", "Provides:", $prov;
@@ -1043,7 +1120,12 @@
END
}
+ print $spec "BuildRoot: \%{_tmppath}/\%{name}-\%{version}-build\n";
+ printf $spec "%-16s%s\n", "BuildArch:", "noarch" if ($noarch);
+ print $spec "%{perl_requires}\n";
+
my $buildpath=$path;
+ $buildpath=~s/$name/\%{cpan_name}/;
$buildpath=~s/$version/\%{version}/;
print $spec <<END;
@@ -1085,7 +1167,8 @@
if ($usebuildpl) {
print $spec <<END;
\%{__perl} Build.PL installdirs=vendor@{[$noarch ? '' : qq{ optimize="$macro{optimize}"} ]}
-./Build
+./Build build flags=\%{?_smp_mflags}
+
END
} else {
print $spec <<END;
@@ -1097,15 +1180,24 @@
if ($compat and !$noarch);
print $spec <<END;
-make \%{?_smp_mflags}
+\%{__make} \%{?_smp_mflags}
+
+END
+ }
+
+ print $spec <<END;
+\%check@{[($compat ? ' || :' : '')]}
END
+ if ($usebuildpl) {
+ print $spec "./Build test\n";
+ } else {
+ print $spec "\%{__make} test\n";
}
+
print $spec <<END;
\%install
-rm -rf $macro{buildroot}
-
END
if ($usebuildpl) {
@@ -1113,24 +1205,12 @@
"./Build install destdir=$macro{buildroot} create_packlist=0\n";
} else {
print $spec <<END;
-make pure_install PERL_INSTALL_ROOT=$macro{buildroot}
-
-find $macro{buildroot} -type f -name .packlist -exec rm -f {} \\;
+%perl_make_install
+%perl_process_packlist
END
}
-
- if (!$noarch) {
- print $spec <<END;
-find $macro{buildroot} -type f -name '*.bs' -size 0 -exec rm -f {} \\;
-END
-}
-
- print $spec <<END;
-find $macro{buildroot} -depth -type d -exec rmdir {} 2>/dev/null \\;
-
-\%{_fixperms} $macro{buildroot}/*
-
-END
+ print $spec
+ "%perl_gen_filelist\n";
if ($addlicense and !grep /copying|artistic|copyright|license/i, @doc) {
print $spec <<END;
@@ -1143,43 +1223,25 @@
}
print $spec <<END;
-\%check@{[($compat ? ' || :' : '')]}
-END
- if ($usebuildpl) {
- print $spec "./Build test\n";
- } else {
- print $spec "make test\n";
- }
-
- print $spec <<END;
\%clean
-rm -rf $macro{buildroot}@{[
+\%{__rm} -rf $macro{buildroot}@{[
(@filter_requires ? ' %{__perl_requires}' : '') .
(@filter_provides ? ' %{__perl_provides}' : '')]}
-\%files
-\%defattr(-,root,root,-)
-\%doc @doc
+\%files -f \%{name}.files
END
+ print $spec "\%defattr(644,root,root,755)\n";
+ print $spec "%doc @doc\n" if (@doc);
if ($scripts) {
print $spec "\%{_bindir}/*\n";
# FIXME - How do we auto-detect man pages?
}
- if ($noarch) {
- print $spec "$lib/*\n";
- } else {
- print $spec "$lib/auto/*\n$lib/" . (split /::/, $module)[0] . "*\n";
- }
-
print $spec <<END;
-\%{_mandir}/man3/*
\%changelog
-* $date $packager $version-$release
-- Specfile autogenerated by $NAME $VERSION.
END
$spec->close();
@@ -1187,6 +1249,11 @@
build_rpm($specfile) if ($buildsrpm or $buildrpm);
push(@processed, $module);
+
+ (my $basename = $specfile) =~ s{\.spec$}{};
+ verbose "Writing $basename.changes";
+ system("osc vc -m 'initial package $version
+ * created by $NAME $VERSION' $basename");
}
# vi: set ai et: