diff options
author | Torne (Richard Coles) <torne@google.com> | 2014-03-18 10:21:37 +0000 |
---|---|---|
committer | Torne (Richard Coles) <torne@google.com> | 2014-03-18 10:21:37 +0000 |
commit | 502819df4bb6aba2350c60c5abd7b0d113c84ba9 (patch) | |
tree | a48868c8e962ae1e5916a5c8dbf37f25608447ad | |
parent | d82e4d92be691b62b040f43f79527f5977bf9104 (diff) | |
parent | 8bac6b817c38a6ca7942ce836e70f7be8dbaaf5a (diff) | |
download | grit-502819df4bb6aba2350c60c5abd7b0d113c84ba9.tar.gz |
Merge from Chromium at DEPS revision 257591
This commit was generated by merge_to_master.py.
Change-Id: I427dd7cf3a8eefedf56b2bdccc882b0f13a6807b
-rw-r--r-- | grit/format/android_xml.py | 2 | ||||
-rw-r--r-- | grit/format/rc_header.py | 14 | ||||
-rw-r--r-- | grit/format/rc_header_unittest.py | 34 | ||||
-rwxr-xr-x | grit/node/misc.py | 11 | ||||
-rw-r--r-- | grit/tool/build.py | 13 |
5 files changed, 65 insertions, 9 deletions
diff --git a/grit/format/android_xml.py b/grit/format/android_xml.py index d960bf4..e835e9b 100644 --- a/grit/format/android_xml.py +++ b/grit/format/android_xml.py @@ -112,7 +112,7 @@ def Format(root, lang='en', output_dir='.'): raise Exception('env variable ANDROID_JAVA_TAGGED_ONLY must have value ' 'true or false. Invalid value: %s' % tagged_only) - for item in root.ActiveDescendants(): + for item in root.Preorder(): with item: if ShouldOutputNode(item, tagged_only): yield _FormatMessage(item, lang) diff --git a/grit/format/rc_header.py b/grit/format/rc_header.py index 118e94c..74e7127 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,9 @@ 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}" + rc_header_format += "\n" seen = set() for item in items: if not isinstance(item, message.MessageNode): @@ -57,7 +62,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 +73,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..5d780e3 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}') + 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..2bb8085 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}" + 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 |