michael@0: #!/usr/bin/perl -w michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: $failure = 0; michael@0: michael@0: sub unJAR michael@0: { michael@0: my ($file, $dir) = @_; michael@0: michael@0: -d $dir && system("rm -rf $dir"); michael@0: system("unzip -q -d $dir $file") && die("Could not unZIP $file"); michael@0: } michael@0: michael@0: sub readDTD michael@0: { michael@0: my ($file) = @_; michael@0: michael@0: open DTD, "<$file" || die ("Couldn't open file $file"); michael@0: michael@0: local $/ = undef; michael@0: my $contents = ; michael@0: close DTD; michael@0: michael@0: $contents =~ s///gs; # strip SGML comments michael@0: michael@0: return $contents =~ //g; michael@0: } michael@0: michael@0: sub compareDTD michael@0: { michael@0: my ($path) = @_; michael@0: michael@0: my @entities1 = readDTD("$gSourceDir1/$path"); michael@0: my %entities2 = map { $_ => 1 } readDTD("$gSourceDir2/$path"); michael@0: michael@0: my @extra1; michael@0: michael@0: foreach my $entity (@entities1) { michael@0: if (exists $entities2{$entity}) { michael@0: delete $entities2{$entity}; michael@0: } else { michael@0: push @extra1, $entity; michael@0: } michael@0: } michael@0: michael@0: if (@extra1 or keys %entities2) { michael@0: $failure = 1; michael@0: print "Entities in $path don't match:\n"; michael@0: if (@extra1) { michael@0: print " In $gSource1: (add these keys to your localization)\n"; michael@0: map { print " $_\n"; } @extra1; michael@0: } michael@0: michael@0: if (keys %entities2) { michael@0: print " In $gSource2: (remove these keys from your localization)\n"; michael@0: map {print " $_\n"; } keys %entities2; michael@0: } michael@0: print "\n"; michael@0: } michael@0: } michael@0: michael@0: sub readProperties michael@0: { michael@0: my ($file) = @_; michael@0: michael@0: open PROPS, "<$file" || die ("Couldn't open file $file"); michael@0: michael@0: local $/ = undef; michael@0: my $contents = ; michael@0: close PROPS; michael@0: michael@0: $contents =~ s/\\$$//gm; michael@0: michael@0: return $contents =~ /^\s*([^#!\s\r\n][^=:\r\n]*?)\s*[=:]/gm; michael@0: } michael@0: michael@0: sub compareProperties michael@0: { michael@0: my ($path) = @_; michael@0: michael@0: my @entities1 = readProperties("$gSourceDir1/$path"); michael@0: my %entities2 = map { $_ => 1 } readProperties("$gSourceDir2/$path"); michael@0: michael@0: my @extra1; michael@0: michael@0: foreach my $entity (@entities1) { michael@0: if (exists $entities2{$entity}) { michael@0: delete $entities2{$entity}; michael@0: } else { michael@0: # hack to ignore non-fatal region.properties differences michael@0: if ($path !~ /chrome\/browser-region\/region\.properties$/ or michael@0: ($entity !~ /browser\.search\.order\.[1-9]/ and michael@0: $entity !~ /browser\.contentHandlers\.types\.[0-5]/ and michael@0: $entity !~ /gecko\.handlerService\.schemes\./ and michael@0: $entity !~ /gecko\.handlerService\.defaultHandlersVersion/)) { michael@0: push @extra1, $entity; michael@0: } michael@0: } michael@0: } michael@0: # hack to ignore non-fatal region.properties differences michael@0: if ($path =~ /chrome\/browser-region\/region\.properties$/) { michael@0: foreach $entity (keys(%entities2)) { michael@0: if ($entity =~ /browser\.search\.order\.[1-9]/ || michael@0: $entity =~ /browser\.contentHandlers\.types\.[0-5]/ || michael@0: $entity =~ /gecko\.handlerService\.schemes\./ || michael@0: $entity =~ /gecko\.handlerService\.defaultHandlersVersion/) { michael@0: delete $entities2{$entity}; michael@0: } michael@0: } michael@0: } michael@0: michael@0: if (@extra1 or keys %entities2) { michael@0: $failure = 1; michael@0: print "Properties in $path don't match:\n"; michael@0: if (@extra1) { michael@0: print " In $gSource1: (add these to your localization)\n"; michael@0: map { print " $_\n"; } @extra1; michael@0: } michael@0: michael@0: if (keys %entities2) { michael@0: print " In $gSource2: (remove these from your localization)\n"; michael@0: map {print " $_\n"; } keys %entities2; michael@0: } michael@0: print "\n"; michael@0: } michael@0: } michael@0: michael@0: sub readDefines michael@0: { michael@0: my ($file) = @_; michael@0: michael@0: open DEFS, "<$file" || die ("Couldn't open file $file"); michael@0: michael@0: local $/ = undef; michael@0: my $contents = ; michael@0: close DEFS; michael@0: michael@0: return $contents =~ /#define\s+(\w+)/gm; michael@0: } michael@0: michael@0: sub compareDefines michael@0: { michael@0: my ($path) = @_; michael@0: michael@0: my @entities1 = readDefines("$gSourceDir1/$path"); michael@0: my %entities2 = map { $_ => 1 } readDefines("$gSourceDir2/$path"); michael@0: michael@0: my @extra1; michael@0: michael@0: foreach my $entity (@entities1) { michael@0: if (exists $entities2{$entity}) { michael@0: delete $entities2{$entity}; michael@0: } else { michael@0: push @extra1, $entity; michael@0: } michael@0: } michael@0: michael@0: if (@extra1 or keys %entities2) { michael@0: $failure = 1; michael@0: print "Defines in $path don't match:\n"; michael@0: if (@extra1) { michael@0: print " In $gSource1: (add these to your localization)\n"; michael@0: map { print " $_\n"; } @extra1; michael@0: } michael@0: michael@0: if (keys %entities2) { michael@0: print " In $gSource2: (remove these from your localization)\n"; michael@0: map {print " $_\n"; } keys %entities2; michael@0: } michael@0: print "\n"; michael@0: } michael@0: } michael@0: michael@0: sub compareDir michael@0: { michael@0: my ($path) = @_; michael@0: michael@0: my (@entries1, %entries2); michael@0: michael@0: opendir(DIR1, "$gSourceDir1/$path") || michael@0: die ("Couldn't list $gSourceDir1/$path"); michael@0: @entries1 = grep(!(/^(\.|CVS)/ || /~$/), readdir(DIR1)); michael@0: closedir(DIR1); michael@0: michael@0: opendir(DIR2, "$gSourceDir2/$path") || michael@0: die ("Couldn't list $gSourceDir2/$path"); michael@0: %entries2 = map { $_ => 1 } grep(!(/^(\.|CVS)/ || /~$/), readdir(DIR2)); michael@0: closedir(DIR2); michael@0: michael@0: foreach my $file (@entries1) { michael@0: if (exists($entries2{$file})) { michael@0: delete $entries2{$file}; michael@0: michael@0: if (-d "$gSourceDir1/$path/$file") { michael@0: compareDir("$path/$file"); michael@0: } else { michael@0: if ($file =~ /\.dtd$/) { michael@0: compareDTD("$path/$file"); michael@0: } elsif ($file =~ /\.inc$/) { michael@0: compareDefines("$path/$file"); michael@0: } elsif ($file =~ /\.properties$/) { michael@0: compareProperties("$path/$file"); michael@0: } else { michael@0: print "no comparison for $path/$file\n"; michael@0: } michael@0: } michael@0: } else { michael@0: push @gSource1Extra, "$path/$file"; michael@0: } michael@0: } michael@0: michael@0: foreach my $file (keys %entries2) { michael@0: push @gSource2Extra, "$path/$file"; michael@0: } michael@0: } michael@0: michael@0: local ($gSource1, $gSource2) = @ARGV; michael@0: ($gSource1 && $gSource2) || die("Specify two directories or ZIP files"); michael@0: michael@0: my ($gSource1IsZIP, $gSource2IsZIP); michael@0: local ($gSourceDir1, $gSourceDir2); michael@0: local (@gSource1Extra, @gSource2Extra); michael@0: michael@0: if (-d $gSource1) { michael@0: $gSource1IsZIP = 0; michael@0: $gSourceDir1 = $gSource1; michael@0: } else { michael@0: $gSource1IsZIP = 1; michael@0: $gSourceDir1 = "temp1"; michael@0: unJAR($gSource1, $gSourceDir1); michael@0: } michael@0: michael@0: if (-d $gSource2) { michael@0: $gSource2IsZIP = 0; michael@0: $gSourceDir2 = $gSource2; michael@0: } else { michael@0: $gSource2IsZIP = 1; michael@0: $gSourceDir2 = "temp2"; michael@0: unJAR($gSource2, $gSourceDir2); michael@0: } michael@0: michael@0: compareDir("."); michael@0: michael@0: if (@gSource1Extra) { michael@0: print "Files in $gSource1 not in $gSource2:\n"; michael@0: map { print " $_\n"; } @gSource1Extra; michael@0: print "\n"; michael@0: } michael@0: michael@0: if (@gSource2Extra) { michael@0: print "Files in $gSource2 not in $gSource1:\n"; michael@0: map { print " $_\n"; } @gSource2Extra; michael@0: print "\n"; michael@0: } michael@0: michael@0: $gSource1IsZIP && system("rm -rf $gSourceDir1"); michael@0: $gSource2IsZIP && system("rm -rf $gSourceDir2"); michael@0: michael@0: exit $failure;