Skip to content

Commit a9fe939

Browse files
committed
pbuild: add support for apk building
1 parent 914c082 commit a9fe939

10 files changed

+39
-13
lines changed

PBuild/AssetMgr.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ sub find_assets {
143143
push @assets, @{$p->{'source_assets'} || []};
144144
push @assets, PBuild::RemoteAssets::fedpkg_parse($p) if $p->{'files'}->{'sources'};
145145
push @assets, PBuild::RemoteAssets::golang_parse($p) if $p->{'files'}->{'go.sum'};
146-
push @assets, PBuild::RemoteAssets::recipe_parse($p) if $bt eq 'spec' || $bt eq 'kiwi' || $bt eq 'arch' || $bt eq 'docker';
146+
push @assets, PBuild::RemoteAssets::recipe_parse($p) if $bt eq 'spec' || $bt eq 'kiwi' || $bt eq 'arch' || $bt eq 'apk' || $bt eq 'docker';
147147
merge_assets($assetmgr, $p, \@assets);
148148
update_srcmd5($assetmgr, $p) if $p->{'asset_files'};
149149
}

PBuild/BuildResult.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use PBuild::Verify;
3030
use PBuild::Container;
3131
use PBuild::Mkosi;
3232

33-
my @binsufs = qw{rpm deb pkg.tar.gz pkg.tar.xz pkg.tar.zst};
33+
my @binsufs = qw{rpm deb pkg.tar.gz pkg.tar.xz pkg.tar.zst apk};
3434
my $binsufsre = join('|', map {"\Q$_\E"} @binsufs);
3535

3636
#

PBuild/Job.pm

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ sub collect_result {
126126
push @d, 'SDEBS';
127127
}
128128
@d = ('ARCHPKGS') if $p->{'recipe'} =~ /PKGBUILD$/;
129+
@d = ('APKS') if $p->{'recipe'} =~ /APKBUILD$/;
129130
@d = ('KIWI') if $p->{'recipe'} =~ /\.kiwi$/;
130131
@d = ('DOCKER') if $p->{'recipe'} =~ /Dockerfile(\.|$)/;
131132
@d = ('FISSILE') if $p->{'recipe'} =~ /fissile\.yml$/;

PBuild/LocalRepo.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use PBuild::Util;
2727
use PBuild::BuildResult;
2828
use PBuild::ExportFilter;
2929

30-
my @binsufs = qw{rpm deb pkg.tar.gz pkg.tar.xz pkg.tar.zst};
30+
my @binsufs = qw{rpm deb pkg.tar.gz pkg.tar.xz pkg.tar.zst apk};
3131
my $binsufsre = join('|', map {"\Q$_\E"} @binsufs);
3232
my $binsufsre_binlnk = join('|', map {"\Q$_\E"} (@binsufs, 'obsbinlnk'));
3333

PBuild/OBS.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use PBuild::SigAuth;
3333

3434
my $cookie_jar;
3535

36-
my @binsufs = qw{rpm deb pkg.tar.gz pkg.tar.xz pkg.tar.zst};
36+
my @binsufs = qw{rpm deb pkg.tar.gz pkg.tar.xz pkg.tar.zst apk};
3737
my $binsufsre = join('|', map {"\Q$_\E"} @binsufs);
3838

3939
my @dtd_disableenable = (

PBuild/Recipe.pm

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ sub find_recipe {
4343
return $files{'Chart.yaml'} if $type eq 'helm' && $files{'Chart.yaml'};
4444
return (grep {/flatpak\.(?:ya?ml|json)$/} sort keys %files)[0] if $type eq 'flatpak';
4545
return $files{'PKGBUILD'} ? $files{'PKGBUILD'} : undef if $type eq 'arch';
46+
return $files{'APKBUILD'} ? $files{'APKBUILD'} : undef if $type eq 'apk';
4647
my $pkg = $p->{'pkg'};
4748
$pkg = $p->{'flavor'} if $p->{'flavor'};
4849
return $files{"Dockerfile.$pkg"} if $type eq 'docker' && $files{"Dockerfile.$pkg"};
@@ -218,6 +219,7 @@ sub looks_like_packagedir {
218219
return 1 if $file eq 'snapcraft.yaml' || $file eq 'appimage.yml';
219220
return 1 if $file eq 'Dockerfile' || $file eq 'fissile.yml' || $file eq 'Chart.yml';
220221
return 1 if $file eq 'PKGBUILD';
222+
return 1 if $file eq 'APKBUILD';
221223
}
222224
return 0;
223225
}

PBuild/RemoteAssets.pm

+9-5
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ sub recipe_parse {
6666
my @assets;
6767
for my $s (@{$p->{'remoteassets'} || []}) {
6868
my $url = $s->{'url'};
69+
my $file = $s->{'file'};
6970
if ($url && $url =~ /^git(?:\+https?)?:.*\/([^\/]+?)(?:.git)?(?:\#[^\#\/]+)?$/) {
70-
my $file = $1;
71+
$file = $1 unless defined $file;
72+
next unless $file =~ /^([^\.\/][^\/]+)$/s;
7173
next if $p->{'files'}->{$file};
7274
push @assets, { 'file' => $file, 'url' => $url, 'type' => 'url', 'isdir' => 1 };
7375
next;
7476
}
75-
my $file = $s->{'file'};
7677
if (($s->{'type'} || '' eq 'webcache')) {
7778
next unless $s->{'url'};
7879
$file = 'build-webcache-'.Digest::SHA::sha256_hex($s->{'url'});
@@ -336,9 +337,12 @@ sub url_fetch {
336337
my $assetid = $asset->{'assetid'};
337338
my $adir = "$assetdir/".substr($assetid, 0, 2);
338339
PBuild::Util::mkdir_p($adir);
339-
if (Build::Download::download($asset->{'url'}, "$adir/.$assetid.$$", undef, 'retry' => 3, 'digest' => $asset->{'digest'}, 'missingok' => 1)) {
340-
rename_unless_present("$adir/.$assetid.$$", "$adir/$assetid");
341-
}
340+
eval {
341+
if (Build::Download::download($asset->{'url'}, "$adir/.$assetid.$$", undef, 'retry' => 3, 'digest' => $asset->{'digest'}, 'missingok' => 1)) {
342+
rename_unless_present("$adir/.$assetid.$$", "$adir/$assetid");
343+
}
344+
};
345+
warn($@) if $@;
342346
}
343347
}
344348
}

PBuild/RemoteRepo.pm

+19-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use Digest::MD5 ();
2929
use Build;
3030
use Build::Rpmmd;
3131
use Build::Archrepo;
32+
use Build::Apkrepo;
3233
use Build::Debrepo;
3334
use Build::Deb;
3435
use Build::Susetags;
@@ -41,7 +42,7 @@ use PBuild::Verify;
4142
use PBuild::OBS;
4243
use PBuild::Cando;
4344

44-
my @binsufs = qw{rpm deb pkg.tar.gz pkg.tar.xz pkg.tar.zst};
45+
my @binsufs = qw{rpm deb pkg.tar.gz pkg.tar.xz pkg.tar.zst apk};
4546
my $binsufsre = join('|', map {"\Q$_\E"} @binsufs);
4647

4748
sub open_uncompressed {
@@ -100,6 +101,15 @@ sub fetchrepo_arch {
100101
return \@bins;
101102
}
102103

104+
sub fetchrepo_apk {
105+
my ($url, $tmpdir, %opts) = @_;
106+
$url .= '/' unless $url =~ /\/$/;
107+
download("${url}APKINDEX.tar.gz", "$tmpdir/APKINDEX.tar.gz");
108+
my @bins;
109+
Build::Apkrepo::parse("$tmpdir/APKINDEX.tar.gz", sub { addpkg(\@bins, $_[0], $url) }, 'addselfprovides' => 1, 'normalizedeps' => 1);
110+
return \@bins;
111+
}
112+
103113
sub fetchrepo_debian {
104114
my ($url, $tmpdir, %opts) = @_;
105115
my ($baseurl, $disturl, $components) = Build::Debrepo::parserepourl($url);
@@ -236,7 +246,8 @@ sub calc_binname {
236246
my $binname = $bin->{'version'};
237247
$binname = "$bin->{'epoch'}:$binname" if $bin->{'epoch'};
238248
$binname .= "-$bin->{'release'}" if defined $bin->{'release'};
239-
$binname .= ".$bin->{'arch'}" if $bin->{'arch'};
249+
# for apk the arch entry in the repo metadata does not match the binary
250+
$binname .= ".$bin->{'arch'}" if $bin->{'arch'} && $suf ne 'apk';
240251
$binname = "$bin->{'name'}-$binname.$suf";
241252
$binname = "$bin->{'hdrmd5'}-$binname" if $binname =~ s/^container:// && $bin->{'hdrmd5'};
242253
return $binname;
@@ -328,10 +339,11 @@ sub guess_repotype {
328339
my ($bconf, $buildtype) = @_;
329340
return undef unless $bconf;
330341
for (@{$bconf->{'repotype'} || []}) {
331-
return $_ if $_ eq 'arch' || $_ eq 'debian' || $_ eq 'hdlist2' || $_ eq 'rpm-md';
342+
return $_ if $_ eq 'arch' || $_ eq 'debian' || $_ eq 'hdlist2' || $_ eq 'rpm-md' || $_ eq 'apk';
332343
}
333344
return 'arch' if ($bconf->{'binarytype'} || '') eq 'arch';
334345
return 'debian' if ($bconf->{'binarytype'} || '') eq 'deb';
346+
return 'apk' if ($bconf->{'binarytype'} || '') eq 'apk';
335347
$buildtype ||= $bconf->{'type'};
336348
return 'rpm-md' if ($buildtype || '') eq 'spec';
337349
return 'debian' if ($buildtype || '') eq 'dsc';
@@ -348,7 +360,7 @@ sub fetchrepo {
348360
$repotype = 'zypp' if $url =~ /^zypp:/;
349361
$repotype = 'obs' if $url =~ /^obs:/;
350362
my $archfilter;
351-
if ($url =~ /^(arch|debian|hdlist2|rpmmd|rpm-md|suse)(?:\+archfilter=([^\@\/]+))?\@(.*)$/) {
363+
if ($url =~ /^(arch|debian|hdlist2|rpmmd|rpm-md|suse|apk)(?:\+archfilter=([^\@\/]+))?\@(.*)$/) {
352364
$repotype = $1;
353365
$archfilter = [ split(',', $2) ] if $2;
354366
$url = $3;
@@ -388,6 +400,8 @@ sub fetchrepo {
388400
$repo = fetchrepo_debian($url, $tmpdir, %opts);
389401
} elsif ($repotype eq 'arch') {
390402
$repo = fetchrepo_arch($url, $tmpdir, %opts);
403+
} elsif ($repotype eq 'apk') {
404+
$repo = fetchrepo_apk($url, $tmpdir, %opts);
391405
} elsif ($repotype eq 'suse') {
392406
$repo = fetchrepo_susetags($url, $tmpdir, %opts);
393407
} elsif ($repotype eq 'zypp') {
@@ -468,6 +482,7 @@ sub fetchbinaries_replace {
468482
my ($repodir, $tmpname, $binname, $bin) = @_;
469483
Build::Download::checkfiledigest("$repodir/$tmpname", $bin->{'checksum'}) if $bin->{'checksum'};
470484
my $q = querybinary($repodir, $tmpname);
485+
$bin->{'arch'} = $q->{'arch'} if $binname =~ /\.apk$/; # see comment in calc_binname
471486
die("downloaded binary $binname does not match repository metadata\n") unless is_matching_binary($bin, $q);
472487
rename("$repodir/$tmpname", "$repodir/$binname") || die("rename $repodir/$tmpname $repodir/$binname\n");
473488
$q->{'filename'} = $binname;

PBuild/Repoquery.pm

+2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ sub repoquery {
211211
print "$nevra\n";
212212
print " repo: $from\n";
213213
print " excluded: $excluded\n" if $excluded;
214+
#print " location: $bin->{'location'}\n" if $bin->{'location'};
215+
#print " checksum: $bin->{'checksum'}\n" if $bin->{'checksum'};
214216
my @modules;
215217
@modules = PBuild::Modules::getmodules($moduledata, $bin) if $moduledata;
216218
if (@modules) {

PBuild/Source.pm

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ sub list_package {
132132
next if -d _ || $file =~ /^\./;
133133
@s = stat("$dir/$file");
134134
next unless @s && -f _; # follow links to files
135+
$files{$file} = gendigest("$dir/$file");
136+
next;
135137
}
136138
}
137139
if (-l _) {

0 commit comments

Comments
 (0)