From 88aad08a78ead47d9c54b4f87d3e52ed5de1070f Mon Sep 17 00:00:00 2001 From: "akalin@chromium.org" Date: Fri, 14 Jan 2011 21:36:56 +0000 Subject: [grit] Avoid intermediate files for HTML inlining when building .pak files This avoids problems where multiple invocations of grit try to write to the same intermediate file. BUG=69633 TEST=Manually Review URL: http://codereview.chromium.org/6245002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71491 0039d316-1c4b-4281-b951-d872f2087c98 --- tools/grit/grit/format/data_pack.py | 2 +- tools/grit/grit/format/html_inline.py | 66 ++++++++++++++++++++++++++++------- tools/grit/grit/format/rc.py | 2 ++ tools/grit/grit/node/include.py | 47 ++++++++++++++++--------- tools/grit/grit/node/message.py | 2 +- tools/grit/grit_info.py | 2 +- 6 files changed, 88 insertions(+), 33 deletions(-) (limited to 'tools/grit') diff --git a/tools/grit/grit/format/data_pack.py b/tools/grit/grit/format/data_pack.py index 664cbaec..20a8f73 100755 --- a/tools/grit/grit/format/data_pack.py +++ b/tools/grit/grit/format/data_pack.py @@ -29,7 +29,7 @@ class DataPack(interface.ItemFormatter): nodes = DataPack.GetDataNodes(item) data = {} for node in nodes: - id, value = node.GetDataPackPair(output_dir, lang) + id, value = node.GetDataPackPair(lang) data[id] = value return DataPack.WriteDataPack(data) diff --git a/tools/grit/grit/format/html_inline.py b/tools/grit/grit/format/html_inline.py index 9979bca..c5cb074 100755 --- a/tools/grit/grit/format/html_inline.py +++ b/tools/grit/grit/format/html_inline.py @@ -69,19 +69,30 @@ def SrcInlineAsDataURL(src_match, base_path, distribution, inlined_files): prefix = src_match.string[src_match.start():src_match.start('filename')-1] return "%s\"data:%s;base64,%s\"" % (prefix, mimetype, inline_data) -def InlineFile(input_filename, output_filename, grd_node): - """Inlines the resources in a specified file. + +class InlinedData: + """Helper class holding the results from DoInline(). + + Holds the inlined data and the set of filenames of all the inlined + files. + """ + def __init__(self, inlined_data, inlined_files): + self.inlined_data = inlined_data + self.inlined_files = inlined_files + +def DoInline(input_filename, grd_node): + """Helper function that inlines the resources in a specified file. Reads input_filename, finds all the src attributes and attempts to - inline the files they are referring to, then writes the result - to output_filename. + inline the files they are referring to, then returns the result and + the set of inlined files. Args: input_filename: name of file to read in - output_filename: name of file to be written to grd_node: html node from the grd file for this include tag Returns: - a set of filenames of all the inlined files + a tuple of the inlined data as a string and the set of filenames + of all the inlined files """ input_filepath = os.path.dirname(input_filename) @@ -198,16 +209,45 @@ def InlineFile(input_filename, output_filename, grd_node): flat_text = re.sub('