Commit 25cc6a0e authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android WebAPK Refactor] Introduce way to define config JSON file as delta

This CL introduces a way of defining a JSON config file as a "base JSON
config file" + "delta config file".
The generated config follows the following rules:
- If a key is present in both the "base config" and the "delta config" the
  value in the "delta config" is used.
- If a key is present in one of the "base config" and the "delta config"
  the key+value are included in the generated config.

The reason for this change are to:
1) Make it easier to add test configs
2) Avoid breakages due to the configs being out of sync such as
https://chromium-review.googlesource.com/c/chromium/src/+/1298428

BUG=899274

Change-Id: I48f236c4d6a86cba32c144b773ba6aab8c99b783
Reviewed-on: https://chromium-review.googlesource.com/c/1302326
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603282}
parent b13ee619
...@@ -98,6 +98,7 @@ template("webapk_tmpl") { ...@@ -98,6 +98,7 @@ template("webapk_tmpl") {
[ [
"apk_package_name", "apk_package_name",
"config_file", "config_file",
"delta_config_file",
]) ])
input = _manifest_to_upload_output input = _manifest_to_upload_output
...@@ -229,7 +230,8 @@ webapk_tmpl("unbound_webapk") { ...@@ -229,7 +230,8 @@ webapk_tmpl("unbound_webapk") {
} }
webapk_tmpl("http_webapk") { webapk_tmpl("http_webapk") {
config_file = "manifest/http_manifest_config.json" config_file = "manifest/bound_manifest_config.json"
delta_config_file = "manifest/http_manifest_config_delta.json"
apk_name = "HttpWebApk" apk_name = "HttpWebApk"
apk_package_name = "org.chromium.webapk.http" apk_package_name = "org.chromium.webapk.http"
} }
......
{
"scope_url": "http://pwa.rocks/",
"intent_filters": {
"scope_url_scheme": "http",
"scope_url_host": "pwa.rocks",
"scope_url_path_type": "android:pathPrefix",
"scope_url_path": "/"
},
"start_url": "http://pwa.rocks/",
"display_mode": "standalone",
"orientation": "portrait",
"theme_color": "2147483648L",
"background_color": "2147483648L",
"has_large_splash_icons": "false",
"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",
"version_code": "1",
"version_name": "1.0",
"bound_webapk": {
"runtime_host": "com.google.android.apps.chrome",
"runtime_host_application_name": "Chromium"
},
"share_template": [{
"index": "0",
"title": "Share All",
"action": "http://pwa.rocks/share.html",
"param_title": "title",
"param_text": "text",
"param_url": "url"
},
{
"index": "1",
"title": "Share Title",
"action": "http://pwa.rocks/share_title.html",
"param_title": "title",
"param_text": "text",
"param_url": "url"
}]
}
{
"scope_url": "http://pwa.rocks/",
"intent_filters": {
"scope_url_scheme": "http",
"scope_url_host": "pwa.rocks",
"scope_url_path_type": "android:pathPrefix",
"scope_url_path": "/"
},
"start_url": "http://pwa.rocks/"
}
...@@ -23,6 +23,10 @@ template("manifest_mustache_pass") { ...@@ -23,6 +23,10 @@ template("manifest_mustache_pass") {
if (defined(invoker.config_file)) { if (defined(invoker.config_file)) {
sources += [ invoker.config_file ] sources += [ invoker.config_file ]
} }
if (defined(invoker.delta_config_file)) {
sources += [ invoker.delta_config_file ]
}
script = script =
"//chrome/android/webapk/shell_apk/manifest/manifest_mustache_pass.py" "//chrome/android/webapk/shell_apk/manifest/manifest_mustache_pass.py"
...@@ -42,6 +46,12 @@ template("manifest_mustache_pass") { ...@@ -42,6 +46,12 @@ template("manifest_mustache_pass") {
rebase_path(invoker.config_file, root_build_dir), rebase_path(invoker.config_file, root_build_dir),
] ]
} }
if (defined(invoker.delta_config_file)) {
args += [
"--delta_config_file",
rebase_path(invoker.delta_config_file, root_build_dir),
]
}
if (defined(invoker.extra_variables)) { if (defined(invoker.extra_variables)) {
extra_variables = invoker.extra_variables extra_variables = invoker.extra_variables
args += [ "--extra_variables=${extra_variables}" ] args += [ "--extra_variables=${extra_variables}" ]
......
...@@ -32,6 +32,7 @@ def _AppendParsedVariables(initial_variable_list, variables_arg, error_func): ...@@ -32,6 +32,7 @@ def _AppendParsedVariables(initial_variable_list, variables_arg, error_func):
variables[name] = value variables[name] = value
return variables return variables
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--template', required=True, parser.add_argument('--template', required=True,
...@@ -40,6 +41,8 @@ def main(): ...@@ -40,6 +41,8 @@ def main():
help='The output file to generate.') help='The output file to generate.')
parser.add_argument('--config_file', parser.add_argument('--config_file',
help='JSON file with values to put into template.') help='JSON file with values to put into template.')
parser.add_argument('--delta_config_file', help='JSON file with '
'substitutions to |config_file|.')
parser.add_argument('--extra_variables', help='Variables to be made ' parser.add_argument('--extra_variables', help='Variables to be made '
'available in the template processing environment (in ' 'available in the template processing environment (in '
'addition to those specified in config file), as a GN ' 'addition to those specified in config file), as a GN '
...@@ -47,10 +50,15 @@ def main(): ...@@ -47,10 +50,15 @@ def main():
default='') default='')
options = parser.parse_args() options = parser.parse_args()
variables = {} config = {}
if options.config_file: if options.config_file:
with open(options.config_file, 'r') as f: with open(options.config_file, 'r') as f:
variables = json.loads(f.read()) config = json.loads(f.read())
if options.delta_config_file:
with open(options.delta_config_file, 'r') as f:
config.update(json.loads(f.read()))
variables = config
variables = _AppendParsedVariables(variables, options.extra_variables, variables = _AppendParsedVariables(variables, options.extra_variables,
parser.error) parser.error)
......
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