-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.pl
177 lines (142 loc) · 3.98 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
#!/usr/bin/perl
use strict;
use warnings;
use Cwd;
use File::Basename;
use File::Which;
use Getopt::Long;
our $VERSION = "1.02";
# An array of relative file paths in which a version number should be updated
my @VERSION_FILES = qw/chrome\\content\\about.xul install.rdf/;
my $bumpVersion = 0;
my $explicitVersion = '';
my $outputFilename = '';
my $outputFolder = "output";
my $outputShortname = "googlebarlite";
GetOptions("bump" => \$bumpVersion,
"output=s" => \$outputFilename,
"version=s" => \$explicitVersion,
"help" => sub { usageMessage() });
print "\nGooglebar Lite Build Script v$VERSION\n";
print "Written by Jonah Bishop\n\n";
my $zipProg = '7z';
my $zipPath = which($zipProg);
if (! defined $zipPath)
{
$zipProg = '7za';
$zipPath = which($zipProg);
if (! defined $zipPath)
{
print "ERROR: Unable to locate 7-zip executable (searched for both '7z' and '7za')!\n";
exit 1;
}
}
print "Building extension...\n";
my $homeDir = getcwd();
if (! -d "$homeDir/$outputFolder")
{
if(! mkdir "$homeDir/$outputFolder")
{
print "ERROR: Failed to create $homeDir/$outputFolder: $!";
exit 1;
}
}
my $versionMajor = 0;
my $versionMinor = 0;
my $versionRev = 0;
scanForVersion();
if ($bumpVersion == 1)
{
# Bump only the versionRev portion if the user wanted to bump
$versionRev++;
updateVersion();
}
elsif ($explicitVersion ne '')
{
grabVersionPieces($explicitVersion);
updateVersion();
}
if (! $outputFilename)
{
$outputFilename = "${outputShortname}_${versionMajor}_${versionMinor}_${versionRev}.xpi";
print " - Output will be written to: $outputFilename\n";
}
# Create the XPI file
print "\nCreating XPI file...\n";
system("$zipProg a -tzip $outputFolder/$outputFilename \@xpizip.txt");
print "\nExtension package created successfully\n";
exit 0;
# ======================================================================
# End Main Script --- Begin Subroutines
# ======================================================================
sub grabVersionPieces
{
my $vs = shift;
my @pieces = split /\./, $vs;
$versionMajor = $pieces[0] || 0;
$versionMinor = $pieces[1] || 0;
$versionRev = $pieces[2] || 0;
}
sub parseVersionFile
{
my $filename = shift;
open my $in, '<', "$filename" or die "Cannot open input ($filename): $!";
my @lines = <$in>;
close $in;
open my $out, '>', "new_$filename" or die "Cannot open output (new_$filename): $!";
foreach my $statement (@lines)
{
# Handle the install.rdf case
$statement =~ s!<em:version>[0-9\.]+</em:version>!<em:version>$versionMajor.$versionMinor.$versionRev</em:version>!;
# Handle the about.xul case
$statement =~ s!value="Version [0-9\.]+"!value="Version $versionMajor.$versionMinor.$versionRev"!;
print $out $statement;
}
close $out;
}
sub scanForVersion
{
print " - Scanning for version string\n";
open my $in, '<', 'install.rdf' or die "Cannot open install.rdf to scan version string: $!";
while (<$in>)
{
if (m!<em:version>([0-9\.]+)</em:version>!)
{
my $vs = $1;
print " Found version string: $vs\n\n";
grabVersionPieces($vs);
last;
}
}
close $in;
}
sub updateVersion
{
foreach my $file (@VERSION_FILES)
{
print "Updating version information in $file\n";
my $dirname = dirname($file);
my $basename = basename($file);
chdir $dirname or die "Cannot change to $dirname: $!";
&parseVersionFile($basename);
print " - Removing $basename\n";
unlink $basename;
print " - Renaming new_$basename\n\n";
rename ("new_$basename", $basename);
chdir $homeDir or die "Cannot change to $homeDir: $!";
}
}
sub usageMessage
{
print <<USAGE;
Options:
--bump
Bumps the revision version portion of the version string (i.e. the third
value: X.Y.Z)
--output <FILENAME>
Explicitly sets the output XPI filename
--version <VERSION>
Explicitly sets the version string to use
USAGE
exit();
}