Commit 81cc62af authored by agrieve's avatar agrieve Committed by Commit bot

Adds GN rule & script for generating AndroidManifest.xml for APK splits

Build rule is not hooked up to any targets yet, but will be used in a
future commit to create split APKs.

.gypi also forthcoming.

BUG=447152

Review URL: https://codereview.chromium.org/1118403004

Cr-Commit-Position: refs/heads/master@{#329850}
parent 84c0386b
#!/usr/bin/env python
#
# Copyright 2015 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.
"""Creates an AndroidManifest.xml for an APK split.
Given the manifest file for the main APK, generates an AndroidManifest.xml with
the value required for a Split APK (package, versionCode, etc).
"""
import lxml.etree
import optparse
from util import build_utils
MANIFEST_TEMPLATE = """<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="%(package)s"
split="%(split)s">
<application android:hasCode="%(has_code)s">
</application>
</manifest>
"""
def ParseArgs():
"""Parses command line options.
Returns:
An options object as from optparse.OptionsParser.parse_args()
"""
parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser)
parser.add_option('--main-manifest', help='The main manifest of the app')
parser.add_option('--out-manifest', help='The output manifest')
parser.add_option('--split', help='The name of the split')
parser.add_option(
'--has-code',
action='store_true',
default=False,
help='Whether the split will contain a .dex file')
(options, args) = parser.parse_args()
if args:
parser.error('No positional arguments should be given.')
# Check that required options have been provided.
required_options = ('main_manifest', 'out_manifest', 'split')
build_utils.CheckOptions(options, parser, required=required_options)
return options
def Build(main_manifest, split, has_code):
"""Builds a split manifest based on the manifest of the main APK.
Args:
main_manifest: the XML manifest of the main APK as a string
split: the name of the split as a string
has_code: whether this split APK will contain .dex files
Returns:
The XML split manifest as a string
"""
doc = lxml.etree.fromstring(main_manifest)
package = doc.xpath('/manifest/@package')[0]
return MANIFEST_TEMPLATE % {
'package': package,
'split': split.replace('-', '_'),
'has_code': str(has_code).lower()
}
def main():
options = ParseArgs()
main_manifest = file(options.main_manifest).read()
split_manifest = Build(
main_manifest,
options.split,
options.has_code)
with file(options.out_manifest, 'w') as f:
f.write(split_manifest)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
[main_manifest] + build_utils.GetPythonDependencies())
if __name__ == '__main__':
main()
...@@ -1177,3 +1177,53 @@ template("deps_dex") { ...@@ -1177,3 +1177,53 @@ template("deps_dex") {
} }
} }
} }
# Creates an AndroidManifest.xml for an APK split.
template("generate_split_manifest") {
assert(defined(invoker.main_manifest))
assert(defined(invoker.out_manifest))
assert(defined(invoker.split_name))
action(target_name) {
depfile = "$target_gen_dir/$target_name.d"
args = [
"--main-manifest",
rebase_path(invoker.main_manifest, root_build_dir),
"--out-manifest",
rebase_path(invoker.out_manifest, root_build_dir),
"--split",
invoker.split_name,
]
if (defined(invoker.version_code)) {
args += [
"--version-code",
invoker.version_code,
]
}
if (defined(invoker.version_name)) {
args += [
"--version-name",
invoker.version_name,
]
}
if (defined(invoker.has_code)) {
args += [
"--has-code",
invoker.has_code,
]
}
args += [
"--depfile",
rebase_path(depfile, root_build_dir),
]
script = "//build/android/gyp/generate_split_manifest.py"
outputs = [
depfile,
invoker.out_manifest,
]
inputs = [
invoker.main_manifest,
]
}
}
...@@ -88,6 +88,7 @@ ...@@ -88,6 +88,7 @@
"build/android/gyp/finalize_apk.py", "build/android/gyp/finalize_apk.py",
"build/android/gyp/find.py", "build/android/gyp/find.py",
"build/android/gyp/gcc_preprocess.py", "build/android/gyp/gcc_preprocess.py",
"build/android/gyp/generate_split_manifest.py",
"build/android/gyp/generate_v14_compatible_resources.py", "build/android/gyp/generate_v14_compatible_resources.py",
"build/android/gyp/get_device_configuration.py", "build/android/gyp/get_device_configuration.py",
"build/android/gyp/insert_chromium_version.py", "build/android/gyp/insert_chromium_version.py",
......
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