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..ffb0f98eabd09d1dd81a984e6e3d8e585a02f317 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): |
+ """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: |
+ 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, |
os.path.relpath(input_file, input_dir)) |
- GenerateV14Resource(input_file, output_path) |
+ dom = minidom.parse(input_file) |
+ if dom.getElementsByTagName('resources'): |
+ if dom.getElementsByTagName('style'): |
+ GenerateV14StyleXmlResource(dom, output_path) |
+ else: |
+ GenerateV14LayoutXmlResource(dom, output_path) |
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) |