Commit a05756be authored by agrieve's avatar agrieve Committed by Commit bot

GN(android): Enhance dependency logic in .build_config files

* Don't let java_library pass through android_assets / android_resources
* Don't let android_apk / deps_dex / resource_rewriter be used as deps

BUG=565359

Review URL: https://codereview.chromium.org/1493803003

Cr-Commit-Position: refs/heads/master@{#363068}
parent a820df1f
...@@ -37,6 +37,13 @@ from util import md5_check ...@@ -37,6 +37,13 @@ from util import md5_check
import write_ordered_libraries import write_ordered_libraries
# Types that should never be used as a dependency of another build config.
_ROOT_TYPES = ('android_apk', 'deps_dex', 'resource_rewriter')
# Types that should not allow code deps to pass through.
_RESOURCE_TYPES = ('android_assets', 'android_resources')
class AndroidManifest(object): class AndroidManifest(object):
def __init__(self, path): def __init__(self, path):
self.path = path self.path = path
...@@ -143,6 +150,16 @@ def _MergeAssets(all_assets): ...@@ -143,6 +150,16 @@ def _MergeAssets(all_assets):
return create_list(compressed), create_list(uncompressed) return create_list(compressed), create_list(uncompressed)
def _FilterUnwantedDepsPaths(dep_paths, target_type):
# Don't allow root targets to be considered as a dep.
ret = [p for p in dep_paths if GetDepConfig(p)['type'] not in _ROOT_TYPES]
# Don't allow java libraries to cross through assets/resources.
if target_type in _RESOURCE_TYPES:
ret = [p for p in ret if GetDepConfig(p)['type'] in _RESOURCE_TYPES]
return ret
def main(argv): def main(argv):
parser = optparse.OptionParser() parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser) build_utils.AddDepfileOption(parser)
...@@ -242,8 +259,11 @@ def main(argv): ...@@ -242,8 +259,11 @@ def main(argv):
direct_deps_config_paths = [ direct_deps_config_paths = [
c for c in possible_deps_config_paths if not c in unknown_deps] c for c in possible_deps_config_paths if not c in unknown_deps]
direct_deps_config_paths = _FilterUnwantedDepsPaths(direct_deps_config_paths,
options.type)
deps = Deps(direct_deps_config_paths) deps = Deps(direct_deps_config_paths)
direct_library_deps = deps.Direct('java_library') direct_library_deps = deps.Direct('java_library')
all_library_deps = deps.All('java_library') all_library_deps = deps.All('java_library')
...@@ -265,12 +285,12 @@ def main(argv): ...@@ -265,12 +285,12 @@ def main(argv):
'name': os.path.basename(options.build_config), 'name': os.path.basename(options.build_config),
'path': options.build_config, 'path': options.build_config,
'type': options.type, 'type': options.type,
'deps_configs': direct_deps_config_paths, 'deps_configs': direct_deps_config_paths
} }
} }
deps_info = config['deps_info'] deps_info = config['deps_info']
if options.type == 'java_library' and not options.bypass_platform_checks: if (options.type == 'java_library' and not options.bypass_platform_checks):
deps_info['requires_android'] = options.requires_android deps_info['requires_android'] = options.requires_android
deps_info['supports_android'] = options.supports_android deps_info['supports_android'] = options.supports_android
...@@ -287,7 +307,7 @@ def main(argv): ...@@ -287,7 +307,7 @@ def main(argv):
raise Exception('Not all deps support the Android platform: ' + raise Exception('Not all deps support the Android platform: ' +
str(deps_not_support_android)) str(deps_not_support_android))
if options.type in ['java_library', 'android_apk']: if options.type in ('java_library', 'android_apk'):
javac_classpath = [c['jar_path'] for c in direct_library_deps] javac_classpath = [c['jar_path'] for c in direct_library_deps]
java_full_classpath = [c['jar_path'] for c in all_library_deps] java_full_classpath = [c['jar_path'] for c in all_library_deps]
deps_info['resources_deps'] = [c['path'] for c in all_resources_deps] deps_info['resources_deps'] = [c['path'] for c in all_resources_deps]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment