Commit 1f295a8d authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android WebAPK] Templatize background color in XML resources

This CL:
- Introduces generation of R.color.background_color from the JSON
  config via mustache
- Renames manifest_mustache_pass to mustache_pass

BUG=969591

Change-Id: Ic434dc69673dfab19559c59894a3686db58b4e09
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1644752
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666597}
parent b088adcb
...@@ -36,7 +36,11 @@ TRIGGER_CURRENT_VERSION_UPDATE_LOCAL_PATHS = [ ...@@ -36,7 +36,11 @@ TRIGGER_CURRENT_VERSION_UPDATE_LOCAL_PATHS = [
'shell_apk/src/', 'shell_apk/src/',
] ]
RES_DIR_LOCAL_PATHS = ['shell_apk/res', 'libs/common/res_splash'] RES_DIR_LOCAL_PATHS = [
'shell_apk/res',
'shell_apk/res_template',
'libs/common/res_splash'
]
def _DoChangedContentsContain(changed_contents, key): def _DoChangedContentsContain(changed_contents, key):
for _, line in changed_contents: for _, line in changed_contents:
......
...@@ -108,7 +108,8 @@ class ShellApkVersion(unittest.TestCase): ...@@ -108,7 +108,8 @@ class ShellApkVersion(unittest.TestCase):
class OverlappingResourceFileNames(unittest.TestCase): class OverlappingResourceFileNames(unittest.TestCase):
RESOURCES_SHOULD_HAVE_DIFFERENT_FILE_NAMES_MESSAGE = ( RESOURCES_SHOULD_HAVE_DIFFERENT_FILE_NAMES_MESSAGE = (
'Resources in different top level res/ directories [\'shell_apk/res\', ' 'Resources in different top level res/ directories [\'shell_apk/res\', '
'\'libs/common/res_splash\'] should have different names:') '\'shell_apk/res_template\', \'libs/common/res_splash\'] should have '
'different names:')
def testAddFileSameNameWithinResDirectory(self): def testAddFileSameNameWithinResDirectory(self):
# Files within a res/ directory can have same file name. # Files within a res/ directory can have same file name.
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
import("current_version/current_version.gni") import("current_version/current_version.gni")
import("manifest/manifest_mustache_pass.gni") import("mustache_pass.gni")
webapk_manifest_to_upload_output = webapk_manifest_to_upload_output =
"${target_gen_dir}/webapk_manifest_to_upload/AndroidManifest.xml" "${target_gen_dir}/webapk_manifest_to_upload/AndroidManifest.xml"
...@@ -87,6 +87,10 @@ template("webapk_tmpl") { ...@@ -87,6 +87,10 @@ template("webapk_tmpl") {
_java_without_services_target_name = "${target_name}_generated_webapk_java" _java_without_services_target_name = "${target_name}_generated_webapk_java"
_java_with_services_target_name = _java_with_services_target_name =
"${target_name}_generated_webapk_with_service_java" "${target_name}_generated_webapk_with_service_java"
_generate_res_background_xml_target_name =
"${target_name}_generate_res_background_xml"
_generated_res_background_dir =
"${target_gen_dir}/${_generate_res_background_xml_target_name}/res"
_resources_target_name = "${target_name}_resources" _resources_target_name = "${target_name}_resources"
_use_new_splash = false _use_new_splash = false
...@@ -106,7 +110,7 @@ template("webapk_tmpl") { ...@@ -106,7 +110,7 @@ template("webapk_tmpl") {
# Generate manifest to upload to WebAPK server. Fills in all of the fields # Generate manifest to upload to WebAPK server. Fills in all of the fields
# that the server cannot customize on a per-site basis. # that the server cannot customize on a per-site basis.
manifest_mustache_pass(_manifest_to_upload_target_name) { mustache_pass(_manifest_to_upload_target_name) {
input = "AndroidManifest.xml" input = "AndroidManifest.xml"
output = _manifest_to_upload_output output = _manifest_to_upload_output
extra_variables = [ extra_variables = [
...@@ -116,7 +120,7 @@ template("webapk_tmpl") { ...@@ -116,7 +120,7 @@ template("webapk_tmpl") {
} }
# Generate manifest with test values. # Generate manifest with test values.
manifest_mustache_pass(_manifest_target_name) { mustache_pass(_manifest_target_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"apk_package_name", "apk_package_name",
...@@ -132,10 +136,21 @@ template("webapk_tmpl") { ...@@ -132,10 +136,21 @@ template("webapk_tmpl") {
] ]
} }
# Populate background color in values/background_color.xml
mustache_pass(_generate_res_background_xml_target_name) {
forward_variables_from(invoker, [ "config_file" ])
input = "res_template/values/background_color.xml"
output = "${_generated_res_background_dir}/values/background_color.xml"
}
android_resources(_resources_target_name) { android_resources(_resources_target_name) {
custom_package = "org.chromium.webapk.shell_apk" custom_package = "org.chromium.webapk.shell_apk"
resource_dirs = [ "res" ] resource_dirs = [ "res" ]
generated_resource_dirs = [ _generated_res_background_dir ]
generated_resource_files =
get_target_outputs(":$_generate_res_background_xml_target_name")
deps = [ deps = [
":$_generate_res_background_xml_target_name",
":webapk_strings_grd", ":webapk_strings_grd",
] ]
} }
......
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
# //chrome/android/webapk/shell_apk:webapk is changed. This includes # //chrome/android/webapk/shell_apk:webapk is changed. This includes
# Java files, Android resource files and AndroidManifest.xml. Does not affect # Java files, Android resource files and AndroidManifest.xml. Does not affect
# Chrome.apk # Chrome.apk
current_shell_apk_version = 93 current_shell_apk_version = 94
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"orientation": "portrait", "orientation": "portrait",
"theme_color": "2147483648L", "theme_color": "2147483648L",
"background_color": "2147483648L", "background_color": "2147483648L",
"background_color_xml": "#F8F9FA",
"icon_urls_and_icon_murmur2_hashes": "http://www.pwa.rocks/icon1.png 0 http://www.pwa.rocks/icon2.png 0", "icon_urls_and_icon_murmur2_hashes": "http://www.pwa.rocks/icon1.png 0 http://www.pwa.rocks/icon2.png 0",
"web_manifest_url": "https://pwa.rocks/pwa.webmanifest", "web_manifest_url": "https://pwa.rocks/pwa.webmanifest",
"distributor": "browser", "distributor": "browser",
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"orientation": "portrait", "orientation": "portrait",
"theme_color": "2147483648L", "theme_color": "2147483648L",
"background_color": "2147483648L", "background_color": "2147483648L",
"background_color_xml": "#F8F9FA",
"icon_urls_and_icon_murmur2_hashes": "https://maps.gstatic.com/mapfiles/maps_lite/pwa/icons/maps_pwa_icon_v0920_48x48.png 0 https://maps.gstatic.com/mapfiles/maps_lite/pwa/icons/maps_pwa_icon_v0920_72x72 0", "icon_urls_and_icon_murmur2_hashes": "https://maps.gstatic.com/mapfiles/maps_lite/pwa/icons/maps_pwa_icon_v0920_48x48.png 0 https://maps.gstatic.com/mapfiles/maps_lite/pwa/icons/maps_pwa_icon_v0920_72x72 0",
"web_manifest_url": "https://maps.gstatic.com/tactile/worker/ml.json", "web_manifest_url": "https://maps.gstatic.com/tactile/worker/ml.json",
"distributor": "other", "distributor": "other",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
"orientation": "portrait", "orientation": "portrait",
"theme_color": "2147483648L", "theme_color": "2147483648L",
"background_color": "2147483648L", "background_color": "2147483648L",
"background_color_xml": "#F8F9FA",
"icon_urls_and_icon_murmur2_hashes": "http://www.pwa.rocks/icon1.png 0 http://www.pwa.rocks/icon2.png 0", "icon_urls_and_icon_murmur2_hashes": "http://www.pwa.rocks/icon1.png 0 http://www.pwa.rocks/icon2.png 0",
"web_manifest_url": "https://pwa.rocks/pwa.webmanifest", "web_manifest_url": "https://pwa.rocks/pwa.webmanifest",
"distributor": "other", "distributor": "other",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
template("manifest_mustache_pass") { template("mustache_pass") {
set_sources_assignment_filter([]) set_sources_assignment_filter([])
forward_variables_from(invoker, [ "testonly" ]) forward_variables_from(invoker, [ "testonly" ])
...@@ -27,8 +27,7 @@ template("manifest_mustache_pass") { ...@@ -27,8 +27,7 @@ template("manifest_mustache_pass") {
sources += [ invoker.delta_config_file ] sources += [ invoker.delta_config_file ]
} }
script = script = "//chrome/android/webapk/shell_apk/mustache_pass.py"
"//chrome/android/webapk/shell_apk/manifest/manifest_mustache_pass.py"
outputs = [ outputs = [
invoker.output, invoker.output,
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""Expands the ShellApk's AndroidManifest.xml using Mustache template engine.""" """Expands template using Mustache template engine."""
import argparse import argparse
import codecs import codecs
...@@ -14,7 +14,7 @@ import sys ...@@ -14,7 +14,7 @@ import sys
#Import pystache from //third_party/pystache #Import pystache from //third_party/pystache
src_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, src_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
os.pardir, os.pardir, os.pardir) os.pardir, os.pardir)
sys.path.insert(0, os.path.join(src_dir, 'third_party')) sys.path.insert(0, os.path.join(src_dir, 'third_party'))
import pystache import pystache
sys.path.insert(0, os.path.join(src_dir, 'build/android/gyp')) sys.path.insert(0, os.path.join(src_dir, 'build/android/gyp'))
......
...@@ -8,5 +8,4 @@ ...@@ -8,5 +8,4 @@
<color name="black_alpha_38">#61000000</color> <color name="black_alpha_38">#61000000</color>
<color name="black_alpha_54">#8A000000</color> <color name="black_alpha_54">#8A000000</color>
<color name="black_alpha_87">#DE000000</color> <color name="black_alpha_87">#DE000000</color>
<color name="background_color">#F8F9FA</color>
</resources> </resources>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<resources>
<color name="background_color">{{{background_color_xml}}}</color>
</resources>
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