Add support for creating firmware patterns at build time

Using the new generate_firmware_patterns script, generate a patterns
file in /firmware/dep11/<package>.patterns as we add a firmware
package onto media.

Deal with size changes as these are added/removed, and add them to the
md5sum.txt file on media too.
This commit is contained in:
Steve McIntyre 2021-07-25 18:19:05 +01:00 committed by Steve McIntyre
parent f7e973a181
commit 4d4399012d
1 changed files with 84 additions and 11 deletions

View File

@ -910,7 +910,7 @@ sub finish_disc {
print " Finishing off md5sum.txt\n";
# Just md5 the bits we won't have seen already
open(MD5LIST, ">>md5sum.txt") or die "Failed to open md5sum.txt file: $!\n";
find (\&md5_files_for_md5sum, ("./.disk", "./dists"));
find (\&md5_files_for_md5sum, ("./.disk", "./dists", "./firmware/dep11"));
close(MD5LIST);
# And sort; it should make things faster for people checking
@ -1064,8 +1064,8 @@ sub add_trans_desc_entry {
m/^Package: (\S+)/m and $p = $1;
m/^Section: (\S+)/m and $section = $1;
m/^Filename: (\S+)/mi and $file = $1;
$idir = Packages_dir($dir, $file, $section, $in_backports) . "/i18n";
if (! -d $idir) {
@ -1165,6 +1165,62 @@ sub add_md5_entry {
return $blocks_added;
}
# Add sym-links and pattern files for firmware packages
sub add_firmware_stuff {
my $dir = shift;
my $arch = shift;
my $in_backports = shift;
local $_ = shift;
my ($p, $file, $section, $dist, $dep11_dir);
my $blocks_added = 0;
my @args = ("$basedir/tools/generate_firmware_patterns",
"--output-dir", "$dir/firmware/dep11");
m/^Package: (\S+)/m and $p = $1;
m/^Section: (\S+)/m and $section = $1;
m/^Filename: (\S+)/mi and $file = $1;
if ($file =~ /\/main\//) {
$dist = "main";
} elsif ($file =~ /\/contrib\//) {
$dist = "contrib";
} elsif ($file =~ /\/non-free\//) {
$dist = "non-free";
} else {
$dist = "local";
}
$dep11_dir = "$mirror/dists/$codename/$dist/dep11";
if ($in_backports) {
$dep11_dir = "$mirror/dists/$codename-backports/$dist/dep11";
}
msg_ap(0, "Symlink fw package $p into /firmware\n");
symlink("../$file", "$dir/firmware/" . basename($file));
msg_ap(0, "Symlink ../$file $dir/firmware/.\n");
if (! -d "$dir/firmware") {
mkdir "$dir/firmware" or die "mkdir $dir/firmware failed $!\n";
mkdir "$dir/firmware/dep11" or die "mkdir $dir/firmware/dep11 failed $!\n";
$blocks_added += 2;
}
# Cope with maybe having the patterns file already
# (e.g. multi-arch), in which case we'll replace it here
if (-f "$dir/firmware/dep11/$p.patterns") {
$blocks_added -= get_file_blocks("$dir/firmware/dep11/$p.patterns");
}
msg_ap(0, "(Maybe) generate fw pattern file $dir/firmware/dep11/$p.patterns\n");
push(@args, "--package", "$p");
push(@args, "$dep11_dir/Components-$arch.yml.gz");
system(@args) == 0 or die "generate_firmware_patterns failed: $?";
if (-f "$dir/firmware/dep11/$p.patterns") {
$blocks_added += get_file_blocks("$dir/firmware/dep11/$p.patterns");
}
return $blocks_added;
}
# Roll back the results of add_Packages_entry()
sub remove_Packages_entry {
my $dir = shift;
@ -1364,6 +1420,29 @@ sub remove_md5_entry {
return $blocks_removed;
}
sub remove_firmware_stuff {
my $dir = shift;
my $arch = shift;
my $in_backports = shift;
my ($p, $file);
local $_ = shift;
my $blocks_removed = 0;
m/^Package: (\S+)/mi and $p = $1;
m/^Filename: (\S+)/mi and $file = $1;
msg_ap(0, "Remove symlink for fw package $p in /firmware\n");
unlink("$dir/firmware/" . basename($file));
if (-f "$dir/firmware/dep11/$p.patterns") {
$blocks_removed += get_file_blocks("$dir/firmware/dep11/$p.patterns");
msg_ap(0, "Remove $dir/firmware/dep11/$p.patterns\n");
unlink("$dir/firmware/dep11/$p.patterns");
}
return $blocks_removed;
}
sub get_file_blocks {
my $realfile = shift;
my $st;
@ -1434,8 +1513,7 @@ sub add_packages {
}
if ($firmware_package{$pkgname}) {
msg_ap(0, "Remove symlink for fw package $pkgname in /firmware\n");
unlink("$dir/firmware/" . basename($file));
$total_blocks -= remove_firmware_stuff($dir, $arch, $in_backports, $package_info);
}
foreach my $file (@files) {
@ -1485,12 +1563,7 @@ sub add_packages {
$total_blocks += good_link ($realfile, "$dir/$file");
msg_ap(0, " Linked $dir/$file\n");
if ($firmware_package{$pkgname}) {
msg_ap(0, "Symlink fw package $pkgname into /firmware\n");
if (! -d "$dir/firmware") {
mkdir "$dir/firmware" or die "symlink failed $!\n";
}
symlink("../$file", "$dir/firmware/" . basename($file));
msg_ap(0, "Symlink ../$file $dir/firmware/.\n");
$total_blocks += add_firmware_stuff($dir, $arch, $in_backports, $package_info);
}
} else {
msg_ap(0, " $dir/$file already linked in\n");