1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | # Usage: all-packages |
---|
4 | |
---|
5 | # Run this script from a build area after running gen-packages and |
---|
6 | # dasource. The script will output a list of normal Debian packages |
---|
7 | # (not equivs or debathenify packages) in dependency order. |
---|
8 | # |
---|
9 | # This script is imperfect in a couple of ways: |
---|
10 | # |
---|
11 | # (1) It knows nothing about Provides declarations, because those are |
---|
12 | # computed when a package is built and this script is intended to |
---|
13 | # operate before binary packages are built. |
---|
14 | # |
---|
15 | # (2) It will always pick the first package of a disjunction. |
---|
16 | |
---|
17 | use strict; |
---|
18 | |
---|
19 | # Process a Build-Depends specification into a list of package names. |
---|
20 | sub list { |
---|
21 | my ($l) = @_; |
---|
22 | my @a = split(/, /, $l); |
---|
23 | foreach (@a) { |
---|
24 | s/ \(.*\)$//; |
---|
25 | s/ \|.*$//; |
---|
26 | s/ \[.*$//; |
---|
27 | } |
---|
28 | return @a; |
---|
29 | } |
---|
30 | |
---|
31 | # Read in the package-to-directory map. |
---|
32 | my %dirmap; |
---|
33 | open(PACKAGES, "<", "packages") |
---|
34 | || die "Can't read packages file; create with gen-packages"; |
---|
35 | while (<PACKAGES>) { |
---|
36 | chomp; |
---|
37 | /^(\S+)\s+(\S+)$/ || die "Malformed packages line"; |
---|
38 | $dirmap{$1} = $2; |
---|
39 | } |
---|
40 | close(PACKAGES); |
---|
41 | |
---|
42 | # Read the dsc file for each package to get build dependencies. |
---|
43 | my %deps; |
---|
44 | foreach my $name (keys(%dirmap)) { |
---|
45 | # Look for dsc files under $name and pick the one that sorts highest. |
---|
46 | my @dscfiles = sort glob("$name/*.dsc"); |
---|
47 | if (scalar @dscfiles == 0) { |
---|
48 | die "No source package for $name; create with dasource" |
---|
49 | } |
---|
50 | my $dscfile = $dscfiles[$#dscfiles]; |
---|
51 | |
---|
52 | open(DSC, "<", $dscfile) || die "Can't read $dscfile"; |
---|
53 | $deps{$name} = []; |
---|
54 | while (<DSC>) { |
---|
55 | chomp; |
---|
56 | (my ($depline) = /^Build-Depends: (.*)$/) || next; |
---|
57 | push @{$deps{$name}}, list($depline); |
---|
58 | } |
---|
59 | close(DSC); |
---|
60 | } |
---|
61 | |
---|
62 | # Recursively output a package's dependency names and then the package |
---|
63 | # name itself, without outputting any name twice. |
---|
64 | my %done; |
---|
65 | sub process { |
---|
66 | my ($name) = @_; |
---|
67 | return if ($done{$name}); |
---|
68 | foreach my $dep (@{${deps{$name}}}) { |
---|
69 | process($dep) if ($dirmap{$dep}); |
---|
70 | } |
---|
71 | print $name, "\n"; |
---|
72 | $done{$name} = 1; |
---|
73 | } |
---|
74 | |
---|
75 | foreach my $name (keys(%dirmap)) { |
---|
76 | process($name); |
---|
77 | } |
---|