Skip to content

Commit

Permalink
Refactor apk package query
Browse files Browse the repository at this point in the history
And also fix the handling of install_if.
  • Loading branch information
mlschroe committed Jan 9, 2025
1 parent 5ce9ed4 commit 1b1b5f4
Showing 1 changed file with 41 additions and 26 deletions.
67 changes: 41 additions & 26 deletions Build/Apk.pm
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,35 @@ sub parse {
return $ret;
}
my %pkginfo_array = (
'depend' => 1,
'replaces' => 1,
'provides' => 1,
);
sub queryvars {
my ($handle, $withhdrmd5) = @_;
my $tar = Archive::Tar->new;
my @read = $tar->read($handle, 1, {'filter' => '^\.PKGINFO$', 'limit' => 1});
die("$handle: not an apk package file\n") unless @read == 1;
my $pkginfo = $read[0]->get_content;
die("$handle: not an apk package file\n") unless defined $pkginfo;
my @lines = split("\n", $pkginfo);
my %q;
while (@lines) {
my $l = shift @lines;
next if $l eq '' || substr($l, 0, 1) eq '#';
next unless $l =~ /^(.+?) = (.*)$/;
if ($pkginfo_array{$1}) {
push @{$q{$1}}, $2;
} else {
$q{$1} = $2;
}
}
$q{'hdrmd5'} = Digest::MD5::md5_hex($pkginfo) if $withhdrmd5;
$q{'install_if'} = [ split(' ', $q{'install_if'}) ] if $q{'install_if'};
return \%q;
}
my %pkginfomap = (
'pkgname' => 'name',
Expand All @@ -433,54 +462,40 @@ my %pkginfomap = (
'arch' => 'arch',
'license' => 'license',
'origin' => 'source',
'depend' => [ 'requires' ],
# 'replaces' => [ 'obsoletes' ],
'provides' => [ 'provides' ],
'install_if' => [ 'install_if' ],
'depend' => 'requires',
# 'replaces' => 'obsoletes',
'provides' => 'provides',
'datahash' => 'apkdatachksum',
'hdrmd5' => 'hdrmd5',
);
sub query {
my ($handle, %opts) = @_;
my $tar = Archive::Tar->new;
my @read = $tar->read($handle, 1, {'filter' => '^\.PKGINFO$', 'limit' => 1});
die("$handle: not an apk package file\n") unless @read == 1;
my $pkginfo = $read[0]->get_content;
die("$handle: not an apk package file\n") unless defined $pkginfo;
my @lines = split("\n", $pkginfo);
my $qq = queryvars($handle, 1);
my %q;
while (@lines) {
my $l = shift @lines;
next if $l eq '' || substr($l, 0, 1) eq '#';
next unless $l =~ /^(.+?) = (.*)$/;
my $m = $pkginfomap{$1};
if (ref($m)) {
push @{$q{$m->[0]}}, $2;
} elsif ($m) {
$q{$m} = $2;
}
for (keys %$qq) {
my $m = $pkginfomap{$_};
$q{$m} = $qq->{$_} if $m;
}
my @conflicts = grep {/^\!/} @{$q{'requires'} || []};
if (@conflicts) {
substr($_, 0, 1, '') for @conflicts;
$q{'conflicts'} = \@conflicts;
$q{'requires'} = [ grep {!/^\!/} @{$q{'requires'} || []} ];
delete $q{'requires'} unless @{$q{'requires'}};
}
if ($q{'name'} && $opts{'addselfprovides'}) {
my $selfprovides = $q{'name'};
$selfprovides .= "=$q{'version'}" if defined $q{'version'};
push @{$q{'provides'}}, $selfprovides unless @{$q{'provides'} || []} && $q{'provides'}->[-1] eq $selfprovides;
}
if ($opts{'normalizedeps'}) {
s/^([a-zA-Z0-9\._+-]+)~/$1=~/ for @{$q{'requires'} || []}, @{$q{'conflicts'} || []};
s/^([a-zA-Z0-9\._+-]+)~/$1=~/ for @{$q{'requires'} || []}, @{$q{'conflicts'} || []}, @{$qq->{'install_if'} || []};
}
$q{'version'} = 0 unless defined $q{'version'};
$q{'release'} = $1 if $q{'version'} =~ s/-([^-]*)$//;
$q{'hdrmd5'} = Digest::MD5::md5_hex($pkginfo);
$q{'source'} ||= $q{'name'} if defined $q{'name'};
my $install_if = delete $q{'install_if'};
$q{'supplements'} = [ join(' & ', @$install_if) ] if @{$install_if || []} && $opts{'weakdeps'};
delete $q{'supplements'} unless $opts{'weakdeps'};
$q{'supplements'} = [ join(' & ', @{$qq->{'install_if'}}) ] if $opts{'weakdeps'} && $qq->{'install_if'};
delete $q{'buildtime'} unless $opts{'buildtime'};
delete $q{'apkdatachksum'} unless $opts{'apkdatachksum'};
return \%q;
Expand Down Expand Up @@ -600,7 +615,7 @@ sub calcapkchksum {
$status = $z->inflate($input, $output);
}
if ($type eq 'raw') {
$ctx .= substr($oldinput, 0, length($oldinput) - length($input));
$ctx .= substr($oldinput, 0, length($oldinput) - length($input)) if $sec == $section;
} else {
$ctx->add(substr($oldinput, 0, length($oldinput) - length($input))) if $sec == $section;
}
Expand Down

0 comments on commit 1b1b5f4

Please sign in to comment.