Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Unified Diff: build/android/gyp/process_resources.py

Issue 2572253002: DO NOT SUBMIT shrink R.java files via inheritance (Closed)
Patch Set: not using org.chromium package prefix Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/process_resources.py
diff --git a/build/android/gyp/process_resources.py b/build/android/gyp/process_resources.py
index 1166788ecaeca87e9bdde34f980af419129847d0..120107f65fde0a59a79d5c04d91521465cd8778b 100755
--- a/build/android/gyp/process_resources.py
+++ b/build/android/gyp/process_resources.py
@@ -23,6 +23,9 @@ import generate_v14_compatible_resources
from util import build_utils
+_ROOT_R_JAVA_PACKAGE_PREFIX = 'gen'
+
+
# Import jinja2 from third_party/jinja2
sys.path.insert(1,
os.path.join(os.path.dirname(__file__), '../../../third_party'))
@@ -149,14 +152,26 @@ def _ParseArgs(args):
def CreateRJavaFiles(srcjar_dir, main_r_txt_file, packages, r_txt_files,
- shared_resources):
+ shared_resources, srcjar_name):
assert len(packages) == len(r_txt_files), 'Need one R.txt file per package'
# Map of (resource_type, name) -> Entry.
# Contains the correct values for resources.
all_resources = {}
+ all_resources_by_type = collections.defaultdict(list)
for entry in _ParseTextSymbolsFile(main_r_txt_file):
all_resources[(entry.resource_type, entry.name)] = entry
+ all_resources_by_type[entry.resource_type].append(entry)
+
+ # Write Root R.java.
+ root_r_java_package = _ROOT_R_JAVA_PACKAGE_PREFIX + '.' + srcjar_name
+ root_r_java_dir = os.path.join(srcjar_dir, *root_r_java_package.split('.'))
+ build_utils.MakeDirectory(root_r_java_dir)
+ root_r_java_path = os.path.join(root_r_java_dir, 'R.java')
+ root_java_file_contents = _CreateRootRJavaFile(
+ root_r_java_package, all_resources_by_type, shared_resources)
+ with open(root_r_java_path, 'w') as f:
+ f.write(root_java_file_contents)
# Map of package_name->resource_type->entry
resources_by_package = (
@@ -197,7 +212,7 @@ def CreateRJavaFiles(srcjar_dir, main_r_txt_file, packages, r_txt_files,
build_utils.MakeDirectory(package_r_java_dir)
package_r_java_path = os.path.join(package_r_java_dir, 'R.java')
java_file_contents = _CreateRJavaFile(
- package, resources_by_type, shared_resources)
+ package, root_r_java_package, resources_by_type, shared_resources)
with open(package_r_java_path, 'w') as f:
f.write(java_file_contents)
@@ -215,7 +230,36 @@ def _ParseTextSymbolsFile(path):
return ret
-def _CreateRJavaFile(package, resources_by_type, shared_resources):
+def _CreateRJavaFile(
+ package, root_r_java_package, resources_by_type, shared_resources):
+ # TODO fix comments
+ """Generates the contents of a R.java file."""
+ template = Template("""/* AUTO-GENERATED FILE. DO NOT MODIFY. */
+
+package {{ package }};
+
+public final class R {
+ {% for resource_type in resource_types %}
+ public static final class {{ resource_type }} extends
+ {{ root_package }}.R.{{ resource_type }} {}
+ {% endfor %}
+ {% if shared_resources %}
+ public static void onResourcesLoaded(int packageId) {
+ {{ root_package }}.R.onResourcesLoaded(packageId);
+ }
+ {% endif %}
+}
+""", trim_blocks=True, lstrip_blocks=True)
+
+ return template.render(package=package,
+ resources=resources_by_type,
+ resource_types=sorted(resources_by_type),
+ root_package=root_r_java_package,
+ shared_resources=shared_resources)
+
+
+def _CreateRootRJavaFile(package, all_resources_by_type, shared_resources):
+ # TODO fix comments
"""Generates the contents of a R.java file."""
# Keep these assignments all on one line to make diffing against regular
# aapt-generated files easier.
@@ -233,7 +277,7 @@ package {{ package }};
public final class R {
private static boolean sResourcesDidLoad;
{% for resource_type in resource_types %}
- public static final class {{ resource_type }} {
+ public static class {{ resource_type }} {
{% for e in resources[resource_type] %}
{% if shared_resources %}
public static {{ e.java_type }} {{ e.name }} = {{ e.value }};
@@ -245,7 +289,9 @@ public final class R {
{% endfor %}
{% if shared_resources %}
public static void onResourcesLoaded(int packageId) {
- assert !sResourcesDidLoad;
+ if (sResourcesDidLoad) {
+ return;
+ }
sResourcesDidLoad = true;
int packageIdTransform = (packageId ^ 0x7f) << 24;
{% for resource_type in resource_types %}
@@ -274,8 +320,8 @@ public final class R {
""", trim_blocks=True, lstrip_blocks=True)
return template.render(package=package,
- resources=resources_by_type,
- resource_types=sorted(resources_by_type),
+ resources=all_resources_by_type,
+ resource_types=sorted(all_resources_by_type),
shared_resources=shared_resources)
@@ -479,7 +525,7 @@ def _OnStaleMd5(options):
if packages:
shared_resources = options.shared_resources or options.app_as_shared_lib
CreateRJavaFiles(srcjar_dir, r_txt_path, packages, r_txt_files,
- shared_resources)
+ shared_resources, os.path.basename(options.srcjar_out))
# This is the list of directories with resources to put in the final .zip
# file. The order of these is important so that crunched/v14 resources
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698