line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RPM::Make::Simple; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
22072
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
64
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
49
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1937
|
use RPM::Make; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use File::Copy; |
8
|
|
|
|
|
|
|
use File::Path; |
9
|
|
|
|
|
|
|
use Carp; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# parameter => default |
14
|
|
|
|
|
|
|
# '' denotes mandatory parameter |
15
|
|
|
|
|
|
|
my %param_defs = ( |
16
|
|
|
|
|
|
|
arch => '', |
17
|
|
|
|
|
|
|
version => '0.01', |
18
|
|
|
|
|
|
|
release => '1', |
19
|
|
|
|
|
|
|
name => '', |
20
|
|
|
|
|
|
|
build_root => './build', |
21
|
|
|
|
|
|
|
temp_build_loc => 'temp_build_loc' |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
|
|
|
|
|
|
my($proto, %params) = @_; |
26
|
|
|
|
|
|
|
my $self = {}; |
27
|
|
|
|
|
|
|
my $class = ref($proto) || $proto; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
bless ($self, $class); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
while(my($param, $val) = each(%param_defs)) { |
32
|
|
|
|
|
|
|
if(($val eq '') && (!defined $params{$param})) { |
33
|
|
|
|
|
|
|
croak("Undefined mandatory parameter $param"); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if(defined $params{$param}) { |
37
|
|
|
|
|
|
|
$self->{$param} = $params{$param}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
|
|
|
|
|
|
$self->{$param} = $val; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$self->{requires} = []; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return($self); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my %built_dirs; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Causes health check nightmares, left here for legacy reasons |
52
|
|
|
|
|
|
|
sub FilePerms { |
53
|
|
|
|
|
|
|
my ($self, %file_perms) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
while(my($file, $perms) = each(%file_perms)) { |
56
|
|
|
|
|
|
|
my $file_build_path = $self->{build_root}."/".$file; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
croak("No such file $file in ".$self->{build_root}) |
59
|
|
|
|
|
|
|
if(!-e $file_build_path); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
croak("Cannot modify $file in ".$self->{build_root}) |
62
|
|
|
|
|
|
|
if(!chmod($perms, $file_build_path)); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub Clean { |
67
|
|
|
|
|
|
|
my($self) = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
rmtree($self->{build_root}); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub Files { |
73
|
|
|
|
|
|
|
my ($self, %locs) = @_; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $err = 0; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
while(my($from, $to) = each(%locs)) { |
78
|
|
|
|
|
|
|
if(!-e $from) { |
79
|
|
|
|
|
|
|
carp("From file $from does not exist"); |
80
|
|
|
|
|
|
|
$err++; |
81
|
|
|
|
|
|
|
next; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
if(-d $from) { |
84
|
|
|
|
|
|
|
carp("From file $from is a directory, won't build"); |
85
|
|
|
|
|
|
|
$err++; |
86
|
|
|
|
|
|
|
next; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $new_dir = $to; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
if($to =~ /\/$/) { |
92
|
|
|
|
|
|
|
my @to_parts = split(/\//, $from); |
93
|
|
|
|
|
|
|
$to .= pop(@to_parts); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else { |
96
|
|
|
|
|
|
|
$new_dir =~ s/\/[^\/]*$//; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
if(!defined $built_dirs{$new_dir}) { |
100
|
|
|
|
|
|
|
mkpath([$self->{build_root}."/$new_dir"], 1, 0711); |
101
|
|
|
|
|
|
|
$built_dirs{$new_dir} = 1; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
print("$from, $self->{build_root}.\"/$to\"\n"); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
copy($from, $self->{build_root}."/$to"); |
107
|
|
|
|
|
|
|
push(@{$self->{build_files}}, $self->{build_root}."/$to"); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
croak("Encountered $err errors, cannot proceed") if($err > 0); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _check_file { |
114
|
|
|
|
|
|
|
my($self, @files) = @_; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my @missing_file; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
foreach(@files) { |
119
|
|
|
|
|
|
|
my $file = $_; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
if(!-e $self->{build_root}."/$file") { |
122
|
|
|
|
|
|
|
push(@missing_file, $file); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
return join(', ', @missing_file); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub Doc { |
130
|
|
|
|
|
|
|
my($self, @docs) = @_; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my $missing = $self->_check_file(@docs); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
croak("Document files missing in ".$self->{build_root}.": $missing") |
135
|
|
|
|
|
|
|
if($missing); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$self->{doc} = { map {$_ => 1} @docs }; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub Conf { |
141
|
|
|
|
|
|
|
my($self, @conf) = @_; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $missing = $self->_check_file(@conf); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
croak("Config files missing in ".$self->{build_root}.": $missing") |
146
|
|
|
|
|
|
|
if($missing); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
$self->{conf} = { map {$_ => 1} @conf }; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub ConfNoReplace { |
152
|
|
|
|
|
|
|
my($self, @conf_no_replace) = @_; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $missing = $self->_check_file(@conf_no_replace); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
croak("Non-replacable config files missing in ".$self->{build_root}. |
157
|
|
|
|
|
|
|
": $missing") if($missing); |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
$self->{confnoreplace} = { map {$_ => 1} @conf_no_replace }; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub Requires { |
163
|
|
|
|
|
|
|
my ($self, %reqs) = @_; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
while(my($req_pack, $req_ver) = each(%reqs)) { |
166
|
|
|
|
|
|
|
my $pre_req = "PreReq: $req_pack"; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# if we have a version defined, use that too |
169
|
|
|
|
|
|
|
if(defined $req_ver) { |
170
|
|
|
|
|
|
|
$pre_req .= " >= $req_ver"; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
push(@{$self->{requires}}, $pre_req); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# all of these are mandatory. if the value is '1' then it's case sensitive |
177
|
|
|
|
|
|
|
my %req_metadata = ( |
178
|
|
|
|
|
|
|
summary => 0, |
179
|
|
|
|
|
|
|
vendor => 0, |
180
|
|
|
|
|
|
|
group => 0, |
181
|
|
|
|
|
|
|
AutoReqProv => 1 |
182
|
|
|
|
|
|
|
); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
my %metadata; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# nightmarishly complicated! |
187
|
|
|
|
|
|
|
sub MetaData { |
188
|
|
|
|
|
|
|
my $self = shift; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
carp("RPM name already defined") |
191
|
|
|
|
|
|
|
if(defined $_->{name}); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
%metadata = @_; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub Build { |
197
|
|
|
|
|
|
|
my($self) = shift; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
$metadata{requires} = $self->{requires}; |
200
|
|
|
|
|
|
|
$metadata{name} = $self->{name}; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
my $bad_meta; |
203
|
|
|
|
|
|
|
foreach(keys(%req_metadata)) { |
204
|
|
|
|
|
|
|
my $tag = $_; |
205
|
|
|
|
|
|
|
$tag = lc($tag) if($req_metadata{$_} ne '1'); |
206
|
|
|
|
|
|
|
if(!defined $metadata{$tag}) { |
207
|
|
|
|
|
|
|
my $msg = "Undefined mandatory metadata tag '$tag'"; |
208
|
|
|
|
|
|
|
$msg .= ", this tag is case sensitive" |
209
|
|
|
|
|
|
|
if($req_metadata{$_} eq '1'); |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
carp($msg); |
212
|
|
|
|
|
|
|
$bad_meta = 1; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
croak("Fatal error, there's some undefined metadata") if($bad_meta); |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
eval { |
219
|
|
|
|
|
|
|
RPM::Make::execute($self->{name}, $self->{version}, $self->{release}, |
220
|
|
|
|
|
|
|
$self->{arch}, $self->{temp_build_loc}, |
221
|
|
|
|
|
|
|
$self->{build_root}, $self->{build_files}, |
222
|
|
|
|
|
|
|
$self->{doc}, $self->{conf}, $self->{confnoreplace}, |
223
|
|
|
|
|
|
|
\%metadata); |
224
|
|
|
|
|
|
|
}; |
225
|
|
|
|
|
|
|
if($@) { |
226
|
|
|
|
|
|
|
croak($!); |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
return(1); |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub DESTROY { |
233
|
|
|
|
|
|
|
my($self) = shift; |
234
|
|
|
|
|
|
|
rmtree($self->{temp_build_loc}) if($self->{temp_build_loc}); |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
1; |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
__END__ |