Chromium Code Reviews| Index: build/android/gyp/generate_v14_resources.py |
| diff --git a/build/android/gyp/generate_v14_resources.py b/build/android/gyp/generate_v14_resources.py |
| index ce9eebb11ca6e7f07b1962960cb3b908581e4731..804969548fc63e0c5b916ac4cde7e4b4ed6705b3 100755 |
| --- a/build/android/gyp/generate_v14_resources.py |
| +++ b/build/android/gyp/generate_v14_resources.py |
| @@ -63,14 +63,30 @@ def IterateXmlElements(node): |
| yield child_node_element |
| -def GenerateV14Resource(input_filename, output_filename): |
| - """Convert resource to API 14 compatible resource. |
| +def GenerateV14StyleXmlResource(dom, output_file): |
|
newt (away)
2013/05/06 16:59:34
I'd remove "Xml" from the function name here and b
Kibeom Kim (inactive)
2013/05/06 19:18:16
Done.
|
| + """Convert style resource to API 14 compatible style resource. |
| It's mostly a simple replacement, s/Start/Left s/End/Right, |
| - on the attribute names. |
| + on the attribute names specified by <item> element. |
| """ |
| - dom = minidom.parse(input_filename) |
| + for style_element in dom.getElementsByTagName('style'): |
| + for item_element in style_element.getElementsByTagName('item'): |
| + namespace, name = item_element.attributes['name'].value.split(':') |
| + if name in ATTRIBUTES_TO_MAP: |
|
newt (away)
2013/05/06 16:59:34
technically you should check the namespace too.
Kibeom Kim (inactive)
2013/05/06 19:18:16
You're right. I was skipping the namespace check.
|
| + mapped_name = ATTRIBUTES_TO_MAP[name] |
| + item_element.attributes['name'] = namespace + ':' + mapped_name |
| + |
| + build_utils.MakeDirectory(os.path.dirname(output_file)) |
| + with open(output_file, 'w') as f: |
| + dom.writexml(f, '', ' ', '\n', encoding='utf-8') |
| + |
| +def GenerateV14LayoutXmlResource(dom, output_file): |
| + """Convert layout resource to API 14 compatible layout resource. |
| + |
| + It's mostly a simple replacement, s/Start/Left s/End/Right, |
| + on the attribute names. |
| + """ |
| for element in IterateXmlElements(dom): |
| all_names = element.attributes.keysNS() |
| @@ -103,17 +119,22 @@ def GenerateV14Resource(input_filename, output_filename): |
| # print >> sys.stderror, 'Warning: layout should use xxx instead of yyy' |
| pass |
| - build_utils.MakeDirectory(os.path.dirname(output_filename)) |
| - with open(output_filename, 'w') as f: |
| - dom.writexml(f, ' ', '\n', encoding='utf-8') |
| + build_utils.MakeDirectory(os.path.dirname(output_file)) |
| + with open(output_file, 'w') as f: |
| + dom.writexml(f, '', ' ', '\n', encoding='utf-8') |
| -def GenerateV14ResourcesInDir(input_dir, output_dir): |
| +def GenerateV14XmlResourcesInDir(input_dir, output_dir): |
| """Convert resources to API 14 compatible XML resources in the directory.""" |
| for input_file in build_utils.FindInDirectory(input_dir, '*.xml'): |
| - output_path = os.path.join(output_dir, |
| + output_file = os.path.join(output_dir, |
| os.path.relpath(input_file, input_dir)) |
| - GenerateV14Resource(input_file, output_path) |
| + dom = minidom.parse(input_file) |
| + if dom.getElementsByTagName('resources'): |
|
newt (away)
2013/05/06 16:59:34
only the root node should be named resources. I'd
Kibeom Kim (inactive)
2013/05/06 19:18:16
Done.
|
| + if dom.getElementsByTagName('style'): |
|
newt (away)
2013/05/06 16:59:34
similarly, the style nodes should all be children
Kibeom Kim (inactive)
2013/05/06 19:18:16
Done.
|
| + GenerateV14StyleXmlResource(dom, output_file) |
| + else: |
| + GenerateV14LayoutXmlResource(dom, output_file) |
| def ParseArgs(): |
| @@ -156,18 +177,17 @@ def main(argv): |
| resource_type = dir_pieces[0] |
| qualifiers = dir_pieces[1:] |
| - # We only convert resources under layout*/ and xml*/. |
| - if resource_type not in ('layout', 'xml'): |
| - continue |
| - |
| # Android pre-v17 API doesn't support RTL. Skip. |
| if 'ldrtl' in qualifiers: |
| continue |
| - # Convert all the resource files. |
| - input_path = os.path.join(options.res_dir, name) |
| - output_path = os.path.join(options.res_v14_dir, name) |
| - GenerateV14ResourcesInDir(input_path, output_path) |
| + input_dir = os.path.join(options.res_dir, name) |
| + output_dir = os.path.join(options.res_v14_dir, name) |
| + |
| + # We only convert resources under layout*/, xml*/, |
| + # and style resources under values*/. |
| + if resource_type in ('layout', 'xml', 'values'): |
| + GenerateV14XmlResourcesInDir(input_dir, output_dir) |
| if options.stamp: |
| build_utils.Touch(options.stamp) |