Commit 2e296d82 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Reland "Android: Link against apk_under_test resources for test apks"

This reverts commit 6fe841a9.

Reason for reland: Fixed the build error. Built all locally.

Test apks are allowed to reference resources that live in the apk_under_test.
We've previous supported such references via R.java constants, but this
CL also adds the ability for resources in the test apk to directly
reference resources in the apk_under_test (e.g. via xml @references).

The need for this has come with the latest version of the support
library.

To accomplish this:
1. Adds a "-I UnderTest.ap_" flag when compiling test apks resources
2. Sets the test apk's arsc package name to match the apk_under_test's
   package name.
3. Uses --emit-ids / --stable-ids to avoid collisions between the
   test apk and the apk_under_test.
4. Updates incremental install manifest logic to do the same trick.

Some other small tweaks to related resource code:
* Removes incremental AndroidManifest.xml as an explicit build output
* Moves most uses of "aapt dump" to "aapt2 dump"
* Removes --check-resources-pkg-id in favor of always enabling it
* Removes --optimize-resources in favor of having it implicitly set by
  --optimized-resources-path

Bug: 896775
Change-Id: I37aa5b969023ccdaad45e7617f811d1781564c29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1567926Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#651093}
parent a4ab7717
This diff is collapsed.
...@@ -36,6 +36,9 @@ def _ParseArgs(args): ...@@ -36,6 +36,9 @@ def _ParseArgs(args):
""" """
parser, input_opts, output_opts = resource_utils.ResourceArgsParser() parser, input_opts, output_opts = resource_utils.ResourceArgsParser()
input_opts.add_argument(
'--aapt-path', required=True, help='Path to the Android aapt tool')
input_opts.add_argument('--resource-dirs', input_opts.add_argument('--resource-dirs',
default='[]', default='[]',
help='A list of input directories containing resources ' help='A list of input directories containing resources '
......
...@@ -8,6 +8,7 @@ import contextlib ...@@ -8,6 +8,7 @@ import contextlib
import os import os
import re import re
import shutil import shutil
import subprocess
import sys import sys
import tempfile import tempfile
from xml.etree import ElementTree from xml.etree import ElementTree
...@@ -24,6 +25,8 @@ from jinja2 import Template # pylint: disable=F0401 ...@@ -24,6 +25,8 @@ from jinja2 import Template # pylint: disable=F0401
EMPTY_ANDROID_MANIFEST_PATH = os.path.join( EMPTY_ANDROID_MANIFEST_PATH = os.path.join(
_SOURCE_ROOT, 'build', 'android', 'AndroidManifest.xml') _SOURCE_ROOT, 'build', 'android', 'AndroidManifest.xml')
ANDROID_NAMESPACE = 'http://schemas.android.com/apk/res/android'
TOOLS_NAMESPACE = 'http://schemas.android.com/tools'
# A variation of these maps also exists in: # A variation of these maps also exists in:
# //base/android/java/src/org/chromium/base/LocaleUtils.java # //base/android/java/src/org/chromium/base/LocaleUtils.java
...@@ -44,6 +47,9 @@ _ANDROID_TO_CHROMIUM_LANGUAGE_MAP = { ...@@ -44,6 +47,9 @@ _ANDROID_TO_CHROMIUM_LANGUAGE_MAP = {
} }
_xml_namespace_initialized = False
def ToAndroidLocaleName(chromium_locale): def ToAndroidLocaleName(chromium_locale):
"""Convert an Chromium locale name into a corresponding Android one.""" """Convert an Chromium locale name into a corresponding Android one."""
# First handle the special cases, these are needed to deal with Android # First handle the special cases, these are needed to deal with Android
...@@ -511,8 +517,38 @@ public final class R { ...@@ -511,8 +517,38 @@ public final class R {
def ExtractPackageFromManifest(manifest_path): def ExtractPackageFromManifest(manifest_path):
"""Extract package name from Android manifest file.""" """Extract package name from Android manifest file."""
doc = ElementTree.parse(manifest_path) return ParseAndroidManifest(manifest_path)[1].get('package')
return doc.getroot().get('package')
def ExtractBinaryManifestValues(aapt2_path, apk_path):
"""Returns (version_code, version_name, package_name) for the given apk."""
output = subprocess.check_output([
aapt2_path, 'dump', 'xmltree', apk_path, '--file', 'AndroidManifest.xml'
])
version_code = re.search(r'versionCode.*?=(\d*)', output).group(1)
version_name = re.search(r'versionName.*?="(.*?)"', output).group(1)
package_name = re.search(r'package.*?="(.*?)"', output).group(1)
return version_code, version_name, package_name
def ExtractArscPackage(aapt2_path, apk_path):
"""Returns (package_name, package_id) of resources.arsc from apk_path."""
proc = subprocess.Popen([aapt2_path, 'dump', 'resources', apk_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
for line in proc.stdout:
# Package name=org.chromium.webview_shell id=7f
if line.startswith('Package'):
proc.kill()
parts = line.split()
package_name = parts[1].split('=')[1]
package_id = parts[2][3:]
return package_name, int(package_id, 16)
# aapt2 currently crashes when dumping webview resources, but not until after
# it prints the "Package" line (b/130553900).
sys.stderr.write(proc.stderr.read())
raise Exception('Failed to find arsc package name')
def ExtractDeps(dep_zips, deps_dir): def ExtractDeps(dep_zips, deps_dir):
...@@ -603,13 +639,6 @@ def ResourceArgsParser(): ...@@ -603,13 +639,6 @@ def ResourceArgsParser():
help='Paths to arsc resource files used to link ' help='Paths to arsc resource files used to link '
'against. Can be specified multiple times.') 'against. Can be specified multiple times.')
input_opts.add_argument('--aapt-path', required=True,
help='Path to the Android aapt tool')
input_opts.add_argument('--aapt2-path',
help='Path to the Android aapt2 tool. If in different'
' directory from --aapt-path.')
input_opts.add_argument('--dependencies-res-zips', required=True, input_opts.add_argument('--dependencies-res-zips', required=True,
help='Resources zip archives from dependents. Required to ' help='Resources zip archives from dependents. Required to '
'resolve @type/foo references into dependent ' 'resolve @type/foo references into dependent '
...@@ -630,15 +659,6 @@ def ResourceArgsParser(): ...@@ -630,15 +659,6 @@ def ResourceArgsParser():
'list of resources to be included in the R.java file in the format ' 'list of resources to be included in the R.java file in the format '
'generated by aapt.') 'generated by aapt.')
input_opts.add_argument(
'--package-name',
help='Package name that will be used to determine package ID.')
input_opts.add_argument(
'--package-name-to-id-mapping',
help='List containing mapping from package name to package IDs that will '
'be assigned.')
return (parser, input_opts, output_opts) return (parser, input_opts, output_opts)
...@@ -671,9 +691,6 @@ def HandleCommonOptions(options): ...@@ -671,9 +691,6 @@ def HandleCommonOptions(options):
else: else:
options.extra_r_text_files = [] options.extra_r_text_files = []
if not options.aapt2_path:
options.aapt2_path = options.aapt_path + '2'
def ParseAndroidResourceStringsFromXml(xml_data): def ParseAndroidResourceStringsFromXml(xml_data):
"""Parse and Android xml resource file and extract strings from it. """Parse and Android xml resource file and extract strings from it.
...@@ -782,3 +799,36 @@ def FilterAndroidResourceStringsXml(xml_file_path, string_predicate): ...@@ -782,3 +799,36 @@ def FilterAndroidResourceStringsXml(xml_file_path, string_predicate):
new_xml_data = GenerateAndroidResourceStringsXml(strings_map, namespaces) new_xml_data = GenerateAndroidResourceStringsXml(strings_map, namespaces)
with open(xml_file_path, 'wb') as f: with open(xml_file_path, 'wb') as f:
f.write(new_xml_data) f.write(new_xml_data)
def _RegisterElementTreeNamespaces():
global _xml_namespace_initialized
if not _xml_namespace_initialized:
_xml_namespace_initialized = True
ElementTree.register_namespace('android', ANDROID_NAMESPACE)
ElementTree.register_namespace('tools', TOOLS_NAMESPACE)
def ParseAndroidManifest(path):
"""Parses an AndroidManifest.xml using ElementTree.
Registers required namespaces & creates application node if missing.
Returns tuple of:
doc: Root xml document.
manifest_node: the <manifest> node.
app_node: the <application> node.
"""
_RegisterElementTreeNamespaces()
doc = ElementTree.parse(path)
# ElementTree.find does not work if the required tag is the root.
if doc.getroot().tag == 'manifest':
manifest_node = doc.getroot()
else:
manifest_node = doc.find('manifest')
app_node = doc.find('application')
if app_node is None:
app_node = ElementTree.SubElement(manifest_node, 'application')
return doc, manifest_node, app_node
...@@ -1075,9 +1075,9 @@ def main(argv): ...@@ -1075,9 +1075,9 @@ def main(argv):
if options.type == 'android_apk' and options.tested_apk_config: if options.type == 'android_apk' and options.tested_apk_config:
tested_apk_deps = Deps([options.tested_apk_config]) tested_apk_deps = Deps([options.tested_apk_config])
tested_apk_name = tested_apk_deps.Direct()[0]['name'] tested_apk_config = tested_apk_deps.Direct()[0]
tested_apk_resources_deps = tested_apk_deps.All('android_resources') tested_apk_resources_deps = tested_apk_deps.All('android_resources')
gradle['apk_under_test'] = tested_apk_name gradle['apk_under_test'] = tested_apk_config['name']
all_resources_deps = [ all_resources_deps = [
d for d in all_resources_deps if not d in tested_apk_resources_deps] d for d in all_resources_deps if not d in tested_apk_resources_deps]
...@@ -1274,6 +1274,9 @@ def main(argv): ...@@ -1274,6 +1274,9 @@ def main(argv):
config['resources']['dependency_zips'] = dependency_zips config['resources']['dependency_zips'] = dependency_zips
config['resources']['extra_package_names'] = extra_package_names config['resources']['extra_package_names'] = extra_package_names
config['resources']['extra_r_text_files'] = extra_r_text_files config['resources']['extra_r_text_files'] = extra_r_text_files
if options.type == 'android_apk' and options.tested_apk_config:
config['resources']['arsc_package_name'] = (
tested_apk_config['package_name'])
if is_apk_or_module_target: if is_apk_or_module_target:
deps_dex_files = [c['dex_path'] for c in all_library_deps] deps_dex_files = [c['dex_path'] for c in all_library_deps]
...@@ -1466,8 +1469,6 @@ def main(argv): ...@@ -1466,8 +1469,6 @@ def main(argv):
# apk-under-test still has all of its code in its classes.dex, none of it is # apk-under-test still has all of its code in its classes.dex, none of it is
# used at runtime because the copy of it within the test apk takes precidence. # used at runtime because the copy of it within the test apk takes precidence.
if options.type == 'android_apk' and options.tested_apk_config: if options.type == 'android_apk' and options.tested_apk_config:
tested_apk_config = GetDepConfig(options.tested_apk_config)
if tested_apk_config['proguard_enabled']: if tested_apk_config['proguard_enabled']:
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.')
......
...@@ -11,8 +11,6 @@ the application class changed to IncrementalApplication. ...@@ -11,8 +11,6 @@ the application class changed to IncrementalApplication.
import argparse import argparse
import os import os
import re
import shutil
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
...@@ -21,9 +19,7 @@ from xml.etree import ElementTree ...@@ -21,9 +19,7 @@ from xml.etree import ElementTree
sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir, 'gyp')) sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir, 'gyp'))
from util import build_utils from util import build_utils
from util import resource_utils
_ANDROID_NAMESPACE = 'http://schemas.android.com/apk/res/android'
ElementTree.register_namespace('android', _ANDROID_NAMESPACE)
_INCREMENTAL_APP_NAME = 'org.chromium.incrementalinstall.BootstrapApplication' _INCREMENTAL_APP_NAME = 'org.chromium.incrementalinstall.BootstrapApplication'
_META_DATA_APP_NAME = 'incremental-install-real-app' _META_DATA_APP_NAME = 'incremental-install-real-app'
...@@ -40,32 +36,28 @@ _INCREMENTAL_INSTRUMENTATION_CLASSES = [ ...@@ -40,32 +36,28 @@ _INCREMENTAL_INSTRUMENTATION_CLASSES = [
def _AddNamespace(name): def _AddNamespace(name):
"""Adds the android namespace prefix to the given identifier.""" """Adds the android namespace prefix to the given identifier."""
return '{%s}%s' % (_ANDROID_NAMESPACE, name) return '{%s}%s' % (resource_utils.ANDROID_NAMESPACE, name)
def _ParseArgs(args): def _ParseArgs(args):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--src-manifest', parser.add_argument(
help='The main manifest of the app', '--src-manifest', required=True, help='The main manifest of the app')
required=True)
parser.add_argument('--out-manifest',
help='The output manifest',
required=True)
parser.add_argument('--disable-isolated-processes', parser.add_argument('--disable-isolated-processes',
help='Changes all android:isolatedProcess to false. ' help='Changes all android:isolatedProcess to false. '
'This is required on Android M+', 'This is required on Android M+',
action='store_true') action='store_true')
parser.add_argument('--out-apk', help='Path to output .ap_ file') parser.add_argument(
parser.add_argument('--in-apk', help='Path to non-incremental .ap_ file') '--out-apk', required=True, help='Path to output .ap_ file')
parser.add_argument('--aapt-path', help='Path to the Android aapt tool') parser.add_argument(
parser.add_argument('--android-sdk-jars', help='Path to the Android SDK jar.') '--in-apk', required=True, help='Path to non-incremental .ap_ file')
parser.add_argument(
'--aapt2-path', required=True, help='Path to the Android aapt tool')
parser.add_argument(
'--android-sdk-jars', help='GN List of resource apks to include.')
ret = parser.parse_args(build_utils.ExpandFileArgs(args)) ret = parser.parse_args(build_utils.ExpandFileArgs(args))
if ret.out_apk and not (ret.in_apk and ret.aapt_path
and ret.android_sdk_jars):
parser.error(
'--out-apk requires --in-apk, --aapt-path, and --android-sdk-jars.')
ret.android_sdk_jars = build_utils.ParseGnList(ret.android_sdk_jars) ret.android_sdk_jars = build_utils.ParseGnList(ret.android_sdk_jars)
return ret return ret
...@@ -75,33 +67,20 @@ def _CreateMetaData(parent, name, value): ...@@ -75,33 +67,20 @@ def _CreateMetaData(parent, name, value):
meta_data_node.set(_AddNamespace('value'), value) meta_data_node.set(_AddNamespace('value'), value)
def _ProcessManifest(main_manifest, disable_isolated_processes): def _ProcessManifest(path, arsc_package_name, disable_isolated_processes):
"""Returns a transformed AndroidManifest.xml for use with _incremental apks. doc, manifest_node, app_node = resource_utils.ParseAndroidManifest(path)
Args:
main_manifest: Manifest contents to transform.
disable_isolated_processes: Whether to set all isolatedProcess attributes to
false
Returns:
The transformed AndroidManifest.xml.
"""
if disable_isolated_processes:
main_manifest = main_manifest.replace('isolatedProcess="true"',
'isolatedProcess="false"')
# Disable check for page-aligned native libraries.
main_manifest = main_manifest.replace('extractNativeLibs="false"',
'extractNativeLibs="true"')
doc = ElementTree.fromstring(main_manifest) # Ensure the manifest package matches that of the apk's arsc package
app_node = doc.find('application') # So that resource references resolve correctly. The actual manifest
if app_node is None: # package name is set via --rename-manifest-package.
app_node = ElementTree.SubElement(doc, 'application') manifest_node.set('package', arsc_package_name)
# Pylint for some reason things app_node is an int.
# pylint: disable=no-member
real_app_class = app_node.get(_AddNamespace('name'), real_app_class = app_node.get(_AddNamespace('name'),
_DEFAULT_APPLICATION_CLASS) _DEFAULT_APPLICATION_CLASS)
app_node.set(_AddNamespace('name'), _INCREMENTAL_APP_NAME) app_node.set(_AddNamespace('name'), _INCREMENTAL_APP_NAME)
# pylint: enable=no-member
_CreateMetaData(app_node, _META_DATA_APP_NAME, real_app_class) _CreateMetaData(app_node, _META_DATA_APP_NAME, real_app_class)
# Seems to be a bug in ElementTree, as doc.find() doesn't work here. # Seems to be a bug in ElementTree, as doc.find() doesn't work here.
...@@ -115,45 +94,46 @@ def _ProcessManifest(main_manifest, disable_isolated_processes): ...@@ -115,45 +94,46 @@ def _ProcessManifest(main_manifest, disable_isolated_processes):
_CreateMetaData(app_node, _META_DATA_INSTRUMENTATION_NAMES[i], _CreateMetaData(app_node, _META_DATA_INSTRUMENTATION_NAMES[i],
real_instrumentation_class) real_instrumentation_class)
return ElementTree.tostring(doc, encoding='UTF-8') ret = ElementTree.tostring(doc.getroot(), encoding='UTF-8')
# Disable check for page-aligned native libraries.
ret = ret.replace('extractNativeLibs="false"', 'extractNativeLibs="true"')
def _ExtractVersionFromApk(aapt_path, apk_path): if disable_isolated_processes:
output = subprocess.check_output([aapt_path, 'dump', 'badging', apk_path]) ret = ret.replace('isolatedProcess="true"', 'isolatedProcess="false"')
version_code = re.search(r"versionCode='(.*?)'", output).group(1) return ret
version_name = re.search(r"versionName='(.*?)'", output).group(1)
return version_code, version_name,
def main(raw_args): def main(raw_args):
options = _ParseArgs(raw_args) options = _ParseArgs(raw_args)
with open(options.src_manifest) as f:
main_manifest_data = f.read() arsc_package, _ = resource_utils.ExtractArscPackage(options.aapt2_path,
new_manifest_data = _ProcessManifest(main_manifest_data, options.in_apk)
# Extract version from the compiled manifest since it might have been set
# via aapt, and not exist in the manifest's text form.
version_code, version_name, manifest_package = (
resource_utils.ExtractBinaryManifestValues(options.aapt2_path,
options.in_apk))
new_manifest_data = _ProcessManifest(options.src_manifest, arsc_package,
options.disable_isolated_processes) options.disable_isolated_processes)
with open(options.out_manifest, 'w') as f: with tempfile.NamedTemporaryFile() as tmp_manifest, \
f.write(new_manifest_data) tempfile.NamedTemporaryFile() as tmp_apk:
tmp_manifest.write(new_manifest_data)
if options.out_apk: tmp_manifest.flush()
version_code, version_name = _ExtractVersionFromApk( cmd = [
options.aapt_path, options.in_apk) options.aapt2_path, 'link', '-o', tmp_apk.name, '--manifest',
with tempfile.NamedTemporaryFile() as f: tmp_manifest.name, '-I', options.in_apk, '--replace-version',
cmd = [options.aapt_path, 'package', '-f', '-F', f.name, '--version-code', version_code, '--version-name', version_name,
'-M', options.out_manifest, '--rename-manifest-package', manifest_package, '--debug-mode'
'-I', options.in_apk, '--replace-version', ]
'--version-code', version_code, '--version-name', version_name, for j in options.android_sdk_jars:
'--debug-mode'] cmd += ['-I', j]
for j in options.android_sdk_jars: subprocess.check_call(cmd)
cmd += ['-I', j] with zipfile.ZipFile(options.out_apk, 'w') as z:
subprocess.check_call(cmd) path_transform = lambda p: None if p != 'AndroidManifest.xml' else p
with zipfile.ZipFile(f.name, 'a') as z: build_utils.MergeZips(z, [tmp_apk.name], path_transform=path_transform)
path_transform = lambda p: None if p == 'AndroidManifest.xml' else p path_transform = lambda p: None if p == 'AndroidManifest.xml' else p
build_utils.MergeZips( build_utils.MergeZips(z, [options.in_apk], path_transform=path_transform)
z, [options.in_apk], path_transform=path_transform)
shutil.copyfile(f.name, options.out_apk)
return 0
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main(sys.argv[1:])) main(sys.argv[1:])
# Generated by running: # Generated by running:
# build/print_python_deps.py --root build/android/incremental_install --output build/android/incremental_install/generate_android_manifest.pydeps build/android/incremental_install/generate_android_manifest.py # build/print_python_deps.py --root build/android/incremental_install --output build/android/incremental_install/generate_android_manifest.pydeps build/android/incremental_install/generate_android_manifest.py
../../../third_party/jinja2/__init__.py
../../../third_party/jinja2/_compat.py
../../../third_party/jinja2/bccache.py
../../../third_party/jinja2/compiler.py
../../../third_party/jinja2/defaults.py
../../../third_party/jinja2/environment.py
../../../third_party/jinja2/exceptions.py
../../../third_party/jinja2/filters.py
../../../third_party/jinja2/idtracking.py
../../../third_party/jinja2/lexer.py
../../../third_party/jinja2/loaders.py
../../../third_party/jinja2/nodes.py
../../../third_party/jinja2/optimizer.py
../../../third_party/jinja2/parser.py
../../../third_party/jinja2/runtime.py
../../../third_party/jinja2/tests.py
../../../third_party/jinja2/utils.py
../../../third_party/jinja2/visitor.py
../../../third_party/markupsafe/__init__.py
../../../third_party/markupsafe/_compat.py
../../../third_party/markupsafe/_native.py
../../gn_helpers.py ../../gn_helpers.py
../gyp/util/__init__.py ../gyp/util/__init__.py
../gyp/util/build_utils.py ../gyp/util/build_utils.py
../gyp/util/md5_check.py ../gyp/util/md5_check.py
../gyp/util/resource_utils.py
generate_android_manifest.py generate_android_manifest.py
...@@ -207,7 +207,7 @@ def _NormalizeResourcesArsc(apk_path, num_arsc_files, num_translations, ...@@ -207,7 +207,7 @@ def _NormalizeResourcesArsc(apk_path, num_arsc_files, num_translations,
print('Skipping resources.arsc normalization (output directory required)') print('Skipping resources.arsc normalization (output directory required)')
return 0 return 0
ap_name = os.path.basename(apk_path).replace('.apk', '.intermediate.ap_') ap_name = os.path.basename(apk_path).replace('.apk', '.intermediate.ap_')
ap_path = os.path.join(out_dir, 'gen/arsc/apks', ap_name) ap_path = os.path.join(out_dir, 'arsc/apks', ap_name)
if not os.path.exists(ap_path): if not os.path.exists(ap_path):
raise Exception('Missing expected file: %s, try rebuilding.' % ap_path) raise Exception('Missing expected file: %s, try rebuilding.' % ap_path)
apk_path = ap_path apk_path = ap_path
......
...@@ -144,9 +144,6 @@ template("write_build_config") { ...@@ -144,9 +144,6 @@ template("write_build_config") {
if (defined(invoker.android_manifest_dep)) { if (defined(invoker.android_manifest_dep)) {
deps += [ invoker.android_manifest_dep ] deps += [ invoker.android_manifest_dep ]
} }
if (defined(invoker.base_module_build_config_target)) {
deps += [ invoker.base_module_build_config_target ]
}
script = "//build/android/gyp/write_build_config.py" script = "//build/android/gyp/write_build_config.py"
depfile = "$target_gen_dir/$target_name.d" depfile = "$target_gen_dir/$target_name.d"
...@@ -481,11 +478,16 @@ template("write_build_config") { ...@@ -481,11 +478,16 @@ template("write_build_config") {
invoker.main_class, invoker.main_class,
] ]
} }
if (defined(invoker.base_module_build_config)) { if (defined(invoker.base_module_target)) {
_rebased_base_module_build_config = _target_label =
rebase_path(invoker.base_module_build_config, root_build_dir) get_label_info(invoker.base_module_target, "label_no_toolchain")
args += _dep_gen_dir = get_label_info(_target_label, "target_gen_dir")
[ "--base-module-build-config=$_rebased_base_module_build_config" ] _dep_name = get_label_info(_target_label, "name")
deps += [ "$_target_label$build_config_target_suffix" ]
args += [
"--base-module-build-config",
rebase_path("$_dep_gen_dir/$_dep_name.build_config", root_build_dir),
]
} }
if (current_toolchain != default_toolchain) { if (current_toolchain != default_toolchain) {
# This has to be a built-time error rather than a GN assert because many # This has to be a built-time error rather than a GN assert because many
...@@ -877,7 +879,6 @@ template("stack_script") { ...@@ -877,7 +879,6 @@ template("stack_script") {
if (enable_java_templates) { if (enable_java_templates) {
android_sdk_jar = "$android_sdk/android.jar" android_sdk_jar = "$android_sdk/android.jar"
android_default_aapt_path = "$android_sdk_build_tools/aapt" android_default_aapt_path = "$android_sdk_build_tools/aapt"
android_default_aapt2_path = "$android_sdk_build_tools/aapt2"
template("android_lint") { template("android_lint") {
action_with_pydeps(target_name) { action_with_pydeps(target_name) {
...@@ -2086,6 +2087,15 @@ if (enable_java_templates) { ...@@ -2086,6 +2087,15 @@ if (enable_java_templates) {
# used to determine which package ID to assign if package_name variable # used to determine which package ID to assign if package_name variable
# was passed in. # was passed in.
# #
# package_id: (optional)
# Use a custom package ID in resource IDs (same purpose as
# package_name_to_id_mapping)
#
# arsc_package_name: (optional)
# Use this package name in the arsc file rather than the package name
# found in the AndroidManifest.xml. Does not affect the package name
# used in AndroidManifest.xml.
#
# Output variables: # Output variables:
# output: Path to a zip file containing the compiled resources. # output: Path to a zip file containing the compiled resources.
# #
...@@ -2161,8 +2171,6 @@ if (enable_java_templates) { ...@@ -2161,8 +2171,6 @@ if (enable_java_templates) {
"--depfile", "--depfile",
rebase_path(depfile, root_build_dir), rebase_path(depfile, root_build_dir),
"--include-resources=@FileArg($_rebased_build_config:android:sdk_jars)", "--include-resources=@FileArg($_rebased_build_config:android:sdk_jars)",
"--aapt-path",
rebase_path(_android_aapt_path, root_build_dir),
"--aapt2-path", "--aapt2-path",
rebase_path(_android_aapt2_path, root_build_dir), rebase_path(_android_aapt2_path, root_build_dir),
"--dependencies-res-zips=@FileArg($_rebased_build_config:resources:dependency_zips)", "--dependencies-res-zips=@FileArg($_rebased_build_config:resources:dependency_zips)",
...@@ -2176,12 +2184,6 @@ if (enable_java_templates) { ...@@ -2176,12 +2184,6 @@ if (enable_java_templates) {
rebase_path(invoker.android_manifest, root_build_dir), rebase_path(invoker.android_manifest, root_build_dir),
] ]
if (defined(invoker.package_name_to_id_mapping)) {
args += [
"--package-name-to-id-mapping=${invoker.package_name_to_id_mapping}",
]
}
if (defined(invoker.no_xml_namespaces) && invoker.no_xml_namespaces) { if (defined(invoker.no_xml_namespaces) && invoker.no_xml_namespaces) {
args += [ "--no-xml-namespaces" ] args += [ "--no-xml-namespaces" ]
} }
...@@ -2212,8 +2214,13 @@ if (enable_java_templates) { ...@@ -2212,8 +2214,13 @@ if (enable_java_templates) {
] ]
} }
if (defined(invoker.optimize_resources) && invoker.optimize_resources) { if (defined(invoker.optimized_resources_path)) {
args += [ "--optimize-resources" ] args += [
"--optimized-resources-path",
rebase_path(invoker.optimized_resources_path, root_build_dir),
]
outputs += [ invoker.optimized_resources_path ]
if (defined(invoker.resources_config_path)) { if (defined(invoker.resources_config_path)) {
inputs += [ invoker.resources_config_path ] inputs += [ invoker.resources_config_path ]
args += [ args += [
...@@ -2221,14 +2228,6 @@ if (enable_java_templates) { ...@@ -2221,14 +2228,6 @@ if (enable_java_templates) {
rebase_path(invoker.resources_config_path, root_build_dir), rebase_path(invoker.resources_config_path, root_build_dir),
] ]
} }
if (defined(invoker.unoptimized_resources_path)) {
args += [
"--unoptimized-resources-path",
rebase_path(invoker.unoptimized_resources_path, root_build_dir),
]
outputs += [ invoker.unoptimized_resources_path ]
}
} }
# Useful to have android:debuggable in the manifest even for Release # Useful to have android:debuggable in the manifest even for Release
...@@ -2270,21 +2269,26 @@ if (enable_java_templates) { ...@@ -2270,21 +2269,26 @@ if (enable_java_templates) {
# generated resources table is correct. It should be 0x02 for runtime # generated resources table is correct. It should be 0x02 for runtime
# shared libraries, and 0x7f otherwise. # shared libraries, and 0x7f otherwise.
_expected_resources_pkg_id = "0x7f"
if (defined(invoker.shared_resources) && invoker.shared_resources) { if (defined(invoker.shared_resources) && invoker.shared_resources) {
args += [ "--shared-resources" ] args += [ "--shared-resources" ]
_expected_resources_pkg_id = "0x02" }
} else if (defined(invoker.app_as_shared_lib) && if (defined(invoker.app_as_shared_lib) && invoker.app_as_shared_lib) {
invoker.app_as_shared_lib) {
args += [ "--app-as-shared-lib" ] args += [ "--app-as-shared-lib" ]
} }
if (defined(invoker.package_id)) {
# NOTE: It is not possible to check the resources package ID of args += [ "--package-id=${invoker.package_id}" ]
# proto-compiled APKs at the moment. }
if (!_proto_format) { if (defined(invoker.package_name)) {
args += [ "--check-resources-pkg-id=$_expected_resources_pkg_id" ] args += [
} else { "--package-name=${invoker.package_name}",
assert(_expected_resources_pkg_id != "") # Mark as used. "--package-name-to-id-mapping=${invoker.package_name_to_id_mapping}",
]
}
if (defined(invoker.arsc_package_name)) {
args += [
"--arsc-package-name",
invoker.arsc_package_name,
]
} }
if (defined(invoker.shared_resources_whitelist)) { if (defined(invoker.shared_resources_whitelist)) {
...@@ -2351,10 +2355,6 @@ if (enable_java_templates) { ...@@ -2351,10 +2355,6 @@ if (enable_java_templates) {
args += invoker.args args += invoker.args
} }
if (defined(invoker.package_name)) {
args += [ "--package-name=${invoker.package_name}" ]
}
if (defined(invoker.emit_ids_out_path)) { if (defined(invoker.emit_ids_out_path)) {
outputs += [ invoker.emit_ids_out_path ] outputs += [ invoker.emit_ids_out_path ]
_rebased_emit_ids_path = _rebased_emit_ids_path =
...@@ -2678,7 +2678,6 @@ if (enable_java_templates) { ...@@ -2678,7 +2678,6 @@ if (enable_java_templates) {
"assets_build_config", "assets_build_config",
"native_lib_placeholders", "native_lib_placeholders",
"native_libs_filearg", "native_libs_filearg",
"packaged_resources_path",
"secondary_native_lib_placeholders", "secondary_native_lib_placeholders",
"secondary_abi_native_libs_filearg", "secondary_abi_native_libs_filearg",
"secondary_abi_loadable_modules", "secondary_abi_loadable_modules",
...@@ -2689,6 +2688,12 @@ if (enable_java_templates) { ...@@ -2689,6 +2688,12 @@ if (enable_java_templates) {
if (!defined(uncompress_shared_libraries)) { if (!defined(uncompress_shared_libraries)) {
uncompress_shared_libraries = _load_library_from_apk uncompress_shared_libraries = _load_library_from_apk
} }
if (defined(invoker.optimized_resources_path)) {
packaged_resources_path = invoker.optimized_resources_path
not_needed(invoker, [ "packaged_resources_path" ])
} else {
packaged_resources_path = invoker.packaged_resources_path
}
deps = _deps deps = _deps
native_libs = _native_libs + _native_libs_even_when_incremental native_libs = _native_libs + _native_libs_even_when_incremental
keystore_path = _keystore_path keystore_path = _keystore_path
...@@ -2717,16 +2722,6 @@ if (enable_java_templates) { ...@@ -2717,16 +2722,6 @@ if (enable_java_templates) {
_incremental_compiled_resources_path = "${_base_path}_incremental.ap_" _incremental_compiled_resources_path = "${_base_path}_incremental.ap_"
_incremental_compile_resources_target_name = _incremental_compile_resources_target_name =
"${target_name}_incremental__compile_resources" "${target_name}_incremental__compile_resources"
_incremental_android_manifest =
get_label_info(_incremental_compile_resources_target_name,
"target_gen_dir") + "/AndroidManifest.xml"
if (defined(invoker.unoptimized_resources_path)) {
_incremental_packaged_resources_path =
invoker.unoptimized_resources_path
} else {
_incremental_packaged_resources_path = invoker.packaged_resources_path
}
_rebased_build_config = _rebased_build_config =
rebase_path(invoker.assets_build_config, root_build_dir) rebase_path(invoker.assets_build_config, root_build_dir)
...@@ -2738,26 +2733,21 @@ if (enable_java_templates) { ...@@ -2738,26 +2733,21 @@ if (enable_java_templates) {
inputs = [ inputs = [
_android_manifest, _android_manifest,
invoker.assets_build_config, invoker.assets_build_config,
_incremental_packaged_resources_path, invoker.packaged_resources_path,
] ]
outputs = [ outputs = [
# Output the non-compiled manifest for easy debugging (as opposed to
# generating to a temp file).
_incremental_android_manifest,
_incremental_compiled_resources_path, _incremental_compiled_resources_path,
] ]
args = [ args = [
"--src-manifest", "--src-manifest",
rebase_path(_android_manifest, root_build_dir), rebase_path(_android_manifest, root_build_dir),
"--out-manifest",
rebase_path(_incremental_android_manifest, root_build_dir),
"--in-apk", "--in-apk",
rebase_path(_incremental_packaged_resources_path, root_build_dir), rebase_path(invoker.packaged_resources_path, root_build_dir),
"--out-apk", "--out-apk",
rebase_path(_incremental_compiled_resources_path, root_build_dir), rebase_path(_incremental_compiled_resources_path, root_build_dir),
"--aapt-path", "--aapt2-path",
rebase_path(android_default_aapt_path, root_build_dir), rebase_path(android_sdk_tools_bundle_aapt2, root_build_dir),
"--android-sdk-jars=@FileArg($_rebased_build_config:android:sdk_jars)", "--android-sdk-jars=@FileArg($_rebased_build_config:android:sdk_jars)",
] ]
if (disable_incremental_isolated_processes) { if (disable_incremental_isolated_processes) {
...@@ -3371,8 +3361,7 @@ if (enable_java_templates) { ...@@ -3371,8 +3361,7 @@ if (enable_java_templates) {
if (type == "android_app_bundle_module") { if (type == "android_app_bundle_module") {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"base_module_build_config", "base_module_target",
"base_module_build_config_target",
"module_rtxt_path", "module_rtxt_path",
"proto_resources_path", "proto_resources_path",
]) ])
......
This diff is collapsed.
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