metasmile / grit-i18n

Automatically exported from code.google.com/p/grit-i18n
BSD 2-Clause "Simplified" License
1 stars 2 forks source link

target_platform isn't set correctly #23

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
On OS X, run

  time python ../tools/grit/grit.py -i app/generated_resources.grd build -f ../tools/gritsettings/resource_ids -o ../out_android/Release/gen/chrome -D _chromium -E "CHROMIUM_BUILD=chromium" -t android -E "ANDROID_JAVA_TAGGED_ONLY=true" -D enable_printing -D use_concatenated_impulse_responses -D enable_webrtc

from the 'chrome' directory. It'll die with

  grit.exception.DuplicateKey: A duplicate key attribute was found.: IDS_CONTENT_CONTEXT_PASTE, IDS_PASTE

which is caused by EvaluateExpression() thinking that is_macosx is true, even 
though `-t android` is passed in. I'm guessing this is broken on linux too but 
doesn't cause problems since there's not much linux-specific stuff in grd files 
on linux?

Original issue reported on code.google.com by thakis@chromium.org on 26 Dec 2013 at 3:35

GoogleCodeExporter commented 8 years ago
This approach of setting the target platform on the root node earlier seems to 
make things work:

Index: grit/grd_reader.py
===================================================================
--- grit/grd_reader.py  (revision 140)
+++ grit/grd_reader.py  (working copy)
@@ -24,7 +24,8 @@

 class GrdContentHandler(xml.sax.handler.ContentHandler):
-  def __init__(self, stop_after, debug, dir, defines, tags_to_ignore):
+  def __init__(self, stop_after, debug, dir, defines, tags_to_ignore,
+               target_platform):
     # Invariant of data:
     # 'root' is the root of the parse tree being created, or None if we haven't
     # parsed out any elements.
@@ -39,6 +40,7 @@
     self.defines = defines
     self.tags_to_ignore = tags_to_ignore or set()
     self.ignore_depth = 0
+    self.target_platform = target_platform

   def startElement(self, name, attrs):
     if self.ignore_depth or name in self.tags_to_ignore:
@@ -61,6 +63,9 @@
     else:
       assert self.root is None
       self.root = node
+      if isinstance(self.root, misc.GritNode):
+        if self.target_platform:
+          self.root.SetTargetPlatform(self.target_platform)
       node.StartParsing(name, None)
       if self.defines:
         node.SetDefines(self.defines)
@@ -175,7 +180,8 @@
     dir = util.dirname(filename_or_stream)

   handler = GrdContentHandler(stop_after=stop_after, debug=debug, dir=dir,
-                              defines=defines, tags_to_ignore=tags_to_ignore)
+                              defines=defines, tags_to_ignore=tags_to_ignore,
+                              target_platform=target_platform)
   try:
     xml.sax.parse(filename_or_stream, handler)
   except StopParsingException:
@@ -195,8 +201,6 @@
     handler.root.SetOwnDir(dir)

   if isinstance(handler.root, misc.GritNode):
-    if target_platform:
-      handler.root.SetTargetPlatform(target_platform)
     if first_ids_file:
       # Make the path to the first_ids_file relative to the grd file,
       # unless it begins with GRIT_DIR.

Original comment by thakis@chromium.org on 26 Dec 2013 at 3:55

GoogleCodeExporter commented 8 years ago

Original comment by thakis@chromium.org on 26 Dec 2013 at 3:58

GoogleCodeExporter commented 8 years ago

Original comment by joi@chromium.org on 27 Dec 2013 at 2:33

GoogleCodeExporter commented 8 years ago
Fixed by r141.

Original comment by joi@chromium.org on 27 Dec 2013 at 2:42