Commit 5e7dcbcb authored by John Budorick's avatar John Budorick Committed by Commit Bot

Revert "Android: Pass whitelist of shared resources for public Monochrome"

This reverts commit 04a7ee63.

Reason for revert: breaks downstream builders, https://bugs.chromium.org/p/chromium/issues/detail?id=796374

Original change's description:
> Android: Pass whitelist of shared resources for public Monochrome
> 
> Allows monochrome_public_apk to specify a whitelist of resources
> that are used by the webview portion of Monochrome. This change only
> marks those as non-final and changes their package id at runtime
> (the rest of the resources are marked as final).
> 
> Bug: 791078
> Change-Id: Id32858c014cabd7d259e00cf603d2d949b690b5e
> Reviewed-on: https://chromium-review.googlesource.com/815235
> Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
> Reviewed-by: agrieve <agrieve@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#525075}

TBR=agrieve@chromium.org,mheikal@chromium.org

Change-Id: Ie7c1905ba9cacf8d08ccac7f729b893d077a112b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 791078
Reviewed-on: https://chromium-review.googlesource.com/835209Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Commit-Queue: John Budorick <jbudorick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525186}
parent 2426e7fc
...@@ -101,21 +101,7 @@ _DENSITY_SPLITS = { ...@@ -101,21 +101,7 @@ _DENSITY_SPLITS = {
), ),
} }
class _ResourceWhitelist(object):
def __init__(self, entries=None):
self._entries = None
if entries:
self._entries = set(self._Key(x) for x in entries)
def __contains__(self, entry):
return self._entries is None or self._Key(entry) in self._entries
@staticmethod
def _Key(entry):
# Whitelists should only care about the name of the resource rather than the
# resource ID (since the whitelist is from another compilation unit, the
# resource IDs may not match).
return (entry.java_type, entry.resource_type, entry.name)
def _ParseArgs(args): def _ParseArgs(args):
...@@ -144,11 +130,6 @@ def _ParseArgs(args): ...@@ -144,11 +130,6 @@ def _ParseArgs(args):
'--app-as-shared-lib', '--app-as-shared-lib',
action='store_true', action='store_true',
help='Make a resource package that can be loaded as shared library.') help='Make a resource package that can be loaded as shared library.')
parser.add_option(
'--shared-resources-whitelist',
help='An R.txt file acting as a whitelist for resources that should be '
'non-final and have their package ID changed at runtime in R.java. If no '
'whitelist is provided, then everything is whitelisted.')
parser.add_option('--resource-dirs', parser.add_option('--resource-dirs',
default='[]', default='[]',
...@@ -263,7 +244,7 @@ def _ParseArgs(args): ...@@ -263,7 +244,7 @@ def _ParseArgs(args):
def _CreateRJavaFiles(srcjar_dir, main_r_txt_file, packages, r_txt_files, def _CreateRJavaFiles(srcjar_dir, main_r_txt_file, packages, r_txt_files,
shared_resources, non_constant_id, whitelist_r_txt_file, is_apk): shared_resources, non_constant_id):
assert len(packages) == len(r_txt_files), 'Need one R.txt file per package' assert len(packages) == len(r_txt_files), 'Need one R.txt file per package'
# Map of (resource_type, name) -> Entry. # Map of (resource_type, name) -> Entry.
...@@ -273,12 +254,6 @@ def _CreateRJavaFiles(srcjar_dir, main_r_txt_file, packages, r_txt_files, ...@@ -273,12 +254,6 @@ def _CreateRJavaFiles(srcjar_dir, main_r_txt_file, packages, r_txt_files,
entry = entry._replace(value=_FixPackageIds(entry.value)) entry = entry._replace(value=_FixPackageIds(entry.value))
all_resources[(entry.resource_type, entry.name)] = entry all_resources[(entry.resource_type, entry.name)] = entry
if whitelist_r_txt_file:
whitelisted_resources = _ResourceWhitelist(
_ParseTextSymbolsFile(whitelist_r_txt_file))
else:
whitelisted_resources = _ResourceWhitelist()
# Map of package_name->resource_type->entry # Map of package_name->resource_type->entry
resources_by_package = ( resources_by_package = (
collections.defaultdict(lambda: collections.defaultdict(list))) collections.defaultdict(lambda: collections.defaultdict(list)))
...@@ -317,8 +292,8 @@ def _CreateRJavaFiles(srcjar_dir, main_r_txt_file, packages, r_txt_files, ...@@ -317,8 +292,8 @@ def _CreateRJavaFiles(srcjar_dir, main_r_txt_file, packages, r_txt_files,
package_r_java_dir = os.path.join(srcjar_dir, *package.split('.')) package_r_java_dir = os.path.join(srcjar_dir, *package.split('.'))
build_utils.MakeDirectory(package_r_java_dir) build_utils.MakeDirectory(package_r_java_dir)
package_r_java_path = os.path.join(package_r_java_dir, 'R.java') package_r_java_path = os.path.join(package_r_java_dir, 'R.java')
java_file_contents = _CreateRJavaFile(package, resources_by_type, java_file_contents = _CreateRJavaFile(
shared_resources, non_constant_id, whitelisted_resources, is_apk) package, resources_by_type, shared_resources, non_constant_id)
with open(package_r_java_path, 'w') as f: with open(package_r_java_path, 'w') as f:
f.write(java_file_contents) f.write(java_file_contents)
...@@ -349,30 +324,8 @@ def _FixPackageIds(resource_value): ...@@ -349,30 +324,8 @@ def _FixPackageIds(resource_value):
def _CreateRJavaFile(package, resources_by_type, shared_resources, def _CreateRJavaFile(package, resources_by_type, shared_resources,
non_constant_id, whitelisted_resources, is_apk): non_constant_id):
"""Generates the contents of a R.java file.""" """Generates the contents of a R.java file."""
final_resources_by_type = collections.defaultdict(list)
non_final_resources_by_type = collections.defaultdict(list)
if shared_resources or non_constant_id:
for res_type, resources in resources_by_type.iteritems():
for entry in resources:
# Entries in stylable that are not int[] are not actually resource ids
# but constants. If we are creating an apk there is no reason for them
# to be non-final. However for libraries, they may be clobbered later on
# and thus should remain non-final. This is regardless of the
# whitelisting rules (since they are not actually resources).
if entry.resource_type == 'styleable' and entry.java_type != 'int[]':
if is_apk:
final_resources_by_type[res_type].append(entry)
else:
non_final_resources_by_type[res_type].append(entry)
elif entry in whitelisted_resources:
non_final_resources_by_type[res_type].append(entry)
else:
final_resources_by_type[res_type].append(entry)
else:
final_resources_by_type = resources_by_type
# Keep these assignments all on one line to make diffing against regular # Keep these assignments all on one line to make diffing against regular
# aapt-generated files easier. # aapt-generated files easier.
create_id = ('{{ e.resource_type }}.{{ e.name }} ^= packageIdTransform;') create_id = ('{{ e.resource_type }}.{{ e.name }} ^= packageIdTransform;')
...@@ -390,11 +343,8 @@ public final class R { ...@@ -390,11 +343,8 @@ public final class R {
private static boolean sResourcesDidLoad; private static boolean sResourcesDidLoad;
{% for resource_type in resource_types %} {% for resource_type in resource_types %}
public static final class {{ resource_type }} { public static final class {{ resource_type }} {
{% for e in final_resources[resource_type] %} {% for e in resources[resource_type] %}
public static final {{ e.java_type }} {{ e.name }} = {{ e.value }}; public static {{ final }}{{ e.java_type }} {{ e.name }} = {{ e.value }};
{% endfor %}
{% for e in non_final_resources[resource_type] %}
public static {{ e.java_type }} {{ e.name }} = {{ e.value }};
{% endfor %} {% endfor %}
} }
{% endfor %} {% endfor %}
...@@ -405,7 +355,7 @@ public final class R { ...@@ -405,7 +355,7 @@ public final class R {
int packageIdTransform = (packageId ^ 0x7f) << 24; int packageIdTransform = (packageId ^ 0x7f) << 24;
{% for resource_type in resource_types %} {% for resource_type in resource_types %}
onResourcesLoaded{{ resource_type|title }}(packageIdTransform); onResourcesLoaded{{ resource_type|title }}(packageIdTransform);
{% for e in non_final_resources[resource_type] %} {% for e in resources[resource_type] %}
{% if e.java_type == 'int[]' %} {% if e.java_type == 'int[]' %}
for(int i = 0; i < {{ e.resource_type }}.{{ e.name }}.length; ++i) { for(int i = 0; i < {{ e.resource_type }}.{{ e.name }}.length; ++i) {
""" + create_id_arr + """ """ + create_id_arr + """
...@@ -417,7 +367,7 @@ public final class R { ...@@ -417,7 +367,7 @@ public final class R {
{% for res_type in resource_types %} {% for res_type in resource_types %}
private static void onResourcesLoaded{{ res_type|title }} ( private static void onResourcesLoaded{{ res_type|title }} (
int packageIdTransform) { int packageIdTransform) {
{% for e in non_final_resources[res_type] %} {% for e in resources[res_type] %}
{% if res_type != 'styleable' and e.java_type != 'int[]' %} {% if res_type != 'styleable' and e.java_type != 'int[]' %}
""" + create_id + """ """ + create_id + """
{% endif %} {% endif %}
...@@ -428,11 +378,12 @@ public final class R { ...@@ -428,11 +378,12 @@ public final class R {
} }
""", trim_blocks=True, lstrip_blocks=True) """, trim_blocks=True, lstrip_blocks=True)
final = '' if shared_resources or non_constant_id else 'final '
return template.render(package=package, return template.render(package=package,
resources=resources_by_type,
resource_types=sorted(resources_by_type), resource_types=sorted(resources_by_type),
shared_resources=shared_resources, shared_resources=shared_resources,
final_resources=final_resources_by_type, final=final)
non_final_resources=non_final_resources_by_type)
def _CrunchDirectory(aapt, input_dir, output_dir): def _CrunchDirectory(aapt, input_dir, output_dir):
...@@ -782,8 +733,7 @@ def _CreateRTxtAndSrcJar(options, r_txt_path, srcjar_dir): ...@@ -782,8 +733,7 @@ def _CreateRTxtAndSrcJar(options, r_txt_path, srcjar_dir):
if packages: if packages:
shared_resources = options.shared_resources or options.app_as_shared_lib shared_resources = options.shared_resources or options.app_as_shared_lib
_CreateRJavaFiles(srcjar_dir, r_txt_path, packages, r_txt_files, _CreateRJavaFiles(srcjar_dir, r_txt_path, packages, r_txt_files,
shared_resources, options.non_constant_id, shared_resources, options.non_constant_id)
options.shared_resources_whitelist, bool(options.apk_path))
if options.srcjar_out: if options.srcjar_out:
build_utils.ZipDir(options.srcjar_out, srcjar_dir) build_utils.ZipDir(options.srcjar_out, srcjar_dir)
...@@ -889,13 +839,11 @@ def main(args): ...@@ -889,13 +839,11 @@ def main(args):
if options.apk_path: if options.apk_path:
input_strings.extend(_CreatePackageApkArgs(options)) input_strings.extend(_CreatePackageApkArgs(options))
possible_input_paths = [ input_paths = [
options.aapt_path, options.aapt_path,
options.android_manifest, options.android_manifest,
options.android_sdk_jar, options.android_sdk_jar,
options.shared_resources_whitelist,
] ]
input_paths = [x for x in possible_input_paths if x]
input_paths.extend(options.dependencies_res_zips) input_paths.extend(options.dependencies_res_zips)
input_paths.extend(options.extra_r_text_files) input_paths.extend(options.extra_r_text_files)
......
...@@ -1509,14 +1509,6 @@ if (enable_java_templates) { ...@@ -1509,14 +1509,6 @@ if (enable_java_templates) {
args += [ "--resource-dirs=$_rebased_all_resource_dirs" ] args += [ "--resource-dirs=$_rebased_all_resource_dirs" ]
} }
if (defined(invoker.shared_resources_whitelist)) {
inputs += [ invoker.shared_resources_whitelist ]
args += [
"--shared-resources-whitelist",
rebase_path(invoker.shared_resources_whitelist, root_build_dir),
]
}
if (defined(invoker.version_code)) { if (defined(invoker.version_code)) {
args += [ args += [
"--version-code", "--version-code",
......
...@@ -1952,19 +1952,6 @@ if (enable_java_templates) { ...@@ -1952,19 +1952,6 @@ if (enable_java_templates) {
":$_merge_manifest_target", ":$_merge_manifest_target",
":$_build_config_target", ":$_build_config_target",
] ]
if (defined(invoker.shared_resources_whitelist_target)) {
_whitelist_gen_dir =
get_label_info(invoker.shared_resources_whitelist_target,
"target_gen_dir")
_whitelist_target_name =
get_label_info(invoker.shared_resources_whitelist_target, "name")
shared_resources_whitelist =
"${_whitelist_gen_dir}/${_whitelist_target_name}" +
"__process_resources_R.txt"
deps += [
"${invoker.shared_resources_whitelist_target}__process_resources",
]
}
} }
_srcjar_deps += [ ":$_process_resources_target" ] _srcjar_deps += [ ":$_process_resources_target" ]
......
...@@ -1080,10 +1080,6 @@ monochrome_public_apk_tmpl("monochrome_public_apk") { ...@@ -1080,10 +1080,6 @@ monochrome_public_apk_tmpl("monochrome_public_apk") {
android_manifest_dep = ":monochrome_public_android_manifest" android_manifest_dep = ":monochrome_public_android_manifest"
apk_name = "MonochromePublic" apk_name = "MonochromePublic"
# Resource whitelist used when generating R.java files and causes
# only the webview subset of resources to be marked as non-final.
shared_resources_whitelist_target = "//android_webview:system_webview_apk"
deps = [ deps = [
":monochrome_java", ":monochrome_java",
"//base:base_java", "//base:base_java",
......
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