Commit 36e2f31e authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Android: Introduce "mergeable_android_manifest" for Android targets

And refactors how input_jars_paths and proguard_configs works a bit.

You can now any put any of these variables on any java target's
build_config.

Bug: 1105693
Change-Id: I332c0ea5637eb7778a12d1ddca3b5fddd54f308f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431788
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811243}
parent e3d45995
...@@ -677,30 +677,34 @@ def RemoveObjDups(obj, base, *key_path): ...@@ -677,30 +677,34 @@ def RemoveObjDups(obj, base, *key_path):
class Deps(object): class Deps(object):
def __init__(self, direct_deps_config_paths): def __init__(self, direct_deps_config_paths):
self.all_deps_config_paths = GetAllDepsConfigsInOrder( self._all_deps_config_paths = GetAllDepsConfigsInOrder(
direct_deps_config_paths) direct_deps_config_paths)
self.direct_deps_configs = [ self._direct_deps_configs = [
GetDepConfig(p) for p in direct_deps_config_paths] GetDepConfig(p) for p in direct_deps_config_paths
self.all_deps_configs = [ ]
GetDepConfig(p) for p in self.all_deps_config_paths] self._all_deps_configs = [
self.direct_deps_config_paths = direct_deps_config_paths GetDepConfig(p) for p in self._all_deps_config_paths
]
self._direct_deps_config_paths = direct_deps_config_paths
def All(self, wanted_type): def All(self, wanted_type=None):
return DepsOfType(wanted_type, self.all_deps_configs) if wanted_type is None:
return self._all_deps_configs
return DepsOfType(wanted_type, self._all_deps_configs)
def Direct(self, wanted_type=None): def Direct(self, wanted_type=None):
if wanted_type is None: if wanted_type is None:
return self.direct_deps_configs return self._direct_deps_configs
return DepsOfType(wanted_type, self.direct_deps_configs) return DepsOfType(wanted_type, self._direct_deps_configs)
def AllConfigPaths(self): def AllConfigPaths(self):
return self.all_deps_config_paths return self._all_deps_config_paths
def RemoveNonDirectDep(self, path): def RemoveNonDirectDep(self, path):
if path in self.direct_deps_config_paths: if path in self._direct_deps_config_paths:
raise Exception('Cannot remove direct dep.') raise Exception('Cannot remove direct dep.')
self.all_deps_config_paths.remove(path) self._all_deps_config_paths.remove(path)
self.all_deps_configs.remove(GetDepConfig(path)) self._all_deps_configs.remove(GetDepConfig(path))
def GradlePrebuiltJarPaths(self): def GradlePrebuiltJarPaths(self):
ret = [] ret = []
...@@ -962,6 +966,9 @@ def main(argv): ...@@ -962,6 +966,9 @@ def main(argv):
parser.add_option('--extra-classpath-jars', parser.add_option('--extra-classpath-jars',
help='GYP-list of .jar files to include on the classpath when compiling, ' help='GYP-list of .jar files to include on the classpath when compiling, '
'but not to include in the final binary.') 'but not to include in the final binary.')
parser.add_option(
'--mergeable-android-manifests',
help='GN-list of AndroidManifest.xml to include in manifest merging.')
parser.add_option('--gradle-treat-as-prebuilt', action='store_true', parser.add_option('--gradle-treat-as-prebuilt', action='store_true',
help='Whether this library should be treated as a prebuilt library by ' help='Whether this library should be treated as a prebuilt library by '
'generate_gradle.py.') 'generate_gradle.py.')
...@@ -1199,10 +1206,10 @@ def main(argv): ...@@ -1199,10 +1206,10 @@ def main(argv):
set(deps.AllConfigPaths() + processor_deps.AllConfigPaths() + set(deps.AllConfigPaths() + processor_deps.AllConfigPaths() +
list(static_library_dependent_configs_by_path))) list(static_library_dependent_configs_by_path)))
direct_deps = deps.Direct()
system_library_deps = deps.Direct('system_java_library') system_library_deps = deps.Direct('system_java_library')
direct_library_deps = deps.Direct('java_library') direct_library_deps = deps.Direct('java_library')
direct_group_deps = deps.Direct('group') all_deps = deps.All()
all_group_deps = deps.All('group')
all_library_deps = deps.All('java_library') all_library_deps = deps.All('java_library')
all_resources_deps = deps.All('android_resources') all_resources_deps = deps.All('android_resources')
...@@ -1227,7 +1234,7 @@ def main(argv): ...@@ -1227,7 +1234,7 @@ def main(argv):
'path': options.build_config, 'path': options.build_config,
'type': options.type, 'type': options.type,
'gn_target': options.gn_target, 'gn_target': options.gn_target,
'deps_configs': deps.direct_deps_config_paths, 'deps_configs': [d['path'] for d in direct_deps],
'chromium_code': not options.non_chromium_code, 'chromium_code': not options.non_chromium_code,
}, },
# Info needed only by generate_gradle.py. # Info needed only by generate_gradle.py.
...@@ -1470,12 +1477,21 @@ def main(argv): ...@@ -1470,12 +1477,21 @@ def main(argv):
config['deps_info']['dependency_zip_overlays'] = dependency_zip_overlays config['deps_info']['dependency_zip_overlays'] = dependency_zip_overlays
config['deps_info']['extra_package_names'] = extra_package_names config['deps_info']['extra_package_names'] = extra_package_names
if options.type == 'group': # These are .jars to add to javac classpath but not to runtime classpath.
if options.extra_classpath_jars: extra_classpath_jars = build_utils.ParseGnList(options.extra_classpath_jars)
# These are .jars to add to javac classpath but not to runtime classpath. if extra_classpath_jars:
extra_classpath_jars = build_utils.ParseGnList( deps_info['extra_classpath_jars'] = extra_classpath_jars
options.extra_classpath_jars)
deps_info['extra_classpath_jars'] = extra_classpath_jars mergeable_android_manifests = build_utils.ParseGnList(
options.mergeable_android_manifests)
if mergeable_android_manifests:
deps_info['mergeable_android_manifests'] = mergeable_android_manifests
extra_proguard_classpath_jars = []
proguard_configs = build_utils.ParseGnList(options.proguard_configs)
if proguard_configs:
# Make a copy of |proguard_configs| since it's mutated below.
deps_info['proguard_configs'] = list(proguard_configs)
if options.type == 'dist_aar': if options.type == 'dist_aar':
# dist_aar combines all dependency R.txt files into one for the aar. # dist_aar combines all dependency R.txt files into one for the aar.
...@@ -1518,11 +1534,11 @@ def main(argv): ...@@ -1518,11 +1534,11 @@ def main(argv):
javac_interface_classpath.add( javac_interface_classpath.add(
base_module_build_config['deps_info']['interface_jar_path']) base_module_build_config['deps_info']['interface_jar_path'])
for dep in direct_group_deps: for dep in direct_deps:
if 'extra_classpath_jars' in dep: if 'extra_classpath_jars' in dep:
javac_classpath.update(dep['extra_classpath_jars']) javac_classpath.update(dep['extra_classpath_jars'])
javac_interface_classpath.update(dep['extra_classpath_jars']) javac_interface_classpath.update(dep['extra_classpath_jars'])
for dep in all_group_deps: for dep in all_deps:
if 'extra_classpath_jars' in dep: if 'extra_classpath_jars' in dep:
javac_full_classpath.update(dep['extra_classpath_jars']) javac_full_classpath.update(dep['extra_classpath_jars'])
javac_full_interface_classpath.update(dep['extra_classpath_jars']) javac_full_interface_classpath.update(dep['extra_classpath_jars'])
...@@ -1533,9 +1549,6 @@ def main(argv): ...@@ -1533,9 +1549,6 @@ def main(argv):
# These are jars specified by input_jars_paths that almost never change. # These are jars specified by input_jars_paths that almost never change.
# Just add them directly to all the classpaths. # Just add them directly to all the classpaths.
if options.extra_classpath_jars: if options.extra_classpath_jars:
extra_classpath_jars = build_utils.ParseGnList(
options.extra_classpath_jars)
deps_info['extra_classpath_jars'] = extra_classpath_jars
javac_classpath.update(extra_classpath_jars) javac_classpath.update(extra_classpath_jars)
javac_interface_classpath.update(extra_classpath_jars) javac_interface_classpath.update(extra_classpath_jars)
javac_full_classpath.update(extra_classpath_jars) javac_full_classpath.update(extra_classpath_jars)
...@@ -1563,10 +1576,6 @@ def main(argv): ...@@ -1563,10 +1576,6 @@ def main(argv):
host_classpath.extend(c['host_jar_path'] for c in all_library_deps) host_classpath.extend(c['host_jar_path'] for c in all_library_deps)
deps_info['host_classpath'] = host_classpath deps_info['host_classpath'] = host_classpath
all_configs = build_utils.ParseGnList(options.proguard_configs)
deps_info['proguard_configs'] = list(all_configs)
extra_proguard_classpath_jars = []
# We allow lint to be run on android_apk targets, so we collect lint # We allow lint to be run on android_apk targets, so we collect lint
# artifacts for them. # artifacts for them.
# We allow lint to be run on android_app_bundle targets, so we need to # We allow lint to be run on android_app_bundle targets, so we need to
...@@ -1664,7 +1673,7 @@ def main(argv): ...@@ -1664,7 +1673,7 @@ def main(argv):
base_config = GetDepConfig(dep_config['base_module_config']) base_config = GetDepConfig(dep_config['base_module_config'])
extra_main_r_text_files.append(base_config['r_text_path']) extra_main_r_text_files.append(base_config['r_text_path'])
static_lib_jar_paths[config_path] = base_config['device_jar_path'] static_lib_jar_paths[config_path] = base_config['device_jar_path']
all_configs.extend(dep_config['proguard_all_configs']) proguard_configs.extend(dep_config['proguard_all_configs'])
extra_proguard_classpath_jars.extend( extra_proguard_classpath_jars.extend(
dep_config['proguard_classpath_jars']) dep_config['proguard_classpath_jars'])
all_java_sources.extend(base_config['jni']['all_source']) all_java_sources.extend(base_config['jni']['all_source'])
...@@ -1712,16 +1721,12 @@ def main(argv): ...@@ -1712,16 +1721,12 @@ def main(argv):
if options.type in ('android_apk', 'dist_aar', if options.type in ('android_apk', 'dist_aar',
'dist_jar', 'android_app_bundle_module', 'android_app_bundle'): 'dist_jar', 'android_app_bundle_module', 'android_app_bundle'):
for c in all_library_deps: for c in all_deps:
all_configs.extend(p for p in c.get('proguard_configs', [])) proguard_configs.extend(c.get('proguard_configs', []))
extra_proguard_classpath_jars.extend( extra_proguard_classpath_jars.extend(c.get('extra_classpath_jars', []))
p for p in c.get('extra_classpath_jars', []))
for c in all_group_deps:
extra_proguard_classpath_jars.extend(
p for p in c.get('extra_classpath_jars', []))
if options.type == 'android_app_bundle': if options.type == 'android_app_bundle':
for c in deps.Direct('android_app_bundle_module'): for c in deps.Direct('android_app_bundle_module'):
all_configs.extend(p for p in c.get('proguard_configs', [])) proguard_configs.extend(p for p in c.get('proguard_configs', []))
if options.type == 'android_app_bundle': if options.type == 'android_app_bundle':
for d in deps.Direct('android_app_bundle_module'): for d in deps.Direct('android_app_bundle_module'):
extra_proguard_classpath_jars.extend( extra_proguard_classpath_jars.extend(
...@@ -1769,7 +1774,8 @@ def main(argv): ...@@ -1769,7 +1774,8 @@ def main(argv):
assert options.proguard_enabled, ('proguard must be enabled for ' assert options.proguard_enabled, ('proguard must be enabled for '
'instrumentation apks if it\'s enabled for the tested apk.') 'instrumentation apks if it\'s enabled for the tested apk.')
# Mutating lists, so no need to explicitly re-assign to dict. # Mutating lists, so no need to explicitly re-assign to dict.
all_configs.extend(p for p in tested_apk_config['proguard_all_configs']) proguard_configs.extend(
p for p in tested_apk_config['proguard_all_configs'])
extra_proguard_classpath_jars.extend( extra_proguard_classpath_jars.extend(
p for p in tested_apk_config['proguard_classpath_jars']) p for p in tested_apk_config['proguard_classpath_jars'])
tested_apk_config = GetDepConfig(options.tested_apk_config) tested_apk_config = GetDepConfig(options.tested_apk_config)
...@@ -1810,7 +1816,7 @@ def main(argv): ...@@ -1810,7 +1816,7 @@ def main(argv):
if options.type in ('android_apk', 'dist_aar', 'dist_jar', if options.type in ('android_apk', 'dist_aar', 'dist_jar',
'android_app_bundle_module', 'android_app_bundle'): 'android_app_bundle_module', 'android_app_bundle'):
deps_info['proguard_all_configs'] = sorted(set(all_configs)) deps_info['proguard_all_configs'] = sorted(set(proguard_configs))
deps_info['proguard_classpath_jars'] = sorted( deps_info['proguard_classpath_jars'] = sorted(
set(extra_proguard_classpath_jars)) set(extra_proguard_classpath_jars))
...@@ -1935,8 +1941,10 @@ def main(argv): ...@@ -1935,8 +1941,10 @@ def main(argv):
'uncompressed_locales_java_list'] = _CreateJavaLocaleListFromAssets( 'uncompressed_locales_java_list'] = _CreateJavaLocaleListFromAssets(
config['uncompressed_assets'], locale_paks) config['uncompressed_assets'], locale_paks)
config['extra_android_manifests'] = filter(None, ( config['extra_android_manifests'] = []
d.get('android_manifest') for d in all_resources_deps)) for c in all_deps:
config['extra_android_manifests'].extend(
c.get('mergeable_android_manifests', []))
# Collect java resources # Collect java resources
java_resources_jars = [d['java_resources_jar'] for d in all_library_deps java_resources_jars = [d['java_resources_jar'] for d in all_library_deps
...@@ -1968,7 +1976,7 @@ def main(argv): ...@@ -1968,7 +1976,7 @@ def main(argv):
if is_java_target: if is_java_target:
jar_to_target = {} jar_to_target = {}
_AddJarMapping(jar_to_target, [deps_info]) _AddJarMapping(jar_to_target, [deps_info])
_AddJarMapping(jar_to_target, deps.all_deps_configs) _AddJarMapping(jar_to_target, all_deps)
if base_module_build_config: if base_module_build_config:
_AddJarMapping(jar_to_target, [base_module_build_config['deps_info']]) _AddJarMapping(jar_to_target, [base_module_build_config['deps_info']])
if options.tested_apk_config: if options.tested_apk_config:
......
...@@ -505,11 +505,6 @@ template("write_build_config") { ...@@ -505,11 +505,6 @@ template("write_build_config") {
rebase_path(invoker.bundled_srcjars, root_build_dir) rebase_path(invoker.bundled_srcjars, root_build_dir)
args += [ "--bundled-srcjars=$_rebased_bundled_srcjars" ] args += [ "--bundled-srcjars=$_rebased_bundled_srcjars" ]
} }
if (defined(invoker.input_jars_paths)) {
_rebased_input_jars_paths =
rebase_path(invoker.input_jars_paths, root_build_dir)
args += [ "--extra-classpath-jars=$_rebased_input_jars_paths" ]
}
if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) { if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) {
args += [ "--proguard-enabled" ] args += [ "--proguard-enabled" ]
} }
...@@ -518,6 +513,18 @@ template("write_build_config") { ...@@ -518,6 +513,18 @@ template("write_build_config") {
rebase_path(invoker.proguard_mapping_path, root_build_dir) rebase_path(invoker.proguard_mapping_path, root_build_dir)
args += [ "--proguard-mapping-path=$_rebased_proguard_mapping_path" ] args += [ "--proguard-mapping-path=$_rebased_proguard_mapping_path" ]
} }
if (defined(invoker.input_jars_paths)) {
_rebased_input_jars_paths =
rebase_path(invoker.input_jars_paths, root_build_dir)
args += [ "--extra-classpath-jars=$_rebased_input_jars_paths" ]
}
if (defined(invoker.mergeable_android_manifests)) {
_rebased_mergeable_android_manifests =
rebase_path(invoker.mergeable_android_manifests, root_build_dir)
args += [
"--mergeable-android-manifests=$_rebased_mergeable_android_manifests",
]
}
if (defined(invoker.proguard_configs)) { if (defined(invoker.proguard_configs)) {
_rebased_proguard_configs = _rebased_proguard_configs =
rebase_path(invoker.proguard_configs, root_build_dir) rebase_path(invoker.proguard_configs, root_build_dir)
......
...@@ -979,6 +979,7 @@ if (enable_java_templates) { ...@@ -979,6 +979,7 @@ if (enable_java_templates) {
"android_manifest", "android_manifest",
"android_manifest_dep", "android_manifest_dep",
"custom_package", "custom_package",
"mergeable_android_manifests",
"resource_overlay", "resource_overlay",
"recursive_resource_deps", "recursive_resource_deps",
]) ])
...@@ -989,6 +990,13 @@ if (enable_java_templates) { ...@@ -989,6 +990,13 @@ if (enable_java_templates) {
} }
possible_config_deps = _deps possible_config_deps = _deps
# Always merge manifests from resources.
# * Might want to change this at some point for consistency and clarity,
# but keeping for backwards-compatibility.
if (!defined(mergeable_android_manifests) && defined(android_manifest)) {
mergeable_android_manifests = [ android_manifest ]
}
} }
prepare_resources(target_name) { prepare_resources(target_name) {
...@@ -1121,9 +1129,14 @@ if (enable_java_templates) { ...@@ -1121,9 +1129,14 @@ if (enable_java_templates) {
# } # }
# } # }
template("java_group") { template("java_group") {
_build_config_vars = [
"input_jars_paths",
"mergeable_android_manifests",
"proguard_configs",
]
forward_variables_from(invoker, [ "testonly" ]) forward_variables_from(invoker, [ "testonly" ])
write_build_config("$target_name$build_config_target_suffix") { write_build_config("$target_name$build_config_target_suffix") {
forward_variables_from(invoker, [ "input_jars_paths" ]) forward_variables_from(invoker, _build_config_vars)
type = "group" type = "group"
build_config = "$target_gen_dir/${invoker.target_name}.build_config" build_config = "$target_gen_dir/${invoker.target_name}.build_config"
supports_android = true supports_android = true
...@@ -1143,7 +1156,7 @@ if (enable_java_templates) { ...@@ -1143,7 +1156,7 @@ if (enable_java_templates) {
} }
} }
group(target_name) { group(target_name) {
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*", _build_config_vars)
if (!defined(deps)) { if (!defined(deps)) {
deps = [] deps = []
} }
...@@ -4219,10 +4232,7 @@ if (enable_java_templates) { ...@@ -4219,10 +4232,7 @@ if (enable_java_templates) {
args += [ "--ignore-resources" ] args += [ "--ignore-resources" ]
} }
inputs = [ invoker.aar_path ] inputs = [ invoker.aar_path ]
outputs = [] outputs = [ "${_output_path}/AndroidManifest.xml" ]
if (!_ignore_manifest) {
outputs += [ "${_output_path}/AndroidManifest.xml" ]
}
if (!_strip_resources && _scanned_files.has_r_text_file) { if (!_strip_resources && _scanned_files.has_r_text_file) {
# Certain packages, in particular Play Services have no R.txt even # Certain packages, in particular Play Services have no R.txt even
# though its presence is mandated by AAR spec. Such packages cause # though its presence is mandated by AAR spec. Such packages cause
...@@ -4315,6 +4325,17 @@ if (enable_java_templates) { ...@@ -4315,6 +4325,17 @@ if (enable_java_templates) {
not_needed(invoker, [ "strip_drawables" ]) not_needed(invoker, [ "strip_drawables" ])
} }
if (_ignore_manifest) {
# Having this available can be useful for DFMs that depend on AARs. It
# provides a way to have manifest entries go into the base split while
# the code goes into a DFM.
java_group("${target_name}__ignored_manifest") {
forward_variables_from(invoker, [ "testonly" ])
deps = [ ":$_unpack_target_name" ]
mergeable_android_manifests = [ "${_output_path}/AndroidManifest.xml" ]
}
}
# Create the android_assets target for assets # Create the android_assets target for assets
if (_use_scanned_assets) { if (_use_scanned_assets) {
_assets_target_name = "${target_name}__assets" _assets_target_name = "${target_name}__assets"
......
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