summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2017-01-31 10:20:14 +0200
committerTimo Teräs <timo.teras@iki.fi>2017-01-31 10:20:14 +0200
commit14f8fcfb372f9f9ab877c33f309431aa2043c097 (patch)
treef00117a58be309e2cfe38fbcd1fb84b27e688644
parent7c1609b1bb4b6b7219b21b0d2750fcfaf02d63bc (diff)
downloadabuild-14f8fcfb372f9f9ab877c33f309431aa2043c097.tar.gz
abuild-14f8fcfb372f9f9ab877c33f309431aa2043c097.tar.bz2
abuild-14f8fcfb372f9f9ab877c33f309431aa2043c097.tar.xz
abuild-14f8fcfb372f9f9ab877c33f309431aa2043c097.zip
apkbuild-cpan: fix warnings, improve recreate, add check support
-rw-r--r--apkbuild-cpan.in62
1 files changed, 47 insertions, 15 deletions
diff --git a/apkbuild-cpan.in b/apkbuild-cpan.in
index 5566f8e..688df6e 100644
--- a/apkbuild-cpan.in
+++ b/apkbuild-cpan.in
@@ -3,7 +3,10 @@
use strict;
use warnings;
-use feature qw(:5.10);
+use 5.016;
+use feature "switch";
+no if $] >= 5.018, warnings => "experimental::smartmatch";
+
use LWP::UserAgent;
use LWP::ConnCache;
use CPAN::Meta;
@@ -21,9 +24,8 @@ my $package_mappings = {
};
our $packager = "";
my $template = <<'EOF';
-# Automatically generated by apkbuild-cpan, template 1
-# Contributor: [% packager %]
-# Maintainer: [% packager %]
+# Automatically generated by apkbuild-cpan, template 2
+[% authors %]
pkgname=[% pkgname %]
_pkgreal=[% pkgreal %]
pkgver=[% pkgver %]
@@ -34,8 +36,10 @@ arch="noarch"
license="GPL PerlArtistic"
cpandepends=""
cpanmakedepends=""
+cpancheckdepends=""
depends="$cpandepends"
makedepends="perl-dev $cpanmakedepends"
+checkdepends="$cpancheckdepends"
subpackages="$pkgname-doc"
source="[% source %]"
builddir="$srcdir/$_pkgreal-$pkgver"
@@ -59,6 +63,10 @@ package() {
:
}
+check() {
+ :
+}
+
EOF
our $ua = LWP::UserAgent->new();
@@ -66,8 +74,7 @@ our $json = JSON->new;
$ua->env_proxy;
$ua->conn_cache(LWP::ConnCache->new());
-sub read_file
-{
+sub read_file {
my ($filename) = @_;
local $/;
open my $fh, "<", $filename or die "could not open $filename: $!";
@@ -76,10 +83,15 @@ sub read_file
sub read_assignments_from_file {
my ($filename) = @_;
+ return () if ( ! -e $filename );
my $text = read_file($filename);
my %sline = $text =~ /^(\w+)\s*=\s*([^\"\n]*)$/mg;
my %mline = $text =~ /^(\w+)\s*=\s*\"([^\"]*)\"$/mg;
my %hash = ( %sline, %mline );
+
+ my $authors = join("\n", $text =~ /^# Contributor: .*$/mg, $text =~ /^# Maintainer: .*$/mg);
+ $hash{'authors'} = $authors if length($authors) > 1;
+
return \%hash;
}
@@ -96,12 +108,13 @@ sub read_apkbuild {
}
sub write_apkbuild {
- my ($distdata) = @_;
+ my ($distdata, $authors) = @_;
my $cpanid = $distdata->{releases}[0]->{cpanid};
$cpanid = substr($cpanid, 0, 1) . "/" . substr($cpanid, 0, 2) . "/$cpanid";
+
my %repl = (
- packager => $packager,
+ authors => ($authors or "# Contributor: $packager\n# Maintainer: $packager"),
pkgname => map_cpan_to_apk($distdata->{name}),
pkgreal => $distdata->{name},
pkgver => $distdata->{releases}[0]->{version},
@@ -147,7 +160,8 @@ sub parse_deps {
my $pkgname = map_cpan_to_apk($distdata->{name});
$deps .= "$pkgname ";
}
- $deps =~ s/\s+$//;
+ $deps =~ s/\h+/ /g;
+ $deps =~ s/ $//;
return $deps;
}
@@ -162,6 +176,7 @@ sub update_functions {
my $metaprefix = "src/" . $apkbuild->{'_pkgreal'} . "-" . $apkbuild->{'pkgver'} . "/";
my $prepare_func;
my $build_func;
+ my $check_func;
my $package_func;
my $text = read_file "APKBUILD";
@@ -203,7 +218,7 @@ EOF
build() {
cd "$builddir"
export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
- make && make test
+ make
}
EOF
$package_func = <<'EOF';
@@ -213,6 +228,13 @@ package() {
find "$pkgdir" \( -name perllocal.pod -o -name .packlist \) -delete
}
EOF
+ $check_func = <<'EOF';
+check() {
+ cd "$builddir"
+ export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
+ make test
+}
+EOF
}
$text =~ s/^prepare\(\) \{.*?^\}\n/$prepare_func/smg or
@@ -221,6 +243,8 @@ EOF
die "Can't replace build function APKBUILD";
$text =~ s/^package\(\) \{.*?^\}\n/$package_func/smg or
die "Can't replace package function APKBUILD";
+ $text =~ s/^check\(\) \{.*?^\}\n/$check_func/smg or
+ die "Can't replace check function APKBUILD";
open my $fh, '>', "APKBUILD" or die;
print $fh $text;
@@ -251,11 +275,13 @@ sub do_depends {
say "CPAN deps: $deps";
say "Recommend: " . parse_deps $meta->effective_prereqs->requirements_for('runtime', 'recommends');
- my $makedeps = parse_deps $meta->effective_prereqs->requirements_for('build', 'requires');
- $makedeps .= ' ' . parse_deps $meta->effective_prereqs->requirements_for('build', 'recommends');
- $makedeps .= ' ' . parse_deps $meta->effective_prereqs->requirements_for('test', 'requires');
- $makedeps .= ' ' . parse_deps $meta->effective_prereqs->requirements_for('test', 'recommends');
+ my $makedeps = parse_deps($meta->effective_prereqs->requirements_for('build', 'requires'), $meta->effective_prereqs->requirements_for('build', 'recommends'));
say "CPAN build deps: $makedeps";
+ say "CPAN requires: " . parse_deps($meta->effective_prereqs->requirements_for('build', 'requires'));
+ say "CPAN recommds: " . parse_deps($meta->effective_prereqs->requirements_for('build', 'recommends'));
+
+ my $checkdeps = parse_deps($meta->effective_prereqs->requirements_for('test', 'requires'), $meta->effective_prereqs->requirements_for('test', 'recommends'));
+ say "CPAN check deps: $makedeps";
my $text = read_file "APKBUILD";
if ($abstract) {
@@ -274,6 +300,8 @@ sub do_depends {
die "Can't find cpandepends line in APKBUILD";
$text =~ s/^cpanmakedepends=\"([^\"]*)\"$/cpanmakedepends=\"$makedeps\"/mg or
die "Can't find cpanmakedepends line in APKBUILD";
+ $text =~ s/^cpancheckdepends=\"([^\"]*)\"$/cpancheckdepends=\"$checkdeps\"/mg or
+ die "Can't find cpancheckdepends line in APKBUILD";
open my $fh, '>', "APKBUILD" or die;
print $fh $text;
@@ -282,6 +310,7 @@ sub do_depends {
sub get_data {
my $apkbuild = read_apkbuild;
+ $apkbuild->{_pkgreal} or die "Not apkbuild-cpan generated APKBUILD";
my $response = $ua->get("http://search.cpan.org/api/dist/$apkbuild->{_pkgreal}");
$response->is_success or die $response->status_line;
my $distdata = $json->decode($response->decoded_content);
@@ -293,6 +322,9 @@ sub get_data {
my $abuild_conf = read_assignments_from_file("/etc/abuild.conf");
$packager = $abuild_conf->{PACKAGER} if $abuild_conf->{PACKAGER};
+my $user_abuild_conf = read_assignments_from_file($ENV{"HOME"} . "/.abuild/abuild.conf");
+$packager = $user_abuild_conf->{PACKAGER} if $user_abuild_conf->{PACKAGER};
+
given ( $ARGV[0] ) {
when ("create") {
my $module = $ARGV[1];
@@ -319,7 +351,7 @@ given ( $ARGV[0] ) {
}
when ("recreate") {
my ($apkbuild, $distdata) = get_data;
- write_apkbuild($distdata);
+ write_apkbuild($distdata, $apkbuild->{authors});
prepare_tree;
update_functions;
do_depends;