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);
|
2023-12-20 05:00:39 +00:00
|
|
|
use File::Basename qw(dirname);
|
|
|
|
use URI;
|
2011-06-02 08:55:00 +00:00
|
|
|
|
|
|
|
my $license_mappings = {
|
2023-07-03 21:52:43 +00:00
|
|
|
"perl_5" => "GPL-1.0-or-later OR Artistic-1.0-Perl",
|
|
|
|
"artistic_2" => "Artistic-2.0",
|
|
|
|
"gpl_2" => "GPL-2.0-only",
|
|
|
|
"gpl_3" => "GPL-3.0-only",
|
|
|
|
"mit" => "MIT",
|
|
|
|
"apache_2_0" => "Apache-2.0",
|
2011-06-02 08:55:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
my $package_mappings = {
|
2023-07-03 21:52:43 +00:00
|
|
|
"LWP" => "perl-libwww",
|
|
|
|
"libwww-perl" => "perl-libwww",
|
|
|
|
"TermReadKey" => "perl-term-readkey",
|
|
|
|
"perl-ldap" => "perl-ldap",
|
|
|
|
"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"
|
2023-12-22 17:54:34 +00:00
|
|
|
options="[% options %]" [% options_comment %]
|
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"
|
2021-07-04 16:55:45 +00:00
|
|
|
makedepends=""
|
2020-02-29 23:53:29 +00:00
|
|
|
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
|
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
our $ua = LWP::UserAgent->new();
|
2011-06-02 08:55:00 +00:00
|
|
|
our $json = JSON->new;
|
|
|
|
$ua->env_proxy;
|
2023-07-03 21:52:43 +00:00
|
|
|
$ua->conn_cache( LWP::ConnCache->new() );
|
2011-06-02 08:55:00 +00:00
|
|
|
|
2017-01-31 08:20:14 +00:00
|
|
|
sub read_file {
|
2023-07-03 21:52:43 +00:00
|
|
|
my ($filename) = @_;
|
|
|
|
local $/;
|
|
|
|
open my $fh, "<", $filename or die "could not open $filename: $!";
|
|
|
|
return <$fh>;
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub read_assignments_from_file {
|
2023-07-03 21:52:43 +00:00
|
|
|
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 );
|
2017-01-31 08:20:14 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
my $authors = join( "\n",
|
|
|
|
$text =~ /^# Contributor: .*$/mg,
|
|
|
|
$text =~ /^# Maintainer: .*$/mg );
|
|
|
|
$hash{'authors'} = $authors if length($authors) > 1;
|
2017-01-31 08:20:14 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
my $provides = $text =~ m/^provides=\"(.*)\"".*$/mg;
|
|
|
|
$hash{'provides'} = $1 if length($provides) >= 1;
|
2020-03-25 00:33:43 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
my $requires = $text =~ m/^requires=\"(.*)\"".*$/mg;
|
|
|
|
$hash{'requires'} = $1 if length($requires) >= 1;
|
2020-03-25 00:33:43 +00:00
|
|
|
|
2023-12-22 17:54:34 +00:00
|
|
|
my $options = $text =~ m/^options=\"(.*)\"(.*)$/mg;
|
|
|
|
$hash{'options'} = "$1" if length($options) >= 1;
|
|
|
|
$hash{'options_comment'} = "$2" if length($options) >= 1;
|
|
|
|
|
2024-01-05 02:24:13 +00:00
|
|
|
if ($text =~ m/^source=\"([^\"]*)\"/mg) {
|
|
|
|
my @patches = split (/\n/m, $1);
|
|
|
|
shift @patches;
|
|
|
|
$hash{'patches'} = \@patches;
|
|
|
|
}
|
2023-12-22 17:54:34 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
return \%hash;
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub map_cpan_to_apk {
|
2023-07-03 21:52:43 +00:00
|
|
|
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;
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub read_apkbuild {
|
2023-07-03 21:52:43 +00:00
|
|
|
return read_assignments_from_file("APKBUILD");
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub write_apkbuild {
|
2023-07-03 21:52:43 +00:00
|
|
|
my ( $distdata, $apkbuild, $moddata ) = @_;
|
|
|
|
|
|
|
|
my $cpanid = $distdata->{id};
|
|
|
|
$cpanid =
|
|
|
|
substr( $cpanid, 0, 1 ) . "/" . substr( $cpanid, 0, 2 ) . "/$cpanid";
|
|
|
|
|
|
|
|
my $authors = undef;
|
|
|
|
my $replaces = undef;
|
|
|
|
my $provides = undef;
|
|
|
|
my $pkgrel = 0;
|
2023-12-22 17:54:34 +00:00
|
|
|
my $options = undef;
|
|
|
|
my $options_comment = undef;
|
|
|
|
my $patches = "";
|
2023-07-03 21:52:43 +00:00
|
|
|
if ( defined $apkbuild ) {
|
|
|
|
$authors = $apkbuild->{authors};
|
|
|
|
$provides = $apkbuild->{provides};
|
|
|
|
$replaces = $apkbuild->{replaces};
|
|
|
|
$pkgrel = $apkbuild->{pkgrel};
|
2023-12-22 17:54:34 +00:00
|
|
|
$options = $apkbuild->{options} if defined $apkbuild->{options};
|
|
|
|
$options_comment = $apkbuild->{options_comment} if defined $apkbuild->{options_comment};
|
|
|
|
$patches = "\n" . join ("\n", @{$apkbuild->{patches}}) if scalar @{$apkbuild->{patches}};
|
2023-07-03 21:52:43 +00:00
|
|
|
if ( $apkbuild->{pkgver} eq $moddata->{version} ) {
|
|
|
|
$pkgrel++;
|
2021-02-16 01:16:48 +00:00
|
|
|
}
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my $builddir;
|
|
|
|
|
2023-12-20 05:00:39 +00:00
|
|
|
my $srcurl = $moddata->{download_url};
|
|
|
|
my $filename = (URI->new($srcurl)->path_segments)[-1];
|
|
|
|
|
|
|
|
my $pkgreal = $moddata->{distribution};
|
2023-07-03 21:52:43 +00:00
|
|
|
my $pkgver = $moddata->{version} =~ s/^[^0-9]+//r;
|
2023-12-20 05:00:39 +00:00
|
|
|
if ( $filename =~ m/$pkgreal-$pkgver/ ) {
|
2023-07-03 21:52:43 +00:00
|
|
|
$builddir = "\$srcdir/\$_pkgreal-\$pkgver";
|
2023-12-20 05:00:39 +00:00
|
|
|
} elsif ( $filename =~ m/$pkgreal-v${pkgver}/ ) {
|
|
|
|
$builddir = "\$srcdir/\$_pkgreal-v\$pkgver";
|
|
|
|
} else {
|
|
|
|
$builddir = "\$srcdir/\$_pkgreal-" . $moddata->{version};
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
2021-02-16 01:16:48 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
my %repl = (
|
|
|
|
authors => (
|
|
|
|
$authors
|
|
|
|
or "# Contributor: $packager\n# Maintainer: $packager"
|
|
|
|
),
|
|
|
|
pkgname => map_cpan_to_apk( $moddata->{distribution} ),
|
2023-12-20 05:00:39 +00:00
|
|
|
pkgreal => $pkgreal,
|
|
|
|
pkgver => $pkgver,
|
2023-07-03 21:52:43 +00:00
|
|
|
pkgrel => $pkgrel,
|
2023-12-22 17:54:34 +00:00
|
|
|
source => defined $patches ? ($srcurl . $patches) : $srcurl,
|
2023-07-03 21:52:43 +00:00
|
|
|
pkgdesc => $distdata->{abstract},
|
|
|
|
provides => ( $provides or '' ),
|
|
|
|
replaces => ( $replaces or '' ),
|
|
|
|
builddir => $builddir,
|
2023-12-22 17:54:34 +00:00
|
|
|
options => ( $options or '' ),
|
|
|
|
options_comment => ( $options_comment or '' ),
|
2023-07-03 21:52:43 +00:00
|
|
|
);
|
2023-12-20 05:00:39 +00:00
|
|
|
$repl{source} =~ s/$repl{pkgver}/\$pkgver/g;
|
2023-07-03 21:52:43 +00:00
|
|
|
$template =~ s/\[% (.*?) %\]/$repl{$1}/g;
|
|
|
|
|
|
|
|
open my $fh, '>', "APKBUILD" or die;
|
|
|
|
print $fh $template;
|
|
|
|
close $fh;
|
|
|
|
|
|
|
|
say "Wrote $repl{pkgname}/APKBUILD";
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub parse_deps {
|
2023-07-03 21:52:43 +00:00
|
|
|
my ($reqs) = @_;
|
|
|
|
my $distfiles = {};
|
|
|
|
my $response;
|
|
|
|
my $deps = "";
|
|
|
|
my $reqmodlist = "";
|
|
|
|
|
|
|
|
#Get list of unique required modules from all parameters
|
|
|
|
foreach $reqs (@_) {
|
|
|
|
for my $module ( $reqs->required_modules ) {
|
|
|
|
$reqmodlist .= "$module " unless $reqmodlist =~ m/^$module$/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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);
|
|
|
|
say " $module is part of core perl since $perlver.";
|
|
|
|
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};
|
|
|
|
}
|
|
|
|
|
|
|
|
# map package names to alpine packages
|
|
|
|
foreach ( keys %{$distfiles} ) {
|
|
|
|
$response = $ua->get("https://fastapi.metacpan.org/module/$_");
|
|
|
|
$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";
|
|
|
|
|
|
|
|
my $pkgname = map_cpan_to_apk( $distdata->{distribution} );
|
|
|
|
$deps .= "$pkgname " unless $deps =~ m/^$pkgname$/;
|
|
|
|
}
|
|
|
|
$deps =~ s/\h+/ /g;
|
|
|
|
$deps =~ s/ $//;
|
2023-12-19 01:55:40 +00:00
|
|
|
return defined $deps ? $deps : '';
|
2011-06-02 08:55:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub prepare_tree {
|
2023-07-03 21:52:43 +00:00
|
|
|
system("abuild checksum unpack prepare") == 0
|
|
|
|
or die "abuild checksum failed";
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub update_functions {
|
2023-07-03 21:52:43 +00:00
|
|
|
my $apkbuild = read_apkbuild;
|
|
|
|
my $metaprefix =
|
|
|
|
"src/" . $apkbuild->{'_pkgreal'} . "-" . $apkbuild->{'pkgver'} . "/";
|
|
|
|
my $build_func;
|
|
|
|
my $check_func;
|
|
|
|
my $package_func;
|
|
|
|
|
|
|
|
my $text = read_file "APKBUILD";
|
|
|
|
if ( -e "$metaprefix/Build.PL" ) {
|
|
|
|
$build_func = <<'EOF';
|
2011-06-02 08:55:00 +00:00
|
|
|
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
|
2023-07-03 21:52:43 +00:00
|
|
|
$package_func = <<'EOF';
|
2011-06-02 08:55:00 +00:00
|
|
|
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
|
2023-07-03 21:52:43 +00:00
|
|
|
$check_func = <<'EOF';
|
2017-07-11 12:04:36 +00:00
|
|
|
check() {
|
|
|
|
./Build test
|
|
|
|
}
|
2011-06-02 08:55:00 +00:00
|
|
|
EOF
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$build_func = <<'EOF';
|
2011-06-02 08:55:00 +00:00
|
|
|
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
|
2023-07-03 21:52:43 +00:00
|
|
|
$package_func = <<'EOF';
|
2011-06-02 08:55:00 +00:00
|
|
|
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
|
2023-07-03 21:52:43 +00:00
|
|
|
$check_func = <<'EOF';
|
2017-01-31 08:20:14 +00:00
|
|
|
check() {
|
|
|
|
export CFLAGS=$(perl -MConfig -E 'say $Config{ccflags}')
|
|
|
|
make test
|
|
|
|
}
|
2011-06-02 08:55:00 +00:00
|
|
|
EOF
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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";
|
|
|
|
$text =~ s/^check\(\) \{.*?^\}\n/$check_func/smg
|
|
|
|
or die "Can't replace check function APKBUILD";
|
|
|
|
|
|
|
|
open my $fh, '>', "APKBUILD" or die;
|
|
|
|
print $fh $text;
|
|
|
|
close $fh;
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 01:54:22 +00:00
|
|
|
sub sort_pkgs_by_orig {
|
2023-12-19 01:55:40 +00:00
|
|
|
my $sort_order = shift;
|
|
|
|
my $list = shift;
|
|
|
|
|
|
|
|
return '' if !defined $list;
|
|
|
|
my @array_to_sort = split / /, $list;
|
2020-07-06 01:54:22 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
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
|
2020-07-06 01:54:22 +00:00
|
|
|
|
|
|
|
my @sort_order = split / /, $sort_order;
|
|
|
|
|
|
|
|
#get order of order by string
|
|
|
|
my $count = 0;
|
|
|
|
my %position_of;
|
|
|
|
$position_of{$_} = $count++ for @sort_order;
|
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
my %sorted; # holds the position of array to sort
|
2020-07-06 01:54:22 +00:00
|
|
|
|
|
|
|
foreach (@array_to_sort) {
|
|
|
|
my $pos = $position_of{$_};
|
2023-07-03 21:52:43 +00:00
|
|
|
if ( !defined $pos ) {
|
|
|
|
|
2020-07-06 01:54:22 +00:00
|
|
|
# not found in sort order so add to the end
|
|
|
|
$sorted{$_} = $count;
|
|
|
|
$count++;
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-07-06 01:54:22 +00:00
|
|
|
$sorted{$_} = $pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my @tmp; # hold array of sorted in position order
|
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
foreach my $name ( sort { $sorted{$a} <=> $sorted{$b} } keys %sorted ) {
|
|
|
|
push @tmp, $name;
|
2020-07-06 01:54:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 23:58:37 +00:00
|
|
|
# remove any duplicates
|
|
|
|
uniq @tmp;
|
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
return join( " ", @tmp );
|
2020-07-06 01:54:22 +00:00
|
|
|
}
|
2018-11-25 17:43:37 +00:00
|
|
|
|
2020-12-22 23:23:50 +00:00
|
|
|
sub format_depends {
|
|
|
|
my $deps = shift;
|
|
|
|
|
2023-12-19 01:55:40 +00:00
|
|
|
return '' if !defined $deps;
|
2020-12-22 23:23:50 +00:00
|
|
|
$columns = 102;
|
2021-02-15 15:22:08 +00:00
|
|
|
|
|
|
|
$deps =~ s/ {2,}/ /g;
|
|
|
|
$deps =~ s/^\s//g;
|
|
|
|
$deps =~ s/\s$//g;
|
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
if ( length($deps) >= $columns ) {
|
|
|
|
$deps = wrap( "\t", "\t", $deps );
|
2021-02-15 15:22:08 +00:00
|
|
|
}
|
|
|
|
$deps =~ s/\s$//g;
|
|
|
|
|
2023-07-03 21:52:43 +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 {
|
2023-07-03 21:52:43 +00:00
|
|
|
my $modver = shift;
|
|
|
|
my $oldapkbuild = shift;
|
|
|
|
my $apkbuild = read_apkbuild;
|
|
|
|
|
|
|
|
my $metaprefix = '';
|
|
|
|
if ( exists $apkbuild->{'_realname'} ) {
|
2023-12-19 01:55:40 +00:00
|
|
|
$metaprefix = "src/" . $apkbuild->{'_realname'};
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
elsif ( exists $apkbuild->{'_pkgreal'} ) {
|
2023-12-19 01:55:40 +00:00
|
|
|
$metaprefix = "src/" . $apkbuild->{'_pkgreal'};
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
elsif ( exists $apkbuild->{'_pkgname'} ) {
|
2023-12-19 01:55:40 +00:00
|
|
|
$metaprefix = "src/" . $apkbuild->{'_pkgname'};
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
elsif ( exists $apkbuild->{'_name'} ) {
|
2023-12-19 01:55:40 +00:00
|
|
|
$metaprefix = "src/" . $apkbuild->{'_name'};
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
elsif ( exists $apkbuild->{'_realpkgname'} ) {
|
|
|
|
$metaprefix =
|
2023-12-19 01:55:40 +00:00
|
|
|
"src/" . $apkbuild->{'_realpkgname'};
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
elsif ( exists $apkbuild->{'_pkg_real'} ) {
|
2023-12-19 01:55:40 +00:00
|
|
|
$metaprefix = "src/" . $apkbuild->{'_pkg_real'};
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
die
|
|
|
|
"Unable to find meta file directory - check APKBUILD Perl Module Name";
|
|
|
|
}
|
|
|
|
|
2023-12-20 05:00:39 +00:00
|
|
|
$modver = defined($modver) ? $modver : $apkbuild->{'pkgver'};
|
|
|
|
$modver =~ s/v//g;
|
|
|
|
|
|
|
|
# try with partial metaprefix
|
|
|
|
my @metafiles = glob("
|
|
|
|
$metaprefix-*${modver}/*META.json
|
|
|
|
$metaprefix-*${modver}/*META.yml
|
|
|
|
");
|
|
|
|
|
|
|
|
if ( @metafiles ) {
|
|
|
|
$metaprefix = dirname($metafiles[0]);
|
|
|
|
} elsif (my $makefile = glob("src/*${modver}/Makefile.PL")) {
|
|
|
|
$metaprefix = dirname($makefile);
|
|
|
|
system("cd $metaprefix && perl -I. Makefile.PL");
|
|
|
|
} elsif (my $buildpl = glob("src/*${modver}/Build.PL")) {
|
|
|
|
$metaprefix = dirname($buildpl);
|
|
|
|
} else {
|
|
|
|
die "Unable to find meta, makefile, and build.pl - cannot proceed"
|
2023-12-19 01:55:40 +00:00
|
|
|
}
|
2023-12-20 05:00:39 +00:00
|
|
|
|
|
|
|
# try again with full metaprefix
|
|
|
|
push @metafiles, glob("
|
|
|
|
$metaprefix/*META.json
|
|
|
|
$metaprefix/*META.yml
|
|
|
|
") unless @metafiles;
|
|
|
|
|
|
|
|
my $builddir = do {
|
|
|
|
my $pkgreal = $apkbuild->{'_pkgreal'};
|
|
|
|
my $oldbuilddir = $apkbuild->{builddir};
|
|
|
|
my $newbuilddir = $metaprefix;
|
|
|
|
|
|
|
|
$newbuilddir =~ s/src/\$srcdir/;
|
|
|
|
$newbuilddir =~ s/$pkgreal/\$_pkgreal/;
|
|
|
|
$newbuilddir =~ s/$modver/\$pkgver/;
|
|
|
|
|
|
|
|
$newbuilddir eq $oldbuilddir ? undef : $newbuilddir
|
|
|
|
};
|
2023-07-03 21:52:43 +00:00
|
|
|
|
|
|
|
my $meta;
|
|
|
|
|
|
|
|
foreach
|
2023-12-20 05:00:39 +00:00
|
|
|
my $metafile ( @metafiles )
|
2023-07-03 21:52:43 +00:00
|
|
|
{
|
2023-12-20 05:00:39 +00:00
|
|
|
if ( -e "$metafile" ) {
|
2023-07-03 21:52:43 +00:00
|
|
|
say "Using meta information from $metafile";
|
2023-12-20 05:00:39 +00:00
|
|
|
$meta = CPAN::Meta->load_file("$metafile");
|
2023-07-03 21:52:43 +00:00
|
|
|
last;
|
2020-07-06 01:54:22 +00:00
|
|
|
}
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
2020-07-06 01:54:22 +00:00
|
|
|
|
2023-12-19 01:55:40 +00:00
|
|
|
my $deps;
|
|
|
|
my $abstract;
|
|
|
|
my $license;
|
|
|
|
if ($meta) {
|
|
|
|
$license = join " OR ",
|
|
|
|
map { $license_mappings->{$_} or $_ } $meta->license;
|
|
|
|
say "License: $license";
|
2020-12-22 23:23:50 +00:00
|
|
|
|
2023-12-19 01:55:40 +00:00
|
|
|
$abstract = $meta->abstract;
|
|
|
|
say "Abstract: $abstract";
|
2020-07-06 01:54:22 +00:00
|
|
|
|
2023-12-19 01:55:40 +00:00
|
|
|
$deps = parse_deps(
|
|
|
|
$meta->effective_prereqs->requirements_for( 'runtime', 'requires' ) );
|
|
|
|
}
|
2011-06-02 08:55:00 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
if ( defined $oldapkbuild->{'depends'} ) {
|
|
|
|
if ( defined $oldapkbuild->{'cpandepends'} ) {
|
|
|
|
$oldapkbuild->{'depends'} =~
|
|
|
|
s/\$cpandepends/$oldapkbuild->{'cpandepends'}/g;
|
|
|
|
}
|
|
|
|
my $libs = $oldapkbuild->{'depends'};
|
|
|
|
$libs =~ s/perl\-\w+[-\w+]+//g;
|
|
|
|
$libs =~ s/perl//g;
|
|
|
|
if ( $libs ne '' ) {
|
2023-12-19 01:55:40 +00:00
|
|
|
$deps = $deps . " " . $libs if defined $deps;
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
$deps = sort_pkgs_by_orig( $oldapkbuild->{'depends'}, $deps );
|
|
|
|
}
|
2020-03-24 23:39:39 +00:00
|
|
|
|
2023-12-19 01:55:40 +00:00
|
|
|
if ( defined $deps && $deps eq '' ) {
|
|
|
|
if (defined $oldapkbuild->{'depends'} && ! $meta ) {
|
|
|
|
$deps = $oldapkbuild->{'depends'};
|
|
|
|
} else {
|
|
|
|
$deps = "perl";
|
|
|
|
}
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2023-12-19 01:55:40 +00:00
|
|
|
$deps = format_depends( "perl " . $deps ) if defined $deps;
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
|
2023-12-19 01:55:40 +00:00
|
|
|
my $makedeps = '';
|
|
|
|
if ($meta) {
|
|
|
|
say "CPAN runtime Required: $deps";
|
|
|
|
say "CPAN runtime Recommended: "
|
|
|
|
. parse_deps(
|
|
|
|
$meta->effective_prereqs->requirements_for( 'runtime', 'recommends' ) );
|
|
|
|
|
|
|
|
$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' )
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( -e "$metaprefix/Build.PL" ) {
|
|
|
|
$makedeps = "$makedeps perl-module-build"
|
|
|
|
unless $makedeps =~ m/^perl-module-build$/;
|
|
|
|
}
|
2023-07-03 21:52:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
if ( defined $oldapkbuild->{'makedepends'} ) {
|
|
|
|
if ( defined $oldapkbuild->{'cpanmakedepends'} ) {
|
|
|
|
$oldapkbuild->{'makedepends'} =~
|
|
|
|
s/\$cpanmakedepends/$oldapkbuild->{'cpanmakedepends'}/g;
|
|
|
|
}
|
|
|
|
my $libs = $oldapkbuild->{'makedepends'};
|
|
|
|
$libs =~ s/perl\-\w+[-\w+]+//g;
|
|
|
|
$makedeps = $makedeps . " " . $libs;
|
|
|
|
$makedeps =
|
|
|
|
sort_pkgs_by_orig( $oldapkbuild->{'makedepends'}, $makedeps );
|
|
|
|
}
|
|
|
|
|
2023-12-19 01:55:40 +00:00
|
|
|
my $perldev = (
|
|
|
|
( defined $oldapkbuild->{'makedepends'}
|
|
|
|
&& $oldapkbuild->{'makedepends'} =~ 'perl-dev' ) ||
|
|
|
|
length(`find $metaprefix -name '*.xs'`) )
|
|
|
|
? "perl-dev" : '';
|
|
|
|
if ( defined $makedeps && $makedeps eq '' ) {
|
|
|
|
if (defined $oldapkbuild->{'makedepends'} && ! $meta) {
|
|
|
|
$makedeps = $oldapkbuild->{'makedepends'};
|
|
|
|
} else {
|
|
|
|
$makedeps = $perldev;
|
|
|
|
}
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2023-12-19 01:55:40 +00:00
|
|
|
$makedeps = format_depends( $perldev . " " . $makedeps );
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
$makedeps =~ s/ +$//g;
|
|
|
|
|
2023-12-19 01:55:40 +00:00
|
|
|
my $checkdeps;
|
|
|
|
if ($meta) {
|
|
|
|
say "CPAN build deps: $makedeps";
|
|
|
|
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' )
|
|
|
|
);
|
|
|
|
|
|
|
|
$checkdeps = parse_deps(
|
|
|
|
$meta->effective_prereqs->requirements_for( 'test', 'requires' ),
|
|
|
|
$meta->effective_prereqs->requirements_for( 'test', 'recommends' )
|
|
|
|
);
|
|
|
|
}
|
2023-07-03 21:52:43 +00:00
|
|
|
|
|
|
|
if ( defined $oldapkbuild->{'checkdepends'} ) {
|
|
|
|
if ( defined $oldapkbuild->{'cpancheckdepends'} ) {
|
|
|
|
$oldapkbuild->{'checkdepends'} =~
|
|
|
|
s/\$cpancheckdepends/$oldapkbuild->{'cpancheckdepends'}/g;
|
|
|
|
}
|
|
|
|
my $libs = $oldapkbuild->{'checkdepends'};
|
|
|
|
$libs =~ s/perl\-\w+[-\w+]+//g;
|
|
|
|
if ( $libs ne "" ) {
|
|
|
|
$checkdeps = $checkdeps . " " . $libs;
|
|
|
|
}
|
|
|
|
$checkdeps =
|
|
|
|
sort_pkgs_by_orig( $oldapkbuild->{'checkdepends'}, $checkdeps );
|
|
|
|
}
|
|
|
|
|
2023-12-19 01:55:40 +00:00
|
|
|
if ( defined $checkdeps && $checkdeps eq '' ) {
|
|
|
|
if (defined $oldapkbuild->{'checkdeps'} && ! $meta) {
|
|
|
|
$checkdeps = $oldapkbuild->{'checkdeps'};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$checkdeps = format_depends($checkdeps);
|
|
|
|
}
|
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
say "CPAN check deps: $checkdeps";
|
|
|
|
|
|
|
|
my $text = read_file "APKBUILD";
|
|
|
|
if ( $abstract && $abstract ne 'unknown' ) {
|
2023-12-21 07:42:39 +00:00
|
|
|
$abstract =~ s/"/\\"/g;
|
|
|
|
$abstract =~ s/[.\s]+$//;
|
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
$text =~ s/^pkgdesc=\"([^\"]*)\"$/pkgdesc=\"$abstract\"/mg
|
|
|
|
or die "Can't find pkgdesc line in APKBUILD";
|
|
|
|
}
|
2023-12-19 01:55:40 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
if ( length(`find $metaprefix -name '*.xs'`) ) {
|
|
|
|
if ( !exists $oldapkbuild->{'arch'} ) {
|
|
|
|
$text =~ s/^arch=\"([^\"]*)\"$/arch="all"/mg
|
|
|
|
or die "Can't find arch line in APKBUILD";
|
2023-12-19 01:55:40 +00:00
|
|
|
} else {
|
|
|
|
$text =~ s/^arch=\"([^\"]*)\"$/arch="$oldapkbuild->{'arch'}"/mg
|
|
|
|
or die "Can't find arch line in APKBUILD";
|
2020-07-06 01:54:22 +00:00
|
|
|
}
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
2023-12-19 01:55:40 +00:00
|
|
|
if ( defined $license && $license ne 'unknown' ) {
|
2023-07-03 21:52:43 +00:00
|
|
|
$text =~ s/^license=\"([^\"]*)\"$/license=\"$license\"/mg
|
|
|
|
or die "Can't find license line in APKBUILD";
|
|
|
|
}
|
|
|
|
$text =~ s/^depends=\"([^\"]*)\"$/depends=\"$deps\"/mg
|
|
|
|
or $text =~ s/(license=.*\n)/$1depends=\"$deps\"/gm
|
2023-12-19 01:55:40 +00:00
|
|
|
or die "Can't insert depends line in APKBUILD" if defined $deps;
|
2023-07-03 21:52:43 +00:00
|
|
|
|
|
|
|
$text =~ s/^makedepends=\"([^\"]*)\"$/makedepends=\"$makedeps\"/mg
|
|
|
|
or $text =~ s/(depends=.*\n)/$1makedepends=\"$makedeps\"/gm
|
2023-12-19 01:55:40 +00:00
|
|
|
or die "Can't insert makedepends line in APKBUILD" if defined $makedeps;
|
2020-07-06 01:54:22 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
$text =~ s/^checkdepends=\"([^\"]*)\"$/checkdepends=\"$checkdeps\"/mg
|
|
|
|
or $text =~ s/(makedepends=.*\n)/$1checkdepends=\"$checkdeps\"/gm
|
2023-12-19 01:55:40 +00:00
|
|
|
or die "Can't insert checkdepends line in APKBUILD" if defined $checkdeps;
|
2020-07-06 01:54:22 +00:00
|
|
|
|
2023-12-20 05:00:39 +00:00
|
|
|
if (defined $builddir) {
|
|
|
|
print "\n\$builddir redefined:\n\tOLD: '", $apkbuild->{builddir},
|
|
|
|
"', NEW: '", $builddir, "'\n";
|
|
|
|
|
|
|
|
$text =~ s/^builddir=\"([^\"]*)\"/builddir="$builddir"/mg;
|
|
|
|
}
|
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
# remove empty variables
|
2023-12-22 17:54:34 +00:00
|
|
|
$text =~ s/.*="".{0,}\n//g;
|
2017-01-31 08:20:14 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
open my $fh, '>', "APKBUILD" or die;
|
|
|
|
print $fh $text;
|
|
|
|
close $fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_data {
|
|
|
|
my $apkbuild = read_apkbuild;
|
|
|
|
my $pkgreal = '';
|
2020-07-06 01:54:22 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
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;
|
2020-07-06 01:54:22 +00:00
|
|
|
}
|
2023-07-03 21:52:43 +00:00
|
|
|
|
|
|
|
# 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 /;
|
2020-12-22 23:23:50 +00:00
|
|
|
}
|
2020-07-06 01:54:22 +00:00
|
|
|
}
|
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
# Want to try the traditional Module::Name first
|
|
|
|
my $list = $module . $distribution;
|
|
|
|
foreach ( split / /, $list ) {
|
|
|
|
my $type = '';
|
|
|
|
if ( $_ =~ m/::/ ) {
|
|
|
|
$type = 'module';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$type = 'release';
|
|
|
|
}
|
2011-06-02 08:55:00 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
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";
|
|
|
|
my $distdata = $json->decode( $response->decoded_content );
|
|
|
|
$distdata->{error}
|
|
|
|
and die "Error trying to locate $pkgreal: $distdata->{error}\n";
|
|
|
|
|
|
|
|
$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};
|
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
my $user_abuild_conf =
|
|
|
|
read_assignments_from_file( $ENV{"HOME"} . "/.abuild/abuild.conf" );
|
2017-01-31 08:20:14 +00:00
|
|
|
$packager = $user_abuild_conf->{PACKAGER} if $user_abuild_conf->{PACKAGER};
|
|
|
|
|
2023-07-03 21:49:52 +00:00
|
|
|
my $command = $ARGV[0];
|
2011-06-02 08:55:00 +00:00
|
|
|
|
2023-07-03 21:52:43 +00:00
|
|
|
if ( $command eq "create" ) {
|
|
|
|
my $module = $ARGV[1];
|
|
|
|
$module or die "Module name is a mandatory argument";
|
|
|
|
|
|
|
|
my $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";
|
|
|
|
|
|
|
|
$response =
|
|
|
|
$ua->get("https://fastapi.metacpan.org/release/$moddata->{distribution}");
|
|
|
|
$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";
|
|
|
|
|
|
|
|
my $apkname = map_cpan_to_apk $distdata->{metadata}{name};
|
|
|
|
mkdir $apkname;
|
|
|
|
chdir $apkname;
|
|
|
|
write_apkbuild( $distdata, undef, $moddata );
|
|
|
|
prepare_tree;
|
|
|
|
update_functions;
|
|
|
|
do_depends $moddata->{version};
|
|
|
|
}
|
|
|
|
elsif ( $command eq "recreate" ) {
|
|
|
|
|
|
|
|
#TODO: likely should keep pkgrel the same on recreate
|
|
|
|
my ( $apkbuild, $distdata, $moddata ) = get_data;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
write_apkbuild( $distdata, $apkbuild, $moddata );
|
|
|
|
prepare_tree;
|
|
|
|
update_functions;
|
|
|
|
do_depends( $moddata->{version}, $apkbuild );
|
|
|
|
}
|
|
|
|
elsif ( $command eq "upgrade" ) {
|
|
|
|
my ( $apkbuild, $distdata, $moddata ) = get_data;
|
|
|
|
|
|
|
|
my $pkgver = $moddata->{version} =~ s/^[^0-9]+//r;
|
|
|
|
if ( $pkgver ne $apkbuild->{pkgver} ) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
#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;
|
|
|
|
open my $fh, '>', "APKBUILD" or die;
|
|
|
|
say $fh $text;
|
|
|
|
close $fh;
|
|
|
|
prepare_tree;
|
|
|
|
do_depends( $moddata->{version}, $apkbuild );
|
|
|
|
}
|
|
|
|
else {
|
2023-07-07 20:48:12 +00:00
|
|
|
say "Up-to-date with CPAN";
|
2023-07-03 21:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ( $command eq "check" ) {
|
|
|
|
my ( $apkbuild, $distdata, $moddata ) = get_data;
|
|
|
|
my $pkgver = $moddata->{version} =~ s/^[^0-9]+//r;
|
|
|
|
say
|
|
|
|
"$apkbuild->{pkgname}: Latest version: $pkgver Packaged version: $apkbuild->{pkgver}";
|
|
|
|
if ( $pkgver ne $apkbuild->{pkgver} ) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ( $command eq "update" ) {
|
|
|
|
prepare_tree;
|
|
|
|
do_depends;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
say
|
|
|
|
"Usage: apkbuild-cpan [create <Module::Name> | check | recreate | update | upgrade]";
|
|
|
|
exit;
|
2011-06-02 08:55:00 +00:00
|
|
|
}
|