generate_firmware_task: implement support for --list-filenames

Treat the output file argument specifically when it's “--list-filenames”:
instead of actually generating a task file with a list of packages (and a
few comments), output the Filename field for each firmware package
matching our criteria.

Move some status messages to STDERR accordingly.

This makes the “find suitable firmware packages” reusable, e.g. by
make-firmware-image.
This commit is contained in:
Cyril Brulebois 2023-01-26 23:22:40 +01:00
parent 90739b8cde
commit bd13392570
1 changed files with 35 additions and 20 deletions

View File

@ -40,8 +40,9 @@ sub contains_firmware($$) {
}
}
sub check_packages($$) {
sub check_packages($$$) {
my $use_bp = shift;
my $orig_mode = shift;
my $packages = shift;
open (INPKG, "\$BASEDIR/tools/catz $packages |") or die "Can't read input package files: $!\n";
@ -58,12 +59,16 @@ sub check_packages($$) {
if (!exists $seen{$filename}) {
$seen{$filename} = 1;
if (contains_firmware($mirror, $filename)) {
print " $pkg ($filename)\n";
print STDERR " $pkg ($filename)\n";
if ($orig_mode) {
if ($use_bp) {
print OUT "$pkg/$codename-backports\n";
} else {
print OUT "$pkg\n";
}
} else {
print "$filename\n";
}
}
}
}
@ -133,6 +138,13 @@ if (defined($localdebs)) {
}
}
# This special filename is an crude but easy way to distinguish the historical
# caller (top-level Makefile) from tools/make-firmware-image which should use
# the same logic, but is interested in the Filename for interesting firmware
# packages:
my $orig_mode = $outfile ne '--list-filenames' ? 1 : 0;
if ($orig_mode) {
# Prepare the output file:
open (OUT, "> $outfile") or die "Can't open outfile for writing: $!\n";
$date = `date -u`;
@ -143,12 +155,15 @@ print OUT " * 'firmware' task file; generated automatically by generate_firmware
print OUT " * for \"$archlist\" on $date\n";
print OUT " * Do not edit - changes will not be preserved\n";
print OUT " */\n";
print "$0: Checking for firmware packages:\n";
if (defined($backports)) {
check_packages(1, $bp_pkgfiles);
}
check_packages(0, $pkgfiles);
# Those function calls will either write the task to OUT (historical mode) or
# filenames to stdout (for make-firmware-image):
if (defined($backports)) {
check_packages(1, $orig_mode, $bp_pkgfiles);
}
check_packages(0, $orig_mode, $pkgfiles);
if ($orig_mode) {
close OUT;
}