toolkit/locales/compare-locales.pl

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 5
michael@0 6 $failure = 0;
michael@0 7
michael@0 8 sub unJAR
michael@0 9 {
michael@0 10 my ($file, $dir) = @_;
michael@0 11
michael@0 12 -d $dir && system("rm -rf $dir");
michael@0 13 system("unzip -q -d $dir $file") && die("Could not unZIP $file");
michael@0 14 }
michael@0 15
michael@0 16 sub readDTD
michael@0 17 {
michael@0 18 my ($file) = @_;
michael@0 19
michael@0 20 open DTD, "<$file" || die ("Couldn't open file $file");
michael@0 21
michael@0 22 local $/ = undef;
michael@0 23 my $contents = <DTD>;
michael@0 24 close DTD;
michael@0 25
michael@0 26 $contents =~ s/<!--.*?-->//gs; # strip SGML comments
michael@0 27
michael@0 28 return $contents =~ /<!ENTITY\s+([\w\.]+)\s+(?:\"[^\"]*\"|\'[^\']*\')\s*>/g;
michael@0 29 }
michael@0 30
michael@0 31 sub compareDTD
michael@0 32 {
michael@0 33 my ($path) = @_;
michael@0 34
michael@0 35 my @entities1 = readDTD("$gSourceDir1/$path");
michael@0 36 my %entities2 = map { $_ => 1 } readDTD("$gSourceDir2/$path");
michael@0 37
michael@0 38 my @extra1;
michael@0 39
michael@0 40 foreach my $entity (@entities1) {
michael@0 41 if (exists $entities2{$entity}) {
michael@0 42 delete $entities2{$entity};
michael@0 43 } else {
michael@0 44 push @extra1, $entity;
michael@0 45 }
michael@0 46 }
michael@0 47
michael@0 48 if (@extra1 or keys %entities2) {
michael@0 49 $failure = 1;
michael@0 50 print "Entities in $path don't match:\n";
michael@0 51 if (@extra1) {
michael@0 52 print " In $gSource1: (add these keys to your localization)\n";
michael@0 53 map { print " $_\n"; } @extra1;
michael@0 54 }
michael@0 55
michael@0 56 if (keys %entities2) {
michael@0 57 print " In $gSource2: (remove these keys from your localization)\n";
michael@0 58 map {print " $_\n"; } keys %entities2;
michael@0 59 }
michael@0 60 print "\n";
michael@0 61 }
michael@0 62 }
michael@0 63
michael@0 64 sub readProperties
michael@0 65 {
michael@0 66 my ($file) = @_;
michael@0 67
michael@0 68 open PROPS, "<$file" || die ("Couldn't open file $file");
michael@0 69
michael@0 70 local $/ = undef;
michael@0 71 my $contents = <PROPS>;
michael@0 72 close PROPS;
michael@0 73
michael@0 74 $contents =~ s/\\$$//gm;
michael@0 75
michael@0 76 return $contents =~ /^\s*([^#!\s\r\n][^=:\r\n]*?)\s*[=:]/gm;
michael@0 77 }
michael@0 78
michael@0 79 sub compareProperties
michael@0 80 {
michael@0 81 my ($path) = @_;
michael@0 82
michael@0 83 my @entities1 = readProperties("$gSourceDir1/$path");
michael@0 84 my %entities2 = map { $_ => 1 } readProperties("$gSourceDir2/$path");
michael@0 85
michael@0 86 my @extra1;
michael@0 87
michael@0 88 foreach my $entity (@entities1) {
michael@0 89 if (exists $entities2{$entity}) {
michael@0 90 delete $entities2{$entity};
michael@0 91 } else {
michael@0 92 # hack to ignore non-fatal region.properties differences
michael@0 93 if ($path !~ /chrome\/browser-region\/region\.properties$/ or
michael@0 94 ($entity !~ /browser\.search\.order\.[1-9]/ and
michael@0 95 $entity !~ /browser\.contentHandlers\.types\.[0-5]/ and
michael@0 96 $entity !~ /gecko\.handlerService\.schemes\./ and
michael@0 97 $entity !~ /gecko\.handlerService\.defaultHandlersVersion/)) {
michael@0 98 push @extra1, $entity;
michael@0 99 }
michael@0 100 }
michael@0 101 }
michael@0 102 # hack to ignore non-fatal region.properties differences
michael@0 103 if ($path =~ /chrome\/browser-region\/region\.properties$/) {
michael@0 104 foreach $entity (keys(%entities2)) {
michael@0 105 if ($entity =~ /browser\.search\.order\.[1-9]/ ||
michael@0 106 $entity =~ /browser\.contentHandlers\.types\.[0-5]/ ||
michael@0 107 $entity =~ /gecko\.handlerService\.schemes\./ ||
michael@0 108 $entity =~ /gecko\.handlerService\.defaultHandlersVersion/) {
michael@0 109 delete $entities2{$entity};
michael@0 110 }
michael@0 111 }
michael@0 112 }
michael@0 113
michael@0 114 if (@extra1 or keys %entities2) {
michael@0 115 $failure = 1;
michael@0 116 print "Properties in $path don't match:\n";
michael@0 117 if (@extra1) {
michael@0 118 print " In $gSource1: (add these to your localization)\n";
michael@0 119 map { print " $_\n"; } @extra1;
michael@0 120 }
michael@0 121
michael@0 122 if (keys %entities2) {
michael@0 123 print " In $gSource2: (remove these from your localization)\n";
michael@0 124 map {print " $_\n"; } keys %entities2;
michael@0 125 }
michael@0 126 print "\n";
michael@0 127 }
michael@0 128 }
michael@0 129
michael@0 130 sub readDefines
michael@0 131 {
michael@0 132 my ($file) = @_;
michael@0 133
michael@0 134 open DEFS, "<$file" || die ("Couldn't open file $file");
michael@0 135
michael@0 136 local $/ = undef;
michael@0 137 my $contents = <DEFS>;
michael@0 138 close DEFS;
michael@0 139
michael@0 140 return $contents =~ /#define\s+(\w+)/gm;
michael@0 141 }
michael@0 142
michael@0 143 sub compareDefines
michael@0 144 {
michael@0 145 my ($path) = @_;
michael@0 146
michael@0 147 my @entities1 = readDefines("$gSourceDir1/$path");
michael@0 148 my %entities2 = map { $_ => 1 } readDefines("$gSourceDir2/$path");
michael@0 149
michael@0 150 my @extra1;
michael@0 151
michael@0 152 foreach my $entity (@entities1) {
michael@0 153 if (exists $entities2{$entity}) {
michael@0 154 delete $entities2{$entity};
michael@0 155 } else {
michael@0 156 push @extra1, $entity;
michael@0 157 }
michael@0 158 }
michael@0 159
michael@0 160 if (@extra1 or keys %entities2) {
michael@0 161 $failure = 1;
michael@0 162 print "Defines in $path don't match:\n";
michael@0 163 if (@extra1) {
michael@0 164 print " In $gSource1: (add these to your localization)\n";
michael@0 165 map { print " $_\n"; } @extra1;
michael@0 166 }
michael@0 167
michael@0 168 if (keys %entities2) {
michael@0 169 print " In $gSource2: (remove these from your localization)\n";
michael@0 170 map {print " $_\n"; } keys %entities2;
michael@0 171 }
michael@0 172 print "\n";
michael@0 173 }
michael@0 174 }
michael@0 175
michael@0 176 sub compareDir
michael@0 177 {
michael@0 178 my ($path) = @_;
michael@0 179
michael@0 180 my (@entries1, %entries2);
michael@0 181
michael@0 182 opendir(DIR1, "$gSourceDir1/$path") ||
michael@0 183 die ("Couldn't list $gSourceDir1/$path");
michael@0 184 @entries1 = grep(!(/^(\.|CVS)/ || /~$/), readdir(DIR1));
michael@0 185 closedir(DIR1);
michael@0 186
michael@0 187 opendir(DIR2, "$gSourceDir2/$path") ||
michael@0 188 die ("Couldn't list $gSourceDir2/$path");
michael@0 189 %entries2 = map { $_ => 1 } grep(!(/^(\.|CVS)/ || /~$/), readdir(DIR2));
michael@0 190 closedir(DIR2);
michael@0 191
michael@0 192 foreach my $file (@entries1) {
michael@0 193 if (exists($entries2{$file})) {
michael@0 194 delete $entries2{$file};
michael@0 195
michael@0 196 if (-d "$gSourceDir1/$path/$file") {
michael@0 197 compareDir("$path/$file");
michael@0 198 } else {
michael@0 199 if ($file =~ /\.dtd$/) {
michael@0 200 compareDTD("$path/$file");
michael@0 201 } elsif ($file =~ /\.inc$/) {
michael@0 202 compareDefines("$path/$file");
michael@0 203 } elsif ($file =~ /\.properties$/) {
michael@0 204 compareProperties("$path/$file");
michael@0 205 } else {
michael@0 206 print "no comparison for $path/$file\n";
michael@0 207 }
michael@0 208 }
michael@0 209 } else {
michael@0 210 push @gSource1Extra, "$path/$file";
michael@0 211 }
michael@0 212 }
michael@0 213
michael@0 214 foreach my $file (keys %entries2) {
michael@0 215 push @gSource2Extra, "$path/$file";
michael@0 216 }
michael@0 217 }
michael@0 218
michael@0 219 local ($gSource1, $gSource2) = @ARGV;
michael@0 220 ($gSource1 && $gSource2) || die("Specify two directories or ZIP files");
michael@0 221
michael@0 222 my ($gSource1IsZIP, $gSource2IsZIP);
michael@0 223 local ($gSourceDir1, $gSourceDir2);
michael@0 224 local (@gSource1Extra, @gSource2Extra);
michael@0 225
michael@0 226 if (-d $gSource1) {
michael@0 227 $gSource1IsZIP = 0;
michael@0 228 $gSourceDir1 = $gSource1;
michael@0 229 } else {
michael@0 230 $gSource1IsZIP = 1;
michael@0 231 $gSourceDir1 = "temp1";
michael@0 232 unJAR($gSource1, $gSourceDir1);
michael@0 233 }
michael@0 234
michael@0 235 if (-d $gSource2) {
michael@0 236 $gSource2IsZIP = 0;
michael@0 237 $gSourceDir2 = $gSource2;
michael@0 238 } else {
michael@0 239 $gSource2IsZIP = 1;
michael@0 240 $gSourceDir2 = "temp2";
michael@0 241 unJAR($gSource2, $gSourceDir2);
michael@0 242 }
michael@0 243
michael@0 244 compareDir(".");
michael@0 245
michael@0 246 if (@gSource1Extra) {
michael@0 247 print "Files in $gSource1 not in $gSource2:\n";
michael@0 248 map { print " $_\n"; } @gSource1Extra;
michael@0 249 print "\n";
michael@0 250 }
michael@0 251
michael@0 252 if (@gSource2Extra) {
michael@0 253 print "Files in $gSource2 not in $gSource1:\n";
michael@0 254 map { print " $_\n"; } @gSource2Extra;
michael@0 255 print "\n";
michael@0 256 }
michael@0 257
michael@0 258 $gSource1IsZIP && system("rm -rf $gSourceDir1");
michael@0 259 $gSource2IsZIP && system("rm -rf $gSourceDir2");
michael@0 260
michael@0 261 exit $failure;

mercurial