Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: tools/grit/grit/node/misc.py

Issue 6685061: Compile the devtools grd file into a .pak file so we (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase and fix win Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/grit/grit/grd_reader_unittest.py ('k') | tools/grit/grit/node/misc_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/node/misc.py
diff --git a/tools/grit/grit/node/misc.py b/tools/grit/grit/node/misc.py
index ec1e489ac04368a227454e7821819bc1376d1e2d..e077b037e7026a5b7fc621cc117e75a2f99653f8 100644
--- a/tools/grit/grit/node/misc.py
+++ b/tools/grit/grit/node/misc.py
@@ -7,6 +7,7 @@
'''
import os.path
+import re
import sys
from grit.node import base
@@ -19,6 +20,33 @@ from grit import util
import grit.format.rc_header
+def _ReadFirstIdsFromFile(filename, defines, src_root_dir):
+ '''Read the starting resource id values from |filename|. We also
+ expand variables of the form <(FOO) based on defines passed in on
+ the command line.'''
+ first_ids_dict = eval(open(filename).read())
+
+ def ReplaceVariable(matchobj):
+ for key, value in defines.iteritems():
+ if matchobj.group(1) == key:
+ value = os.path.abspath(value)[len(src_root_dir) + 1:]
+ return value
+ return ''
+
+ renames = []
+ for grd_filename in first_ids_dict:
+ new_grd_filename = re.sub(r'<\(([A-Za-z_]+)\)', ReplaceVariable,
+ grd_filename)
+ if new_grd_filename != grd_filename:
+ new_grd_filename = new_grd_filename.replace('\\', '/')
+ renames.append((grd_filename, new_grd_filename))
+
+ for grd_filename, new_grd_filename in renames:
+ first_ids_dict[new_grd_filename] = first_ids_dict[grd_filename]
+ del(first_ids_dict[grd_filename])
+
+ return first_ids_dict
+
class IfNode(base.Node):
'''A node for conditional inclusion of resources.
@@ -267,7 +295,7 @@ class GritNode(base.Node):
def SetDefines(self, defines):
self.defines = defines
- def AssignFirstIds(self, filename_or_stream, first_id_filename):
+ def AssignFirstIds(self, filename_or_stream, first_id_filename, defines):
'''Assign first ids to each grouping node based on values from
tools/grit/resource_ids.'''
# If the input is a stream, then we're probably in a unit test and
@@ -293,7 +321,8 @@ class GritNode(base.Node):
len(src_root_dir) + 1:]
filename = filename.replace('\\', '/')
if not first_ids:
- first_ids = eval(open(first_id_filename).read())
+ first_ids = _ReadFirstIdsFromFile(first_id_filename, defines,
+ src_root_dir)
if node.attrs['first_id'] != '':
raise Exception("Don't set the first_id attribute, update "
« no previous file with comments | « tools/grit/grit/grd_reader_unittest.py ('k') | tools/grit/grit/node/misc_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698