-
Notifications
You must be signed in to change notification settings - Fork 187
/
Build.pm
1422 lines (1352 loc) · 46.7 KB
/
Build.pm
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
################################################################
#
# Copyright (c) 1995-2014 SUSE Linux Products GmbH
#
# 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 Build;
use strict;
use Digest::MD5;
use Build::Rpm;
use Build::Intrepo;
use Build::Expand;
use POSIX qw(strftime);
#use Data::Dumper;
our $expand_dbg;
*expand_dbg = *Build::Expand::expand_dbg;
our $do_rpm;
our $do_deb;
our $do_kiwi;
our $do_arch;
our $do_collax;
our $do_livebuild;
our $do_snapcraft;
our $do_appimage;
our $do_docker;
our $do_fissile;
our $do_helm;
our $do_flatpak;
our $do_mkosi;
our $do_productcompose;
our $do_apk;
sub import {
for (@_) {
$do_rpm = 1 if $_ eq ':rpm';
$do_deb = 1 if $_ eq ':deb';
$do_kiwi = 1 if $_ eq ':kiwi';
$do_arch = 1 if $_ eq ':arch';
$do_collax = 1 if $_ eq ':collax';
$do_livebuild = 1 if $_ eq ':livebuild';
$do_snapcraft = 1 if $_ eq ':snapcraft';
$do_appimage = 1 if $_ eq ':appimage';
$do_docker = 1 if $_ eq ':docker';
$do_fissile = 1 if $_ eq ':fissile';
$do_helm = 1 if $_ eq ':helm';
$do_flatpak = 1 if $_ eq ':flatpak';
$do_mkosi = 1 if $_ eq ':mkosi';
$do_productcompose = 1 if $_ eq ':productcompose';
$do_apk = 1 if $_ eq ':apk';
}
$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;
if ($do_deb) {
require Build::Deb;
}
if ($do_kiwi) {
require Build::Kiwi;
}
if ($do_arch) {
require Build::Arch;
}
if ($do_collax) {
require Build::Collax;
}
if ($do_livebuild) {
require Build::LiveBuild;
}
if ($do_snapcraft) {
require Build::Snapcraft;
}
if ($do_appimage) {
require Build::Appimage;
}
if ($do_docker) {
require Build::Docker;
}
if ($do_fissile) {
require Build::Fissile;
}
if ($do_helm) {
require Build::Helm;
}
if ($do_flatpak) {
require Build::Flatpak;
}
if ($do_mkosi) {
require Build::Mkosi;
}
if ($do_productcompose) {
require Build::ProductCompose;
}
if ($do_apk) {
require Build::Apk;
}
}
package Build::Features;
our $preinstallimage = 1; # on sale now
package Build;
# this is synced with rpm 4.17.0. The additional architectures of arm behind the spaces are
# from MeeGo project. They don't exist elsewhere, but don't conflict either luckily
my $std_macros = q{
%define nil
%define ix86 i386 i486 i586 i686 pentium3 pentium4 athlon geode
%define arm32 armv3l armv4b armv4l armv4tl armv5tl armv5tel armv5tejl armv6l armv6hl armv7l armv7hl armv7hnl armv8l armv8hl armv8hnl armv8hcnl
%define arm %{arm32}
%define arml armv3l armv4l armv5l armv5tel armv6l armv6hl armv7l armv7hl armv7hnl
%define armb armv4b armv5b armv5teb
%define arm64 aarch64
%define mips32 mips mipsel mipsr6 mipsr6el
%define mips64 mips64 mips64el mips64r6 mips64r6el
%define mipseb mips mipsr6 mips64 mips64r6
%define mipsel mipsel mipsr6el mips64el mips64r6el
%define mips %{mips32} %{mips64}
%define loongarch64 loongarch64
%define sparc sparc sparcv8 sparcv9 sparcv9v sparc64 sparc64v
%define alpha alpha alphaev56 alphaev6 alphaev67
%define power64 ppc64 ppc64p7 ppc64le
%define riscv32 riscv32
%define riscv64 riscv64
%define riscv128 riscv128
%define riscv %{riscv32} %{riscv64} %{riscv128}
};
my %subst_defaults = (
# defaults live-build package dependencies base on 4.0~a26 gathered with:
# grep Check_package -r /usr/lib/live/build
'build-packages:livebuild' => [
'apt-utils', 'dctrl-tools', 'debconf', 'dosfstools', 'e2fsprogs', 'grub',
'librsvg2-bin', 'live-boot', 'live-config', 'mtd-tools', 'parted',
'squashfs-tools', 'syslinux', 'syslinux-common', 'wget', 'xorriso', 'zsync',
],
'build-packages:helm' => [
'helm',
],
'build-packages:flatpak' => [
'flatpak', 'flatpak-builder', 'fuse', 'unzip', 'gzip', 'xz', 'elfutils',
'gdk-pixbuf-loader-rsvg', 'perl(YAML::LibYAML)',
],
'system-packages:livebuild' => [
'apt-utils', 'cpio', 'dpkg-dev', 'live-build', 'lsb-release', 'tar',
],
'build-packages:mkosi:rpm' => [
'btrfs-progs | btrfsprogs', 'dracut', 'e2fsprogs', 'systemd',
'systemd-networkd | systemd-network', 'systemd-udev | udev', 'xfsprogs',
],
'build-packages:mkosi:deb' => [
'apt', 'btrfs-progs', 'ca-certificates', 'dracut', 'e2fsprogs', 'file',
'libpam-systemd', 'mawk', 'systemd', 'systemd-boot', 'systemd-resolved',
'systemd-sysv', 'tar', 'xfsprogs',
],
'build-packages:mkosi:arch' => [
'base', 'btrfs-progs', 'cryptsetup', 'device-mapper', 'dracut', 'e2fsprogs',
'linux', 'systemd', 'xfsprogs',
],
'system-packages:mkosi:rpm' => [
'mkosi', 'binutils', 'btrfs-progs | btrfsprogs', 'cpio', 'createrepo',
'cryptsetup', 'dnf', 'dosfstools', 'e2fsprogs', 'integritysetup', 'gnupg',
'python3dist(cryptography)', 'squashfs-tools | squashfs',
'system-release | openSUSE-release', 'systemd-container', 'util-linux',
'veritysetup', 'tar', 'xz', 'xfsprogs', 'zstd', 'zypper',
],
'system-packages:mkosi:deb' => [
'mkosi', 'apt', 'btrfs-progs', 'cpio', 'cryptsetup-bin', 'dctrl-tools',
'debootstrap', 'debconf', 'dosfstools', 'dpkg-dev', 'e2fsprogs', 'fdisk',
'gnupg', 'linux-base', 'lsb-release', 'python3-cryptography',
'squashfs-tools', 'systemd-container', 'tar', 'xz-utils', 'xfsprogs',
'zstd',
],
'system-packages:mkosi:arch' => [
'mkosi', 'arch-install-scripts', 'binutils', 'btrfs-progs', 'cpio',
'cryptsetup', 'dosfstools', 'e2fsprogs', 'gnupg', 'gzip',
'python-cryptography', 'squashfs-tools', 'systemd', 'util-linux', 'tar',
'xfsprogs', 'xz', 'zstd',
],
'system-packages:mock' => [
'mock', 'system-packages:repo-creation',
],
'system-packages:debootstrap' => [
'debootstrap', 'lsb-release',
],
'system-packages:kiwi-image' => [
'kiwi', 'tar', 'system-packages:repo-creation',
],
'system-packages:kiwi-product' => [
'kiwi',
],
'system-packages:productcompose' => [
'product-composer',
],
'system-packages:docker' => [
'docker', 'system-packages:repo-creation',
],
'system-packages:podman' => [
'podman', 'buildah', 'system-packages:repo-creation',
],
'system-packages:fissile' => [
'docker', # TODO: Add fissile here as soon as it is packaged
],
'system-packages:deltarpm' => [
'deltarpm',
],
'system-packages:repo-creation:rpm' => [
'createrepo',
],
'system-packages:repo-creation:deb' => [
'dpkg-dev',
],
'system-packages:repo-creation:arch' => [
'pacman',
],
);
sub unify {
my %h = map {$_ => 1} @_;
return grep(delete($h{$_}), @_);
}
sub init_helper_hashes {
my ($config) = @_;
$config->{'preferh'} = { map {$_ => 1} @{$config->{'prefer'}} };
my %ignore;
for (@{$config->{'ignore'}}) {
if (!/:/) {
$ignore{$_} = 1;
next;
}
my @s = split(/[,:]/, $_);
my $s = shift @s;
$ignore{"$s:$_"} = 1 for @s;
}
$config->{'ignoreh'} = \%ignore;
my %conflicts;
for (@{$config->{'conflict'}}) {
my @s = split(/[,:]/, $_);
my $s = shift @s;
push @{$conflicts{':'}}, $s if $s && !@s;
push @{$conflicts{$s}}, @s if @s;
push @{$conflicts{$_}}, $s for @s;
}
for (keys %conflicts) {
$conflicts{$_} = [ unify(@{$conflicts{$_}}) ]
}
$config->{'conflicth'} = \%conflicts;
}
# 'canonicalize' dist string as found in rpm dist tags
sub dist_canon($$) {
my ($rpmdist, $arch) = @_;
$rpmdist = lc($rpmdist);
$rpmdist =~ s/-/_/g;
$rpmdist =~ s/opensuse/suse linux/;
my $rpmdista;
if ($rpmdist =~ /\(/) {
$rpmdista = $rpmdist;
$rpmdista =~ s/.*\(//;
$rpmdista =~ s/\).*//;
} else {
$rpmdista = $arch;
}
$rpmdista =~ s/i[456]86/i386/;
$rpmdist = '' unless $rpmdista =~ /^(i386|x86_64|ia64|ppc|ppc64|ppc64le|s390|s390x)$/;
my $dist = 'default';
if ($rpmdist =~ /unitedlinux 1\.0.*/) {
$dist = "ul1-$rpmdista";
} elsif ($rpmdist =~ /suse sles_(\d+)/) {
$dist = "sles$1-$rpmdista";
} elsif ($rpmdist =~ /suse linux enterprise (\d+)/) {
$dist = "sles$1-$rpmdista";
} elsif ($rpmdist =~ /suse linux (\d+)\.(\d+)\.[4-9]\d/) {
# alpha version
$dist = "$1.".($2 + 1)."-$rpmdista";
} elsif ($rpmdist =~ /suse linux (?:leap )?(\d+\.\d+)/) {
$dist = "$1-$rpmdista";
}
return $dist;
}
# combine multiple config files into a single config
sub combine_configs {
my (@c) = @_;
my $config = '';
my $macros = '';
for my $c (@c) {
$c =~ s/\n?$/\n/s if $c ne '';
if ($c =~ /^\s*:macros\s*$/im) {
# probably multiple macro sections with %if statements
# flush out macros
$config .= "\nMacros:\n$macros:Macros\n\n" if $macros ne '';
$macros = '';
my $s1 = '\A(.*^\s*:macros\s*$)(.*?)\z'; # should always match
if ($c =~ /$s1/msi) {
$config .= $1;
$c = $2;
} else {
$config .= $c;
$c = '';
}
}
if ($c =~ /^(.*\n)?\s*macros:[^\n]*\n(.*)/si) {
# has single macro section at end. cumulate
$c = defined($1) ? $1 : '';
$macros .= $2;
}
$config .= $c;
}
$config .= "\nMacros:\n$macros" if $macros ne '';
return $config;
}
sub find_config_file {
my ($dist, $configdir) = @_;
die("Please specify a distribution!\n") unless defined $dist;
if ($dist !~ /\//) {
my $saved = $dist;
$configdir = '.' unless defined $configdir;
$dist =~ s/-.*//;
$dist = "sl$dist" if $dist =~ /^\d/;
$dist = "$configdir/$dist.conf";
if (! -e $dist) {
$dist =~ s/-.*//;
$dist = "sl$dist" if $dist =~ /^\d/;
$dist = "$configdir/$dist.conf";
}
if (! -e $dist) {
warn "$saved.conf not found, using default.conf\n" unless $saved eq 'default';
$dist = "$configdir/default.conf";
}
}
die("$dist: $!\n") unless -e $dist;
return $dist;
}
sub slurp_config_file {
my ($file, $seen) = @_;
local *CONF;
die("$file: $!\n") unless open(CONF, '<', $file);
my @config = <CONF>;
close CONF;
chomp @config;
if (@config && $config[0] =~ /^#!PrependConfigFile:\s*([^\.\/][^\/]*?)\s*$/) {
my $otherfile = $1;
if (!$seen) {
$seen = {};
$seen->{$1} = 1 if $file =~ /([^\/]*)$/;
}
if (!$seen->{$otherfile}++) {
$file =~ s/[^\/]*$/$otherfile/;
my $otherconfig = slurp_config_file($file, $seen) || [];
return [ split("\n", combine_configs(join("\n", @$otherconfig), join("\n", @config))) ];
}
}
return \@config;
}
sub read_config_dist {
my ($dist, $archpath, $configdir) = @_;
$dist = find_config_file($dist, $configdir);
my $arch = $archpath;
$arch = 'noarch' unless defined $arch;
$arch =~ s/:.*//;
$arch = 'noarch' if $arch eq '';
my $cfile = slurp_config_file($dist);
my $cf = read_config($arch, $cfile);
die("$dist: parse error\n") unless $cf;
return $cf;
}
sub read_config {
my ($arch, $cfile) = @_;
my @macros = split("\n", $std_macros);
push @macros, "%define _target_cpu $arch";
push @macros, "%define _target_os linux";
my $config = {'macros' => \@macros, 'arch' => $arch};
my @config;
if (ref($cfile)) {
@config = @$cfile;
} elsif (defined($cfile)) {
local *CONF;
return undef unless open(CONF, '<', $cfile);
@config = <CONF>;
close CONF;
chomp @config;
}
# create verbatim macro blobs
my @newconfig;
while (@config) {
push @newconfig, shift @config;
next unless $newconfig[-1] =~ /^\s*macros:\s*$/si;
$newconfig[-1] = "macros:\n";
while (@config) {
my $l = shift @config;
last if $l =~ /^\s*:macros\s*$/si;
$newconfig[-1] .= "$l\n";
}
$newconfig[-1] = [ $newconfig[-1] ]; # verbatim quote, see Rpm.pm
}
my @spec;
$config->{'save_expanded'} = 1;
$config->{'parsing_config'} = 1;
Build::Rpm::parse($config, \@newconfig, \@spec);
delete $config->{'save_expanded'};
delete $config->{'parsing_config'};
$config->{'preinstall'} = [];
$config->{'vminstall'} = [];
$config->{'runscripts'} = [];
$config->{'required'} = [];
$config->{'support'} = [];
$config->{'keep'} = [];
$config->{'prefer'} = [];
$config->{'ignore'} = [];
$config->{'conflict'} = [];
$config->{'alsonative'} = [];
$config->{'onlynative'} = [];
$config->{'substitute'} = {};
$config->{'substitute_vers'} = {};
$config->{'optflags'} = {};
$config->{'order'} = {};
$config->{'exportfilter'} = {};
$config->{'publishfilter'} = [];
$config->{'rawmacros'} = '';
$config->{'release'} = '<CI_CNT>.<B_CNT>';
$config->{'repotype'} = [];
$config->{'patterntype'} = [];
$config->{'fileprovides'} = {};
$config->{'constraint'} = [];
$config->{'expandflags'} = [];
$config->{'buildflags'} = [];
$config->{'publishflags'} = [];
$config->{'singleexport'} = '';
$config->{'repourl'} = [];
$config->{'registryurl'} = [];
$config->{'assetsurl'} = [];
for my $l (@spec) {
$l = $l->[1] if ref $l;
next unless defined $l;
my @l = split(' ', $l);
next unless @l;
my $ll = shift @l;
my $l0 = lc($ll);
if ($l0 eq 'macros:') {
$l =~ s/.*?\n//s;
if ($l =~ /^!\n/s) {
$config->{'rawmacros'} = substr($l, 2);
} else {
$config->{'rawmacros'} .= $l;
}
next;
}
if ($l0 eq 'distmacro:') {
@l = split(' ', $l, 2);
push @macros, "%define $l[1]" if @l == 2;
next;
}
if ($l0 eq 'preinstall:' || $l0 eq 'vminstall:' || $l0 eq 'required:' || $l0 eq 'support:' || $l0 eq 'keep:' || $l0 eq 'prefer:' || $l0 eq 'ignore:' || $l0 eq 'conflict:' || $l0 eq 'runscripts:' || $l0 eq 'expandflags:' || $l0 eq 'buildflags:' || $l0 eq 'publishflags:' || $l0 eq 'repourl:' || $l0 eq 'registryurl:' || $l0 eq 'assetsurl:' || $l0 eq 'onlynative:' || $l0 eq 'alsonative:') {
my $t = substr($l0, 0, -1);
for my $l (@l) {
if ($l eq '!*') {
$config->{$t} = [];
} elsif ($l =~ /^!/) {
$config->{$t} = [ grep {"!$_" ne $l} @{$config->{$t}} ];
} else {
push @{$config->{$t}}, $l;
}
}
} elsif ($l0 eq 'substitute:') {
next unless @l;
$ll = shift @l;
if ($ll eq '!*') {
$config->{'substitute'} = {};
} elsif ($ll =~ /^!(.*)$/) {
delete $config->{'substitute'}->{$1};
} else {
$config->{'substitute'}->{$ll} = [ @l ];
}
} elsif ($l0 eq 'fileprovides:') {
next unless @l;
$ll = shift @l;
if ($ll eq '!*') {
$config->{'fileprovides'} = {};
} elsif ($ll =~ /^!(.*)$/) {
delete $config->{'fileprovides'}->{$1};
} else {
$config->{'fileprovides'}->{$ll} = [ @l ];
}
} elsif ($l0 eq 'exportfilter:') {
next unless @l;
$ll = shift @l;
$config->{'exportfilter'}->{$ll} = [ @l ];
} elsif ($l0 eq 'publishfilter:') {
$config->{'publishfilter'} = [ @l ];
} elsif ($l0 eq 'optflags:') {
next unless @l;
$ll = shift @l;
$config->{'optflags'}->{$ll} = join(' ', @l);
} elsif ($l0 eq 'order:') {
for my $l (@l) {
if ($l eq '!*') {
$config->{'order'} = {};
} elsif ($l =~ /^!(.*)$/) {
delete $config->{'order'}->{$1};
} else {
$config->{'order'}->{$l} = 1;
}
}
} elsif ($l0 eq 'repotype:') { # type of generated repository data
$config->{'repotype'} = [ @l ];
} elsif ($l0 eq 'type:') { # kind of recipe system (spec,dsc,arch,kiwi,...)
$config->{'type'} = $l[0];
} elsif ($l0 eq 'buildengine:') { # build engine (build,mock)
$config->{'buildengine'} = $l[0];
} elsif ($l0 eq 'binarytype:') { # kind of binary packages (rpm,deb,arch,...)
$config->{'binarytype'} = $l[0];
} elsif ($l0 eq 'patterntype:') { # kind of generated patterns in repository
$config->{'patterntype'} = [ @l ];
} elsif ($l0 eq 'release:') {
$config->{'release'} = $l[0];
$config->{'release@'} = [ @l ];
} elsif ($l0 eq 'cicntstart:') {
$config->{'cicntstart'} = $l[0];
} elsif ($l0 eq 'releaseprg:') {
$config->{'releaseprg'} = $l[0];
} elsif ($l0 eq 'releasesuffix:') {
$config->{'releasesuffix'} = join(' ', @l);
} elsif ($l0 eq 'changetarget:' || $l0 eq 'target:') {
$config->{'target'} = join(' ', @l);
push @macros, "%define _target_cpu ".(split('-', $config->{'target'}))[0] if $config->{'target'};
} elsif ($l0 eq 'hostarch:') {
$config->{'hostarch'} = join(' ', @l);
} elsif ($l0 eq 'constraint:') {
my $l = join(' ', @l);
if ($l eq '!*') {
$config->{'constraint'} = [];
} else {
push @{$config->{'constraint'}}, $l;
}
} elsif ($l0 eq 'singleexport:') {
$config->{'singleexport'} = $l[0]; # avoid to export multiple package container in maintenance_release projects
} elsif ($l0 !~ /^[#%]/) {
warn("unknown keyword in config: $l0\n");
}
}
for my $l (qw{preinstall vminstall required support keep runscripts repotype patterntype}) {
$config->{$l} = [ unify(@{$config->{$l}}) ];
}
init_helper_hashes($config);
# calculate type and binarytype
if (!$config->{'type'}) {
# Fallback to old guessing method if no type (spec, dsc or kiwi) is defined
if (grep {$_ eq 'rpm'} @{$config->{'preinstall'} || []}) {
$config->{'type'} = 'spec';
} elsif (grep {$_ eq 'debianutils'} @{$config->{'preinstall'} || []}) {
$config->{'type'} = 'dsc';
} elsif (grep {$_ eq 'pacman'} @{$config->{'preinstall'} || []}) {
$config->{'type'} = 'arch';
} elsif (grep {$_ eq 'apk-tools'} @{$config->{'preinstall'} || []}) {
$config->{'type'} = 'apk';
}
$config->{'type'} ||= 'UNDEFINED';
}
if (!$config->{'binarytype'}) {
$config->{'binarytype'} = 'rpm' if $config->{'type'} eq 'spec';
$config->{'binarytype'} = 'deb' if $config->{'type'} eq 'dsc' || $config->{'type'} eq 'collax' || $config->{'type'} eq 'livebuild';
$config->{'binarytype'} = 'arch' if $config->{'type'} eq 'arch';
$config->{'binarytype'} = 'apk' if $config->{'type'} eq 'apk';
if (grep {$_ eq $config->{'type'}} qw{snapcraft appimage docker fissile kiwi mkosi}){
if (grep {$_ eq 'rpm'} @{$config->{'preinstall'} || []}) {
$config->{'binarytype'} = 'rpm';
} elsif (grep {$_ eq 'debianutils'} @{$config->{'preinstall'} || []}) {
$config->{'binarytype'} = 'deb';
} elsif (grep {$_ eq 'pacman'} @{$config->{'preinstall'} || []}) {
$config->{'binarytype'} = 'arch';
}
}
$config->{'binarytype'} ||= 'UNDEFINED';
}
# add default substitutes
if (!$config->{'substitute'}->{'system-packages:repo-creation'}) {
$config->{'substitute'}->{'system-packages:repo-creation'} = $subst_defaults{"system-packages:repo-creation:$config->{'binarytype'}"} if $subst_defaults{"system-packages:repo-creation:$config->{'binarytype'}"};
}
# create substitute_vers hash from substitute entries
for my $l (keys %{$config->{'substitute'}}) {
$config->{'substitute_vers'}->{$l} = [ map {/^(.*?)(=)?$/g} unify(@{$config->{'substitute'}->{$l}}) ];
$config->{'substitute'}->{$l} = [ unify(@{$config->{'substitute'}->{$l}}) ];
s/=$// for @{$config->{'substitute'}->{$l}};
}
# add rawmacros to our macro list
Build::Rpm::add_macros($config, $config->{'rawmacros'}) if $config->{'rawmacros'} ne '';
# extract some helper hashes for the flags
my %modules;
for (@{$config->{'expandflags'} || []}) {
if (/^([^:]+):(.*)$/s) {
$config->{"expandflags:$1"} = $2;
$modules{$2} = 1 if $1 eq 'module';
} else {
$config->{"expandflags:$_"} = 1;
}
}
for (@{$config->{'buildflags'} || []}) {
if (/^([^:]+):(.*)$/s) {
$config->{"buildflags:$1"} = $2;
} else {
$config->{"buildflags:$_"} = 1;
}
}
for (@{$config->{'publishflags'} || []}) {
if (/^([^:]+):(.*)$/s) {
$config->{"publishflags:$1"} = $2;
} else {
$config->{"publishflags:$_"} = 1;
}
}
$config->{'modules'} = [ sort keys %modules ] if %modules;
return $config;
}
sub add_distmacro {
my ($config, $name_value) = @_;
push @{$config->{'macros'}}, "%define $name_value\n";
}
sub gettargetarchos {
my ($config) = @_;
my ($arch, $os);
for (@{$config->{'macros'} || []}) {
$arch = $1 if /^%define _target_cpu (\S+)/;
$os = $1 if /^%define _target_os (\S+)/;
}
return ($arch, $os);
}
sub do_subst {
my ($config, @deps) = @_;
my @res;
my %done;
my $subst = $config->{'substitute'};
while (@deps) {
my $d = shift @deps;
next if $done{$d};
my $ds = $d;
$ds =~ s/\s*[<=>].*$//s;
if ($subst->{$ds}) {
unshift @deps, @{$subst->{$ds}};
push @res, $d if grep {$_ eq $ds} @{$subst->{$ds}};
} else {
push @res, $d;
}
$done{$d} = 1;
}
return @res;
}
sub do_subst_vers {
my ($config, @deps) = @_;
my @res;
my %done;
my $subst = $config->{'substitute_vers'};
while (@deps) {
my ($d, $dv) = splice(@deps, 0, 2);
next if $done{$d};
if ($subst->{$d}) {
unshift @deps, map {defined($_) && $_ eq '=' ? $dv : $_} @{$subst->{$d}};
push @res, $d, $dv if grep {defined($_) && $_ eq $d} @{$subst->{$d}};
} else {
push @res, $d, $dv;
}
$done{$d} = 1;
}
return @res;
}
# expand the preinstalls/vminstalls
sub expandpreinstalls {
my ($config) = @_;
return if !$config->{'expandflags:preinstallexpand'} || $config->{'preinstallisexpanded'};
my (@pre, @vm);
if (@{$config->{'preinstall'} || []}) {
my $c = $config;
@pre = expand($c, @{$config->{'preinstall'} || []});
return "preinstalls: $pre[0]" unless shift @pre;
@pre = sort(@pre);
}
if ($config->{'no_vminstall_expand'}) {
@vm = ('expandpreinstalls_error');
} elsif (@{$config->{'vminstall'} || []}) {
my %pre = map {$_ => 1} @pre;
my %vmx = map {+"-$_" => 1} @{$config->{'vminstall'} || []};
my @pren = grep {/^-/ && !$vmx{$_}} @{$config->{'preinstall'} || []};
my $c = $config;
@vm = expand($c, @pre, @pren, @{$config->{'vminstall'} || []});
return "vminstalls: $vm[0]" unless shift @vm;
@vm = sort(grep {!$pre{$_}} @vm);
}
$config->{'preinstall'} = \@pre;
$config->{'vminstall'} = \@vm;
#print STDERR "pre: @pre\n";
#print STDERR "vm: @vm\n";
$config->{'preinstallisexpanded'} = 1;
return '';
}
# Delivers all packages which get used for building
sub get_build {
my ($config, $subpacks, @deps) = @_;
if ($config->{'expandflags:preinstallexpand'} && !$config->{'preinstallisexpanded'}) {
my $err = expandpreinstalls($config);
return (undef, $err) if $err;
}
my $buildtype = $config->{'type'} || '';
my $nobasepackages;
if ($buildtype eq 'mkosi') {
my $binarytype = $config->{'binarytype'} || '';
push @deps, @{$config->{'substitute'}->{"build-packages:$buildtype:$binarytype"} || $subst_defaults{"build-packages:$buildtype:$binarytype"} || []};
} else {
push @deps, @{$config->{'substitute'}->{"build-packages:$buildtype"} || $subst_defaults{"build-packages:$buildtype"} || []};
}
$nobasepackages = 1 if $buildtype eq 'docker';
if ($buildtype eq 'kiwi') {
$nobasepackages = 1 if $config->{"expandflags:kiwi-nobasepackages"};
@deps = grep {!/^kiwi-image:/} @deps; # only needed for sysdeps
@deps = grep {!/^kiwi-packagemanager:/} @deps if $nobasepackages; # only needed for sysdeps
}
my @ndeps = grep {/^-/} @deps;
my %ndeps = map {$_ => 1} @ndeps;
my @directdepsend;
if ($ndeps{'--directdepsend--'}) {
@directdepsend = @deps;
for (splice @deps) {
last if $_ eq '--directdepsend--';
push @deps, $_;
}
@directdepsend = grep {!/^-/} splice(@directdepsend, @deps + 1);
}
my @extra = (@{$config->{'required'}}, @{$config->{'support'}});
if (@{$config->{'keep'} || []}) {
my %keep = map {$_ => 1} (@deps, @{$config->{'keep'} || []}, @{$config->{'preinstall'}});
for (@{$subpacks || []}) {
next if $keep{$_};
push @ndeps, "-$_";
$ndeps{"-$_"} = 1;
}
} else {
# new "empty keep" mode, filter subpacks from required/support
my %subpacks = map {$_ => 1} @{$subpacks || []};
@extra = grep {!$subpacks{$_}} @extra;
}
@deps = grep {!$ndeps{$_}} @deps;
if (!$nobasepackages) {
push @deps, @{$config->{'preinstall'}}, @extra;
@deps = grep {!$ndeps{"-$_"}} @deps;
}
@deps = do_subst($config, @deps);
@deps = grep {!$ndeps{"-$_"}} @deps;
if (@directdepsend) {
@directdepsend = do_subst($config, @directdepsend);
@directdepsend = grep {!$ndeps{"-$_"}} @directdepsend;
unshift @directdepsend, '--directdepsend--' if @directdepsend;
}
@deps = expand($config, @deps, @ndeps, @directdepsend);
return @deps;
}
# Delivers all packages which get used for the cross building sysroot
sub get_sysroot {
my ($config, $subpacks, @deps) = @_;
my @extractnative;
(@extractnative) = splice(@deps, 0, 2) if @deps > 1 && $deps[0] eq '--extractnative--' && ref($deps[1]);
my @ndeps = grep {/^-/} @deps;
my %ndeps = map {$_ => 1} @ndeps;
my @directdepsend;
if ($ndeps{'--directdepsend--'}) {
@directdepsend = @deps;
for (splice @deps) {
last if $_ eq '--directdepsend--';
push @deps, $_;
}
@directdepsend = grep {!/^-/} splice(@directdepsend, @deps + 1);
}
unshift @deps, 'sysroot-packages' if $config->{'substitute'}->{'sysroot-packages'};
@deps = grep {!$ndeps{$_}} @deps;
@deps = do_subst($config, @deps);
@deps = grep {!$ndeps{"-$_"}} @deps;
if (@directdepsend) {
@directdepsend = do_subst($config, @directdepsend);
@directdepsend = grep {!$ndeps{"-$_"}} @directdepsend;
unshift @directdepsend, '--directdepsend--' if @directdepsend;
}
@deps = expand($config, @extractnative, @deps, @ndeps, @directdepsend);
return @deps;
}
# return the package needed for setting up the build environment.
# an empty result means that the packages from get_build should
# be used instead.
sub get_sysbuild {
my ($config, $buildtype, $extradeps) = @_;
my $engine = $config->{'buildengine'} || '';
$buildtype ||= $config->{'type'} || '';
my @sysdeps;
if ($engine eq 'mock' && $buildtype eq 'spec') {
@sysdeps = @{$config->{'substitute'}->{'system-packages:mock'} || []};
@sysdeps = @{$subst_defaults{'system-packages:mock'} || []} unless @sysdeps;
} elsif ($engine eq 'debootstrap' && $buildtype eq 'dsc') {
@sysdeps = @{$config->{'substitute'}->{'system-packages:debootstrap'} || []};
@sysdeps = @{$subst_defaults{'system-packages:debootstrap'} || []} unless @sysdeps;
} elsif ($buildtype eq 'livebuild') {
# packages used for build environment setup (build-recipe-livebuild deps)
@sysdeps = @{$config->{'substitute'}->{'system-packages:livebuild'} || []};
@sysdeps = @{$subst_defaults{'system-packages:livebuild'} || []} unless @sysdeps;
} elsif ($buildtype eq 'kiwi-image') {
@sysdeps = @{$config->{'substitute'}->{'system-packages:kiwi-image'} || []};
@sysdeps = @{$config->{'substitute'}->{'kiwi-setup:image'} || []} unless @sysdeps;
@sysdeps = @{$subst_defaults{'system-packages:kiwi-image'} || []} unless @sysdeps;
} elsif ($buildtype eq 'productcompose') {
@sysdeps = @{$config->{'substitute'}->{'system-packages:productcompose'} || []};
@sysdeps = @{$subst_defaults{'system-packages:productcompose'} || []} unless @sysdeps;
} elsif ($buildtype eq 'kiwi-product') {
@sysdeps = @{$config->{'substitute'}->{'system-packages:kiwi-product'} || []};
@sysdeps = @{$config->{'substitute'}->{'kiwi-setup:product'} || []} unless @sysdeps;
@sysdeps = @{$subst_defaults{'system-packages:kiwi-product'} || []} unless @sysdeps;
} elsif ($engine eq 'podman' && $buildtype eq 'docker') {
@sysdeps = @{$config->{'substitute'}->{'system-packages:podman'} || []} unless @sysdeps;
@sysdeps = @{$subst_defaults{'system-packages:podman'} || []} unless @sysdeps;
} elsif ($buildtype eq 'docker') {
@sysdeps = @{$config->{'substitute'}->{'system-packages:docker'} || []} unless @sysdeps;
@sysdeps = @{$subst_defaults{'system-packages:docker'} || []} unless @sysdeps;
} elsif ($buildtype eq 'fissile') {
@sysdeps = @{$config->{'substitute'}->{'system-packages:fissile'} || []} unless @sysdeps;
@sysdeps = @{$subst_defaults{'system-packages:fissile'} || []} unless @sysdeps;
} elsif ($buildtype eq 'deltarpm') {
@sysdeps = @{$config->{'substitute'}->{'system-packages:deltarpm'} || []};
@sysdeps = @{$subst_defaults{'system-packages:deltarpm'} || []} unless @sysdeps;
} elsif ($buildtype eq 'mkosi') {
my $binarytype = $config->{'binarytype'} || '';
@sysdeps = @{$config->{'substitute'}->{"system-packages:mkosi:$binarytype"} || []};
@sysdeps = @{$subst_defaults{"system-packages:mkosi:$binarytype"} || []} unless @sysdeps;
}
return () unless @sysdeps; # no extra build environment used
push @sysdeps, @$extradeps if $extradeps;
if ($config->{'expandflags:preinstallexpand'} && !$config->{'preinstallisexpanded'}) {
my $err = expandpreinstalls($config);
return (undef, $err) if $err;
}
my @ndeps = grep {/^-/} @sysdeps;
my %ndeps = map {$_ => 1} @ndeps;
@sysdeps = grep {!$ndeps{$_}} @sysdeps;
push @sysdeps, @{$config->{'preinstall'}}, @{$config->{'required'}};
push @sysdeps, @{$config->{'support'}} if $buildtype eq 'kiwi-image' || $buildtype eq 'kiwi-product'; # compat to old versions
@sysdeps = do_subst($config, @sysdeps);
@sysdeps = grep {!$ndeps{$_}} @sysdeps;
my $configtmp = $config;
@sysdeps = expand($configtmp, @sysdeps, @ndeps);
return @sysdeps unless $sysdeps[0];
shift @sysdeps;
@sysdeps = unify(@sysdeps, get_preinstalls($config));
return (1, @sysdeps);
}
# Delivers all packages which shall have an influence to other package builds (get_build reduced by support packages)
sub get_deps {
my ($config, $subpacks, @deps) = @_;
if ($config->{'expandflags:preinstallexpand'} && !$config->{'preinstallisexpanded'}) {
my $err = expandpreinstalls($config);
return (undef, $err) if $err;
}
my @ndeps = grep {/^-/} @deps;
my @extra = @{$config->{'required'}};
if (@{$config->{'keep'} || []}) {
my %keep = map {$_ => 1} (@deps, @{$config->{'keep'} || []}, @{$config->{'preinstall'}});
for (@{$subpacks || []}) {
push @ndeps, "-$_" unless $keep{$_};
}
} else {
# new "empty keep" mode, filter subpacks from required
my %subpacks = map {$_ => 1} @{$subpacks || []};
@extra = grep {!$subpacks{$_}} @extra;
}
my %ndeps = map {$_ => 1} @ndeps;
@deps = grep {!$ndeps{$_}} @deps;
push @deps, @extra;
@deps = grep {!$ndeps{"-$_"}} @deps;
@deps = do_subst($config, @deps);
@deps = grep {!$ndeps{"-$_"}} @deps;
my %bdeps = map {$_ => 1} (@{$config->{'preinstall'}}, @{$config->{'support'}});
delete $bdeps{$_} for @deps;
@deps = expand($config, @deps, @ndeps);
if (@deps && $deps[0]) {
my $r = shift @deps;
@deps = grep {!$bdeps{$_}} @deps;
unshift @deps, $r;
}
return @deps;
}
sub get_preinstalls {
my ($config) = @_;
if ($config->{'expandflags:preinstallexpand'} && !$config->{'preinstallisexpanded'}) {
my $err = expandpreinstalls($config);
return ('expandpreinstalls_error') if $err;
}
return @{$config->{'preinstall'}};
}
sub get_vminstalls {
my ($config) = @_;
if ($config->{'expandflags:preinstallexpand'} && !$config->{'preinstallisexpanded'}) {
my $err = expandpreinstalls($config);
return ('expandpreinstalls_error') if $err;
}
return @{$config->{'vminstall'}};
}
sub get_runscripts {
my ($config) = @_;
return @{$config->{'runscripts'}};
}
###########################################################################
sub parse_depfile {
return Build::Intrepo::parse(@_);
}
sub readdeps {
my ($config, $pkginfo, @depfiles) = @_;
my $nofiledeps = %{$config->{'fileprovides'} || {}} || $config->{'expandflags:keepfilerequires'} ? 0 : 1;
$pkginfo ||= {};
for my $depfile (@depfiles) {
if (ref($depfile) eq 'HASH') {
$pkginfo->{$_} = $depfile->{$_} for keys %$depfile;
} else {
my $pkgs = Build::Intrepo::parse($depfile, [], 'nofiledeps' => $nofiledeps);
$pkginfo->{$_->{'name'}} = $_ for @$pkgs;
}
}
# put repository data into the build config
my %requires;
my %provides;
my %pkgconflicts;
my %pkgobsoletes;
my %recommends;
my %supplements;
my %multiarch;
for my $pkgid (sort keys %$pkginfo) {
my $pkg = $pkginfo->{$pkgid};
$provides{$pkgid} = $pkg->{'provides'} if $pkg->{'provides'};
$requires{$pkgid} = $pkg->{'requires'} if $pkg->{'requires'};
$pkgconflicts{$pkgid} = $pkg->{'conflicts'} if $pkg->{'conflicts'};
$pkgobsoletes{$pkgid} = $pkg->{'obsoletes'} if $pkg->{'obsoletes'};
$recommends{$pkgid} = $pkg->{'recommends'} if $pkg->{'recommends'};
$supplements{$pkgid} = $pkg->{'supplements'} if $pkg->{'supplements'};
$multiarch{$pkgid} = $pkg->{'multiarch'} if $pkg->{'multiarch'};
}
$config->{'providesh'} = \%provides;
$config->{'requiresh'} = \%requires;
$config->{'pkgconflictsh'} = \%pkgconflicts;
$config->{'pkgobsoletesh'} = \%pkgobsoletes;
$config->{'recommendsh'} = \%recommends;
$config->{'supplementsh'} = \%supplements;
$config->{'multiarchh'} = \%multiarch;
makewhatprovidesh($config);
}
sub writedeps {
Build::Intrepo::writepkg(@_);
}
sub getbuildid {
return Build::Intrepo::getbuildid(@_);
}
sub makewhatprovidesh {
my ($config) = @_;