force enable DO_CUMULATE
[platform/upstream/build.git] / order
1 #!/usr/bin/perl -w
2
3 BEGIN {
4   unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
5 }
6
7 use Build;
8 use strict;
9
10 my ($dist, $archs, $configdir, $manifest);
11
12
13 while (@ARGV)  {
14   if ($ARGV[0] eq '--dist') {
15     shift @ARGV;
16     $dist = shift @ARGV;
17     next;
18   }
19   if ($ARGV[0] eq '--archpath') {
20     shift @ARGV;
21     $archs = shift @ARGV;
22     next;
23   }
24   if ($ARGV[0] eq '--configdir') {
25     shift @ARGV;
26     $configdir = shift @ARGV;
27     next;
28   }
29   if (@ARGV && $ARGV[0] eq '--manifest') {
30     shift @ARGV;
31     $manifest = shift @ARGV;
32     next;
33   }
34   last;
35 }
36
37 die("usage: order [--manifest manifest] cachedir [packages...]\n") unless @ARGV;
38 my $cachedir = shift @ARGV;
39
40 my @p;
41 if ($manifest) {
42   if ($manifest eq '-') {
43     @p = <STDIN>;
44   } else {
45     local *F;
46     open(F, '<', $manifest) || die("$manifest: $!\n");
47     @p = <F>;
48     close F;
49   }
50   chomp @p;
51 }
52
53 push @p, @ARGV;
54
55 my $config = Build::read_config_dist($dist, $archs, $configdir);
56
57 my %deps;
58 my %bins;
59
60 for my $p (@p) {
61   my $q;
62   for my $suf ('rpm', 'deb', 'arch') {
63     next unless -f "$cachedir/$p.$suf";
64     if (! -s "$cachedir/$p.$suf") {
65       $q = {'provides' => [], 'requires' => []}; # package from preinstallimage, no need to order
66       last;
67     }
68     $q = Build::query("$cachedir/$p.$suf", 'filelist' => 1, 'alldeps' => 1);
69     die("bad binary: $p.$suf\n") unless $q;
70     push @{$q->{'provides'}}, @{$q->{'filelist'}} if $suf eq 'rpm' && $q->{'filelist'};
71     delete $q->{'filelist'};
72     last;
73   }
74   die("binary not found: $p\n") unless $q;
75   $deps{$p} = $q;
76 }
77
78 Build::readdeps($config, undef, \%deps);
79 @p = Build::order($config, @p);
80 print "@p\n";