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..1ae9f19cb4626f4422162d38e31febb232b0eec5 100755 |
| --- a/build/android/gyp/generate_v14_resources.py |
| +++ b/build/android/gyp/generate_v14_resources.py |
| @@ -63,14 +63,34 @@ def IterateXmlElements(node): |
| yield child_node_element |
| -def GenerateV14Resource(input_filename, output_filename): |
| - """Convert resource to API 14 compatible resource. |
| +def GenerateV14StyleResource(dom, output_file): |
| + """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(':') |
| + # Note: namespace == 'android' is not precise because |
|
newt (away)
2013/05/06 20:55:55
agreed, checking for "android" is plenty. if we st
|
| + # we are looking for 'http://schemas.android.com/apk/res/android' and |
| + # 'android' can be aliased to another name in layout xml files where |
| + # this style is used. e.g. xmlns:android="http://crbug.com/". |
| + if namespace == 'android' and name in ATTRIBUTES_TO_MAP: |
| + 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 GenerateV14LayoutResource(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 +123,23 @@ 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) |
| + root_element = IterateXmlElements(dom).next() |
| + if root_element.nodeName == 'resources': |
| + if root_element.getElementsByTagName('style'): |
| + GenerateV14StyleResource(dom, output_file) |
| + else: |
| + GenerateV14LayoutResource(dom, output_file) |
| def ParseArgs(): |
| @@ -156,18 +182,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'): |
|
newt (away)
2013/05/06 20:55:55
we know that style resources live in "values", and
Kibeom Kim (inactive)
2013/05/06 22:28:01
Done.
|
| + GenerateV14XmlResourcesInDir(input_dir, output_dir) |
| if options.stamp: |
| build_utils.Touch(options.stamp) |