From bd13392570b8930e5cc926f0bb64297e9f934dec Mon Sep 17 00:00:00 2001 From: Cyril Brulebois Date: Thu, 26 Jan 2023 23:22:40 +0100 Subject: [PATCH] generate_firmware_task: implement support for --list-filenames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tools/generate_firmware_task | 55 +++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/tools/generate_firmware_task b/tools/generate_firmware_task index f62b02b0..0162852c 100755 --- a/tools/generate_firmware_task +++ b/tools/generate_firmware_task @@ -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,11 +59,15 @@ sub check_packages($$) { if (!exists $seen{$filename}) { $seen{$filename} = 1; if (contains_firmware($mirror, $filename)) { - print " $pkg ($filename)\n"; - if ($use_bp) { - print OUT "$pkg/$codename-backports\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 OUT "$pkg\n"; + print "$filename\n"; } } } @@ -133,22 +138,32 @@ if (defined($localdebs)) { } } -open (OUT, "> $outfile") or die "Can't open outfile for writing: $!\n"; +# 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`; -chomp $date; + $date = `date -u`; + chomp $date; -print OUT "/*\n"; -print OUT " * 'firmware' task file; generated automatically by generate_firmware_task\n"; -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); + print OUT "/*\n"; + print OUT " * 'firmware' task file; generated automatically by generate_firmware_task\n"; + print OUT " * for \"$archlist\" on $date\n"; + print OUT " * Do not edit - changes will not be preserved\n"; + print OUT " */\n"; } -check_packages(0, $pkgfiles); -close OUT; +# 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; +}