-
Notifications
You must be signed in to change notification settings - Fork 5
/
Build.PL
282 lines (222 loc) · 7.33 KB
/
Build.PL
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/perl
use strict;
use warnings;
use Module::Build;
my $class = Module::Build->subclass(
class => 'Module::Build::VirtConvert',
code => <<'SUBCLASS' );
__PACKAGE__->add_property('confdoc_files');
__PACKAGE__->add_property('syntaxcheck_exclude');
# Define a 'po' action which runs all the make targets under po/
sub ACTION_po
{
my $self = shift;
system($self->config('make'), '-C', 'po', 'pot', 'update-po') == 0
or return 1;
}
# Generate locale files and install them to blib/locale
sub process_locale_files
{
my $self = shift;
# Make them first
$self->log_info("process_locale_files\n");
system($self->config('make'), '-C', 'po', 'install',
'LOCALEDIR=../blib/locale') == 0
or die(); # We need to die() here because process_foo_files return isn't
# checked.
}
# Remove the .pl extension from installed scripts
sub process_script_files
{
my $self = shift;
# Run the regular process_script_files action
$self->SUPER::process_script_files();
foreach my $script (<blib/script/*>) {
if($script =~ /^(.*)\.pl$/) {
unless(rename($script, $1)) {
$self->log_info("rename $script to $1 failed: $1\n");
die(); # Return isn't checked
}
}
}
}
# Also process confdoc files
sub process_confdoc_files
{
my $self = shift;
# The following substantially cut/paste from
# Module::Build::Base->manify_bin_pods
my $mandir = File::Spec->catdir($self->blib(), 'confdoc' );
File::Path::mkpath($mandir, 0, oct(777));
require Pod::Man;
foreach my $pod (@{$self->confdoc_files()}) {
# Pod::Simple based parsers only support one document per instance.
# This is expected to change in a future version (Pod::Simple > 3.03).
my $parser = Pod::Man->new( section => 5 ); # config goes in section 5
my (undef, undef, $manpage) = File::Spec->splitpath($pod);
$manpage =~ s/\.pod\z//i;
$manpage .= '.5';
my $outfile = File::Spec->catfile($mandir, $manpage);
next if $self->up_to_date( $pod, $outfile );
$self->log_info("Manifying $pod -> $outfile\n");
$parser->parse_from_file( $pod, $outfile );
}
}
# Add syntaxcheck target
sub ACTION_syntaxcheck
{
my $self = shift;
# Populate %exclude with files we won't syntax check
my %excludes;
# Glob expand syntaxcheck_excludes into %excludes
if(defined($self->syntaxcheck_exclude())) {
foreach my $exclude (@{$self->syntaxcheck_exclude()}) {
foreach my $match (glob($exclude)) {
$excludes{$match} = 1;
}
}
}
my $error = 0;
# Check for trailing whitespace in all files in the manifest
require ExtUtils::Manifest;
foreach my $file (keys(%{ExtUtils::Manifest::maniread()})) {
# Skip file if it's excluded
next if($excludes{$file});
my $fh;
unless(open($fh, '<', $file)) {
$self->log_info("Unable to read manifest file $file: $!\n");
return 1;
}
# Check for leading tabs by default
my $checktabs = 1;
# Don't check for leading tabs in Makefiles
my (undef, undef, $name) = File::Spec->splitpath($file);
$checktabs = 0 if($name =~ /^Makefile(\..*)?$/);
while(<$fh>) {
if(/\s\n$/) {
$self->log_info("$file: trailing whitespace on line $.\n");
$error = 1;
}
if($checktabs && /^\s*\t/) {
$self->log_info("$file: indentation uses tabs on line $.\n");
$error = 1;
}
}
}
return $error;
}
# Add changelog target
sub ACTION_changelog
{
my $self = shift;
# Check that this is a git repository
unless(-d '.git') {
$self->log_info('ChangeLog can only be generated from a git '.
"repository\n");
return 1;
}
unless(system("git", "submodule", "init") == 0) {
$self->log_info("Failed to initialise git2cl submodule: $@\n");
return 1;
}
unless(system("git", "submodule", "update") == 0) {
$self->log_info("Failed to update git2cl submodule: $@\n");
return 1;
}
my $git2cl;
unless(open($git2cl, '-|', './git2cl/git2cl')) {
$self->log_info("Failed to execute git2cl: $!");
return 1;
}
$self->log_info("Creating ChangeLog\n");
my $changelog;
unless(open($changelog, '>', 'ChangeLog')) {
$self->log_info("Failed to open ChangeLog for writing: $!\n");
return 1;
}
while(<$git2cl>) {
# Replace leading tabs with spaces
s/^(\t+)/' ' x (length($1) * 8)/e;
# Remove trailing whitespace
s/\s+$//;
# Write the output to the ChangeLog
print $changelog $_."\n";
}
return 0;
}
# Create all generated files
sub ACTION_generated
{
my $self = shift;
# Changelog
$self->depends_on('changelog') == 0 or return 1;
# Runs .PL files to generate spec files
$self->depends_on('code') == 0 or return 1;
my $version = $self->{properties}->{dist_version};
$version =~ /^v(.*)$/ and $version = $1;
# Write p2v/image-builder/version.ks
my $kspath = "p2v/image-builder/version.ks";
$self->log_info("Creating $kspath\n");
my $ks;
unless(open($ks, '>', $kspath)) {
$self->log_info("Failed to open $kspath for writing: $!\n");
return 1;
}
print $ks "VERSION=$version\n";
close($ks) or return 1;
return 0;
}
# Include version.ks in p2v-image-builder in dist
sub ACTION_dist
{
my $self = shift;
# Ensure we can include all generated flies
$self->depends_on('generated') == 0 or return 1;
return $self->SUPER::ACTION_dist;
}
# Make Build test depend on distmeta so syntax test succeeds
sub ACTION_test
{
my $self = shift;
# Ensure we can include all generated flies
$self->depends_on('generated') == 0 or return 1;
# Ensure distmeta runs first
$self->depends_on('distmeta') == 0 or return 1;
# Run the regular test action
return $self->SUPER::ACTION_test;
}
# Display the version number
sub ACTION_version
{
my $self = shift;
my $version = $self->{properties}->{dist_version};
$version =~ /^v(.*)$/ and $version = $1;
print "$version\n";
return 0;
}
SUBCLASS
my $build = $class->new (
configure_requires => {
'Module::Build' => 0.36
},
license => 'gpl',
dist_name => 'virt-v2v',
dist_version_from => 'lib/Sys/VirtConvert.pm',
confdoc_files => [ 'v2v/virt-v2v.conf.pod' ],
install_path => { 'locale' => '/usr/local/share/locale' },
script_files => [ 'v2v/virt-v2v.pl', 'p2v/server/virt-p2v-server.pl' ],
meta_add => {
resources => {
license => "http://www.gnu.org/licenses/gpl.html",
homepage => "http://people.redhat.com/mbooth/virt-v2v/",
repository => "git://git.fedorahosted.org/virt-v2v.git",
MailingList => "http://www.redhat.com/mailman/listinfo/libguestfs",
},
},
syntaxcheck_exclude => [ "COPYING", "COPYING.LIB", "README-NLS",
"windows/rhsrvany.exe", "po/*.po" ],
PL_files => [ 'virt-v2v.spec.PL', 'rubygem-virt-p2v.spec.PL' ],
);
$build->add_build_element('confdoc');
$build->add_build_element('locale');
$build->create_build_script();