summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xtools/grit/grit/format/data_pack.py7
-rw-r--r--tools/grit/grit/node/base.py17
-rw-r--r--tools/grit/grit/tool/build.py63
-rwxr-xr-xtools/grit/grit_info.py5
4 files changed, 82 insertions, 10 deletions
diff --git a/tools/grit/grit/format/data_pack.py b/tools/grit/grit/format/data_pack.py
index 20a8f73..c8a46ad 100755
--- a/tools/grit/grit/format/data_pack.py
+++ b/tools/grit/grit/format/data_pack.py
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
-# Copyright (c) 2009 The Chromium Authors. All rights reserved.
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -41,7 +41,10 @@ class DataPack(interface.ItemFormatter):
return nodes
if (isinstance(item, include.IncludeNode) or
isinstance(item, message.MessageNode)):
- return [item]
+ # Include this node if it wasn't marked as skipped by a whitelist.
+ if not item.WhitelistMarkedAsSkip():
+ return [item]
+ return nodes
for child in item.children:
nodes.extend(DataPack.GetDataNodes(child))
return nodes
diff --git a/tools/grit/grit/node/base.py b/tools/grit/grit/node/base.py
index b35c200..631733a 100644
--- a/tools/grit/grit/node/base.py
+++ b/tools/grit/grit/node/base.py
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
-# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -26,6 +26,9 @@ class Node(grit.format.interface.ItemFormatter):
_CONTENT_TYPE_CDATA = 1 # Only CDATA, no children.
_CONTENT_TYPE_MIXED = 2 # CDATA and children, possibly intermingled
+ # Default nodes to not whitelist skipped
+ _whitelist_marked_as_skip = False
+
def __init__(self):
self.children = [] # A list of child elements
self.mixed_content = [] # A list of u'' and/or child elements (this
@@ -520,6 +523,18 @@ class Node(grit.format.interface.ItemFormatter):
p = p.parent
return False
+ def WhitelistMarkedAsSkip(self):
+ '''Returns true if the node is marked to be skipped in the output by a
+ whitelist.
+ '''
+ return self._whitelist_marked_as_skip
+
+ def SetWhitelistMarkedAsSkip(self, mark_skipped):
+ '''Sets WhitelistMarkedAsSkip.
+ '''
+ self._whitelist_marked_as_skip = mark_skipped
+
+
class ContentNode(Node):
'''Convenience baseclass for nodes that can have content.'''
def _ContentType(self):
diff --git a/tools/grit/grit/tool/build.py b/tools/grit/grit/tool/build.py
index 4b7ddd9..635cc41 100644
--- a/tools/grit/grit/tool/build.py
+++ b/tools/grit/grit/tool/build.py
@@ -1,5 +1,5 @@
#!/usr/bin/python2.4
-# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -61,6 +61,9 @@ Options:
resources_ids next to grit.py. Set to an empty string
if you don't want to use a first id file.
+ -w WHITELISTFILE Path to a file containing the string names of the
+ resources to include. Anything not listed is dropped.
+
Conditional inclusion of resources only affects the output of files which
control which resources get linked into a binary, e.g. it affects .rc files
@@ -75,7 +78,8 @@ are exported to translation interchange files (e.g. XMB files), etc.
def Run(self, opts, args):
self.output_directory = '.'
first_id_filename = None
- (own_opts, args) = getopt.getopt(args, 'o:D:E:f:')
+ whitelist_filenames = []
+ (own_opts, args) = getopt.getopt(args, 'o:D:E:f:w:')
for (key, val) in own_opts:
if key == '-o':
self.output_directory = val
@@ -87,6 +91,8 @@ are exported to translation interchange files (e.g. XMB files), etc.
os.environ[env_name] = env_value
elif key == '-f':
first_id_filename = val
+ elif key == '-w':
+ whitelist_filenames.append(val)
if len(args):
print "This tool takes no tool-specific arguments."
@@ -98,6 +104,15 @@ are exported to translation interchange files (e.g. XMB files), etc.
self.VerboseOut('Output directory: %s (absolute path: %s)\n' %
(self.output_directory,
os.path.abspath(self.output_directory)))
+
+ if whitelist_filenames:
+ self.whitelist_names = set()
+ for whitelist_filename in whitelist_filenames:
+ self.VerboseOut('Using whitelist: %s\n' % whitelist_filename);
+ whitelist_file = open(whitelist_filename)
+ self.whitelist_names |= set(whitelist_file.read().strip().split('\n'))
+ whitelist_file.close()
+
self.res = grd_reader.Parse(opts.input, first_id_filename=first_id_filename,
debug=opts.extra_verbose, defines=self.defines)
self.res.RunGatherers(recursive = True)
@@ -122,6 +137,28 @@ are exported to translation interchange files (e.g. XMB files), etc.
# output nodes in the file.
self.scons_targets = None
+ # The set of names that are whitelisted to actually be included in the
+ # output.
+ self.whitelist_names = None
+
+
+ # static method
+ def AddWhitelistTags(start_node, whitelist_names):
+ # Walk the tree of nodes added attributes for the nodes that shouldn't
+ # be written into the target files (skip markers).
+ from grit.node import include
+ from grit.node import message
+ for node in start_node.inorder():
+ # Same trick data_pack.py uses to see what nodes actually result in
+ # real items.
+ if (isinstance(node, include.IncludeNode) or
+ isinstance(node, message.MessageNode)):
+ text_ids = node.GetTextualIds()
+ # Mark the item to be skipped if it wasn't in the whitelist.
+ if text_ids and not text_ids[0] in whitelist_names:
+ node.SetWhitelistMarkedAsSkip(True)
+ AddWhitelistTags = staticmethod(AddWhitelistTags)
+
# static method
def ProcessNode(node, output_node, outfile):
'''Processes a node in-order, calling its formatter before and after
@@ -132,13 +169,20 @@ are exported to translation interchange files (e.g. XMB files), etc.
output_node: grit.node.io.File
outfile: open filehandle
'''
+ # See if the node should be skipped by a whitelist.
+ # Note: Some Format calls have side effects, so Format is always called
+ # and the whitelist is used to only avoid the output.
+ should_write = not node.WhitelistMarkedAsSkip()
+
base_dir = util.dirname(output_node.GetOutputFilename())
try:
formatter = node.ItemFormatter(output_node.GetType())
if formatter:
- outfile.write(formatter.Format(node, output_node.GetLanguage(),
- begin_item=True, output_dir=base_dir))
+ formatted = formatter.Format(node, output_node.GetLanguage(),
+ begin_item=True, output_dir=base_dir)
+ if should_write:
+ outfile.write(formatted)
except:
print u"Error processing node %s" % unicode(node)
raise
@@ -148,8 +192,10 @@ are exported to translation interchange files (e.g. XMB files), etc.
try:
if formatter:
- outfile.write(formatter.Format(node, output_node.GetLanguage(),
- begin_item=False, output_dir=base_dir))
+ formatted = formatter.Format(node, output_node.GetLanguage(),
+ begin_item=False, output_dir=base_dir)
+ if should_write:
+ outfile.write(formatted)
except:
print u"Error processing node %s" % unicode(node)
raise
@@ -172,6 +218,11 @@ are exported to translation interchange files (e.g. XMB files), etc.
output.output_filename = os.path.abspath(os.path.join(
self.output_directory, output.GetFilename()))
+ # If there are whitelisted names, tag the tree once up front, this way
+ # while looping through the actual output, it is just an attribute check.
+ if self.whitelist_names:
+ self.AddWhitelistTags(self.res, self.whitelist_names)
+
for output in self.res.GetOutputFiles():
self.VerboseOut('Creating %s...' % output.GetFilename())
diff --git a/tools/grit/grit_info.py b/tools/grit/grit_info.py
index 9bb7c430..700dba3 100755
--- a/tools/grit/grit_info.py
+++ b/tools/grit/grit_info.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -86,6 +86,7 @@ def main(argv):
# grit build also supports '-E KEY=VALUE', support that to share command
# line flags.
parser.add_option("-E", action="append", dest="build_env", default=[])
+ parser.add_option("-w", action="append", dest="whitelist_files", default=[])
options, args = parser.parse_args()
@@ -102,6 +103,8 @@ def main(argv):
inputs = Inputs(filename, defines)
# Include grd file as second input (works around gyp expecting it).
inputs = [inputs[0], filename] + inputs[1:]
+ if options.whitelist_files:
+ inputs.extend(options.whitelist_files)
print '\n'.join(inputs)
elif options.outputs:
if len(args) < 2: