Changeset 177741 in webkit


Ignore:
Timestamp:
Dec 25, 2014, 2:45:31 PM (11 years ago)
Author:
mitz@apple.com
Message:

Give extract-localizable-strings an option to treat warnings as errors
https://bugs.webkit.org/show_bug.cgi?id=139943

Reviewed by Darin Adler.

Add a --treat-warnings-as-errors option, which makes the script emit its warnings as errors
and exit with a non-0 return code if it emitted any warnings.

  • extract-localizable-strings.pl:

Added $treatWarningsAsErrors variable, set to true if the option is passed in.

(emitWarning): Added. If $treatWarningsAsErrors is true, omits the "warning: " token from
the message, which makes it appear as an error in Xcode, and sets $sawError to 1.

Replaced all print statements that printed warnings with calls to emitWarning.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/Source/WebCore/ChangeLog

    r177739 r177741  
     12014-12-25  Dan Bernstein  <mitz@apple.com>
     2
     3        Give extract-localizable-strings an option to treat warnings as errors
     4        https://bugs.webkit.org/show_bug.cgi?id=139943
     5
     6        Reviewed by Darin Adler.
     7
     8        Add a --treat-warnings-as-errors option, which makes the script emit its warnings as errors
     9        and exit with a non-0 return code if it emitted any warnings.
     10
     11        * extract-localizable-strings.pl:
     12        Added $treatWarningsAsErrors variable, set to true if the option is passed in.
     13
     14        (emitWarning): Added. If $treatWarningsAsErrors is true, omits the "warning: " token from
     15        the message, which makes it appear as an error in Xcode, and sets $sawError to 1.
     16
     17        Replaced all print statements that printed warnings with calls to emitWarning.
     18
    1192014-12-25  Dan Bernstein  <mitz@apple.com>
    220
  • TabularUnified trunk/Source/WebCore/extract-localizable-strings.pl

    r165676 r177741  
    5454my $exceptionsFile;
    5555my @directoriesToSkip = ();
     56my $treatWarningsAsErrors;
    5657
    5758my %options = (
     
    5960    'exceptions=s' => \$exceptionsFile,
    6061    'skip=s' => \@directoriesToSkip,
     62    'treat-warnings-as-errors' => \$treatWarningsAsErrors,
    6163);
    6264
    6365GetOptions(%options);
    6466
    65 @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";
     67@ARGV >= 2 or die "Usage: extract-localizable-strings [--verify] [--treat-warnings-as-errors] [--exceptions <exceptions file>] <file to update> [--skip directory | directory]...\nDid you mean to run update-webkit-localizable-strings instead?\n";
    6668
    6769-f $exceptionsFile or die "Couldn't find exceptions file $exceptionsFile\n" unless !defined $exceptionsFile;
     
    9193my %usedException;
    9294
     95sub emitWarning($$$)
     96{
     97    my ($file, $line, $message) = @_;
     98    my $prefix = $treatWarningsAsErrors ? "" : "warning: ";
     99    print "$file:$line: $prefix$message\n";
     100    $sawError = 1 if $treatWarningsAsErrors;
     101}
     102
    93103if (defined $exceptionsFile && open EXCEPTIONS, $exceptionsFile) {
    94104    while (<EXCEPTIONS>) {
     
    96106        if (/^"([^\\"]|\\.)*"$/ or /^[-_\/\w\s.]+.(h|m|mm|c|cpp)$/ or /^[-_\/\w\s.]+.(h|m|mm|c|cpp):"([^\\"]|\\.)*"$/) {
    97107            if ($exception{$_}) {
    98                 print "$exceptionsFile:$.: warning: exception for $_ appears twice\n";
    99                 print "$exceptionsFile:$exception{$_}: warning: first appearance\n";
     108                emitWarning($exceptionsFile, $., "exception for $_ appears twice");
     109                emitWarning($exceptionsFile, $exception{$_}, "first appearance");
    100110            } else {
    101111                $exception{$_} = $.;
    102112            }
    103113        } else {
    104             print "$exceptionsFile:$.: warning: syntax error\n";
     114            emitWarning($exceptionsFile, $., "syntax error");
    105115        }
    106116    }
     
    205215                        $usedException{"$file:\"$string\""} = 1;
    206216                    } else {
    207                         print "$file:$stringLine: warning: \"$string\" is not marked for localization\n" if $warnAboutUnlocalizedStrings;
     217                        emitWarning($file, $stringLine, "\"$string\" is not marked for localization") if $warnAboutUnlocalizedStrings;
    208218                        $notLocalizedCount++;
    209219                    }
     
    344354   
    345355    if ($stringByKey{$key} && $stringByKey{$key} ne $string) {
    346         print "$file:$line: warning: encountered the same key, \"$key\", twice, with different strings\n";
    347         print "$fileByKey{$key}:$lineByKey{$key}: warning: previous occurrence\n";
     356        emitWarning($file, $line, "encountered the same key, \"$key\", twice, with different strings");
     357        emitWarning($fileByKey{$key}, $lineByKey{$key}, "previous occurrence");
    348358        $keyCollisionCount++;
    349359        return;
    350360    }
    351361    if ($commentByKey{$key} && $commentByKey{$key} ne $comment) {
    352         print "$file:$line: warning: encountered the same key, \"$key\", twice, with different comments\n";
    353         print "$fileByKey{$key}:$lineByKey{$key}: warning: previous occurrence\n";
     362        emitWarning($file, $line, "encountered the same key, \"$key\", twice, with different comments");
     363        emitWarning($fileByKey{$key}, $lineByKey{$key}, "previous occurrence");
    354364        $keyCollisionCount++;
    355365        return;
     
    367377if (@unusedExceptions) {
    368378    for my $unused (@unusedExceptions) {
    369         print "$exceptionsFile:$exception{$unused}: warning: exception $unused not used\n";
     379        emitWarning($exceptionsFile, $exception{$unused}, "exception $unused not used");
    370380    }
    371381    print "\n";
Note: See TracChangeset for help on using the changeset viewer.