diff options
author | kkimlabs@chromium.org <kkimlabs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-09 14:07:51 +0000 |
---|---|---|
committer | kkimlabs@chromium.org <kkimlabs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-09 14:07:51 +0000 |
commit | fe3fa42b08116996a91bcfcd56076033e50531ca (patch) | |
tree | 62e831315ceff724b4b1c129ec6a715c635c0630 | |
parent | 4efe8f28015c34dadde83fd4e7de7d3788668cee (diff) | |
download | chromium_src-fe3fa42b08116996a91bcfcd56076033e50531ca.zip chromium_src-fe3fa42b08116996a91bcfcd56076033e50531ca.tar.gz chromium_src-fe3fa42b08116996a91bcfcd56076033e50531ca.tar.bz2 |
[Android] Add an gyp option to disable generating v14 resources script.
Currently, we are generating v14 layout and style resources from v17
resources by replacing Start and End attributes to Left and Right
attributes. However, it is not necessary for all cases, so make an
option to disable generate_v14_compatible_resources.py script and
only verify that there is no RTL attributes in the pre-v17 resources.
BUG=247049
Review URL: https://chromiumcodereview.appspot.com/18653002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210555 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | build/android/gyp/generate_v14_compatible_resources.py | 114 | ||||
-rw-r--r-- | build/java.gypi | 12 |
2 files changed, 94 insertions, 32 deletions
diff --git a/build/android/gyp/generate_v14_compatible_resources.py b/build/android/gyp/generate_v14_compatible_resources.py index 6b84808..7155744 100755 --- a/build/android/gyp/generate_v14_compatible_resources.py +++ b/build/android/gyp/generate_v14_compatible_resources.py @@ -98,16 +98,17 @@ def ErrorIfStyleResourceExistsInDir(input_dir): if HasStyleResource(dom): raise Exception('error: style file ' + input_filename + ' should be under ' + input_dir + - '-v17 directory. Please refer to crbug.com/243952 ' - 'for the details.') + '-v17 directory. Please refer to ' + 'http://crbug.com/243952 for the details.') -def GenerateV14LayoutResourceDom(dom, filename): +def GenerateV14LayoutResourceDom(dom, filename_for_warning): """Convert layout resource to API 14 compatible layout resource. Args: dom: parsed minidom object to be modified. - filename: file name to display in case we print warnings. + filename_for_warning: file name to display in case we print warnings. + If None, do not print warning. Returns: True if dom is modified, False otherwise. """ @@ -125,27 +126,35 @@ def GenerateV14LayoutResourceDom(dom, filename): element.setAttribute(ATTRIBUTES_TO_MAP[name], value) del element.attributes[name] is_modified = True - else: - WarnIfDeprecatedAttribute(name, value, filename) + elif filename_for_warning: + WarnIfDeprecatedAttribute(name, value, filename_for_warning) return is_modified -def GenerateV14StyleResourceDom(dom, filename): +def GenerateV14StyleResourceDom(dom, filename_for_warning): """Convert style resource to API 14 compatible style resource. Args: dom: parsed minidom object to be modified. - filename: file name to display in case we print warnings. + filename_for_warning: file name to display in case we print warnings. + If None, do not print warning. + Returns: + True if dom is modified, False otherwise. """ + is_modified = False + for style_element in dom.getElementsByTagName('style'): for item_element in style_element.getElementsByTagName('item'): name = item_element.attributes['name'].value value = item_element.childNodes[0].nodeValue if name in ATTRIBUTES_TO_MAP: item_element.attributes['name'].value = ATTRIBUTES_TO_MAP[name] - else: - WarnIfDeprecatedAttribute(name, value, filename) + is_modified = True + elif filename_for_warning: + WarnIfDeprecatedAttribute(name, value, filename_for_warning) + + return is_modified def GenerateV14LayoutResource(input_filename, output_v14_filename, @@ -202,6 +211,36 @@ def GenerateV14StyleResourcesInDir(input_dir, output_v14_dir): GenerateV14StyleResource(input_filename, output_v14_filename) +def VerifyV14ResourcesInDir(input_dir, resource_type): + """Verify that the resources in input_dir is compatible with v14, i.e., they + don't use attributes that cause crashes on certain devices. Print an error if + they have.""" + for input_filename in build_utils.FindInDirectory(input_dir, '*.xml'): + exception_message = ('error : ' + input_filename + ' has an RTL attribute, ' + 'i.e., attribute that has "start" or "end" in its name.' + ' Pre-v17 resources should not include it because it ' + 'can cause crashes on certain devices. Please refer to ' + 'http://crbug.com/243952 for the details.') + dom = minidom.parse(input_filename) + if resource_type in ('layout', 'xml'): + if GenerateV14LayoutResourceDom(dom, None): + raise Exception(exception_message) + elif resource_type == 'values': + if GenerateV14StyleResourceDom(dom, None): + raise Exception(exception_message) + + +def WarnIfDeprecatedAttributeInDir(input_dir, resource_type): + """Print warning if resources in input_dir have deprecated attributes, e.g., + paddingLeft, PaddingRight""" + for input_filename in build_utils.FindInDirectory(input_dir, '*.xml'): + dom = minidom.parse(input_filename) + if resource_type in ('layout', 'xml'): + GenerateV14LayoutResourceDom(dom, input_filename) + elif resource_type == 'values': + GenerateV14StyleResourceDom(dom, input_filename) + + def ParseArgs(): """Parses command line options. @@ -216,6 +255,10 @@ def ParseArgs(): help='output directory into which ' 'v14 compatible resources will be generated') parser.add_option('--stamp', help='File to touch on success') + parser.add_option('--verify-only', action="store_true", help='Do not generate' + ' v14 resources. Instead, just verify that the resources are already ' + "compatible with v14, i.e. they don't use attributes that cause crashes " + 'on certain devices.') options, args = parser.parse_args() @@ -254,29 +297,36 @@ def main(argv): if 'ldrtl' in qualifiers: continue - # We also need to copy the original v17 resource to *-v17 directory - # because the generated v14 resource will hide the original resource. - input_dir = os.path.join(options.res_dir, name) - output_v14_dir = os.path.join(options.res_v14_compatibility_dir, name) - output_v17_dir = os.path.join(options.res_v14_compatibility_dir, name + - '-v17') + input_dir = os.path.abspath(os.path.join(options.res_dir, name)) - # We only convert layout resources under layout*/, xml*/, - # and style resources under values*/. - if resource_type in ('layout', 'xml'): - if not api_level_qualifier: - GenerateV14LayoutResourcesInDir(input_dir, output_v14_dir, - output_v17_dir) - elif resource_type == 'values': - if api_level_qualifier == 'v17': - output_qualifiers = qualifiers[:] - del output_qualifiers[api_level_qualifier_index] - output_v14_dir = os.path.join(options.res_v14_compatibility_dir, - '-'.join([resource_type] + - output_qualifiers)) - GenerateV14StyleResourcesInDir(input_dir, output_v14_dir) - elif not api_level_qualifier: - ErrorIfStyleResourceExistsInDir(input_dir) + if options.verify_only: + if not api_level_qualifier or int(api_level_qualifier[1:]) < 17: + VerifyV14ResourcesInDir(input_dir, resource_type) + else: + WarnIfDeprecatedAttributeInDir(input_dir, resource_type) + else: + # We also need to copy the original v17 resource to *-v17 directory + # because the generated v14 resource will hide the original resource. + output_v14_dir = os.path.join(options.res_v14_compatibility_dir, name) + output_v17_dir = os.path.join(options.res_v14_compatibility_dir, name + + '-v17') + + # We only convert layout resources under layout*/, xml*/, + # and style resources under values*/. + if resource_type in ('layout', 'xml'): + if not api_level_qualifier: + GenerateV14LayoutResourcesInDir(input_dir, output_v14_dir, + output_v17_dir) + elif resource_type == 'values': + if api_level_qualifier == 'v17': + output_qualifiers = qualifiers[:] + del output_qualifiers[api_level_qualifier_index] + output_v14_dir = os.path.join(options.res_v14_compatibility_dir, + '-'.join([resource_type] + + output_qualifiers)) + GenerateV14StyleResourcesInDir(input_dir, output_v14_dir) + elif not api_level_qualifier: + ErrorIfStyleResourceExistsInDir(input_dir) if options.stamp: build_utils.Touch(options.stamp) diff --git a/build/java.gypi b/build/java.gypi index 3fd6429..0e41ab3 100644 --- a/build/java.gypi +++ b/build/java.gypi @@ -65,6 +65,7 @@ 'java_strings_grd%': '', 'res_extra_dirs': [], 'res_extra_files': [], + 'res_v14_verify_only%': 0, 'resource_input_paths': ['>@(res_extra_files)'], 'intermediate_dir': '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)', 'classes_dir': '<(intermediate_dir)/classes', @@ -185,6 +186,16 @@ { 'action_name': 'generate_api_14_resources_<(_target_name)', 'message': 'Generating Android API 14 resources <(_target_name)', + 'variables' : { + 'res_v14_additional_options': [], + }, + 'conditions': [ + ['res_v14_verify_only == 1', { + 'variables': { + 'res_v14_additional_options': ['--verify-only'] + }, + }], + ], 'inputs': [ '<(DEPTH)/build/android/gyp/util/build_utils.py', '<(DEPTH)/build/android/gyp/generate_v14_compatible_resources.py', @@ -198,6 +209,7 @@ '--res-dir=<(res_dir)', '--res-v14-compatibility-dir=<(res_v14_compatibility_dir)', '--stamp', '<(res_v14_compatibility_stamp)', + '<@(res_v14_additional_options)', ] }, ], |