Debian Codegraph @

tools/generate_di_list

raw
1 #!/usr/bin/perl
2 # Generate a list of packages required for debian-installer
3 # This script makes use of the following variables that need to be preset:
4 # MIRROR, DI_CODENAME, BASEDIR
5
6 use strict;
7 use warnings;
8
9 die "Missing \$MIRROR variable" unless $ENV{MIRROR};
10 die "Missing \$DI_CODENAME variable" unless $ENV{DI_CODENAME};
11 die "Missing \$BASEDIR variable" unless $ENV{BASEDIR};
12 die "Missing \$ARCHES variable" unless $ENV{ARCHES};
13
14 my $catz = $ENV{BASEDIR} . "/tools/catz";
15
16 # Early exit if we're building a source-only CD
17 exit 0 if $ENV{ARCHES} =~ /^\s*source\s*$/;
18
19 my @ARCHES;
20 if ( $ENV{ARCHES} ) {
21 push @ARCHES, 'i386' if $ENV{ARCHES} =~ /(^|\s)i386(\s|$)/;
22 push @ARCHES, 'amd64' if $ENV{ARCHES} =~ /(^|\s)amd64(\s|$)/;
23 push @ARCHES, grep { !/^(source|i386|amd64)$/ } split /\s+/, $ENV{ARCHES};
24 }
25 @ARCHES = qw{i386 amd64} unless @ARCHES;
26
27 my @VARIANTS;
28 if ( $ENV{VARIANTS} ) {
29 @VARIANTS = split(" ", $ENV{VARIANTS});
30 }
31
32 my $DATE=`date`;
33 chomp $DATE;
34 open(OUT, ">debian-installer") || die "write: $!";
35 print OUT << "EOF";
36 /* List of udebs to be included so that debian-installer works fine
37 *
38 * This list can be generated with the command:
39 * ../tools/generate_di_list
40 *
41 * DO NOT EDIT THIS FILE, edit the above script
42 *
43 * Last update: $DATE
44 */
45 EOF
46
47 sub di_ker_abi_to_number ($$$$) {
48 # Make up a version we can compare sensibly from
49 # the version and ABI
50 my $maj = shift;
51 my $min = shift;
52 my $patch = shift;
53 my $abi = shift;
54 my $kernel_ver = ($maj * 1000000000)
55 + ($min * 1000000)
56 + ($patch * 1000)
57 + $abi;
58 return $kernel_ver;
59 }
60
61 sub number_to_di_ker_abi ($) {
62 # Convert back to a useful string
63 my $num = shift;
64 my $maj = int($num / 1000000000);
65 $num -= ($maj * 1000000000);
66 my $min = int($num / 1000000);
67 $num -= ($min * 1000000);
68 my $patch = int($num / 1000);
69 $num -= ($patch * 1000);
70 my $abi = $num;
71 return "$maj.$min.$patch-$abi";
72 }
73
74 my @common_excludes = read_exclude("exclude-udebs");
75 my $mirror_path = "$ENV{MIRROR}/dists/$ENV{DI_CODENAME}";
76 my @components = qw(main);
77 push @components, 'contrib' if $ENV{CONTRIB};
78 if ($ENV{NONFREE}) {
79 push @components, split /\ /,$ENV{NONFREE_COMPONENTS};
80 }
81 push @components, 'unreleased' if $ENV{UNRELEASED};
82 push @components, 'local' if $ENV{LOCAL};
83
84 foreach my $arch (@ARCHES) {
85 (my $cpparch = $arch) =~ s/-/_/g;
86 my $output = '';
87 for my $component ( @components ) {
88 my $pgz="$mirror_path/$component/debian-installer/binary-$arch/Packages.gz";
89 my $pxz="$mirror_path/$component/debian-installer/binary-$arch/Packages.xz";
90 if ( $component eq 'unreleased' and $ENV{UNRELEASED} ) {
91 $pgz="$ENV{MIRROR}/dists/unreleased/main/debian-installer/binary-$arch/Packages.gz";
92 $pxz="$ENV{MIRROR}/dists/unreleased/main/debian-installer/binary-$arch/Packages.xz";
93 }
94 if ( $component eq 'local' and $ENV{LOCALDEBS} ) {
95 $pgz="$ENV{LOCALDEBS}/dists/$ENV{DI_CODENAME}/local/debian-installer/binary-$arch/Packages.gz";
96 $pxz="$ENV{LOCALDEBS}/dists/$ENV{DI_CODENAME}/local/debian-installer/binary-$arch/Packages.xz";
97 }
98
99 my @exclude = @common_excludes;
100 push @exclude, read_exclude("exclude-udebs-$arch")
101 if -e exclude_path("exclude-udebs-$arch");
102
103 my $pz = $pgz;
104 if (! -f $pz) {
105 $pz = $pxz;
106 }
107 if (! -f $pz) {
108 print "Missing package file for $arch/$component.\n";
109 next;
110 }
111
112 # Two passes here
113 # First, need to find the highest kernel ABI in the archive
114 # Next, list all the udebs that:
115 # 1. are not otherwise excluded
116 # 2. are not kernel driver udebs, OR
117 # are kernel driver udebs with the right kernel ABI
118
119 unless ( open (PZ, "$catz $pz |") ) {
120 warn "failed to read package file $pz: $1";
121 next;
122 }
123
124 my @output_udebs;
125 my %driver_udebs;
126 my $highest_kernel_ver = 0;
127
128 while (defined (my $line = <PZ>)) {
129 chomp $line;
130 if ($line =~ m/^Package: (\S+)/) {
131 my $udeb = $1;
132 if (grep { $udeb =~ /^${_}$/ } @exclude) {
133 next;
134 }
135 if ($udeb =~ m/-modules-(\d+)\.(\d+)\.(\d+)-(\d+)-.*-di/) {
136 # Older udeb package names included the ABI here
137 my $kernel_ver = di_ker_abi_to_number($1, $2, $3, $4);
138 if ($kernel_ver > $highest_kernel_ver) {
139 $highest_kernel_ver = $kernel_ver;
140 }
141 # Append this driver udeb to a list for that kernel_ver
142 push(@{ $driver_udebs{$kernel_ver} }, $udeb);
143
144 } elsif ($udeb =~ m/-modules-(\d+)\.(\d+)\.(\d+)-.*-di/) {
145 # Newer udeb package names don't, so use "0" as a dummy value here
146 my $kernel_ver = di_ker_abi_to_number($1, $2, $3, 0);
147 if ($kernel_ver > $highest_kernel_ver) {
148 $highest_kernel_ver = $kernel_ver;
149 }
150 # Append this driver udeb to a list for that kernel_ver
151 push(@{ $driver_udebs{$kernel_ver} }, $udeb);
152
153 } else {
154 #print "found non-driver udeb $udeb\n";
155 push @output_udebs, $udeb;
156 }
157 }
158 }
159 close PZ;
160 $output .= "/* Udebs found in $pz: */\n";
161 if (scalar (@output_udebs) > 0) {
162 $output .= "/* Non-kernel udebs */\n";
163 foreach my $udeb (@output_udebs) {
164 $output .= "$udeb\n";
165 }
166 }
167 if ($highest_kernel_ver != 0) {
168 my $num_this_abi = scalar (@{ $driver_udebs{$highest_kernel_ver}});
169 $output .= "/* Next: $num_this_abi udebs for kernel/ABI version ";
170 $output .= number_to_di_ker_abi($highest_kernel_ver);
171 $output .= " */\n";
172 foreach my $udeb (@{ $driver_udebs{$highest_kernel_ver}}) {
173 $output .= "$udeb\n";
174 }
175 foreach my $key (keys (%driver_udebs)) {
176 if ($key != $highest_kernel_ver) {
177 $num_this_abi = scalar (@{ $driver_udebs{$key}});
178 $output .= "/* IGNORING $num_this_abi udebs for kernel/ABI version ";
179 $output .= number_to_di_ker_abi($key);
180 $output .= " */\n";
181 }
182 }
183 }
184 }
185
186 next unless $output;
187 print OUT "#ifdef ARCH_$cpparch\n";
188 print OUT $output;
189 print OUT "#endif /* ARCH_$cpparch */\n";
190 }
191
192 sub read_exclude {
193 my $file=exclude_path(shift);
194 unless ( open (IN, "<$file") ) {
195 warn "failed to read exclude file $file";
196 return;
197 }
198 my @ret;
199 while (<IN>) {
200 chomp;
201 s/^#.*//;
202 next unless length;
203 my ($pkg,@cond) = split(" ", $_);
204 my $skip = 0;
205 foreach my $cond ( @cond ) {
206 if ($cond =~ /^!(.*)/) {
207 $skip = 1 if grep { $_ eq $1 } @VARIANTS;
208 } else {
209 $skip = 1 unless grep { $_ eq $cond } @VARIANTS;
210 }
211 }
212 next if $skip;
213 $pkg=quotemeta($pkg);
214 $pkg=~s/\\\*/.*/g;
215 push @ret, $pkg;
216 }
217 close IN;
218 return @ret;
219 }
220
221 sub exclude_path {
222 my $file=shift;
223 return "$ENV{BASEDIR}/data/$ENV{DI_CODENAME}/$file";
224 }