source: trunk/debathena/scripts/build-server/build-all/gen-build-deps @ 25795

Revision 25795, 2.7 KB checked in by jdreed, 12 years ago (diff)
Enable debugging info to stderr if DEBATHENA_DEBUG is set
  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6my $psuite = $ARGV[0];
7$psuite or die "Usage: gen-build-deps <previous suite name>";
8$ENV{DEBATHENA_APT} or $ENV{DEBATHENA_APT}="/mit/debathena/apt";
9
10my $debugmode = $ENV{DEBATHENA_DEBUG} ? 1 : 0;
11
12sub debug {
13    if ($debugmode) {
14        print STDERR "D: ", @_, "\n";
15    }
16}
17
18sub list {
19        my ($l) = @_;
20        my @a = split(/, /, $l);
21        foreach (@a) {
22            s/ \(.*\)$//;
23            s/ \|.*$//;
24            s/ \[.*$//;
25        }
26        return @a;
27}
28
29# For each source package, add its build-deps to the list
30open(DPKG, '-|', "zcat $ENV{DEBATHENA_APT}/dists/$psuite/*/source/Sources.gz | dpkg-awk -f - -- Package Build-Depends") or die;
31my %src_deps = ();
32while (<DPKG>) {
33        last if /^$/;
34        my ($source) = /^Package: (.*)$/ or die;
35        debug("Examining $source");
36        @{$src_deps{$source}} = ();
37        while (<DPKG>) {
38                last if ($_ eq "\n");
39                if (my ($depends) = /^Build-Depends: (.*)$/) {
40                    for (list($depends)) {
41                        debug("  Adding $_ as build-dep of $source");
42                        push @{$src_deps{$source}}, $_ ;
43                    }
44                } else {
45                        die;
46                }
47        }
48}
49close DPKG;
50
51# For each binary package, add itself as a source and provider.  If
52# there are actually different Sources and Provides for the package,
53# use them instead.  Note: This will fail miserably if we ever build
54# packages only for one architecture.
55open(DPKG, '-|', "zcat $ENV{DEBATHENA_APT}/dists/$psuite/debathena/binary-amd64/Packages.gz | dpkg-awk -f - -- Package Source Provides Depends") or die;
56my %pkg_src = ();
57my %pkg_provider = ();
58my %pkg_deps=();
59while (<DPKG>) {
60        last if /^$/;
61        my ($package) = /^Package: (.*)$/ or die;
62        debug("Examining binary package $package");
63        $pkg_src{$package} = $package;
64        $pkg_provider{$package} = $package;
65        debug("Setting src and provider to itself");
66        @{$pkg_deps{$package}} = ();
67        while (<DPKG>) {
68                last if ($_ eq "\n");
69                if (my ($source) = /^Source: (.*)$/) {
70                        $pkg_src{$package} = $source;
71                        debug("  Changing src to $source");
72                } elsif (my ($provides) = /^Provides: (.*)$/) {
73                    for (list($provides)) {
74                        $pkg_provider{$_} = $package;
75                        debug("  Adding $package as a provider of $_");
76                    }
77                } elsif (my ($depends) = /^Depends: (.*)$/) {
78                        for (list($depends)) {
79                            push @{$pkg_deps{$package}}, $_;
80                            debug("--Adding $_ to dependencies of $package");
81                        }
82                } else {
83                        die;
84                }
85        }
86}
87
88for my $source (keys %src_deps) {
89        print "build-all: \$(call package,$source)\n";
90        if ($source ne "debathena-build-depends") {
91            print "\$(call package,debathena-build-depends): \$(call package,$source)\n";
92        }
93        for (@{$src_deps{$source}}) {
94                print "\$(call package,$source): \$(call package,$pkg_src{$pkg_provider{$_}})\n" if (defined $pkg_provider{$_});
95                foreach my $dep (@{$pkg_deps{$_}}) {
96                    print "\$(call package,$source): \$(call package,$pkg_src{$dep})\n" if (defined $pkg_provider{$dep});
97                }
98        }
99}
Note: See TracBrowser for help on using the repository browser.