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 = [
'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):
for _, line in changed_contents:
......
......@@ -108,7 +108,8 @@ class ShellApkVersion(unittest.TestCase):
class OverlappingResourceFileNames(unittest.TestCase):
RESOURCES_SHOULD_HAVE_DIFFERENT_FILE_NAMES_MESSAGE = (
'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):
# Files within a res/ directory can have same file name.
......
......@@ -4,7 +4,7 @@
import("//build/config/android/rules.gni")
import("current_version/current_version.gni")
import("manifest/manifest_mustache_pass.gni")
import("mustache_pass.gni")
webapk_manifest_to_upload_output =
"${target_gen_dir}/webapk_manifest_to_upload/AndroidManifest.xml"
......@@ -87,6 +87,10 @@ template("webapk_tmpl") {
_java_without_services_target_name = "${target_name}_generated_webapk_java"
_java_with_services_target_name =
"${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"
_use_new_splash = false
......@@ -106,7 +110,7 @@ template("webapk_tmpl") {
# Generate manifest to upload to WebAPK server. Fills in all of the fields
# 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"
output = _manifest_to_upload_output
extra_variables = [
......@@ -116,7 +120,7 @@ template("webapk_tmpl") {
}
# Generate manifest with test values.
manifest_mustache_pass(_manifest_target_name) {
mustache_pass(_manifest_target_name) {
forward_variables_from(invoker,
[
"apk_package_name",
......@@ -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) {
custom_package = "org.chromium.webapk.shell_apk"
resource_dirs = [ "res" ]
generated_resource_dirs = [ _generated_res_background_dir ]
generated_resource_files =
get_target_outputs(":$_generate_res_background_xml_target_name")
deps = [
":$_generate_res_background_xml_target_name",
":webapk_strings_grd",
]
}
......
......@@ -12,4 +12,4 @@
# //chrome/android/webapk/shell_apk:webapk is changed. This includes
# Java files, Android resource files and AndroidManifest.xml. Does not affect
# Chrome.apk
current_shell_apk_version = 93
current_shell_apk_version = 94
......@@ -11,6 +11,7 @@
"orientation": "portrait",
"theme_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",
"web_manifest_url": "https://pwa.rocks/pwa.webmanifest",
"distributor": "browser",
......
......@@ -11,6 +11,7 @@
"orientation": "portrait",
"theme_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",
"web_manifest_url": "https://maps.gstatic.com/tactile/worker/ml.json",
"distributor": "other",
......
......@@ -12,6 +12,7 @@
"orientation": "portrait",
"theme_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",
"web_manifest_url": "https://pwa.rocks/pwa.webmanifest",
"distributor": "other",
......
......@@ -4,7 +4,7 @@
import("//build/config/android/rules.gni")
template("manifest_mustache_pass") {
template("mustache_pass") {
set_sources_assignment_filter([])
forward_variables_from(invoker, [ "testonly" ])
......@@ -27,8 +27,7 @@ template("manifest_mustache_pass") {
sources += [ invoker.delta_config_file ]
}
script =
"//chrome/android/webapk/shell_apk/manifest/manifest_mustache_pass.py"
script = "//chrome/android/webapk/shell_apk/mustache_pass.py"
outputs = [
invoker.output,
......
......@@ -4,7 +4,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Expands the ShellApk's AndroidManifest.xml using Mustache template engine."""
"""Expands template using Mustache template engine."""
import argparse
import codecs
......@@ -14,7 +14,7 @@ import sys
#Import pystache from //third_party/pystache
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'))
import pystache
sys.path.insert(0, os.path.join(src_dir, 'build/android/gyp'))
......
......@@ -8,5 +8,4 @@
<color name="black_alpha_38">#61000000</color>
<color name="black_alpha_54">#8A000000</color>
<color name="black_alpha_87">#DE000000</color>
<color name="background_color">#F8F9FA</color>
</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