From 726e37920c581c5d78b301d3e56efef91bea6096 Mon Sep 17 00:00:00 2001 From: Timothy Legge Date: Tue, 30 Jan 2024 23:05:45 -0400 Subject: [PATCH] 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 --- apkbuild-cpan.in | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/apkbuild-cpan.in b/apkbuild-cpan.in index 899f4b3..d34faac 100755 --- a/apkbuild-cpan.in +++ b/apkbuild-cpan.in @@ -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++; }