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