forked from openSUSE/obs-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunservices
executable file
·80 lines (68 loc) · 1.87 KB
/
runservices
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
#!/usr/bin/perl -w
BEGIN {
unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
}
use POSIX;
use File::Temp ();
use File::Copy ();
use strict;
use Build::SimpleXML;
sub ls {
local *D;
opendir(D, $_[0]) || return ();
my @r = grep {$_ ne '.' && $_ ne '..'} readdir(D);
closedir D;
return @r;
}
sub run_services {
my ($xml, $count) = @_;
$count ||= 0;
die("_service inclusion depth limit reached\n") if $count++ > 10;
my $servicedir = "/usr/lib/obs/service";
my @servicxml;
my $servicexml = Build::SimpleXML::parse($xml);
die("not a _service file\n") unless $servicexml && $servicexml->{'services'};
$servicexml = $servicexml->{'services'}->[0];
my $tempdir = File::Temp::tempdir('CLEANUP' => 1);
# take default version setting
my $services = ($servicexml->{'service'} || []);
for my $s (@{$services || []}) {
# buildtime only is default
next unless $s->{'mode'} && $s->{'mode'} eq 'buildtime';
die("missing name in service\n") unless $s->{'name'};
if (!-x "$servicedir/$s->{'name'}") {
die("service '$s->{'name'}' configured to run, but is not available\n");
}
my @run;
push @run, "$servicedir/$s->{'name'}";
for my $param (@{$s->{'param'}}) {
next if $param->{'name'} eq 'outdir';
next unless $param->{'_content'};
push @run, "--$param->{'name'}";
push @run, $param->{'_content'};
}
push @run, "--outdir";
push @run, $tempdir;
if (system(@run) != 0) {
die("service run failed for $s->{'name'}\n")
}
# copy back
for my $file (grep {!/^[:\.]/} ls($tempdir)) {
File::Copy::move("$tempdir/$file", $file) if -f "$tempdir/$file";
}
}
}
local *F;
open(F, '<', "_service") || die("_service: $!\n");
my $xml = '';
1 while sysread(F, $xml, 4096, length($xml)) > 0;
close F;
my $d;
eval {
$d = run_services($xml);
};
if ($@) {
print $@;
exit(1);
}
exit(0);