apkbuild-cpan.in: fix read_assignments_from_file

remove unnecessary regex in functions

Return early if not processing an APKBUILD file

and fix undefined variable of there are no patches
This commit is contained in:
Timothy Legge 2024-01-30 23:05:45 -04:00
parent 1c017bb5d5
commit 726e37920c

View File

@ -96,25 +96,23 @@ sub read_assignments_from_file {
my %mline = $text =~ /^(\w+)\s*=\s*\"([^\"]*)\"$/mg;
my %hash = ( %sline, %mline );
return \%hash if $filename ne 'APKBUILD';
my $authors = join( "\n",
$text =~ /^# Contributor: .*$/mg,
$text =~ /^# Maintainer: .*$/mg );
$hash{'authors'} = $authors if length($authors) > 1;
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;
my $options = $text =~ m/^options=\"(.*)\"(.*)$/mg;
$hash{'options'} = "$1" if length($options) >= 1;
$hash{'options_comment'} = "$2" if length($options) >= 1;
if ($text =~ m/^source=\"([^\"]*)\"/mg) {
my @patches = split (/\n/m, $1);
if ($hash{source} ne '') {
$hash{source} =~ s/^\n//g;
my @patches = split (/\n/m, $hash{source});
shift @patches;
$hash{'patches'} = \@patches;
} else {
warn "Unexpected: unable to find 'source' in APKBUILD!!!";
}
return \%hash;
@ -155,7 +153,7 @@ sub write_apkbuild {
$pkgrel = $apkbuild->{pkgrel};
$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}};
$patches = "\n" . join ("\n", @{$apkbuild->{patches}}) if defined $apkbuild->{patches} and scalar @{$apkbuild->{patches}};
if ( $apkbuild->{pkgver} eq $moddata->{version} ) {
$pkgrel++;
}