Also support uncompressed control.tar files
[tools/build.git] / order
1 #!/usr/bin/perl -w
2
3 ################################################################
4 #
5 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 2 or 3 as
9 # published by the Free Software Foundation.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program (see the file COPYING); if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #
21 ################################################################
22
23 BEGIN {
24   unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
25 }
26
27 use Build;
28 use strict;
29
30 my ($dist, $archs, $configdir, $manifest);
31
32 $configdir = ($::ENV{'BUILD_DIR'} || '/usr/lib/build') . '/configs';
33
34 while (@ARGV)  {
35   if ($ARGV[0] eq '--dist') {
36     shift @ARGV;
37     $dist = shift @ARGV;
38     next;
39   }
40   if ($ARGV[0] eq '--archpath') {
41     shift @ARGV;
42     $archs = shift @ARGV;
43     next;
44   }
45   if ($ARGV[0] eq '--configdir') {
46     shift @ARGV;
47     $configdir = shift @ARGV;
48     next;
49   }
50   if (@ARGV && $ARGV[0] eq '--manifest') {
51     shift @ARGV;
52     $manifest = shift @ARGV;
53     next;
54   }
55   last;
56 }
57
58 die("usage: order [--manifest manifest] cachedir [packages...]\n") unless @ARGV;
59 my $cachedir = shift @ARGV;
60
61 my @p;
62 if ($manifest) {
63   if ($manifest eq '-') {
64     @p = <STDIN>;
65   } else {
66     local *F;
67     open(F, '<', $manifest) || die("$manifest: $!\n");
68     @p = <F>;
69     close F;
70   }
71   chomp @p;
72 }
73
74 push @p, @ARGV;
75
76 my $config = Build::read_config_dist($dist, $archs, $configdir);
77
78 my %deps;
79 my %bins;
80
81 for my $p (@p) {
82   my $q;
83   for my $suf ('rpm', 'deb', 'arch') {
84     next unless -f "$cachedir/$p.$suf";
85     if (! -s "$cachedir/$p.$suf") {
86       $q = {'provides' => [], 'requires' => []}; # package from preinstallimage, no need to order
87       last;
88     }
89     $q = Build::query("$cachedir/$p.$suf", 'filelist' => 1, 'alldeps' => 1, 'addselfprovides' => 1, 'normalizedeps' => 1);
90     die("bad binary: $p.$suf\n") unless $q;
91     push @{$q->{'provides'}}, @{$q->{'filelist'}} if $suf eq 'rpm' && $q->{'filelist'};
92     delete $q->{'filelist'};
93     last;
94   }
95   die("binary not found: $p\n") unless $q;
96   $deps{$p} = $q;
97 }
98
99 Build::readdeps($config, undef, \%deps);
100 @p = Build::order($config, @p);
101 print "@p\n";