aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Chromium Automerger <chromium-automerger@android>2014-02-22 08:32:03 +0000
committerAndroid Chromium Automerger <chromium-automerger@android>2014-02-22 08:32:03 +0000
commit400f25636fc176e8a76a7456f328565b74aa35ae (patch)
treedd1070b47bbede1fb63f77ec254847b1f97ed6fd
parent368e90f2c01201a54124e57f3550d1da5e7dd9cb (diff)
parentdb2e077842c311c22eb33a13cc9eb9fadb7def5a (diff)
downloadgrit-400f25636fc176e8a76a7456f328565b74aa35ae.tar.gz
Merge tools/grit from https://chromium.googlesource.com/external/grit-i18n.git at db2e077842c311c22eb33a13cc9eb9fadb7def5a
This commit was generated by merge_from_chromium.py. Change-Id: Iae1781925643198c4f19648c34780463a041e135
-rw-r--r--grit/format/rc_header.py13
-rw-r--r--grit/format/rc_header_unittest.py34
-rwxr-xr-xgrit/node/misc.py11
-rw-r--r--grit/tool/build.py13
4 files changed, 63 insertions, 8 deletions
diff --git a/grit/format/rc_header.py b/grit/format/rc_header.py
index 118e94c..ef53b0f 100644
--- a/grit/format/rc_header.py
+++ b/grit/format/rc_header.py
@@ -30,11 +30,13 @@ def Format(root, lang='en', output_dir='.'):
for line in emit_lines or default_includes:
yield line + '\n'
- for line in FormatDefines(root, root.ShouldOutputAllResourceDefines()):
+ for line in FormatDefines(root, root.ShouldOutputAllResourceDefines(),
+ root.GetRcHeaderFormat()):
yield line
-def FormatDefines(root, output_all_resource_defines=True):
+def FormatDefines(root, output_all_resource_defines=True,
+ rc_header_format=None):
'''Yields #define SYMBOL 1234 lines.
Args:
@@ -50,6 +52,8 @@ def FormatDefines(root, output_all_resource_defines=True):
else:
items = root.ActiveDescendants()
+ if not rc_header_format:
+ rc_header_format = "#define {textual_id} {numeric_id}\n"
seen = set()
for item in items:
if not isinstance(item, message.MessageNode):
@@ -57,7 +61,8 @@ def FormatDefines(root, output_all_resource_defines=True):
for tid in item.GetTextualIds():
if tid in tids and tid not in seen:
seen.add(tid)
- yield '#define %s %d\n' % (tid, tids[tid])
+ yield rc_header_format.format(textual_id=tid,numeric_id=tids[tid])
+
# Temporarily mimic old behavior: MessageNodes were only output if active,
# even with output_all_resource_defines set. TODO(benrg): Remove this after
# fixing problems in the Chrome tree.
@@ -67,7 +72,7 @@ def FormatDefines(root, output_all_resource_defines=True):
for tid in item.GetTextualIds():
if tid in tids and tid not in seen:
seen.add(tid)
- yield '#define %s %d\n' % (tid, tids[tid])
+ yield rc_header_format.format(textual_id=tid,numeric_id=tids[tid])
_cached_ids = {}
diff --git a/grit/format/rc_header_unittest.py b/grit/format/rc_header_unittest.py
index 433ff7d..dccead1 100644
--- a/grit/format/rc_header_unittest.py
+++ b/grit/format/rc_header_unittest.py
@@ -154,6 +154,40 @@ class RcHeaderFormatterUnittest(unittest.TestCase):
output = util.StripBlankLinesAndComments(output)
self.assertEqual('#pragma once\nBingo', output)
+ def testRcHeaderFormat(self):
+ grd = grd_reader.Parse(StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?>
+ <grit latest_public_release="2" source_lang_id="en" current_release="3" base_dir=".">
+ <release seq="3">
+ <includes first_id="300" comment="bingo">
+ <include type="gif" name="IDR_LOGO" file="images/logo.gif" />
+ </includes>
+ <messages first_id="10000">
+ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user">
+ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today?
+ </message>
+ <message name="IDS_BONGO">
+ Bongo!
+ </message>
+ </messages>
+ </release>
+ </grit>'''), '.')
+
+ # Using the default rc_header format string.
+ output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(),
+ grd.GetRcHeaderFormat())
+ self.assertEqual(('#define IDR_LOGO 300\n'
+ '#define IDS_GREETING 10000\n'
+ '#define IDS_BONGO 10001\n'), ''.join(output))
+
+ # Using a custom rc_header format string.
+ grd.AssignRcHeaderFormat(
+ '#define {textual_id} _Pragma("{textual_id}") {numeric_id}\n')
+ output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(),
+ grd.GetRcHeaderFormat())
+ self.assertEqual(('#define IDR_LOGO _Pragma("IDR_LOGO") 300\n'
+ '#define IDS_GREETING _Pragma("IDS_GREETING") 10000\n'
+ '#define IDS_BONGO _Pragma("IDS_BONGO") 10001\n'),
+ ''.join(output))
if __name__ == '__main__':
unittest.main()
diff --git a/grit/node/misc.py b/grit/node/misc.py
index 345081f..9a23263 100755
--- a/grit/node/misc.py
+++ b/grit/node/misc.py
@@ -182,7 +182,7 @@ class GritNode(base.Node):
if name not in ['base_dir', 'first_ids_file', 'source_lang_id',
'latest_public_release', 'current_release',
'enc_check', 'tc_project', 'grit_version',
- 'output_all_resource_defines']:
+ 'output_all_resource_defines', 'rc_header_format']:
return False
if name in ['latest_public_release', 'current_release'] and value.strip(
'0123456789') != '':
@@ -200,7 +200,8 @@ class GritNode(base.Node):
'source_lang_id' : 'en',
'enc_check' : constants.ENCODING_CHECK,
'tc_project' : 'NEED_TO_SET_tc_project_ATTRIBUTE',
- 'output_all_resource_defines': 'true'
+ 'output_all_resource_defines': 'true',
+ 'rc_header_format': None
}
def EndParsing(self):
@@ -298,6 +299,12 @@ class GritNode(base.Node):
"""
return self.attrs['output_all_resource_defines'] == 'true'
+ def GetRcHeaderFormat(self):
+ return self.attrs['rc_header_format']
+
+ def AssignRcHeaderFormat(self, rc_header_format):
+ self.attrs['rc_header_format'] = rc_header_format
+
def GetInputFiles(self):
"""Returns the list of files that are read to produce the output."""
diff --git a/grit/tool/build.py b/grit/tool/build.py
index 64f1d27..d152d64 100644
--- a/grit/tool/build.py
+++ b/grit/tool/build.py
@@ -83,6 +83,11 @@ Options:
flag should match what sys.platform would report for your
target platform; see grit.node.base.EvaluateCondition.
+ -h HEADERFORMAT Custom format string to use for generating rc header files.
+ The string should have two placeholders: {textual_id}
+ and {numeric_id}. E.g. "#define {textual_id} {numeric_id}\n"
+ Otherwise it will use the default "#define SYMBOL 1234"
+
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
meant for compilation but it does not affect resource header files (that define
@@ -100,7 +105,8 @@ are exported to translation interchange files (e.g. XMB files), etc.
target_platform = None
depfile = None
depdir = None
- (own_opts, args) = getopt.getopt(args, 'o:D:E:f:w:t:', ('depdir=','depfile='))
+ rc_header_format = None
+ (own_opts, args) = getopt.getopt(args, 'o:D:E:f:w:t:h:', ('depdir=','depfile='))
for (key, val) in own_opts:
if key == '-o':
self.output_directory = val
@@ -119,6 +125,8 @@ are exported to translation interchange files (e.g. XMB files), etc.
whitelist_filenames.append(val)
elif key == '-t':
target_platform = val
+ elif key == '-h':
+ rc_header_format = val
elif key == '--depdir':
depdir = val
elif key == '--depfile':
@@ -151,6 +159,8 @@ are exported to translation interchange files (e.g. XMB files), etc.
# gathering stage; we use a dummy language here since we are not outputting
# a specific language.
self.res.SetOutputLanguage('en')
+ if rc_header_format:
+ self.res.AssignRcHeaderFormat(rc_header_format)
self.res.RunGatherers()
self.Process()
@@ -181,7 +191,6 @@ are exported to translation interchange files (e.g. XMB files), etc.
# output.
self.whitelist_names = None
-
@staticmethod
def AddWhitelistTags(start_node, whitelist_names):
# Walk the tree of nodes added attributes for the nodes that shouldn't