2011-06-02 08:55:00 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# apk add perl-libwww perl-json
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2017-01-31 08:20:14 +00:00
|
|
|
use 5.016;
|
|
|
|
use feature "switch";
|
|
|
|
no if $] >= 5.018, warnings => "experimental::smartmatch";
|
|
|
|
|
2011-06-02 08:55:00 +00:00
|
|
|
use LWP::UserAgent;
|
|
|
|
use LWP::ConnCache;
|
|
|
|
use CPAN::Meta;
|
|
|
|
use Module::CoreList;
|
|
|
|
use JSON;
|
2020-12-22 23:23:50 +00:00
|
|
|
use Text::Wrap qw(wrap $columns);
|
2020-12-22 23:58:37 +00:00
|
|
|
use List::Util qw (uniq);
|
2011-06-02 08:55:00 +00:00
|
|
|
|
|
|
|
my $license_mappings = {
|
2019-06-07 01:01:58 +00:00
|
|
|
"perl_5" => "GPL-1.0-or-later OR Artistic-1.0-Perl",
|
2019-04-22 16:16:31 +00:00
|
|
|
"artistic_2" => "Artistic-2.0",
|
2020-08-20 21:17:13 +00:00
|
|
|
"gpl_2" => "GPL-2.0-only",
|
2019-04-22 16:16:31 +00:00
|
|
|
"gpl_3" => "GPL-3.0-only",
|
2020-03-25 00:10:41 +00:00
|
|
|
"mit" => "MIT",
|
2020-12-22 20:34:22 +00:00
|
|
|
"apache_2_0" => "Apache-2.0",
|
2011-06-02 08:55:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
my $package_mappings = {
|
|
|
|
"LWP" => "perl-libwww",
|
2020-03-25 00:10:41 +00:00
|
|
|
"libwww-perl" => "perl-libwww",
|
2011-06-02 08:55:00 +00:00
|
|
|
"TermReadKey" => "perl-term-readkey",
|
2020-03-03 20:41:10 +00:00
|
|
|
"perl-ldap" => "perl-ldap",
|
2020-03-25 00:10:41 +00:00
|
|
|
"PerlIO-gzip" => "perl-io-gzip",
|
2011-06-02 08:55:00 +00:00
|
|
|
};
|
|
|
|
our $packager = "";
|
|
|
|
my $template = <<'EOF';
|
2020-02-29 23:53:29 +00:00
|
|
|
# Automatically generated by apkbuild-cpan, template 3
|
2017-01-31 08:20:14 +00:00
|
|
|
[% authors %]
|
2011-06-02 08:55:00 +00:00
|
|
|
pkgname=[% pkgname %]
|
2020-03-25 00:33:43 +00:00
|
|
|
#_pkgreal is used by apkbuild-cpan to find modules at MetaCpan
|
2011-06-02 08:55:00 +00:00
|
|
|
_pkgreal=[% pkgreal %]
|
|
|
|
pkgver=[% pkgver %]
|
2020-03-25 00:33:43 +00:00
|
|
|
pkgrel=[% pkgrel %]
|
2011-06-02 08:55:00 +00:00
|
|
|
pkgdesc="Perl module for [% pkgreal %]"
|
2020-03-25 00:33:43 +00:00
|
|
|
provides="[% provides %]"
|
|
|
|
replaces="[% replaces %]"
|
2018-11-25 01:51:08 +00:00
|
|
|
url="https://metacpan.org/release/[% pkgreal %]/"
|
2011-06-02 08:55:00 +00:00
|
|
|
arch="noarch"
|
2020-02-27 15:58:41 +00:00
|
|
|
license="GPL-1.0-or-later OR Artistic-1.0-Perl"
|
2020-03-03 23:03:42 +00:00
|
|
|
depends="perl"
|
2020-02-29 23:53:29 +00:00
|
|
|
makedepends="perl-dev"
|
|
|
|
checkdepends=""
|
2011-06-02 08:55:00 +00:00
|
|
|
subpackages="$pkgname-doc"
|
|
|
|
source="[% source %]"
|
2021-02-16 01:16:48 +00:00
|
|
|
builddir="[% builddir %]"
|
2011-06-02 08:55:00 +00:00
|
|
|
|
|
|
|
build() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
2019-03-21 10:25:52 +00:00
|
|
|
check() {
|
2011-06-02 08:55:00 +00:00
|
|
|
:
|
|
|
|
}
|
|
|
|
|
2019-03-21 10:25:52 +00:00
|
|
|
package() {
|
2017-01-31 08:20:14 +00:00
|
|
|
:
|
|
|
|
}
|
|
|
|
|
2011-06-02 08:55:00 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
our $ua = LWP::UserAgent->new();
|
|
|
|
our $json = JSON->new;
|
|
|
|
$ua->env_proxy;
|
|
|
|
$ua->conn_cache(LWP::ConnCache->new());
|
|
|
|
|
2017-01-31 08:20:14 +00:00
|
|
|
sub read_file {
|
2011-06-02 08:55:00 +00:00
|
|
|
my ($filename) = @_;
|
|
|
|
local $/;
|
|
|
|
open my $fh, "<", $filename or die "could not open $filename: $!";
|
|
|
|
return <$fh>;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub read_assignments_from_file {
|
|
|
|
my ($filename) = @_;
|
2017-01-31 08:20:14 +00:00
|
|
|
return () if ( ! -e $filename );
|
2011-06-02 08:55:00 +00:00
|
|
|
my $text = read_file($filename);
|
|
|
|
my %sline = $text =~ /^(\w+)\s*=\s*([^\"\n]*)$/mg;
|
|
|
|
my %mline = $text =~ /^(\w+)\s*=\s*\"([^\"]*)\"$/mg;
|
|
|
|
my %hash = ( %sline, %mline );
|
2017-01-31 08:20:14 +00:00
|
|
|
|
|
|
|
my $authors = join("\n", $text =~ /^# Contributor: .*$/mg, $text =~ /^# Maintainer: .*$/mg);
|
|
|
|
$hash{'authors'} = $authors if length($authors) > 1;
|
|
|
|
|
2020-03-25 00:33:43 +00:00
|
|
|
my $provides = $text =~ m/^provides=\"(.*)\"".*$/mg;
|
|
|
|
$hash{'provides'} = $1 if length($provides) >= 1;
|
|
|
|
|
|
|
|
my $requires = $text =~ m/^requires=\"(.*)\"".*$/mg;
|
|
|
|
$hash{'requires'} = $1 if length($requires) >= 1;
|
|
|
|
|
2011-06-02 08:55:00 +00:00
|
|
|
return \%hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub map_cpan_to_apk {
|
|
|
|
my ($cpan_distrib) = @_;
|
|
|
|
return $package_mappings->{$cpan_distrib} if exists $package_mappings->{$cpan_distrib};
|
|
|
|
# most packages are named according to the
|
|
|
|
# distribution name
|
|
|
|
return 'perl-' . lc $cpan_distrib;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub read_apkbuild {
|
|
|
|
return read_assignments_from_file("APKBUILD");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub write_apkbuild {
|
2020-03-25 00:33:43 +00:00
|
|
|
my ($distdata, $apkbuild, $moddata) = @_;
|
2011-06-02 08:55:00 +00:00
|
|
|
|
2018-11-26 03:18:10 +00:00
|
|
|
my $cpanid = $distdata->{id};
|
2011-06-02 08:55:00 +00:00
|
|
|
$cpanid = substr($cpanid, 0, 1) . "/" . substr($cpanid, 0, 2) . "/$cpanid";
|
2017-01-31 08:20:14 +00:00
|
|
|
|
2020-03-25 00:33:43 +00:00
|
|
|
my $authors = undef;
|
|
|
|
my $replaces = undef;
|
|
|
|
my $provides = undef;
|
|
|
|
my $pkgrel = 0;
|
|
|
|
if (defined $apkbuild) {
|
|
|
|
$authors = $apkbuild->{authors};
|
|
|
|
$provides = $apkbuild->{provides};
|
|
|
|
$replaces = $apkbuild->{replaces};
|
|
|
|
$pkgrel = $apkbuild->{pkgrel};
|
|
|
|
if ($apkbuild->{pkgver} eq $moddata->{version}) {
|
|
|
|
$pkgrel++;
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 01:16:48 +00:00
|
|
|
|
|
|
|
my $builddir;
|
|
|
|
|
|
|
|
my $pkgver = $moddata->{version} =~ s/^[^0-9]+//r;
|
|
|
|
if ($pkgver ne $moddata->{version}) {
|
|
|
|
# Appears to only be needed for Class::DBI
|
|
|
|
$builddir = "\$srcdir/\$_pkgreal-" . $moddata->{version};
|
|
|
|
} else {
|
|
|
|
$builddir = "\$srcdir/\$_pkgreal-\$pkgver";
|
|
|
|
}
|
|
|
|
|
2011-06-02 08:55:00 +00:00
|
|
|
my %repl = (
|
2017-01-31 08:20:14 +00:00
|
|
|
authors => ($authors or "# Contributor: $packager\n# Maintainer: $packager"),
|
2018-11-25 17:43:37 +00:00
|
|
|
pkgname => map_cpan_to_apk($moddata->{distribution}),
|
2019-03-21 10:25:52 +00:00
|
|
|
pkgreal => $moddata->{distribution},
|
2019-08-20 19:38:23 +00:00
|
|
|
pkgver => $moddata->{version} =~ s/^[^0-9]+//r,
|
2020-03-25 00:33:43 +00:00
|
|
|
pkgrel => $pkgrel,
|
2019-08-20 19:38:23 +00:00
|
|
|
source => $moddata->{download_url},
|
2019-03-22 01:18:47 +00:00
|
|
|
pkgdesc => $distdata->{abstract},
|
2020-03-25 00:33:43 +00:00
|
|
|
provides => ($provides or ''),
|
|
|
|
replaces => ($replaces or ''),
|
2021-02-16 01:16:48 +00:00
|
|
|
builddir => $builddir,
|
2011-06-02 08:55:00 +00:00
|
|
|
);
|
2020-07-06 01:54:22 +00:00
|
|
|
$repl{source} =~ s/-$repl{pkgver}/-\$pkgver/g;
|
2011-06-02 08:55:00 +00:00
|
|
|
$template =~ s/\[% (.*?) %\]/$repl{$1}/g;
|
|
|
|
|
|
|
|
open my $fh, '>', "APKBUILD" or die;
|
|
|
|
print $fh $template;
|
|
|
|
close $fh;
|
|
|
|
|
|
|
|
say "Wrote $repl{pkgname}/APKBUILD";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub parse_deps {
|
|
|
|
my ($reqs) = @_;
|
|
|
|
my $distfiles = {};
|
|
|
|
my $response;
|
|
|
|
my $deps = "";
|
2020-03-24 23:51:11 +00:00
|
|
|
my $reqmodlist = "";
|
2011-06-02 08:55:00 +00:00
|
|
|
|
2020-03-24 23:51:11 +00:00
|
|
|
#Get list of unique required modules from all parameters
|
2020-03-03 19:14:05 +00:00
|
|
|
foreach $reqs (@_) {
|
|
|
|
for my $module ($reqs->required_modules) {
|
2021-02-15 01:21:18 +00:00
|
|
|
$reqmodlist .= "$module " unless $reqmodlist =~ m/^$module$/;
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-24 23:51:11 +00:00
|
|
|
|
|
|
|
# Check add the require module to $dep if not part of core perl
|
|
|
|
foreach my $module (split " ", $reqmodlist) {
|
|
|
|
next if $module eq 'perl';
|
|
|
|
if (Module::CoreList->is_core($module)) {
|
|
|
|
my $perlver = Module::CoreList->first_release($module);
|
2020-07-06 01:54:22 +00:00
|
|
|
say " $module is part of core perl since $perlver.";
|
2020-03-24 23:51:11 +00:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
# map module name to package name
|
|
|
|
$response = $ua->get("https://fastapi.metacpan.org/module/$module");
|
|
|
|
$response->is_success or die $response->status_line;
|
|
|
|
my $moddata = $json->decode($response->decoded_content);
|
|
|
|
$moddata->{error} and die "Error trying to locate $module: $moddata->{error}\n";
|
|
|
|
$distfiles->{$module} = $moddata->{distribution};
|
|
|
|
}
|
|
|
|
|
2011-06-02 08:55:00 +00:00
|
|
|
# map package names to alpine packages
|
2016-07-28 09:17:14 +00:00
|
|
|
foreach ( keys %{ $distfiles } ) {
|
2020-02-29 23:53:29 +00:00
|
|
|
$response = $ua->get("https://fastapi.metacpan.org/module/$_");
|
2011-06-02 08:55:00 +00:00
|
|
|
$response->is_success or die $response->status_line;
|
|
|
|
my $distdata = $json->decode($response->decoded_content);
|
|
|
|
$distdata->{error} and die "Error trying to locate $_: $distdata->{error}\n";
|
|
|
|
|
2020-02-29 23:53:29 +00:00
|
|
|
my $pkgname = map_cpan_to_apk($distdata->{distribution});
|
2021-02-15 01:21:18 +00:00
|
|
|
$deps .= "$pkgname " unless $deps =~ m/^$pkgname$/;
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
2017-01-31 08:20:14 +00:00
|
|
|
$deps =~ s/\h+/ /g;
|
|
|
|
$deps =~ s/ $//;
|
2011-06-02 08:55:00 +00:00
|
|
|
return $deps;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub prepare_tree {
|
|
|
|
system("abuild checksum unpack prepare") == 0 or
|
|
|
|
die "abuild checksum failed";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub update_functions {
|
|
|
|
my $apkbuild = read_apkbuild;
|
|
|
|
my $metaprefix = "src/" . $apkbuild->{'_pkgreal'} . "-" . $apkbuild->{'pkgver'} . "/";
|
|
|
|
my $build_func;
|
2017-01-31 08:20:14 +00:00
|
|
|
my $check_func;
|
2011-06-02 08:55:00 +00:00
|
|
|
my $package_func;
|
|
|
|
|
|
|
|
my $text = read_file "APKBUILD";
|
|
|
|
if (-e "$metaprefix/Build.PL" ) {
|
|
|
|
$build_func = <<'EOF';
|
|
|
|
build() {
|
2016-06-12 13:58:47 +00:00
|
|
|
export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
|
2020-03-24 23:39:39 +00:00
|
|
|
perl Build.PL --installdirs=vendor
|
2017-07-11 12:04:36 +00:00
|
|
|
./Build
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
$package_func = <<'EOF';
|
|
|
|
package() {
|
2020-03-24 23:39:39 +00:00
|
|
|
./Build install --destdir="$pkgdir"
|
2011-06-02 08:55:00 +00:00
|
|
|
find "$pkgdir" \( -name perllocal.pod -o -name .packlist \) -delete
|
|
|
|
}
|
2017-07-11 12:04:36 +00:00
|
|
|
EOF
|
|
|
|
$check_func = <<'EOF';
|
|
|
|
check() {
|
|
|
|
./Build test
|
|
|
|
}
|
2011-06-02 08:55:00 +00:00
|
|
|
EOF
|
|
|
|
} else {
|
|
|
|
$build_func = <<'EOF';
|
|
|
|
build() {
|
2016-06-12 13:58:47 +00:00
|
|
|
export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
|
2019-03-21 10:25:52 +00:00
|
|
|
PERL_MM_USE_DEFAULT=1 perl -I. Makefile.PL INSTALLDIRS=vendor
|
2017-01-31 08:20:14 +00:00
|
|
|
make
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
$package_func = <<'EOF';
|
|
|
|
package() {
|
2017-07-11 11:57:29 +00:00
|
|
|
make DESTDIR="$pkgdir" install
|
2011-06-02 08:55:00 +00:00
|
|
|
find "$pkgdir" \( -name perllocal.pod -o -name .packlist \) -delete
|
|
|
|
}
|
2017-01-31 08:20:14 +00:00
|
|
|
EOF
|
|
|
|
$check_func = <<'EOF';
|
|
|
|
check() {
|
|
|
|
export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
|
|
|
|
make test
|
|
|
|
}
|
2011-06-02 08:55:00 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
$text =~ s/^build\(\) \{.*?^\}\n/$build_func/smg or
|
|
|
|
die "Can't replace build function APKBUILD";
|
|
|
|
$text =~ s/^package\(\) \{.*?^\}\n/$package_func/smg or
|
|
|
|
die "Can't replace package function APKBUILD";
|
2017-01-31 08:20:14 +00:00
|
|
|
$text =~ s/^check\(\) \{.*?^\}\n/$check_func/smg or
|
|
|
|
die "Can't replace check function APKBUILD";
|
2011-06-02 08:55:00 +00:00
|
|
|
|
|
|
|
open my $fh, '>', "APKBUILD" or die;
|
|
|
|
print $fh $text;
|
|
|
|
close $fh;
|
|
|
|
}
|
|
|
|
|
2020-07-06 01:54:22 +00:00
|
|
|
sub sort_pkgs_by_orig {
|
|
|
|
my $sort_order = shift;
|
|
|
|
my @array_to_sort = split / /, shift;;
|
|
|
|
|
|
|
|
s/[\t\n\r\f]/ /g for $sort_order; # remove embedded new lines from sort order
|
|
|
|
s/\h+/ /g for $sort_order; # remove embedded spaces from sort order
|
|
|
|
|
|
|
|
my @sort_order = split / /, $sort_order;
|
|
|
|
|
|
|
|
#get order of order by string
|
|
|
|
my $count = 0;
|
|
|
|
my %position_of;
|
|
|
|
$position_of{$_} = $count++ for @sort_order;
|
|
|
|
|
|
|
|
my %sorted; # holds the position of array to sort
|
|
|
|
|
|
|
|
foreach (@array_to_sort) {
|
|
|
|
my $pos = $position_of{$_};
|
|
|
|
if (!defined $pos) {
|
|
|
|
# not found in sort order so add to the end
|
|
|
|
$sorted{$_} = $count;
|
|
|
|
$count++;
|
|
|
|
} else {
|
|
|
|
$sorted{$_} = $pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my @tmp; # hold array of sorted in position order
|
|
|
|
|
|
|
|
foreach my $name (sort { $sorted{$a} <=> $sorted{$b} } keys %sorted) {
|
|
|
|
push @tmp, $name;
|
|
|
|
}
|
|
|
|
|
2020-12-22 23:58:37 +00:00
|
|
|
# remove any duplicates
|
|
|
|
uniq @tmp;
|
|
|
|
|
2020-07-06 01:54:22 +00:00
|
|
|
return join(" ", @tmp);
|
|
|
|
}
|
2018-11-25 17:43:37 +00:00
|
|
|
|
2020-12-22 23:23:50 +00:00
|
|
|
sub format_depends {
|
|
|
|
my $deps = shift;
|
|
|
|
|
|
|
|
$columns = 102;
|
2021-02-15 15:22:08 +00:00
|
|
|
|
|
|
|
$deps =~ s/ {2,}/ /g;
|
|
|
|
$deps =~ s/^\s//g;
|
|
|
|
$deps =~ s/\s$//g;
|
|
|
|
|
|
|
|
if (length($deps) >= $columns) {
|
|
|
|
$deps = wrap("\t", "\t", $deps);
|
|
|
|
}
|
|
|
|
$deps =~ s/\s$//g;
|
|
|
|
|
2020-12-23 03:58:20 +00:00
|
|
|
if (length($deps) >= $columns) {
|
2021-02-15 15:22:08 +00:00
|
|
|
$deps = "\n" . $deps . "\n\t";
|
2020-12-23 03:58:20 +00:00
|
|
|
}
|
2020-12-22 23:23:50 +00:00
|
|
|
return $deps;
|
|
|
|
}
|
|
|
|
|
2020-07-06 01:54:22 +00:00
|
|
|
sub do_depends {
|
2021-02-16 01:16:48 +00:00
|
|
|
my $modver = shift;
|
2020-07-06 01:54:22 +00:00
|
|
|
my $oldapkbuild = shift;
|
2011-06-02 08:55:00 +00:00
|
|
|
my $apkbuild = read_apkbuild;
|
2020-07-06 01:54:22 +00:00
|
|
|
|
2021-02-16 01:16:48 +00:00
|
|
|
$modver = defined($modver) ? $modver : $apkbuild->{'pkgver'};
|
2020-03-03 20:41:10 +00:00
|
|
|
my $metaprefix = '';
|
|
|
|
if ( exists $apkbuild->{'_realname'} ) {
|
2021-02-16 01:16:48 +00:00
|
|
|
$metaprefix = "src/" . $apkbuild->{'_realname'} . "-" . $modver . "/";
|
2020-03-03 20:41:10 +00:00
|
|
|
}
|
|
|
|
elsif ( exists $apkbuild->{'_pkgreal'} ) {
|
2021-02-16 01:16:48 +00:00
|
|
|
$metaprefix = "src/" . $apkbuild->{'_pkgreal'} . "-" . $modver . "/";
|
2020-03-03 20:41:10 +00:00
|
|
|
}
|
|
|
|
elsif ( exists $apkbuild->{'_pkgname'} ) {
|
2021-02-16 01:16:48 +00:00
|
|
|
$metaprefix = "src/" . $apkbuild->{'_pkgname'} . "-" . $modver . "/";
|
2020-03-03 20:41:10 +00:00
|
|
|
}
|
|
|
|
elsif ( exists $apkbuild->{'_name'} ) {
|
2021-02-16 01:16:48 +00:00
|
|
|
$metaprefix = "src/" . $apkbuild->{'_name'} . "-" . $modver . "/";
|
2020-03-03 20:41:10 +00:00
|
|
|
}
|
|
|
|
elsif ( exists $apkbuild->{'_realpkgname'} ) {
|
2021-02-16 01:16:48 +00:00
|
|
|
$metaprefix = "src/" . $apkbuild->{'_realpkgname'} . "-" . $modver . "/";
|
2020-03-03 20:41:10 +00:00
|
|
|
}
|
|
|
|
elsif ( exists $apkbuild->{'_pkg_real'} ) {
|
2021-02-16 01:16:48 +00:00
|
|
|
$metaprefix = "src/" . $apkbuild->{'_pkg_real'} . "-" . $modver . "/";
|
2020-03-03 20:41:10 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
die "Unable to find meta file directory - check APKBUILD Perl Module Name";
|
|
|
|
}
|
|
|
|
|
|
|
|
$metaprefix =~ s/-\$pkgver//g;
|
2021-02-15 01:21:18 +00:00
|
|
|
print "\nMetaprefix: $metaprefix\n";
|
2020-03-03 20:41:10 +00:00
|
|
|
|
2011-06-02 08:55:00 +00:00
|
|
|
my $meta;
|
|
|
|
|
|
|
|
foreach my $metafile ("MYMETA.json", "META.json", "MYMETA.yml", "META.yml") {
|
|
|
|
if (-e "$metaprefix$metafile") {
|
|
|
|
say "Using meta information from $metafile";
|
|
|
|
$meta = CPAN::Meta->load_file("$metaprefix$metafile");
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
die "No dependency meta file found" unless $meta;
|
|
|
|
|
|
|
|
my $abstract = $meta->abstract;
|
|
|
|
say "Abstract: $abstract";
|
|
|
|
|
2020-03-25 00:14:32 +00:00
|
|
|
my $license = join " OR ", map {$license_mappings->{$_} or $_} $meta->license;
|
2011-06-02 08:55:00 +00:00
|
|
|
say "License: $license";
|
|
|
|
|
2021-02-15 01:21:18 +00:00
|
|
|
my $deps = parse_deps( $meta->effective_prereqs->requirements_for('runtime', 'requires') );
|
2020-03-25 00:33:43 +00:00
|
|
|
|
2020-07-06 01:54:22 +00:00
|
|
|
if (defined $oldapkbuild->{'depends'}){
|
|
|
|
if (defined $oldapkbuild->{'cpandepends'}) {
|
|
|
|
$oldapkbuild->{'depends'} =~ s/\$cpandepends/$oldapkbuild->{'cpandepends'}/g;
|
|
|
|
}
|
2020-07-06 19:49:46 +00:00
|
|
|
my $libs = $oldapkbuild->{'depends'};
|
|
|
|
$libs =~ s/perl\-\w+[-\w+]+//g;
|
|
|
|
$libs =~ s/perl//g;
|
2020-12-23 03:58:20 +00:00
|
|
|
if ($libs ne '') {
|
2020-12-22 23:23:50 +00:00
|
|
|
$deps = $deps . " " .$libs;
|
|
|
|
}
|
2020-07-06 01:54:22 +00:00
|
|
|
$deps = sort_pkgs_by_orig ($oldapkbuild->{'depends'}, $deps);
|
|
|
|
}
|
|
|
|
|
2020-03-03 23:03:42 +00:00
|
|
|
if ($deps eq '') {
|
|
|
|
$deps = "perl";
|
|
|
|
} else {
|
2020-12-22 23:23:50 +00:00
|
|
|
$deps = format_depends("perl " . $deps);
|
|
|
|
|
2020-03-03 23:03:42 +00:00
|
|
|
}
|
2020-07-06 01:54:22 +00:00
|
|
|
|
|
|
|
say "CPAN runtime Required: $deps";
|
2021-02-15 01:21:18 +00:00
|
|
|
say "CPAN runtime Recommended: " . parse_deps( $meta->effective_prereqs->requirements_for('runtime', 'recommends'));
|
2011-06-02 08:55:00 +00:00
|
|
|
|
2019-08-20 19:44:24 +00:00
|
|
|
my $makedeps = parse_deps(
|
|
|
|
$meta->effective_prereqs->requirements_for('configure', 'requires'),
|
|
|
|
$meta->effective_prereqs->requirements_for('configure', 'recommends'),
|
|
|
|
$meta->effective_prereqs->requirements_for('build', 'requires'),
|
|
|
|
$meta->effective_prereqs->requirements_for('build', 'recommends')
|
|
|
|
);
|
2020-03-24 23:39:39 +00:00
|
|
|
|
|
|
|
if (-e "$metaprefix/Build.PL" ) {
|
2021-02-15 02:29:00 +00:00
|
|
|
$makedeps = "$makedeps perl-module-build" unless $makedeps =~ m/^perl-module-build$/;
|
2020-03-24 23:39:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 01:54:22 +00:00
|
|
|
if (defined $oldapkbuild->{'makedepends'}){
|
|
|
|
if (defined $oldapkbuild->{'cpanmakedepends'}) {
|
|
|
|
$oldapkbuild->{'makedepends'} =~ s/\$cpanmakedepends/$oldapkbuild->{'cpanmakedepends'}/g;
|
|
|
|
}
|
2020-07-06 19:49:46 +00:00
|
|
|
my $libs = $oldapkbuild->{'makedepends'};
|
|
|
|
$libs =~ s/perl\-\w+[-\w+]+//g;
|
|
|
|
$makedeps = $makedeps . " " .$libs;
|
2020-07-06 01:54:22 +00:00
|
|
|
$makedeps = sort_pkgs_by_orig ($oldapkbuild->{'makedepends'}, $makedeps);
|
|
|
|
}
|
|
|
|
|
2020-03-03 23:03:42 +00:00
|
|
|
if ($makedeps eq '') {
|
|
|
|
$makedeps = "perl-dev";
|
|
|
|
} else {
|
2020-12-22 23:23:50 +00:00
|
|
|
$makedeps = format_depends("perl-dev " . $makedeps);
|
2020-03-03 23:03:42 +00:00
|
|
|
}
|
2021-02-15 01:21:18 +00:00
|
|
|
$makedeps =~ s/ +$//g;
|
2020-07-06 01:54:22 +00:00
|
|
|
|
2011-06-02 08:55:00 +00:00
|
|
|
say "CPAN build deps: $makedeps";
|
2020-07-06 01:54:22 +00:00
|
|
|
say " CPAN build requires: " . parse_deps($meta->effective_prereqs->requirements_for('configure', 'requires'), $meta->effective_prereqs->requirements_for('build', 'requires'));
|
|
|
|
say " CPAN build recommends: " . parse_deps($meta->effective_prereqs->requirements_for('configure', 'recommends'), $meta->effective_prereqs->requirements_for('build', 'recommends'));
|
2017-01-31 08:20:14 +00:00
|
|
|
|
|
|
|
my $checkdeps = parse_deps($meta->effective_prereqs->requirements_for('test', 'requires'), $meta->effective_prereqs->requirements_for('test', 'recommends'));
|
2020-07-06 01:54:22 +00:00
|
|
|
|
|
|
|
if (defined $oldapkbuild->{'checkdepends'}){
|
|
|
|
if (defined $oldapkbuild->{'cpancheckdepends'}) {
|
|
|
|
$oldapkbuild->{'checkdepends'} =~ s/\$cpancheckdepends/$oldapkbuild->{'cpancheckdepends'}/g;
|
|
|
|
}
|
2020-07-06 19:49:46 +00:00
|
|
|
my $libs = $oldapkbuild->{'checkdepends'};
|
|
|
|
$libs =~ s/perl\-\w+[-\w+]+//g;
|
2020-12-22 23:23:50 +00:00
|
|
|
if ($libs ne "") {
|
|
|
|
$checkdeps = $checkdeps . " " .$libs;
|
|
|
|
}
|
2020-07-06 01:54:22 +00:00
|
|
|
$checkdeps = sort_pkgs_by_orig ($oldapkbuild->{'checkdepends'}, $checkdeps);
|
|
|
|
}
|
|
|
|
|
2020-12-22 23:23:50 +00:00
|
|
|
$checkdeps = format_depends($checkdeps);
|
2020-02-29 23:53:29 +00:00
|
|
|
say "CPAN check deps: $checkdeps";
|
2011-06-02 08:55:00 +00:00
|
|
|
|
|
|
|
my $text = read_file "APKBUILD";
|
2019-03-22 01:18:47 +00:00
|
|
|
if ($abstract && $abstract ne 'unknown') {
|
2011-06-02 08:55:00 +00:00
|
|
|
$text =~ s/^pkgdesc=\"([^\"]*)\"$/pkgdesc=\"$abstract\"/mg or
|
2020-02-29 23:53:29 +00:00
|
|
|
die "Can't find pkgdesc line in APKBUILD";
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
2011-06-02 11:31:17 +00:00
|
|
|
if (length(`find $metaprefix -name '*.xs'`)) {
|
2021-05-15 00:46:47 +00:00
|
|
|
if (!exists $oldapkbuild->{'arch'}) {
|
|
|
|
$text =~ s/^arch=\"([^\"]*)\"$/arch="all"/mg or
|
|
|
|
die "Can't find arch line in APKBUILD";
|
|
|
|
}
|
2011-06-02 11:31:17 +00:00
|
|
|
}
|
2011-06-02 10:35:06 +00:00
|
|
|
if ($license ne 'unknown') {
|
|
|
|
$text =~ s/^license=\"([^\"]*)\"$/license=\"$license\"/mg or
|
|
|
|
die "Can't find license line in APKBUILD";
|
|
|
|
}
|
2020-02-29 23:53:29 +00:00
|
|
|
$text =~ s/^depends=\"([^\"]*)\"$/depends=\"$deps\"/mg or
|
2021-02-15 15:22:08 +00:00
|
|
|
$text =~ s/(license=.*\n)/$1depends=\"$deps\"/gm or
|
2020-03-03 22:33:19 +00:00
|
|
|
die "Can't insert depends line in APKBUILD";
|
|
|
|
|
2020-03-03 23:03:42 +00:00
|
|
|
$text =~ s/^makedepends=\"([^\"]*)\"$/makedepends=\"$makedeps\"/mg or
|
2021-02-15 15:22:08 +00:00
|
|
|
$text =~ s/(depends=.*\n)/$1makedepends=\"$makedeps\"/gm or
|
2020-03-03 22:33:19 +00:00
|
|
|
die "Can't insert makedepends line in APKBUILD";
|
|
|
|
|
2021-05-14 21:28:07 +00:00
|
|
|
$text =~ s/^checkdepends=\"([^\"]*)\"$/checkdepends=\"$checkdeps\"/mg or
|
|
|
|
$text =~ s/(makedepends=.*\n)/$1checkdepends=\"$checkdeps\"/gm or
|
2020-03-03 22:33:19 +00:00
|
|
|
die "Can't insert checkdepends line in APKBUILD";
|
|
|
|
|
|
|
|
# remove empty variables
|
|
|
|
$text =~ s/.*=""\n//g;
|
2011-06-02 08:55:00 +00:00
|
|
|
|
|
|
|
open my $fh, '>', "APKBUILD" or die;
|
|
|
|
print $fh $text;
|
|
|
|
close $fh;
|
|
|
|
}
|
|
|
|
|
2011-06-28 14:51:07 +00:00
|
|
|
sub get_data {
|
|
|
|
my $apkbuild = read_apkbuild;
|
2020-03-03 20:41:10 +00:00
|
|
|
my $pkgreal = '';
|
|
|
|
|
|
|
|
if (exists $apkbuild->{_realname}) {
|
|
|
|
$pkgreal = $apkbuild->{_realname};
|
|
|
|
} elsif (exists $apkbuild->{_pkgreal}) {
|
|
|
|
$pkgreal = $apkbuild->{_pkgreal};
|
|
|
|
} elsif (exists $apkbuild->{_pkgname}) {
|
|
|
|
$pkgreal = $apkbuild->{_pkgname};
|
|
|
|
} elsif (exists $apkbuild->{_name}) {
|
|
|
|
$pkgreal = $apkbuild->{_name};
|
|
|
|
} elsif (exists $apkbuild->{_realpkgname}) {
|
|
|
|
$pkgreal = $apkbuild->{_realpkgname};
|
|
|
|
} elsif (exists $apkbuild->{_pkg_real}) {
|
|
|
|
$pkgreal = $apkbuild->{_pkg_real};
|
|
|
|
} else {
|
|
|
|
my $module = '';
|
|
|
|
my $distribution = '';
|
|
|
|
while ((my $key, my $value ) = each (%$apkbuild)) {
|
|
|
|
# Do not parse any depends lines to not find incorrect module
|
|
|
|
if ($key =~ m/.*depends.*/) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
# Try to find a perl module name in APKBUILD
|
|
|
|
if ($value=~m/((\w+::)+\w+)/g) {
|
|
|
|
# Match Perl Module names containing ::
|
|
|
|
$module .= "$1 " unless $module =~ m/$1/;
|
|
|
|
}
|
|
|
|
elsif ($value =~ m/(([A-Z]\w+-)+\w+)/) {
|
|
|
|
# Match possible distribution names with -
|
|
|
|
$distribution .= "$1 " unless $distribution =~ m/ *$1 /;
|
|
|
|
}
|
|
|
|
elsif ( $value =~ m/.*release\/([A-Z]\w+).*/ ) {
|
|
|
|
# Match Single Word Perl Module Name after release in URL?
|
|
|
|
$distribution .= "$1 " unless $distribution =~ m/ *$1 /;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Want to try the traditional Module::Name first
|
|
|
|
my $list = $module . $distribution;
|
|
|
|
foreach (split / /, $list) {
|
|
|
|
my $type = '';
|
|
|
|
if( $_ =~ m/::/ ) {
|
|
|
|
$type = 'module';
|
|
|
|
} else {
|
|
|
|
$type = 'release';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $response = $ua->get("https://fastapi.metacpan.org/$type/$_");
|
|
|
|
$response->is_success or next;;
|
|
|
|
|
|
|
|
my $moddata = $json->decode($response->decoded_content);
|
|
|
|
$moddata->{error} and next;
|
|
|
|
|
|
|
|
$pkgreal = $moddata->{distribution};
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$pkgreal =~ s/-\$pkgver//g;
|
|
|
|
|
|
|
|
my $response = $ua->get("https://fastapi.metacpan.org/release/$pkgreal");
|
|
|
|
$response->is_success or
|
|
|
|
die $response->status_line . " unable to find $pkgreal verify Perl Module name in APKBUILD\n";
|
2011-06-28 14:51:07 +00:00
|
|
|
my $distdata = $json->decode($response->decoded_content);
|
2020-03-03 20:41:10 +00:00
|
|
|
$distdata->{error} and die "Error trying to locate $pkgreal: $distdata->{error}\n";
|
2011-06-28 14:51:07 +00:00
|
|
|
|
2018-11-26 03:18:10 +00:00
|
|
|
$response = $ua->get("https://fastapi.metacpan.org/module/$distdata->{main_module}");
|
|
|
|
$response->is_success or die $response->status_line;
|
|
|
|
my $moddata = $json->decode($response->decoded_content);
|
|
|
|
$moddata->{error} and die "Error trying to locate $distdata->{main_module}: $moddata->{error}\n";
|
|
|
|
|
|
|
|
return ($apkbuild, $distdata, $moddata);
|
2011-06-28 14:51:07 +00:00
|
|
|
}
|
|
|
|
|
2011-06-02 08:55:00 +00:00
|
|
|
my $abuild_conf = read_assignments_from_file("/etc/abuild.conf");
|
|
|
|
$packager = $abuild_conf->{PACKAGER} if $abuild_conf->{PACKAGER};
|
|
|
|
|
2017-01-31 08:20:14 +00:00
|
|
|
my $user_abuild_conf = read_assignments_from_file($ENV{"HOME"} . "/.abuild/abuild.conf");
|
|
|
|
$packager = $user_abuild_conf->{PACKAGER} if $user_abuild_conf->{PACKAGER};
|
|
|
|
|
2011-06-02 08:55:00 +00:00
|
|
|
given ( $ARGV[0] ) {
|
|
|
|
when ("create") {
|
|
|
|
my $module = $ARGV[1];
|
|
|
|
$module or die "Module name is a mandatory argument";
|
|
|
|
|
2020-03-03 20:41:10 +00:00
|
|
|
my $response = $ua->get("https://fastapi.metacpan.org/module/$module");
|
2011-06-02 08:55:00 +00:00
|
|
|
$response->is_success or die $response->status_line;
|
|
|
|
my $moddata = $json->decode($response->decoded_content);
|
|
|
|
$moddata->{error} and die "Error trying to locate $module: $moddata->{error}\n";
|
|
|
|
|
2018-11-25 01:51:08 +00:00
|
|
|
$response = $ua->get("https://fastapi.metacpan.org/release/$moddata->{distribution}");
|
2011-06-02 08:55:00 +00:00
|
|
|
$response->is_success or die $response->status_line;
|
|
|
|
my $distdata = $json->decode($response->decoded_content);
|
|
|
|
$distdata->{error} and die "Error trying to locate $module: $distdata->{error}\n";
|
|
|
|
|
2018-11-25 01:51:08 +00:00
|
|
|
my $apkname = map_cpan_to_apk $distdata->{metadata}{name};
|
2011-06-02 08:55:00 +00:00
|
|
|
mkdir $apkname;
|
|
|
|
chdir $apkname;
|
2018-11-25 17:43:37 +00:00
|
|
|
write_apkbuild($distdata, undef, $moddata);
|
2011-06-02 08:55:00 +00:00
|
|
|
prepare_tree;
|
|
|
|
update_functions;
|
2021-02-16 01:16:48 +00:00
|
|
|
do_depends $moddata->{version};
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
when ("recreate") {
|
2020-03-03 20:41:10 +00:00
|
|
|
#TODO: likely should keep pkgrel the same on recreate
|
2018-11-26 03:18:10 +00:00
|
|
|
my ($apkbuild, $distdata, $moddata) = get_data;
|
2020-03-24 23:38:09 +00:00
|
|
|
my $pkgver = $moddata->{version} =~ s/^[^0-9]+//r;
|
|
|
|
if ($pkgver ne $apkbuild->{pkgver}) {
|
|
|
|
#Reset pkgrel on upgrade on recreate
|
|
|
|
say "Upgrading CPAN module from $apkbuild->{pkgver} to $pkgver";
|
|
|
|
$apkbuild->{pkgrel}=0;
|
|
|
|
}
|
2020-03-25 00:33:43 +00:00
|
|
|
write_apkbuild($distdata, $apkbuild, $moddata);
|
2011-06-02 08:55:00 +00:00
|
|
|
prepare_tree;
|
|
|
|
update_functions;
|
2021-02-16 01:16:48 +00:00
|
|
|
do_depends($moddata->{version}, $apkbuild);
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
when ("upgrade") {
|
2018-11-26 03:18:10 +00:00
|
|
|
my ($apkbuild, $distdata, $moddata) = get_data;
|
2011-06-02 08:55:00 +00:00
|
|
|
|
2019-08-20 19:38:23 +00:00
|
|
|
my $pkgver = $moddata->{version} =~ s/^[^0-9]+//r;
|
2020-03-03 20:41:10 +00:00
|
|
|
if ($pkgver ne $apkbuild->{pkgver}) {
|
2011-06-02 08:55:00 +00:00
|
|
|
say "Upgrading CPAN module from $apkbuild->{pkgver} to $pkgver";
|
|
|
|
|
|
|
|
my $text = read_file "APKBUILD";
|
|
|
|
$text =~ s/^pkgver=(.*)$/pkgver=$pkgver/mg or
|
|
|
|
die "Can't find pkgver line in APKBUILD";
|
|
|
|
$text =~ s/^pkgrel=(.*)$/pkgrel=0/mg;
|
2021-05-15 00:48:37 +00:00
|
|
|
#FIXME: review whether this works over time
|
|
|
|
# It deletes the blank line before the checksum
|
|
|
|
# So prepare_tree does not insert extra blank line
|
|
|
|
$text =~ s/\n^(.*sums=.*\n)/$1/mg;
|
2011-06-02 08:55:00 +00:00
|
|
|
open my $fh, '>', "APKBUILD" or die;
|
|
|
|
say $fh $text;
|
|
|
|
close $fh;
|
|
|
|
prepare_tree;
|
2021-04-04 03:27:34 +00:00
|
|
|
do_depends ($moddata->{version}, $apkbuild);
|
2011-06-02 08:55:00 +00:00
|
|
|
} else {
|
|
|
|
say "Up-to-data with CPAN";
|
|
|
|
}
|
|
|
|
}
|
2011-06-28 14:51:07 +00:00
|
|
|
when ('check') {
|
2018-11-26 03:18:10 +00:00
|
|
|
my ($apkbuild, $distdata, $moddata) = get_data;
|
2019-08-20 19:38:23 +00:00
|
|
|
my $pkgver = $moddata->{version} =~ s/^[^0-9]+//r;
|
2011-06-28 15:05:04 +00:00
|
|
|
say "$apkbuild->{pkgname}: Latest version: $pkgver Packaged version: $apkbuild->{pkgver}";
|
|
|
|
if ($pkgver ne $apkbuild->{pkgver}) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-06-28 14:51:07 +00:00
|
|
|
}
|
2011-06-02 08:55:00 +00:00
|
|
|
when ("update") {
|
|
|
|
prepare_tree;
|
|
|
|
do_depends;
|
|
|
|
}
|
|
|
|
default {
|
2011-06-28 14:51:07 +00:00
|
|
|
say "Usage: apkbuild-cpan [create <Module::Name> | check | recreate | update | upgrade]";
|
2011-06-02 08:55:00 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|