-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.pl
132 lines (99 loc) · 2.91 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
#!/usr/bin/env perl
use strict;
use warnings;
use File::Path qw(make_path remove_tree);
use File::Spec::Functions qw(catfile);
use File::Copy qw(copy);
use Time::Piece;
use App::FatPacker;
use Archive::Tar;
use IO::Compress::Zip qw(zip $ZipError);
# Clean up after previous build
remove_tree('build', { error => \my $error });
die join "\n", map { join " => ", %$_ } @$error if @$error;
system(qw(perl -c nimbusapp.pl));
die "Compile failed with code $?. Please check above for compile errors.\n" if $?;
make_path('build');
# Pre-process nimbusapp.pl
my %buildInfo = (
DATE => localtime->ymd,
RELEASE => shift // sprintf "DEV.%s", localtime->datetime,
);
{
open my $in, '<:raw', 'nimbusapp.pl';
open my $out, '>:raw', 'build/nimbusapp.pl';
while (<$in>) {
die "Input file contains carriage return at line $." if /\r/;
s/CHANGEME_(\w+)/$buildInfo{$1}/eg;
print $out $_;
}
close $in;
close $out;
}
# Find modules to be packed in the final file
my @modules = ();
{
open my $fh, '<', 'cpanfile' or die $!;
while (<$fh>) {
/^\s*requires\s*(['"])(.+?)\g1/ or next;
push @modules, $2;
}
close $fh;
}
print "Packing with modules: @modules\n";
# Copy modules for packing
chdir 'build';
for my $module (@modules) {
my @parts = split /::/, $module;
my $destFile = pop(@parts) . '.pm';
my $destDir = catfile 'fatlib', @parts;
my $destPath = catfile $destDir, $destFile;
my $srcPath = qx(perldoc -lm $module);
chomp $srcPath;
make_path($destDir);
open my $in, '<:raw', $srcPath or die "Can't open $srcPath: $!";
open my $out, '>:raw', $destPath or die "Can't open $destPath: $!";
my $inPod = 0;
my $size = 0;
while (<$in>) {
if (1) {
last if /^__(END|DATA)__$/;
next if /^\s*#/;
next if /^\s*$/;
$inPod = 1 if /^\s*(=\w+)/;
if ($inPod) {
$inPod = 0 if /=cut/;
next;
}
}
$size += length;
print $out $_;
}
close $in;
close $out;
print "$module => $size\n";
}
# Build and pack final artifacts
{
# system('fatpack file nimbusapp.pl > nimbusapp.packed.pl');
my $packed = App::FatPacker->new->fatpack_file('nimbusapp.pl');
open my $out, '>:raw', 'nimbusapp.packed.pl';
print $out $packed;
}
chmod 0755, 'nimbusapp.packed.pl';
print "\nBuild Complete:\n";
system("$^X ./nimbusapp.packed.pl version");
print "\n";
my $tar = Archive::Tar->new();
$tar->add_files('nimbusapp.packed.pl');
$tar->rename('nimbusapp.packed.pl', 'nimbusapp');
$tar->chmod('nimbusapp', 755);
$tar->write('nimbusapp.tar.gz', COMPRESS_GZIP);
my %zipFiles = (
'../nimbusapp.bat' => 'nimbusapp.bat',
'nimbusapp.packed.pl' => 'nimbusapp.pl'
);
zip [ keys %zipFiles ] => 'nimbusapp.zip',
FilterName => sub { $_ = $zipFiles{$_} }
or die $ZipError;
print "\nPackaging Complete.\n";