Merge branch 'master' into devel
[tools/build.git] / createyastdeps
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 ':rpm';
28 use Build::Susetags;
29 use Getopt::Long;
30 use File::Path qw(mkpath);
31
32 use strict;
33
34 Getopt::Long::Configure("no_ignore_case");
35
36 my $opt_zypp;
37 my $cachedir = "/var/cache/build";
38
39 GetOptions ("zypp=s" => \$opt_zypp, "cachedir=s" => \$cachedir) or exit(1);
40
41 for my $url (@ARGV) {
42   # XXX: use descrdir/datadir from content file
43   my $descrdir = 'suse/setup/descr';
44   my $datadir = 'suse';
45
46   my $dir;
47   my $baseurl = $url;
48   if ($opt_zypp) {
49     $dir =  $opt_zypp;
50   } elsif ($url =~ /^(?:ftps?|https?):\/\/([^\/]*)\/?/) {
51     my $repoid = Digest::MD5::md5_hex($url);
52     $dir = "$cachedir/$repoid/";
53     $baseurl .= '/' unless $baseurl =~ /\/$/;
54     mkpath($dir);
55     system("$INC[0]/download", "$dir/", "${baseurl}$descrdir/packages.gz");
56     $descrdir = '.';
57   } else {
58     $dir = $url;
59   }
60   $dir .= '/' unless $dir =~ /\/$/;
61   $baseurl .= '/' unless $baseurl =~ /\/$/;
62
63   my $packages = "$dir$descrdir/packages";
64   $packages = "$packages.gz" if ! -e $packages && -e "$packages.gz";
65   Build::Susetags::parse($packages, sub {
66     my $xurl = $baseurl;
67     # multi cd support hack
68     $xurl =~ s/1\/$/$_[0]->{'medium'}/ if $_[0]->{'medium'};
69     $xurl .= "$datadir/" if $datadir;
70     Build::writedeps(\*STDOUT, $_[0], $xurl);
71   }, 'addselfprovides' => 1);
72 }
73