Skip to content

Commit d180eb3

Browse files
committed
Build::Archsrcinfo: use .SRCINFO as a choice of build recipe for Arch
Introduce the capability to use `.SRCINFO` files as alternative build recipe for Arch Linux packages. Using static `.SRCINFO` files is a faster and more reliable method for extracting package metadata (like dependencies, version, and source URLs).
1 parent 8519fd3 commit d180eb3

File tree

6 files changed

+156
-3
lines changed

6 files changed

+156
-3
lines changed

Build.pm

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ our $do_rpm;
3535
our $do_deb;
3636
our $do_kiwi;
3737
our $do_arch;
38+
our $do_archsrcinfo;
3839
our $do_collax;
3940
our $do_livebuild;
4041
our $do_snapcraft;
@@ -52,6 +53,7 @@ sub import {
5253
$do_rpm = 1 if $_ eq ':rpm';
5354
$do_deb = 1 if $_ eq ':deb';
5455
$do_kiwi = 1 if $_ eq ':kiwi';
56+
$do_archsrcinfo = 1 if $_ eq ':archsrcinfo';
5557
$do_arch = 1 if $_ eq ':arch';
5658
$do_collax = 1 if $_ eq ':collax';
5759
$do_livebuild = 1 if $_ eq ':livebuild';
@@ -65,14 +67,17 @@ sub import {
6567
$do_productcompose = 1 if $_ eq ':productcompose';
6668
$do_apk = 1 if $_ eq ':apk';
6769
}
68-
$do_rpm = $do_deb = $do_kiwi = $do_productcompose = $do_arch = $do_collax = $do_livebuild = $do_snapcraft = $do_appimage = $do_docker = $do_fissile = $do_helm = $do_flatpak = $do_mkosi = $do_apk = 1 if !$do_rpm && !$do_deb && !$do_kiwi && !$do_arch && !$do_collax && !$do_livebuild && !$do_snapcraft && !$do_appimage && !$do_docker && !$do_fissile && !$do_helm && !$do_flatpak && !$do_mkosi && !$do_productcompose && !$do_apk;
70+
$do_rpm = $do_deb = $do_kiwi = $do_productcompose = $do_arch = $do_archsrcinfo = $do_collax = $do_livebuild = $do_snapcraft = $do_appimage = $do_docker = $do_fissile = $do_helm = $do_flatpak = $do_mkosi = $do_apk = 1 if !$do_rpm && !$do_deb && !$do_kiwi && !$do_arch && !$do_collax && !$do_livebuild && !$do_snapcraft && !$do_appimage && !$do_docker && !$do_fissile && !$do_helm && !$do_flatpak && !$do_mkosi && !$do_productcompose && !$do_apk;
6971

7072
if ($do_deb) {
7173
require Build::Deb;
7274
}
7375
if ($do_kiwi) {
7476
require Build::Kiwi;
7577
}
78+
if ($do_archsrcinfo) {
79+
require Build::Archsrcinfo;
80+
}
7681
if ($do_arch) {
7782
require Build::Arch;
7883
}
@@ -562,6 +567,7 @@ sub read_config {
562567
if (!$config->{'binarytype'}) {
563568
$config->{'binarytype'} = 'rpm' if $config->{'type'} eq 'spec';
564569
$config->{'binarytype'} = 'deb' if $config->{'type'} eq 'dsc' || $config->{'type'} eq 'collax' || $config->{'type'} eq 'livebuild';
570+
$config->{'binarytype'} = 'arch' if $config->{'type'} eq 'archsrcinfo';
565571
$config->{'binarytype'} = 'arch' if $config->{'type'} eq 'arch';
566572
$config->{'binarytype'} = 'apk' if $config->{'type'} eq 'apk';
567573
if (grep {$_ eq $config->{'type'}} qw{snapcraft appimage docker fissile kiwi mkosi}){
@@ -1261,6 +1267,7 @@ sub recipe2buildtype {
12611267
return $1 if $recipe =~ /\.(spec|dsc|kiwi|productcompose|livebuild)$/;
12621268
$recipe =~ s/.*\///;
12631269
$recipe =~ s/^_service:.*://;
1270+
return 'archsrcinfo' if $recipe eq 'SRCINFO';
12641271
return 'arch' if $recipe eq 'PKGBUILD';
12651272
return 'apk' if $recipe eq 'APKBUILD';
12661273
return 'collax' if $recipe eq 'build.collax';
@@ -1334,6 +1341,7 @@ sub parse_typed {
13341341
return Build::Docker::parse($cf, $fn, @args) if $do_docker && $buildtype eq 'docker';
13351342
return Build::Fissile::parse($cf, $fn, @args) if $do_fissile && $buildtype eq 'fissile';
13361343
return parse_simpleimage($cf, $fn, @args) if $buildtype eq 'simpleimage';
1344+
return Build::Archsrcinfo::parse($cf, $fn, @args) if $do_archsrcinfo && $buildtype eq 'archsrcinfo';
13371345
return Build::Arch::parse($cf, $fn, @args) if $do_arch && $buildtype eq 'arch';
13381346
return Build::Apk::parse($cf, $fn, @args) if $do_apk && $buildtype eq 'apk';
13391347
return Build::Collax::parse($cf, $fn, @args) if $do_collax && $buildtype eq 'collax';
@@ -1356,6 +1364,8 @@ sub query {
13561364
return Build::Kiwi::queryiso($handle, %opts) if $do_kiwi && $binname =~ /\.iso$/;
13571365
return Build::Arch::query($handle, %opts) if $do_arch && $binname =~ /\.pkg\.tar(?:\.gz|\.xz|\.zst)?$/;
13581366
return Build::Arch::query($handle, %opts) if $do_arch && $binname =~ /\.arch$/;
1367+
return Build::Arch::query($handle, %opts) if $do_archsrcinfo && $binname =~ /\.pkg\.tar(?:\.gz|\.xz|\.zst)?$/;
1368+
return Build::Arch::query($handle, %opts) if $do_archsrcinfo && $binname =~ /\.arch$/;
13591369
return Build::Apk::query($handle, %opts) if $do_arch && $binname =~ /\.apk$/;
13601370
return undef;
13611371
}
@@ -1387,6 +1397,8 @@ sub queryhdrmd5 {
13871397
return Build::Kiwi::queryhdrmd5(@_) if $do_kiwi && $binname =~ /\.raw.install$/;
13881398
return Build::Arch::queryhdrmd5(@_) if $do_arch && $binname =~ /\.pkg\.tar(?:\.gz|\.xz|\.zst)?$/;
13891399
return Build::Arch::queryhdrmd5(@_) if $do_arch && $binname =~ /\.arch$/;
1400+
return Build::Arch::queryhdrmd5(@_) if $do_archsrcinfo && $binname =~ /\.pkg\.tar(?:\.gz|\.xz|\.zst)?$/;
1401+
return Build::Arch::queryhdrmd5(@_) if $do_archsrcinfo && $binname =~ /\.arch$/;
13901402
return Build::Apk::queryhdrmd5(@_) if $do_apk && $binname =~ /\.apk$/;
13911403
return undef;
13921404
}

Build/Archsrcinfo.pm

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
################################################################
2+
#
3+
# Copyright (c) 1995-2014 SUSE Linux Products GmbH
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License version 2 or 3 as
7+
# published by the Free Software Foundation.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program (see the file COPYING); if not, write to the
16+
# Free Software Foundation, Inc.,
17+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18+
#
19+
################################################################
20+
21+
package Build::Archsrcinfo;
22+
23+
use strict;
24+
use warnings;
25+
26+
sub _get_srcinfo_assets {
27+
my ($vars, $asuf) = @_;
28+
29+
my @sources = @{ $vars->{"source$asuf"} || [] };
30+
return () unless @sources;
31+
32+
my @digests;
33+
for my $digest_type ('sha512', 'sha384', 'sha256', 'sha224', 'sha1', 'md5') {
34+
my $sums_key = "${digest_type}sums$asuf";
35+
if (exists $vars->{$sums_key} && @{$vars->{$sums_key}}) {
36+
@digests = map { $_ eq 'SKIP' ? $_ : "$digest_type:$_" } @{ $vars->{$sums_key} };
37+
last;
38+
}
39+
}
40+
41+
my @assets;
42+
for my $i (0 .. $#sources) {
43+
my $source_entry = $sources[$i];
44+
45+
# parse filename::URL formats
46+
my $url = $source_entry;
47+
if ($source_entry =~ /::/) {
48+
($url) = (split /::/, $source_entry, 2)[1];
49+
}
50+
51+
# parse http/https/ftp protocols only
52+
next unless $url =~ /^(https?|ftp):\/\//;
53+
54+
my $asset = { 'url' => $url };
55+
my $digest = $digests[$i];
56+
57+
if ($digest && $digest ne 'SKIP') {
58+
$asset->{'digest'} = $digest;
59+
}
60+
61+
push @assets, $asset;
62+
}
63+
64+
return @assets;
65+
}
66+
67+
sub parse {
68+
my ($config, $srcinfo_file) = @_;
69+
70+
my $ret = {};
71+
my $fh;
72+
unless (open($fh, '<', $srcinfo_file)) {
73+
$ret->{'error'} = "$srcinfo_file: $!";
74+
return $ret;
75+
}
76+
77+
my %vars;
78+
while (my $line = <$fh>) {
79+
chomp $line;
80+
# newline / comment
81+
next if $line =~ /^\s*(#.*)?$/;
82+
83+
if ($line =~ /^\s*([^=\s]+)\s*=\s*(.*)\s*$/) {
84+
my ($key, $value) = ($1, $2);
85+
push @{ $vars{$key} }, $value;
86+
}
87+
}
88+
close $fh;
89+
90+
$ret->{'name'} = $vars{'pkgname'}->[0] if exists $vars{'pkgname'};
91+
if (exists $vars{'pkgver'} && exists $vars{'pkgrel'}) {
92+
$ret->{'version'} = $vars{'pkgver'}->[0] . '-' . $vars{'pkgrel'}->[0];
93+
} elsif (exists $vars{'pkgver'}) {
94+
$ret->{'version'} = $vars{'pkgver'}->[0];
95+
}
96+
97+
$ret->{'deps'} = [];
98+
my @dep_types = qw(depends makedepends checkdepends);
99+
foreach my $dep_type (@dep_types) {
100+
push @{ $ret->{'deps'} }, @{ $vars{$dep_type} || [] };
101+
}
102+
103+
# i*86
104+
my ($arch) = Build::gettargetarchos($config);
105+
$arch = 'i686' if $arch =~ /^i[345]86$/;
106+
foreach my $dep_type (@dep_types) {
107+
my $arch_dep_key = "${dep_type}_$arch";
108+
push @{ $ret->{'deps'} }, @{ $vars{$arch_dep_key} || [] };
109+
}
110+
111+
# extract remote assets
112+
$ret->{'remoteassets'} = [];
113+
for my $asuf ('', "_$arch") {
114+
my @assets = _get_srcinfo_assets(\%vars, $asuf);
115+
push @{ $ret->{'remoteassets'} }, @assets if @assets;
116+
}
117+
118+
if (exists $vars{'arch'} && !grep { $_ eq 'any' } @{ $vars{'arch'} }) {
119+
my %supported_arches = map { $_ => 1 } @{ $vars{'arch'} };
120+
121+
if (exists $supported_arches{'i686'}) {
122+
$supported_arches{'i386'} = $supported_arches{'i486'} = $supported_arches{'i586'} = 1;
123+
}
124+
125+
$ret->{'exclarch'} = [ sort keys %supported_arches ];
126+
}
127+
128+
return $ret;
129+
}
130+
131+
132+
1;

Build/Repo.pm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use strict;
2525
our $do_rpmmd;
2626
our $do_deb;
2727
our $do_arch;
28+
our $do_archsrcinfo;
2829
our $do_susetags;
2930
our $do_mdk;
3031
our $do_apk;
@@ -33,12 +34,13 @@ sub import {
3334
for (@_) {
3435
$do_rpmmd = 1 if $_ eq ':rpmmd';
3536
$do_deb = 1 if $_ eq ':deb';
37+
$do_archsrcinfo = 1 if $_ eq ':archsrcinfo';
3638
$do_arch = 1 if $_ eq ':arch';
3739
$do_susetags = 1 if $_ eq ':susetags';
3840
$do_mdk = 1 if $_ eq ':mdk';
3941
$do_apk = 1 if $_ eq ':apk';
4042
}
41-
$do_rpmmd = $do_deb = $do_arch = $do_susetags = $do_mdk = $do_apk = 1 unless $do_rpmmd || $do_deb || $do_arch || $do_susetags || $do_mdk || $do_apk;
43+
$do_rpmmd = $do_deb = $do_arch = $do_archsrcinfo = $do_susetags = $do_mdk = $do_apk = 1 unless $do_rpmmd || $do_deb || $do_arch || $do_susetags || $do_mdk || $do_apk;
4244
if ($do_rpmmd) {
4345
require Build::Rpmmd;
4446
}
@@ -51,6 +53,9 @@ sub import {
5153
if ($do_arch) {
5254
require Build::Archrepo;
5355
}
56+
if ($do_archsrcinfo) {
57+
require Build::Archrepo;
58+
}
5459
if ($do_mdk) {
5560
require Build::Mdkrepo;
5661
}
@@ -64,6 +69,7 @@ sub parse {
6469
return Build::Rpmmd::parse(@args) if $do_rpmmd && $type eq 'rpmmd';
6570
return Build::Susetags::parse(@args) if $do_susetags && $type eq 'susetags';
6671
return Build::Debrepo::parse(@args) if $do_deb && $type eq 'deb';
72+
return Build::Archrepo::parse(@args) if $do_archsrcinfo && $type eq 'archsrcinfo';
6773
return Build::Archrepo::parse(@args) if $do_arch && $type eq 'arch';
6874
return Build::Mdkrepo::parse(@args) if $do_arch && $type eq 'mdk';
6975
return Build::Apkrepo::parse(@args) if $do_apk && $type eq 'apk';

PBuild/Job.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ sub collect_result {
125125
@d = map {"DEBS/$_"} sort(PBuild::Util::ls("$buildroot/.build.packages/DEBS")); # assume debbuild
126126
push @d, 'SDEBS';
127127
}
128+
@d = ('ARCHPKGS') if $p->{'recipe'} =~ /SRCINFO$/;
128129
@d = ('ARCHPKGS') if $p->{'recipe'} =~ /PKGBUILD$/;
129130
@d = ('APKS') if $p->{'recipe'} =~ /APKBUILD$/;
130131
@d = ('KIWI') if $p->{'recipe'} =~ /\.kiwi$/;

PBuild/Recipe.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ sub find_recipe {
4242
return $files{'fissile.yml'} if $type eq 'fissile' && $files{'fissile.yml'};
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';
45+
return $files{'SRCINFO'} if $type eq 'archsrcinfo' && $files{'SRCINFO'};
4546
return $files{'PKGBUILD'} if $type eq 'arch' && $files{'PKGBUILD'};
4647
return $files{'APKBUILD'} if $type eq 'apk' && $files{'APKBUILD'};
4748
my $pkg = $p->{'pkg'};
@@ -218,6 +219,7 @@ sub looks_like_packagedir {
218219
return 1 if $file =~ /^(?:Dockerfile|mkosi)\./;
219220
return 1 if $file eq 'snapcraft.yaml' || $file eq 'appimage.yml';
220221
return 1 if $file eq 'Dockerfile' || $file eq 'fissile.yml' || $file eq 'Chart.yml';
222+
return 1 if $file eq 'SRCINFO';
221223
return 1 if $file eq 'PKGBUILD';
222224
return 1 if $file eq 'APKBUILD';
223225
}

build-recipe

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ recipe_set_buildtype() {
123123
*.dsc) BUILDTYPE=dsc ;;
124124
*.kiwi) BUILDTYPE=kiwi ;;
125125
*.productcompose) BUILDTYPE=productcompose ;;
126+
SRCINFO) BUILDTYPE=arch ;;
126127
PKGBUILD) BUILDTYPE=arch ;;
127128
APKBUILD) BUILDTYPE=apk ;;
128129
snapcraft.yaml) BUILDTYPE=snapcraft ;;
@@ -343,4 +344,3 @@ recipe_gendiff() {
343344
fi
344345
fi
345346
}
346-

0 commit comments

Comments
 (0)