File: getbuildids

package info (click to toggle)
obs-build 20180831-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 2,396 kB
  • sloc: perl: 10,030; sh: 3,142; ansic: 284; makefile: 151; python: 35
file content (79 lines) | stat: -rwxr-xr-x 2,059 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w

################################################################
#
# Copyright (c) 2016 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 strict;

sub getbuildid {
  my ($pkg) = @_;
  my $d = Build::query($pkg, 'evra' => 1, 'buildtime' => 1);
  return $d ? Build::getbuildid($d) : undef;
}

if (@ARGV && $ARGV[0] eq 'cachecheck') {
  my $pkg;
  my $buildid;
  my $dst;
  while (<STDIN>) {
    chomp;
    if (/^PKG (\S+) (.+)$/) {
      ($pkg, $buildid, $dst) = ($1, $2, undef);
    } elsif (/^PKG (\S+)$/) {
      ($pkg, $buildid, $dst) = ($1, undef, undef);
    } elsif (/^DST (.+)$/) {
      $dst = $1;
      unlink($dst) if -e $dst;
    } elsif (/^CACHE (.+)$/) {
      next unless $dst;
      my $cpkg = $1;
      next unless -s $cpkg;
      if ($buildid) {
	my $bid = getbuildid($cpkg);
	next unless $bid;
	if ($bid =~ / 0-/) {
	  my $buildid2 = $buildid;
	  $buildid2 =~ s/ .*?-/0-/;
	  next if $bid ne $buildid2;
	} else {
	  next if $bid ne $buildid;
 	}
      }
      symlink($cpkg, $dst);
      $dst = undef;	# first hit wins
    }
  }
  exit(0);
}

while (<STDIN>) {
  chomp;
  my $dst = $_;
  my $buildid = getbuildid($dst);
  next unless $buildid;
  open(F, '>', "$dst.buildid") || next;
  print F "$buildid\n";
  close(F);
}