OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Convert Android xml resources to API 14 compatible. | 7 """Convert Android xml resources to API 14 compatible. |
8 | 8 |
9 There are two reasons that we cannot just use API 17 attributes, | 9 There are two reasons that we cannot just use API 17 attributes, |
10 so we are generating another set of resources by this script. | 10 so we are generating another set of resources by this script. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 root_node = IterateXmlElements(dom).next() | 106 root_node = IterateXmlElements(dom).next() |
107 return bool(root_node.nodeName == 'resources' and | 107 return bool(root_node.nodeName == 'resources' and |
108 list(root_node.getElementsByTagName('style'))) | 108 list(root_node.getElementsByTagName('style'))) |
109 | 109 |
110 | 110 |
111 def ErrorIfStyleResourceExistsInDir(input_dir): | 111 def ErrorIfStyleResourceExistsInDir(input_dir): |
112 """If a style resource is in input_dir, raises an exception.""" | 112 """If a style resource is in input_dir, raises an exception.""" |
113 for input_filename in build_utils.FindInDirectory(input_dir, '*.xml'): | 113 for input_filename in build_utils.FindInDirectory(input_dir, '*.xml'): |
114 dom = ParseAndReportErrors(input_filename) | 114 dom = ParseAndReportErrors(input_filename) |
115 if HasStyleResource(dom): | 115 if HasStyleResource(dom): |
116 raise Exception('error: style file ' + input_filename + | 116 # Allow style file in third_party to exist in non-v17 directories so long |
117 ' should be under ' + input_dir + | 117 # as they do not contain deprecated attributes. |
118 '-v17 directory. Please refer to ' | 118 if not 'third_party' in input_dir or ( |
119 'http://crbug.com/243952 for the details.') | 119 GenerateV14StyleResourceDom(dom, input_filename)): |
| 120 raise Exception('error: style file ' + input_filename + |
| 121 ' should be under ' + input_dir + |
| 122 '-v17 directory. Please refer to ' |
| 123 'http://crbug.com/243952 for the details.') |
120 | 124 |
121 | 125 |
122 def GenerateV14LayoutResourceDom(dom, filename, assert_not_deprecated=True): | 126 def GenerateV14LayoutResourceDom(dom, filename, assert_not_deprecated=True): |
123 """Convert layout resource to API 14 compatible layout resource. | 127 """Convert layout resource to API 14 compatible layout resource. |
124 | 128 |
125 Args: | 129 Args: |
126 dom: Parsed minidom object to be modified. | 130 dom: Parsed minidom object to be modified. |
127 filename: Filename that the DOM was parsed from. | 131 filename: Filename that the DOM was parsed from. |
128 assert_not_deprecated: Whether deprecated attributes (e.g. paddingLeft) will | 132 assert_not_deprecated: Whether deprecated attributes (e.g. paddingLeft) will |
129 cause an exception to be thrown. | 133 cause an exception to be thrown. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 build_utils.MakeDirectory(res_v14_dir) | 315 build_utils.MakeDirectory(res_v14_dir) |
312 | 316 |
313 GenerateV14Resources(options.res_dir, res_v14_dir) | 317 GenerateV14Resources(options.res_dir, res_v14_dir) |
314 | 318 |
315 if options.stamp: | 319 if options.stamp: |
316 build_utils.Touch(options.stamp) | 320 build_utils.Touch(options.stamp) |
317 | 321 |
318 if __name__ == '__main__': | 322 if __name__ == '__main__': |
319 sys.exit(main()) | 323 sys.exit(main()) |
320 | 324 |
OLD | NEW |