generate_firmware_task: build lists of Packages files and iterate on them

The next step for make-firmware-image is to use generate_firmware_patterns
for each firmware package that was detected. That command requires DEP-11
metadata, so needs to know which Packages file each firmware package comes
from.

Instead of building long $pkgfiles and $bp_pkgfiles strings, and passing
them to catz, build lists instead and iterate over them. This means a few
more catz calls, but that also means being able to derive the DEP-11
directory from Packages paths.

There should be no functional changes.
This commit is contained in:
Cyril Brulebois 2023-01-26 23:22:40 +01:00
parent a2c722b735
commit 45db7e1582
1 changed files with 34 additions and 35 deletions

View File

@ -19,8 +19,7 @@ use strict;
my ($mirror, $codename, $archlist, $outfile, $localdebs, $backports); my ($mirror, $codename, $archlist, $outfile, $localdebs, $backports);
my $date; my $date;
my $pkgfiles = ""; my (@pkgfiles, @bp_pkgfiles);
my $bp_pkgfiles = "";
my ($pkg, $filename, $arch); my ($pkg, $filename, $arch);
my %seen; my %seen;
my @components; my @components;
@ -40,39 +39,39 @@ sub contains_firmware($$) {
} }
} }
sub check_packages($$$) { sub check_packages($$@) {
my $use_bp = shift; my ($use_bp, $orig_mode, @pkgfiles) = @_;
my $orig_mode = shift;
my $packages = shift;
open (INPKG, "\$BASEDIR/tools/catz $packages |") or die "Can't read input package files: $!\n"; for my $pkgfile (@pkgfiles) {
$/ = ''; # Browse by paragraph open (INPKG, "\$BASEDIR/tools/catz $pkgfile |") or die "Can't read input package files: $!\n";
$/ = ''; # Browse by paragraph
while (defined($_ = <INPKG>)) { while (defined($_ = <INPKG>)) {
m/^Package: (\S+)/m and $pkg = $1; m/^Package: (\S+)/m and $pkg = $1;
m/^Filename: (\S+)/m and $filename = $1; m/^Filename: (\S+)/m and $filename = $1;
if (! ($pkg =~ /(microcode|firmware)/)) { if (! ($pkg =~ /(microcode|firmware)/)) {
next; next;
} }
if (!exists $seen{$filename}) { if (!exists $seen{$filename}) {
$seen{$filename} = 1; $seen{$filename} = 1;
if (contains_firmware($mirror, $filename)) { if (contains_firmware($mirror, $filename)) {
print STDERR " $pkg ($filename)\n"; print STDERR " $pkg ($filename)\n";
if ($orig_mode) { if ($orig_mode) {
if ($use_bp) { if ($use_bp) {
print OUT "$pkg/$codename-backports\n"; print OUT "$pkg/$codename-backports\n";
} else {
print OUT "$pkg\n";
}
} else { } else {
print OUT "$pkg\n"; print "$filename\n";
} }
} else {
print "$filename\n";
} }
} }
} }
close INPKG;
} }
close INPKG;
} }
@ -117,11 +116,11 @@ if (!defined($codename) || !defined($mirror) ||
foreach $arch (split(' ', $archlist)) { foreach $arch (split(' ', $archlist)) {
for my $component (@components) { for my $component (@components) {
if (defined($backports)) { if (defined($backports)) {
$bp_pkgfiles = "$pkgfiles $mirror/dists/$codename-backports/$component/binary-$arch/Packages.gz"; push @bp_pkgfiles, "$mirror/dists/$codename-backports/$component/binary-$arch/Packages.gz";
$bp_pkgfiles = "$pkgfiles $mirror/dists/$codename-backports/$component/binary-$arch/Packages.xz"; push @bp_pkgfiles, "$mirror/dists/$codename-backports/$component/binary-$arch/Packages.xz";
} }
$pkgfiles = "$pkgfiles $mirror/dists/$codename/$component/binary-$arch/Packages.gz"; push @pkgfiles, "$mirror/dists/$codename/$component/binary-$arch/Packages.gz";
$pkgfiles = "$pkgfiles $mirror/dists/$codename/$component/binary-$arch/Packages.xz"; push @pkgfiles, "$mirror/dists/$codename/$component/binary-$arch/Packages.xz";
} }
} }
@ -129,11 +128,11 @@ if (defined($localdebs)) {
for my $component (@components) { for my $component (@components) {
foreach $arch (split(' ', $archlist)) { foreach $arch (split(' ', $archlist)) {
if (defined($backports)) { if (defined($backports)) {
$bp_pkgfiles = "$pkgfiles $localdebs/dists/$codename-backports/$component/binary-$arch/Packages.gz"; push @bp_pkgfiles, "$localdebs/dists/$codename-backports/$component/binary-$arch/Packages.gz";
$bp_pkgfiles = "$pkgfiles $localdebs/dists/$codename-backports/$component/binary-$arch/Packages.xz"; push @bp_pkgfiles, "$localdebs/dists/$codename-backports/$component/binary-$arch/Packages.xz";
} }
$pkgfiles = "$pkgfiles $localdebs/dists/$codename/$component/binary-$arch/Packages.gz"; push @pkgfiles, "$localdebs/dists/$codename/$component/binary-$arch/Packages.gz";
$pkgfiles = "$pkgfiles $localdebs/dists/$codename/$component/binary-$arch/Packages.xz"; push @pkgfiles, "$localdebs/dists/$codename/$component/binary-$arch/Packages.xz";
} }
} }
} }
@ -160,9 +159,9 @@ if ($orig_mode) {
# Those function calls will either write the task to OUT (historical mode) or # Those function calls will either write the task to OUT (historical mode) or
# filenames to stdout (for make-firmware-image): # filenames to stdout (for make-firmware-image):
if (defined($backports)) { if (defined($backports)) {
check_packages(1, $orig_mode, $bp_pkgfiles); check_packages(1, $orig_mode, @bp_pkgfiles);
} }
check_packages(0, $orig_mode, $pkgfiles); check_packages(0, $orig_mode, @pkgfiles);
if ($orig_mode) { if ($orig_mode) {
close OUT; close OUT;