- Revision
- 153976
- Author
- [email protected]
- Date
- 2013-08-12 22:53:05 -0700 (Mon, 12 Aug 2013)
Log Message
extract-localizable-strings doesn't know how to verify an existing strings file
https://bugs.webkit.org/show_bug.cgi?id=119704
Reviewed by Darin Adler.
* Scripts/extract-localizable-strings: Added an --exceptions option for specifying the
exceptions file, changing the way “no exceptions file” is expressed from passing “-” as the
exceptions file name to omitting the --exceptions option. Added a --skip option, changing
the way directories to skip are specified from prefixing the directory with a “-” to
specifying it with --skip.
Finally, added a --verify option. When specified, the strings file is not written to, but
instead read in and checked for consistency with the comments, keys and values derived from
the source files and the exceptions file. Missing keys, unused keys, mismatching values and
mismatching comments are reported as errors.
* Scripts/update-webkit-localizable-strings: Updated for the new way of specifying
directories to skip and no exceptions file.
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (153975 => 153976)
--- trunk/Tools/ChangeLog 2013-08-13 05:48:32 UTC (rev 153975)
+++ trunk/Tools/ChangeLog 2013-08-13 05:53:05 UTC (rev 153976)
@@ -1,3 +1,22 @@
+2013-08-12 Dan Bernstein <[email protected]>
+
+ extract-localizable-strings doesn't know how to verify an existing strings file
+ https://bugs.webkit.org/show_bug.cgi?id=119704
+
+ Reviewed by Darin Adler.
+
+ * Scripts/extract-localizable-strings: Added an --exceptions option for specifying the
+ exceptions file, changing the way “no exceptions file” is expressed from passing “-” as the
+ exceptions file name to omitting the --exceptions option. Added a --skip option, changing
+ the way directories to skip are specified from prefixing the directory with a “-” to
+ specifying it with --skip.
+ Finally, added a --verify option. When specified, the strings file is not written to, but
+ instead read in and checked for consistency with the comments, keys and values derived from
+ the source files and the exceptions file. Missing keys, unused keys, mismatching values and
+ mismatching comments are reported as errors.
+ * Scripts/update-webkit-localizable-strings: Updated for the new way of specifying
+ directories to skip and no exceptions file.
+
2013-08-12 Alexey Proskuryakov <[email protected]>
http/tests/security/sandboxed-iframe-invalid.html is flaky on Mac
Modified: trunk/Tools/Scripts/extract-localizable-strings (153975 => 153976)
--- trunk/Tools/Scripts/extract-localizable-strings 2013-08-13 05:48:32 UTC (rev 153975)
+++ trunk/Tools/Scripts/extract-localizable-strings 2013-08-13 05:53:05 UTC (rev 153976)
@@ -43,33 +43,40 @@
# The exceptions file has a list of strings in quotes, filenames, and filename/string pairs separated by :.
use strict;
+use Getopt::Long;
no warnings 'deprecated';
sub UnescapeHexSequence($);
my %isDebugMacro = ( ASSERT_WITH_MESSAGE => 1, LOG_ERROR => 1, ERROR => 1, NSURL_ERROR => 1, FATAL => 1, LOG => 1, LOG_WARNING => 1, UI_STRING_LOCALIZE_LATER => 1, UI_STRING_LOCALIZE_LATER_KEY => 1, LPCTSTR_UI_STRING_LOCALIZE_LATER => 1, UNLOCALIZED_STRING => 1, UNLOCALIZED_LPCTSTR => 1, dprintf => 1, NSException => 1, NSLog => 1, printf => 1 );
-@ARGV >= 2 or die "Usage: extract-localizable-strings <exceptions file> <file to update> [ directory... ]\nDid you mean to run update-webkit-localizable-strings instead?\n";
+my $verify;
+my $exceptionsFile;
+my @directoriesToSkip = ();
-my $exceptionsFile = shift @ARGV;
--f $exceptionsFile or die "Couldn't find exceptions file $exceptionsFile\n" unless $exceptionsFile eq "-";
+my %options = (
+ 'verify' => \$verify,
+ 'exceptions=s' => \$exceptionsFile,
+ 'skip=s' => \@directoriesToSkip,
+);
+GetOptions(%options);
+
+@ARGV >= 2 or die "Usage: extract-localizable-strings [--verify] [--exceptions <exceptions file>] <file to update> [--skip directory | directory]...\nDid you mean to run update-webkit-localizable-strings instead?\n";
+
+-f $exceptionsFile or die "Couldn't find exceptions file $exceptionsFile\n" unless !defined $exceptionsFile;
+
my $fileToUpdate = shift @ARGV;
-f $fileToUpdate or die "Couldn't find file to update $fileToUpdate\n";
-my $warnAboutUnlocalizedStrings = $exceptionsFile ne "-";
+my $warnAboutUnlocalizedStrings = defined $exceptionsFile;
my @directories = ();
-my @directoriesToSkip = ();
if (@ARGV < 1) {
push(@directories, ".");
} else {
for my $dir (@ARGV) {
- if ($dir =~ /^-(.*)$/) {
- push @directoriesToSkip, $1;
- } else {
- push @directories, $dir;
- }
+ push @directories, $dir;
}
}
@@ -83,7 +90,7 @@
my %exception;
my %usedException;
-if ($exceptionsFile ne "-" && open EXCEPTIONS, $exceptionsFile) {
+if (defined $exceptionsFile && open EXCEPTIONS, $exceptionsFile) {
while (<EXCEPTIONS>) {
chomp;
if (/^"([^\\"]|\\.)*"$/ or /^[-_\/\w\s.]+.(h|m|mm|c|cpp)$/ or /^[-_\/\w\s.]+.(h|m|mm|c|cpp):"([^\\"]|\\.)*"$/) {
@@ -379,11 +386,55 @@
$localizedStrings .= "/* $commentByKey{$key} */\n\"$key\" = \"$stringByKey{$key}\";\n\n";
}
-# Write out the strings file as UTF-8
if (-e "$fileToUpdate") {
- open STRINGS, ">", "$fileToUpdate" or die;
- print STRINGS $localizedStrings;
- close STRINGS;
+ if (!$verify) {
+ # Write out the strings file as UTF-8
+ open STRINGS, ">", "$fileToUpdate" or die;
+ print STRINGS $localizedStrings;
+ close STRINGS;
+ } else {
+ open STRINGS, $fileToUpdate or die;
+
+ my $lastComment;
+
+ while (<STRINGS>) {
+ chomp;
+
+ next if (/^\s*$/);
+
+ if (/^\/\* (.*) \*\/$/) {
+ $lastComment = $1;
+ } elsif (/^"((?:[^\\]|\\[^"])*)"\s*=\s*"((?:[^\\]|\\[^"])*)";$/) #
+ {
+ my $string = delete $stringByKey{$1};
+ if (!defined $string) {
+ print "error: $fileToUpdate contains unused key \"$1\" (preceding comment: /* $lastComment */)\n";
+ $sawError = 1;
+ } else {
+ if (!($string eq $2)) {
+ print "error: $fileToUpdate contains unexpected value \"$2\" for key \"$1\" (expected \"$string\")\n";
+ $sawError = 1;
+ }
+ if (!($lastComment eq $commentByKey{$1})) {
+ print "error: $fileToUpdate contains unexpected comment /* $lastComment */ for key \"$1\" (expected /* $commentByKey{$1} */)\n";
+ }
+ }
+ } else {
+ print "error: $fileToUpdate contains line with unexpected format: $_\n";
+ $sawError = 1;
+ }
+ }
+
+ for my $missing (keys %stringByKey) {
+ print "error: $fileToUpdate is missing key \"$missing\"\n";
+ $sawError = 1;
+ }
+
+ if ($sawError) {
+ print "\nerror: $fileToUpdate is not up to date.\n";
+ exit 1;
+ }
+ }
} else {
print "$fileToUpdate does not exist\n";
exit 1;
Modified: trunk/Tools/Scripts/update-webkit-localizable-strings (153975 => 153976)
--- trunk/Tools/Scripts/update-webkit-localizable-strings 2013-08-13 05:48:32 UTC (rev 153975)
+++ trunk/Tools/Scripts/update-webkit-localizable-strings 2013-08-13 05:53:05 UTC (rev 153976)
@@ -35,7 +35,7 @@
use webkitdirs;
# WebKit and WebKit2 strings go into WebCore's Localizable.strings.
-my @webKitDirectoriesToScan = ("Source/WebCore", "Source/WebKit/mac", "Source/WebKit/win", "Source/WebKit2", "-Source/WebCore/icu", "-Source/WebKit/mac/icu");
+my @webKitDirectoriesToScan = ("Source/WebCore", "Source/WebKit/mac", "Source/WebKit/win", "Source/WebKit2", "--skip", "Source/WebCore/icu", "--skip", "Source/WebKit/mac/icu");
my @webInspectorUIDirectoriesToScan = ("Source/WebInspectorUI/UserInterface");
my $webCoreFileToUpdate = "Source/WebCore/English.lproj/Localizable.strings";
@@ -45,5 +45,5 @@
chdirWebKit();
-system "Tools/Scripts/extract-localizable-strings", "-", $webCoreFileToUpdate, @webKitDirectoriesToScan;
+system "Tools/Scripts/extract-localizable-strings", $webCoreFileToUpdate, @webKitDirectoriesToScan;
system "Tools/Scripts/extract-localizable-js-strings", $webInspectorUIFileToUpdate, @webInspectorUIDirectoriesToScan;