summaryrefslogtreecommitdiff
path: root/createyastdeps
blob: 4aa124fffbe5df275e5695bf63e732492f482dab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/perl -w

BEGIN {
  unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
}

use Build;
use strict;

sub print_pkg($)
{
  my $pkg = shift;

  return if $pkg->{'arch'} eq 'src' || $pkg->{'arch'} eq 'nosrc';
  my $id = sprintf("%s.%s-%d/%d/%d: ",
	  $pkg->{'name'},
	  $pkg->{'arch'},
	  $pkg->{'buildtime'},
	  0,
	  0);
  print sprintf('F:%s%ssuse/%s/%s',$id,$pkg->{'baseurl'},
    $pkg->{'arch'}, $pkg->{'location'}), "\n";

  if(!$pkg->{'provides'}) # happens in 8.1 packages file
  {
    $pkg->{'provides'} = sprintf("%s = %s-%s", $pkg->{'name'}, $pkg->{'ver'}, $pkg->{'rel'});
  }

  print "P:$id".$pkg->{'provides'}."\n";
  print "R:$id".$pkg->{'requires'}."\n";

  my $tag = sprintf("%s-%s-%s %s",
	  $pkg->{'name'},
	  $pkg->{'ver'},
	  $pkg->{'rel'},
#			$pkg->{'rpm:buildhost'},
	  $pkg->{'buildtime'});
  print "I:$id$tag\n";
}

while (@ARGV)
{
  my $url = shift;
  $url .= '/' unless $url =~ /\/$/;

# a really fucked up system
#  if (-e $url."/yast/order") {
#    if(open(F, '<', $url."/yast/order")) {
#      my $found_products;
#      while(<F>) {
#	chomp;
#	my ($a, $b) = split(/ /);
#	$a =~ s/^\///;
#	if(-e $url.$a)
#	{
#	  push @ARGV, $url.$a;
#	  $found_products = 1;
#	  print STDERR "$url -> $url$a\n";
#	}
#      }
#      close(F);
#      next if $found_products;
#    }
#  }
  # XXX: location is actually defined in content file
  my $packages = $url.'suse/setup/descr/packages';

  if(!open(F, '<', $packages)) {
    if(!open(F, '-|', "gzip -dc $packages".'.gz')) {
      die "$packages: $!";
    }
  }

  {
    my $pkg;
    my ($req, $prv);
    while (<F>) {
      chomp;
      next unless /^[=+]/;
      my ($tag, $data);
      if (/^\+(.*)$/) {
	$tag = $1;
	$data = '';
	while (<F>) {
	  chomp;
	  last if $_ eq "-$tag";
	  $data .= "$_\n";
	}
	chop $data;
      } else {
	($tag, $data) = split(' ', $_, 2);
	$tag = substr($tag, 1);
      }
      if ($tag eq 'Pkg:') {
	if($pkg) {
	  print_pkg($pkg);
	  undef $pkg;
	}
	my ($name, $vers, $rel, $arch) = split(' ', $data);
	$pkg = {};
	$pkg->{'name'} = $name;
	$pkg->{'ver'} = $vers;
	$pkg->{'rel'} = $rel;
	$pkg->{'arch'} = $arch;
	$pkg->{'baseurl'} = $url;
      } elsif ($tag eq 'Req:') {
	next unless $pkg;
	$data =~ s/\n/ /gs;
	$pkg->{'requires'} = $data;
      } elsif ($tag eq 'Prv:') {
	next unless $pkg;
	# add self provides for old rpm versions
	my $name = $pkg->{'name'};
	$data = sprintf("%s = %s-%s",
	  $name,
	  $pkg->{'ver'},
	  $pkg->{'rel'}) ."\n".$data unless "\n$data" =~ /\n\Q$name\E =/s;
	$data =~ s/\n/ /gs;
	$pkg->{'provides'} = $data;
      } elsif ($tag eq 'Tim:') {
	$pkg->{'buildtime'} = $data;
      } elsif ($tag eq 'Loc:') {
	my @data = split(' ', $data);
	# multi cd support hack
	my $num = $data[0];
	if($pkg->{'baseurl'} =~ /1\/$/ && $num ne 0) {
	  $pkg->{'baseurl'} =~ s/1\/$/$num\//;
	}
	$pkg->{'location'} = $data[1];
      } elsif ($tag eq 'Siz:') {
	my @data = split(' ', $data);
	$pkg->{'size'} = $data[0];
      }
    }
    close F;

    print_pkg($pkg) if $pkg;
  }
}

# vim: sw=2