-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathMultibuild.pm
More file actions
97 lines (87 loc) · 2.63 KB
/
Multibuild.pm
File metadata and controls
97 lines (87 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
################################################################
#
# Copyright (c) 2021 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
package PBuild::Multibuild;
use strict;
use PBuild::Structured;
use PBuild::Verify;
my $dtd_multibuild = [
'multibuild' =>
'buildemptyflavor',
[ 'package' ], # obsolete
[ 'flavor' ],
];
sub find_mbname {
my ($files) = @_;
my $mbname = '_multibuild';
# support service generated multibuild files, see findfile
if ($files->{'_service'}) {
for (sort keys %$files) {
next unless /^_service:.*:(.*?)$/s;
$mbname = $_ if $1 eq '_multibuild';
}
}
return $mbname;
}
sub readmbxml {
my ($xmlfile) = @_;
my $mb = PBuild::Structured::readxml($xmlfile, $dtd_multibuild);
PBuild::Verify::verify_multibuild($mb);
return $mb;
}
sub getmultibuild_fromfiles {
my ($srcdir, $files) = @_;
my $mbname = find_mbname($files);
my $mb;
if ($files->{$mbname}) {
eval { $mb = readmbxml("$srcdir/$mbname") };
if ($@) {
warn("$srcdir/$mbname: $@");
return undef;
}
$mb->{'_md5'} = $files->{$mbname} if $mb;
}
return $mb;
}
sub expand_multibuilds {
my ($pkgs) = @_;
for my $pkg (sort keys %$pkgs) {
my $p = $pkgs->{$pkg};
my $mb = getmultibuild_fromfiles($p->{'dir'}, $p->{'files'});
next unless $mb;
my @mbp = @{$mb->{'flavor'} || $mb->{'package'} || []};
my $buildemptyflavor = !defined($mb->{'buildemptyflavor'}) || $mb->{'buildemptyflavor'} eq 'true' ? 1 : 0;
for my $flavor (@mbp) {
my $mpkg = "$pkg:$flavor";
$pkgs->{$mpkg} = { %$p, 'pkg' => $mpkg, 'flavor' => $flavor, 'originpackage' => $pkg };
}
delete $pkgs->{$pkg} if @mbp && !$buildemptyflavor;
}
}
sub count_multibuilds {
my ($pkgs) = @_;
my $c = 0;
for (values %$pkgs) {
my $files = $_->{'files'} || {};
next unless $files->{'_multibuild'} || ($files->{'_service'} && $files->{find_mbname($files)});
$c++;
}
return $c;
}
1;