diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-07 08:31:25 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-07 08:31:25 +0000 |
commit | 8b8e08fc71edee37dd34324701f143ff66046683 (patch) | |
tree | 925105c0e080a97841e50bca459162a45fe115f9 | |
parent | c5d45432c531e091b2d7a904d4e5995e9c17f792 (diff) | |
download | chromium_src-8b8e08fc71edee37dd34324701f143ff66046683.zip chromium_src-8b8e08fc71edee37dd34324701f143ff66046683.tar.gz chromium_src-8b8e08fc71edee37dd34324701f143ff66046683.tar.bz2 |
Fix a bug that caused messages to wrongly fallback to English in some cases.
Before this fix, <message> elements with use_name_for_id attribute,
inside <if expr='pp_ifdef(...)'> were falling back to English,
because defines information was not present when evaluating conditions.
TEST=wrote and ran testUseNameForIdAndPpIfdef (python grit.py unit). There were failing tests before this change, and this change did not increase the number of failing tests. Also confirmed that http://codereview.chromium.org/3275008/show worked fine with this patch.
BUG=54360
Review URL: http://codereview.chromium.org/3335003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58678 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | tools/grit/grit/grd_reader.py | 13 | ||||
-rw-r--r-- | tools/grit/grit/grd_reader_unittest.py | 22 | ||||
-rw-r--r-- | tools/grit/grit/tool/build.py | 3 |
3 files changed, 31 insertions, 7 deletions
diff --git a/tools/grit/grit/grd_reader.py b/tools/grit/grit/grd_reader.py index 308c1e7..a6a1c8c 100644 --- a/tools/grit/grit/grd_reader.py +++ b/tools/grit/grit/grd_reader.py @@ -24,7 +24,7 @@ class StopParsingException(Exception): class GrdContentHandler(xml.sax.handler.ContentHandler): - def __init__(self, stop_after=None, debug=False): + def __init__(self, stop_after=None, debug=False, defines=None): # Invariant of data: # 'root' is the root of the parse tree being created, or None if we haven't # parsed out any elements. @@ -35,6 +35,7 @@ class GrdContentHandler(xml.sax.handler.ContentHandler): self.stack = [] self.stop_after = stop_after self.debug = debug + self.defines = defines def startElement(self, name, attrs): assert not self.root or len(self.stack) > 0 @@ -55,6 +56,8 @@ class GrdContentHandler(xml.sax.handler.ContentHandler): if not self.root: self.root = node + if self.defines: + self.root.SetDefines(self.defines) if len(self.stack) > 0: self.stack[-1].AddChild(node) @@ -88,7 +91,8 @@ class GrdContentHandler(xml.sax.handler.ContentHandler): def Parse(filename_or_stream, dir=None, flexible_root=False, - stop_after=None, debug=False, first_id_filename=None): + stop_after=None, debug=False, first_id_filename=None, + defines=None): '''Parses a GRD file into a tree of nodes (from grit.node). If flexible_root is False, the root node must be a <grit> element. Otherwise @@ -114,6 +118,7 @@ def Parse(filename_or_stream, dir=None, flexible_root=False, stop_after: 'inputs' debug: False first_id_filename: None + defines: dictionary of defines, like {'chromeos': '1'} Return: Subclass of grit.node.base.Node @@ -121,7 +126,8 @@ def Parse(filename_or_stream, dir=None, flexible_root=False, Throws: grit.exception.Parsing ''' - handler = GrdContentHandler(stop_after=stop_after, debug=debug) + handler = GrdContentHandler(stop_after=stop_after, debug=debug, + defines=defines) try: xml.sax.parse(filename_or_stream, handler) except StopParsingException: @@ -149,4 +155,3 @@ def Parse(filename_or_stream, dir=None, flexible_root=False, if __name__ == '__main__': util.ChangeStdoutEncoding() print unicode(Parse(sys.argv[1])) - diff --git a/tools/grit/grit/grd_reader_unittest.py b/tools/grit/grit/grd_reader_unittest.py index e1482e0..6de2260 100644 --- a/tools/grit/grit/grd_reader_unittest.py +++ b/tools/grit/grit/grd_reader_unittest.py @@ -145,6 +145,26 @@ class GrdReaderUnittest(unittest.TestCase): self.failUnless(isinstance(messages_node, empty.MessagesNode)) self.failUnless(messages_node.attrs["first_id"] == 10000) + def testUseNameForIdAndPpIfdef(self): + input = u'''<?xml version="1.0" encoding="UTF-8"?> +<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> + <release seq="3"> + <messages> + <if expr="pp_ifdef('hello')"> + <message name="IDS_HELLO" use_name_for_id="true"> + Hello! + </message> + </if> + </messages> + </release> +</grit>''' + pseudo_file = StringIO.StringIO(input) + root = grd_reader.Parse(pseudo_file, '.', defines={'hello': '1'}) + + # Check if the ID is set to the name. In the past, there was a bug + # that caused the ID to be a generated number. + hello = root.GetNodeById('IDS_HELLO') + self.failUnless(hello.GetCliques()[0].GetId() == 'IDS_HELLO') + if __name__ == '__main__': unittest.main() - diff --git a/tools/grit/grit/tool/build.py b/tools/grit/grit/tool/build.py index 2882c95..771a737 100644 --- a/tools/grit/grit/tool/build.py +++ b/tools/grit/grit/tool/build.py @@ -99,8 +99,7 @@ are exported to translation interchange files (e.g. XMB files), etc. (self.output_directory, os.path.abspath(self.output_directory))) self.res = grd_reader.Parse(opts.input, first_id_filename=first_id_filename, - debug=opts.extra_verbose) - self.res.SetDefines(self.defines) + debug=opts.extra_verbose, defines=self.defines) self.res.RunGatherers(recursive = True) self.Process() return 0 |