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