summaryrefslogtreecommitdiff
path: root/createdirdeps
blob: 49bf09e37f4bcf67b9f1780a41a8ce54f5de47d6 (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
#!/usr/bin/perl -w

################################################################
#
# Copyright (c) 1995-2014 SUSE Linux Products GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################

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

use Build;
use Getopt::Long;

use strict;

Getopt::Long::Configure("no_ignore_case");

my $oldfile;

GetOptions ("oldfile=s" => \$oldfile) or exit(1);

sub queryfromfilename {
  my ($fn) = @_;
  $fn =~ s/.*\///;
  return {'name' => $1, 'arch' => $2} if $fn =~ /^(.*)-[^-]+-[^-]+\.([^\. ]+)\.rpm$/;
  return {'name' => $1, 'arch' => $2} if $fn =~ /^([^_]*)_(?:[^_]*)_([^_]*)\.deb$/;
  return {'name' => $1, 'arch' => $2} if $fn =~ /^(.*)-[^-]+-[^-]+-([^-]+)\.pkg\.tar\.[gx]z$/;
  return undef;
}


######################################################################

my %old;
if (defined($oldfile) && open(F, '<', $oldfile)) {
  while (<F>) {
    chomp;
    $old{$1} = $_ if /^([PRrsCOI]:[^ ]+): /;
  }
  close F;
}

my %seen;

for my $dir (@ARGV) {
  my $cmd = "find $dir -follow -type f \\( -name \"*.rpm\" -o -name \"*.deb\" -o -name \"*.pkg.tar.gz\" -o -name \"*.pkg.tar.xz\" \\) -a ! -name \"*src.rpm\" -printf '\%T@/\%s/\%i \%p\\n'";
  open(F, '-|', $cmd) or next;
  while (<F>) {
    chomp;
    next unless /^([\d\.]+\/\d+\/\d+) (.*)$/;
    my $id = $1;
    my $path = $2;
    # newer find version add a fraction part to %T@, strip it
    $id =~ s/^(\d+)\.\d+/$1/;
    next if $path =~ /\.(?:patch|delta)\.rpm$/;	# not good for building...
    if (%old) {
      my $q = queryfromfilename($path);
      if ($q && defined($q->{'name'}) && defined($q->{'arch'})) {
        my $idx = "$q->{'name'}.$q->{'arch'}-$id";
	if ($old{"I:$idx"} && $old{"P:$idx"}) {
	  # reuse old data
	  next if $seen{$idx};
	  $seen{$idx} = 1;
	  print "F:$idx: $path\n";
	  for (qw{P R r s C O I}) {
	    print $old{"$_:$idx"}."\n" if $old{"$_:$idx"};
	  }
	  next;
	}
      }
    }
    my $q = Build::query($path, 'addselfprovides' => 1, 'conflicts' => 1, 'evra' => 1, 'buildtime' => 1, 'weakdeps' => 1);
    next unless $q && defined($q->{'name'}) && defined($q->{'arch'}) && defined($q->{'version'});
    my $idx = "$q->{'name'}.$q->{'arch'}-$id";
    next if $seen{$idx};
    $seen{$idx} = 1;
    $q->{'id'} = $id;
    $q->{'location'} = $path;
    Build::writedeps(\*STDOUT, $q);
  }
  close F;
}