Skip to content

Latest commit

 

History

History
executable file
·
374 lines (329 loc) · 11.3 KB

version_win.pl

File metadata and controls

executable file
·
374 lines (329 loc) · 11.3 KB
 
May 21, 2012
May 21, 2012
3
4
5
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Mar 26, 2002
Mar 26, 2002
7
#use diagnostics;
Nov 8, 2002
Nov 8, 2002
9
10
11
12
my $dir = $0;
$dir =~ s/[^\/]*$//;
push(@INC, "$dir");
require "Moz/Milestone.pm";
13
14
use Getopt::Long;
use Getopt::Std;
Jan 14, 2008
Jan 14, 2008
15
16
17
18
19
20
21
use POSIX;
# Calculate the number of days since Jan. 1, 2000 from a buildid string
sub daysFromBuildID
{
my ($buildid,) = @_;
Aug 7, 2008
Aug 7, 2008
22
my ($y, $m, $d, $h) = ($buildid =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/);
Jan 14, 2008
Jan 14, 2008
23
24
25
$d || die("Unrecognized buildid string.");
my $secondstodays = 60 * 60 * 24;
Aug 16, 2009
Aug 16, 2009
26
27
28
return sprintf("%d",
(POSIX::mktime(00, 00, 00, $d, $m - 1, $y - 1900) -
POSIX::mktime(00, 00, 00, 01, 00, 100)) / $secondstodays);
Jan 14, 2008
Jan 14, 2008
29
}
30
31
32
33
34
#Creates version resource file
#Paramaters are passed on the command line:
Jan 14, 2008
Jan 14, 2008
35
#Example: -MODNAME nsToolkitCompsModule -DEBUG=1
36
37
38
39
40
41
42
43
44
45
# DEBUG - Mozilla's global debug variable - tells if its debug version
# OFFICIAL - tells Mozilla is building a milestone or nightly
# MSTONE - tells which milestone is being built;
# OBJDIR - Holds the object directory;
# MODNAME - tells what the name of the module is like nsBMPModule
# DEPTH - Holds the path to the root obj dir
# TOPSRCDIR - Holds the path to the root mozilla dir
# SRCDIR - Holds module.ver and source
# BINARY - Holds the name of the binary file
Apr 10, 2005
Apr 10, 2005
46
# DISPNAME - Holds the display name of the built application
May 5, 2009
May 5, 2009
47
# APPVERSION - Holds the version string of the built application
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
# RCINCLUDE - Holds the name of the RC File to include or ""
# QUIET - Turns off output
#Description and Comment come from module.ver
#Bug 23560
#http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/rc_7x2d.asp
#Get next .ver file entry
sub getNextEntry
{
while (<VERFILE>)
{
my $mline = $_;
($mline) = split(/#/,$mline);
my ($entry, $value)=split(/=/,$mline,2);
if (defined($entry))
{
if (defined($value))
{
$entry =~ s/^\s*(.*?)\s*$/$1/;
$value =~ s/^\s*(.*?)\s*$/$1/;
return ($entry,$value);
}
}
}
return undef;
}
Aug 8, 2009
Aug 8, 2009
76
my ($quiet,$objdir,$debug,$official,$milestone,$buildid,$module,$binary,$depth,$rcinclude,$srcdir,$fileversion,$productversion);
77
78
79
80
81
82
83
GetOptions( "QUIET" => \$quiet,
"DEBUG=s" => \$debug,
"OFFICIAL=s" => \$official,
"MSTONE=s" => \$milestone,
"MODNAME=s" => \$module,
"BINARY=s" => \$binary,
Apr 10, 2005
Apr 10, 2005
84
"DISPNAME=s" => \$displayname,
May 5, 2009
May 5, 2009
85
"APPVERSION=s" => \$appversion,
86
87
88
89
"SRCDIR=s" => \$srcdir,
"TOPSRCDIR=s" => \$topsrcdir,
"DEPTH=s" => \$depth,
"RCINCLUDE=s" => \$rcinclude,
Aug 8, 2009
Aug 8, 2009
90
"OBJDIR=s" => \$objdir);
91
92
93
94
95
if (!defined($debug)) {$debug="";}
if (!defined($official)) {$official="";}
if (!defined($milestone)) {$milestone="";}
if (!defined($module)) {$module="";}
if (!defined($binary)) {$binary="";}
Apr 10, 2005
Apr 10, 2005
96
if (!defined($displayname)) {$displayname="Mozilla";}
May 5, 2009
May 5, 2009
97
if (!defined($appversion)) {$appversion=$milestone;}
98
99
100
101
102
103
104
if (!defined($depth)) {$depth=".";}
if (!defined($rcinclude)) {$rcinclude="";}
if (!defined($objdir)) {$objdir=".";}
if (!defined($srcdir)) {$srcdir=".";}
if (!defined($topsrcdir)) {$topsrcdir=".";}
my $mfversion = "Personal";
my $mpversion = "Personal";
Jan 14, 2008
Jan 14, 2008
105
my @fileflags = ("0");
106
107
108
109
110
111
112
113
114
115
my $comment="";
my $description="";
if (!defined($module))
{
$module = $binary;
($module) = split(/\./,$module);
}
my $bufferstr=" ";
Nov 11, 2002
Nov 11, 2002
116
my $MILESTONE_FILE = "$topsrcdir/config/milestone.txt";
Feb 11, 2016
Feb 11, 2016
117
my $BUILDID_FILE = "$depth/buildid.h";
Nov 11, 2002
Nov 11, 2002
118
119
120
121
122
123
124
125
126
127
128
129
#Read module.ver file
#Version file overrides for WIN32:
#WIN32_MODULE_COMMENT
#WIN32_MODULE_DESCRIPTION
#WIN32_MODULE_FILEVERSION
#WIN32_MODULE_COMPANYNAME
#WIN32_MODULE_FILEVERSION_STRING
#WIN32_MODULE_NAME
#WIN32_MODULE_COPYRIGHT
#WIN32_MODULE_TRADEMARKS
#WIN32_MODULE_ORIGINAL_FILENAME
Oct 1, 2002
Oct 1, 2002
130
#WIN32_MODULE_PRODUCTNAME
Jul 24, 2005
Jul 24, 2005
131
132
#WIN32_MODULE_PRODUCTVERSION
#WIN32_MODULE_PRODUCTVERSION_STRING
133
134
135
136
137
138
139
140
141
142
143
#Override values obtained from the .ver file
my $override_comment;
my $override_description;
my $override_fileversion;
my $override_company;
my $override_mfversion;
my $override_module;
my $override_copyright;
my $override_trademarks;
my $override_filename;
Oct 1, 2002
Oct 1, 2002
144
my $override_productname;
Jul 24, 2005
Jul 24, 2005
145
146
my $override_productversion;
my $override_mpversion;
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
if (open(VERFILE, "<$srcdir/module.ver"))
{
my ($a,$b) = getNextEntry();
while (defined($a))
{
if ($a eq "WIN32_MODULE_COMMENT") { $override_comment = $b; }
if ($a eq "WIN32_MODULE_DESCRIPTION") { $override_description = $b; }
if ($a eq "WIN32_MODULE_FILEVERSION") { $override_fileversion = $b; }
if ($a eq "WIN32_MODULE_COMPANYNAME") { $override_company = $b; }
if ($a eq "WIN32_MODULE_FILEVERSION_STRING") { $override_mfversion = $b; }
if ($a eq "WIN32_MODULE_NAME") { $override_module = $b; }
if ($a eq "WIN32_MODULE_COPYRIGHT") { $override_copyright = $b; }
if ($a eq "WIN32_MODULE_TRADEMARKS") { $override_trademarks = $b; }
if ($a eq "WIN32_MODULE_ORIGINAL_FILENAME") { $override_filename = $b; }
Oct 1, 2002
Oct 1, 2002
162
if ($a eq "WIN32_MODULE_PRODUCTNAME") { $override_productname = $b; }
Jul 24, 2005
Jul 24, 2005
163
164
if ($a eq "WIN32_MODULE_PRODUCTVERSION") { $override_productversion = $b; }
if ($a eq "WIN32_MODULE_PRODUCTVERSION_STRING") { $override_mpversion = $b; }
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
($a,$b) = getNextEntry();
}
close(VERFILE)
}
else
{
if (!$quiet || $quiet ne "1") { print "$bufferstr" . "WARNING: No module.ver file included ($module, $binary). Default values used\n"; }
}
#Get rid of trailing and leading whitespace
$debug =~ s/^\s*(.*)\s*$/$1/;
$comment =~ s/^\s*(.*)\s*$/$1/;
$official =~ s/^\s*(.*)\s*$/$1/;
$milestone =~ s/^\s*(.*)\s*$/$1/;
$description =~ s/^\s*(.*)\s*$/$1/;
$module =~ s/^\s*(.*)\s*$/$1/;
$depth =~ s/^\s*(.*)\s*$/$1/;
$binary =~ s/^\s*(.*)\s*$/$1/;
Apr 10, 2005
Apr 10, 2005
182
$displayname =~ s/^\s*(.*)\s*$/$1/;
Jan 14, 2008
Jan 14, 2008
184
185
open(BUILDID, "<", $BUILDID_FILE) || die("Couldn't open buildid file: $BUILDID_FILE");
$buildid = <BUILDID>;
Feb 11, 2016
Feb 11, 2016
186
$buildid =~ s/^#define MOZ_BUILDID\s+(\S+)\s*$/$1/;
Jan 14, 2008
Jan 14, 2008
187
188
189
190
191
192
193
194
195
close BUILDID;
my $daycount = daysFromBuildID($buildid);
if ($milestone eq "") {
$milestone = Moz::Milestone::getOfficialMilestone($MILESTONE_FILE);
}
$mfversion = $mpversion = $milestone;
May 5, 2009
May 5, 2009
196
197
198
if ($appversion eq "") {
$appversion = $milestone;
}
Jan 14, 2008
Jan 14, 2008
199
200
201
if ($debug eq "1")
{
Jan 14, 2008
Jan 14, 2008
202
push @fileflags, "VS_FF_DEBUG";
203
204
205
206
$mpversion .= " Debug";
$mfversion .= " Debug";
}
Jan 14, 2008
Jan 14, 2008
207
208
209
if ($official ne "1") {
push @fileflags, "VS_FF_PRIVATEBUILD";
}
Jan 14, 2008
Jan 14, 2008
211
212
213
if ($milestone =~ /[a-z]/) {
push @fileflags, "VS_FF_PRERELEASE";
}
Jan 14, 2008
Jan 14, 2008
215
216
217
218
219
220
221
my @mstone = split(/\./,$milestone);
$mstone[1] =~s/\D.*$//;
if (!$mstone[2]) {
$mstone[2] = "0";
}
else {
$mstone[2] =~s/\D.*$//;
Jan 14, 2008
Jan 14, 2008
223
$fileversion = $productversion="$mstone[0],$mstone[1],$mstone[2],$daycount";
May 5, 2009
May 5, 2009
225
226
227
228
229
230
231
232
233
234
235
236
my @appver = split(/\./,$appversion);
for ($j = 1; $j < 4; $j++)
{
if (!$appver[$j]) {
$appver[$j] = "0";
}
else {
$appver[$j] =~s/\D.*$//;
}
}
my $winappversion = "$appver[0],$appver[1],$appver[2],$appver[3]";
Sep 20, 2012
Sep 20, 2012
237
my $copyright = "License: MPL 2";
Jan 22, 2004
Jan 22, 2004
238
239
my $company = "Mozilla Foundation";
my $trademarks = "Mozilla";
Apr 10, 2005
Apr 10, 2005
240
my $productname = $displayname;
Apr 10, 2005
Apr 10, 2005
243
244
if (defined($override_comment)){$override_comment =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $comment=$override_comment;}
if (defined($override_description)){$override_description =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $description=$override_description;}
May 5, 2009
May 5, 2009
245
246
if (defined($override_fileversion)){$override_fileversion =~ s/\@MOZ_APP_WINVERSION\@/$winappversion/g; $fileversion=$override_fileversion;}
if (defined($override_mfversion)){$override_mfversion =~ s/\@MOZ_APP_VERSION\@/$appversion/g; $mfversion=$override_mfversion;}
247
if (defined($override_company)){$company=$override_company;}
Apr 10, 2005
Apr 10, 2005
248
if (defined($override_module)){$override_module =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $module=$override_module;}
Jan 14, 2008
Jan 14, 2008
249
if (defined($override_copyright)){$override_copyright =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $copyright=$override_copyright;}
Apr 10, 2005
Apr 10, 2005
250
if (defined($override_trademarks)){$override_trademarks =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $trademarks=$override_trademarks;}
251
if (defined($override_filename)){$binary=$override_filename;}
Apr 10, 2005
Apr 10, 2005
252
if (defined($override_productname)){$override_productname =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g; $productname=$override_productname;}
May 5, 2009
May 5, 2009
253
254
if (defined($override_productversion)){$override_productversion =~ s/\@MOZ_APP_WINVERSION\@/$winappversion/g; $productversion=$override_productversion;}
if (defined($override_mpversion)){$override_mpversion =~ s/\@MOZ_APP_VERSION\@/$appversion/g; $mpversion=$override_mpversion;}
255
256
257
258
259
260
#Override section
open(RCFILE, ">$objdir/module.rc") || die("Can't edit module.rc - It must be locked.\n");
print RCFILE qq{
May 29, 2012
May 29, 2012
261
262
263
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#include<winver.h>
// Note: if you contain versioning information in an included
// RC script, it will be discarded
// Use module.ver to explicitly set these values
// Do not edit this file. Changes won't affect the build.
};
my $versionlevel=0;
my $insideversion=0;
if (open(RCINCLUDE, "<$rcinclude"))
{
print RCFILE "// From included resource $rcinclude\n";
Aug 19, 2002
Aug 19, 2002
280
# my $mstring="";
281
282
while (<RCINCLUDE>)
{
Apr 10, 2005
Apr 10, 2005
283
284
$_ =~ s/\@MOZ_APP_DISPLAYNAME\@/$displayname/g;
print RCFILE $_;
Aug 19, 2002
Aug 19, 2002
285
286
287
# my $instr=$_;
# chomp($instr);
# $mstring .= "$instr\;";
288
289
}
close(RCINCLUDE);
Aug 19, 2002
Aug 19, 2002
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# $mstring =~ s/\/\*.*\*\///g;
# my @mlines = split(/\;/,$mstring);
# for(@mlines)
# {
# my ($nocomment)=split(/\/\//,$_);
# if (defined($nocomment) && $nocomment ne "")
# {
# my ($firststring,$secondstring) = split(/\s+/,$nocomment);
# if (!defined($firststring)) {$firststring="";}
# if (!defined($secondstring)) {$secondstring="";}
# if ($secondstring eq "VERSIONINFO")
# {
#if (!$quiet || $quiet ne "1") {
# print "$bufferstr" . "WARNING: Included RC file ($rcinclude, $module, $binary)\n";
# print "$bufferstr" . "WARNING: contains versioning information that will be discarded\n";
# print "$bufferstr" . "WARNING: Remove it and use relevant overrides (in module.ver)\n";
#}
# $versionlevel = 0;
# $insideversion = 1;
# }
# if ($firststring eq "BEGIN") { $versionlevel++; }
# if ($secondstring eq "END")
# {
# $versionlevel--;
# if ($insideversion==1 && $versionlevel==0) {$versionlevel=0;}
# }
# my $includecheck = $firststring . $secondstring;
# $includecheck =~ s/<|>/"/g;
# $includecheck = lc($includecheck);
# if ($includecheck ne "#include\"winver.h\"")
# {
# if ($insideversion == 0 && $versionlevel == 0)
# {
# print RCFILE "$nocomment\n";
# }
# }
# }
# }
Jan 14, 2008
Jan 14, 2008
331
332
my $fileflags = join(' | ', @fileflags);
333
334
335
336
337
338
339
340
341
print RCFILE qq{
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
1 VERSIONINFO
Jan 14, 2008
Jan 14, 2008
342
FILEVERSION $fileversion
343
344
345
PRODUCTVERSION $productversion
FILEFLAGSMASK 0x3fL
FILEFLAGS $fileflags
Aug 8, 2009
Aug 8, 2009
346
FILEOS VOS__WINDOWS32
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "Comments", "$comment"
VALUE "LegalCopyright", "$copyright"
VALUE "CompanyName", "$company"
VALUE "FileDescription", "$description"
VALUE "FileVersion", "$mfversion"
VALUE "ProductVersion", "$mpversion"
VALUE "InternalName", "$module"
VALUE "LegalTrademarks", "$trademarks"
VALUE "OriginalFilename", "$binary"
Oct 1, 2002
Oct 1, 2002
363
VALUE "ProductName", "$productname"
Jan 14, 2008
Jan 14, 2008
364
VALUE "BuildID", "$buildid"
365
366
367
368
369
370
371
372
373
374
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0, 1200
END
END
};
close(RCFILE);