~ubuntu-core-dev/debian-installer/xenial-proposed

« back to all changes in this revision

Viewing changes to build/pkg-list

  • Committer: Colin Watson
  • Date: 2007-11-28 15:27:10 UTC
  • mfrom: (664.1.1444)
  • Revision ID: cjwatson@canonical.com-20071128152710-u9183jjlufbt4vxy
Tags: 20041027ubuntu1
* Resynchronise with Debian.
* build/boot/powerpc/yaboot.conf, build/config/common,
  doc/manual/build/common.ent: Update for Hoary.
* doc/manual/en/administrivia/contributors.xml: Remove specific mention of
  Warty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/perl
2
2
# Outputs a list of udebs to install. Pass it the type of image to build as
3
 
# the first parameter, then the kernel flavour, then the major kernel type
4
 
# (2.4, 2.6, etc), then the sub architecture (or an empty string if there
5
 
# are none) and then the kernel version(s) as the rest of the parameters.
6
 
# Reads the lists in pkg-lists.
 
3
# the first parameter. The second parameter can point to a different image
 
4
# type which the image is a driver disk for. Next the kernel flavour, then
 
5
# the major kernel type (2.4, 2.6, etc), then the sub architecture (or an
 
6
# empty string if there are none) and then the kernel version(s) as the rest
 
7
# of the parameters. Reads the lists in pkg-lists.
7
8
 
8
9
use warnings;
9
10
use strict;
10
11
 
11
12
if (int(@ARGV) < 5) {
12
 
        die "Usage: $0 type KERNEL_FLAVOUR KERNELMAJOR SUB_ARCH KERNEL_VERSION [KERNEL_VERSION ...]\n";
 
13
        die "Usage: $0 type DRIVER_FOR KERNEL_FLAVOUR KERNELMAJOR SUB_ARCH KERNEL_VERSION [KERNEL_VERSION ...]\n";
13
14
}
14
15
my $type=shift;
 
16
my $driver_for=shift;
15
17
my $kernel_flavour=shift;
16
18
my $kernel_major=shift;
17
19
my $sub_arch=shift;
20
22
my $deb_host_arch=`dpkg-architecture -qDEB_HOST_ARCH`;
21
23
chomp $deb_host_arch;
22
24
 
23
 
my @lists = ("pkg-lists/local");
24
 
my $t="";
25
 
foreach my $subtype (split "/", $type) {
26
 
        if (! length $t) {
27
 
                $t=$subtype;
28
 
        }
29
 
        else {
30
 
                $t="$t/$subtype";
31
 
        }
32
 
        push @lists, ("pkg-lists/$t/local", "pkg-lists/$t/common",
33
 
                      "pkg-lists/$t/$deb_host_arch.cfg");
34
 
        push @lists, "pkg-lists/$t/$deb_host_arch/$sub_arch.cfg" if $sub_arch;
35
 
}
36
 
 
37
 
while (@lists) {
38
 
        my $list=pop @lists;
39
 
        if (! -e $list) {
40
 
                print STDERR "warning: missing list, $list, for type $type\n"
41
 
                        if $list !~ /local$/ && $list !~
42
 
                        m#$deb_host_arch/$sub_arch.cfg$#;
43
 
        }
44
 
        else {
45
 
                open (LIST, $list) || die "open $list $!";
46
 
                while (<LIST>) {
47
 
                        chomp;
48
 
 
49
 
                        # includes
50
 
                        if (/^#include \"(.*)\"/) {
51
 
                                my $include=$1;
52
 
                                if (-e "pkg-lists/kernel_specific/$kernel_major/$include") {
53
 
                                        push @lists, "pkg-lists/kernel_specific/$kernel_major/$include";
54
 
                                }
55
 
                                else {
56
 
                                        push @lists, "pkg-lists/$include";
57
 
                                }
58
 
                        }
59
 
                        
60
 
                        # comments
61
 
                        s/^#.*//;
62
 
                        next unless length;
63
 
                        
64
 
                        # normal kernel version substitution
65
 
                        if (/\${kernel:Version}/) {
66
 
                                foreach my $v (@kernel_versions) {
67
 
                                        my $l=$_;
68
 
                                        $l=~s/\${kernel:Version}/$v-$kernel_flavour/g;
69
 
                                        print "$l\n";
70
 
                                }
71
 
                                next; # move on to the next line
72
 
                        }
73
 
 
74
 
                        # if nothing else matches print the line untouched
75
 
                        print "$_\n";
76
 
                    }
77
 
                close LIST;
78
 
        }
 
25
my ($collect, $exclude)=getlists($type);
 
26
my ($parentcollect, $parentexclude)=getlists($driver_for) if length $driver_for;
 
27
foreach my $p (sort keys %$collect) {
 
28
        print "$p\n" unless $exclude->{$p} || $parentcollect->{$p};
 
29
 
 
30
        # Warn about missing deps. This is not perfect, in since pkgdeps
 
31
        # ignores dependencies on virtual packages and does not support
 
32
        # alternates (which are not really allowed for udebs anyway).
 
33
        # Still, it will catch most common mistakes.
 
34
        foreach my $dep (pkgdeps($p)) {
 
35
                if (! $collect->{$dep} && ! $exclude->{$dep} && ! $parentcollect->{$dep}) {
 
36
                        warning("in $type, $p has unsatisfied dependency on $dep");
 
37
                }
 
38
        }
 
39
}
 
40
 
 
41
# Add a package, possibly expanding dependencies.
 
42
sub collectpackage {
 
43
        my $line=shift;
 
44
        my $collect=shift;
 
45
        my $exclude=shift;
 
46
        if ($line=~/^(.*) \*$/) {
 
47
                # Asterisk at end means include all dependencies of this
 
48
                # package.
 
49
                $collect->{$1}=1;
 
50
                collectdeps($1, $collect);
 
51
        }
 
52
        elsif ($line=~/^(.*) \-$/) {
 
53
                # Minus sign at the end means exclude this package from the
 
54
                # list.
 
55
                $exclude->{$1}=1;
 
56
        }
 
57
        else {
 
58
                $collect->{$line}=1;
 
59
        }
 
60
}
 
61
 
 
62
# Recursively add dependencies of package.
 
63
sub collectdeps {
 
64
        my $package=shift;
 
65
        my $collect=shift;
 
66
        my %seendeps;
 
67
        %seendeps=%{shift()} if @_;
 
68
        return if $seendeps{$package};
 
69
        $seendeps{$package}=1;
 
70
        foreach my $dep (pkgdeps($package)) {
 
71
                $collect->{$dep}=1;
 
72
                collectdeps($dep, $collect, \%seendeps);
 
73
        }
 
74
}
 
75
 
 
76
# Get the dependencies of a package;
 
77
sub pkgdeps {
 
78
        my $package=shift;
 
79
        my @ret;
 
80
        my $sourceslist;
 
81
        if (-f 'sources.list.udeb.local') {
 
82
                $sourceslist='sources.list.udeb.local';
 
83
        } else {
 
84
                $sourceslist='sources.list.udeb';
 
85
        }
 
86
        my @deps=`LANG=C apt-cache \\
 
87
                -o Dir::Etc::sourcelist=./$sourceslist \\
 
88
                -o Dir::State=./apt.udeb/state \\
 
89
                -o Dir::State::Status=./apt.udeb/state/status \\
 
90
                -o Dir::Cache=./apt.udeb/cache depends $package`;
 
91
        shift @deps; # package name;
 
92
        foreach my $dep (@deps) {
 
93
                chomp $dep;
 
94
                # Note that this intentionally skips alternate
 
95
                # dependencies, taking only the first.
 
96
                if ($dep=~/^\s*Depends:\s/) {
 
97
                        $dep=~s/^\s*Depends:\s*//;
 
98
                        next if $dep=~/\<.*\>/; # skip virtual packages
 
99
                        push @ret, $dep;
 
100
                }
 
101
        }
 
102
        return @ret;
 
103
}
 
104
 
 
105
# Return two hash references, one of udebs to include, one to exclude.
 
106
sub getlists {
 
107
        my $type=shift;
 
108
 
 
109
        my %collect;
 
110
        my %exclude;
 
111
        
 
112
        my @lists = ("pkg-lists/local", "pkg-lists/exclude");
 
113
        my $t="";
 
114
        foreach my $subtype (split "/", $type) {
 
115
                if (! length $t) {
 
116
                        $t=$subtype;
 
117
                }
 
118
                else {
 
119
                        $t="$t/$subtype";
 
120
                }
 
121
                push @lists, ("pkg-lists/$t/local", "pkg-lists/$t/common",
 
122
                              "pkg-lists/$t/$deb_host_arch.cfg");
 
123
                push @lists, "pkg-lists/$t/$deb_host_arch/$sub_arch.cfg" if $sub_arch;
 
124
        }
 
125
 
 
126
        while (@lists) {
 
127
                my $list=pop @lists;
 
128
                if (! -e $list) {
 
129
                        warning("missing list, $list, for type $type")
 
130
                                if $list !~ /local$/ && $list !~ m#$deb_host_arch/$sub_arch.cfg$#;
 
131
                }
 
132
                else {
 
133
                        open (LIST, $list) || die "open $list $!";
 
134
                        while (<LIST>) {
 
135
                                chomp;
 
136
        
 
137
                                # includes
 
138
                                if (/^#include \"(.*)\"/) {
 
139
                                        my $include=$1;
 
140
                                        if (-e "pkg-lists/kernel_specific/$kernel_major/$deb_host_arch/$sub_arch/$include") {
 
141
                                                push @lists, "pkg-lists/kernel_specific/$kernel_major/$deb_host_arch/$sub_arch/$include";
 
142
                                        }
 
143
                                        if (-e "pkg-lists/kernel_specific/$kernel_major/$deb_host_arch/$include") {
 
144
                                                push @lists, "pkg-lists/kernel_specific/$kernel_major/$deb_host_arch/$include";
 
145
                                        }
 
146
                                        if (-e "pkg-lists/kernel_specific/$kernel_major/$include") {
 
147
                                                push @lists, "pkg-lists/kernel_specific/$kernel_major/$include";
 
148
                                        }
 
149
                                        else {
 
150
                                                push @lists, "pkg-lists/$include";
 
151
                                        }
 
152
                                }
 
153
                                
 
154
                                # comments
 
155
                                s/^#.*//;
 
156
                                next unless length;
 
157
                                
 
158
                                # normal kernel version substitution
 
159
                                if (/\${kernel:Version}/) {
 
160
                                        foreach my $v (@kernel_versions) {
 
161
                                                my $l=$_;
 
162
                                                $l=~s/\${kernel:Version}/$v-$kernel_flavour/g;
 
163
                                                collectpackage($l, \%collect, \%exclude);
 
164
                                        }
 
165
                                        next; # move on to the next line
 
166
                                }
 
167
                                collectpackage($_, \%collect, \%exclude);
 
168
                        }
 
169
                        close LIST;
 
170
                }
 
171
        }
 
172
 
 
173
        return \%collect, \%exclude;
 
174
}
 
175
 
 
176
sub warning {
 
177
        print STDERR "** warning: @_\n";
79
178
}