summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xapkbuild-cpan.in103
1 files changed, 95 insertions, 8 deletions
diff --git a/apkbuild-cpan.in b/apkbuild-cpan.in
index c538d34..6a7ff52 100755
--- a/apkbuild-cpan.in
+++ b/apkbuild-cpan.in
@@ -22,6 +22,7 @@ my $license_mappings = {
my $package_mappings = {
"LWP" => "perl-libwww",
"TermReadKey" => "perl-term-readkey",
+ "perl-ldap" => "perl-ldap",
};
our $packager = "";
my $template = <<'EOF';
@@ -79,6 +80,8 @@ sub read_assignments_from_file {
my $authors = join("\n", $text =~ /^# Contributor: .*$/mg, $text =~ /^# Maintainer: .*$/mg);
$hash{'authors'} = $authors if length($authors) > 1;
+ my $tmplver = $text =~ m/^# Automatically generated by apkbuild-cpan, template (.*)/;
+ $hash{'tmplver'} = $1 if length($tmplver) >= 1;
return \%hash;
}
@@ -226,7 +229,31 @@ EOF
sub do_depends {
my $apkbuild = read_apkbuild;
- my $metaprefix = "src/" . $apkbuild->{'_pkgreal'} . "-" . $apkbuild->{'pkgver'} . "/";
+ my $metaprefix = '';
+ if ( exists $apkbuild->{'_realname'} ) {
+ $metaprefix = "src/" . $apkbuild->{'_realname'} . "-" . $apkbuild->{'pkgver'} . "/";
+ }
+ elsif ( exists $apkbuild->{'_pkgreal'} ) {
+ $metaprefix = "src/" . $apkbuild->{'_pkgreal'} . "-" . $apkbuild->{'pkgver'} . "/";
+ }
+ elsif ( exists $apkbuild->{'_pkgname'} ) {
+ $metaprefix = "src/" . $apkbuild->{'_pkgname'} . "-" . $apkbuild->{'pkgver'} . "/";
+ }
+ elsif ( exists $apkbuild->{'_name'} ) {
+ $metaprefix = "src/" . $apkbuild->{'_name'} . "-" . $apkbuild->{'pkgver'} . "/";
+ }
+ elsif ( exists $apkbuild->{'_realpkgname'} ) {
+ $metaprefix = "src/" . $apkbuild->{'_realpkgname'} . "-" . $apkbuild->{'pkgver'} . "/";
+ }
+ elsif ( exists $apkbuild->{'_pkg_real'} ) {
+ $metaprefix = "src/" . $apkbuild->{'_pkg_real'} . "-" . $apkbuild->{'pkgver'} . "/";
+ }
+ else {
+ die "Unable to find meta file directory - check APKBUILD Perl Module Name";
+ }
+
+ $metaprefix =~ s/-\$pkgver//g;
+
my $meta;
foreach my $metafile ("MYMETA.json", "META.json", "MYMETA.yml", "META.yml") {
@@ -288,11 +315,71 @@ sub do_depends {
sub get_data {
my $apkbuild = read_apkbuild;
- $apkbuild->{_pkgreal} or die "Not apkbuild-cpan generated APKBUILD";
- my $response = $ua->get("https://fastapi.metacpan.org/release/$apkbuild->{_pkgreal}");
- $response->is_success or die $response->status_line;
+ 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";
my $distdata = $json->decode($response->decoded_content);
- $distdata->{error} and die "Error trying to locate $apkbuild->{_pkgreal}: $distdata->{error}\n";
+ $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;
@@ -311,10 +398,9 @@ $packager = $user_abuild_conf->{PACKAGER} if $user_abuild_conf->{PACKAGER};
given ( $ARGV[0] ) {
when ("create") {
my $module = $ARGV[1];
- my $response;
$module or die "Module name is a mandatory argument";
- $response = $ua->get("https://fastapi.metacpan.org/module/$module");
+ 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";
@@ -333,6 +419,7 @@ given ( $ARGV[0] ) {
do_depends;
}
when ("recreate") {
+ #TODO: likely should keep pkgrel the same on recreate
my ($apkbuild, $distdata, $moddata) = get_data;
write_apkbuild($distdata, $apkbuild->{authors}, $moddata);
prepare_tree;
@@ -343,7 +430,7 @@ given ( $ARGV[0] ) {
my ($apkbuild, $distdata, $moddata) = get_data;
my $pkgver = $moddata->{version} =~ s/^[^0-9]+//r;
- if ($pkgver != $apkbuild->{pkgver}) {
+ if ($pkgver ne $apkbuild->{pkgver}) {
say "Upgrading CPAN module from $apkbuild->{pkgver} to $pkgver";
my $text = read_file "APKBUILD";