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

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

Issue 1118403004: Adds GN rule & script for generating AndroidManifest.xml for APK splits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | build/config/android/internal_rules.gni » ('j') | build/config/android/internal_rules.gni » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/generate_split_manifest.py
diff --git a/build/android/gyp/generate_split_manifest.py b/build/android/gyp/generate_split_manifest.py
new file mode 100755
index 0000000000000000000000000000000000000000..ecc36e6e7378c270ba98a2fddae7b4d302a73646
--- /dev/null
+++ b/build/android/gyp/generate_split_manifest.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 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"
+ android:versionCode="%(version_code)s"
+ android:versionName="%(version_name)s"
+ 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('--version-code', help='value for android:versionCode')
+ parser.add_option('--version-name', help='value for android:versionName')
+ parser.add_option(
+ '--has-code',
+ action='store_true',
+ 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, version_code, version_name, 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)
+ ns = {'android': 'http://schemas.android.com/apk/res/android'}
+ package = doc.xpath('/manifest/@package')[0]
+
+ if not version_code:
+ version_code = doc.xpath('/manifest/@android:versionCode', namespaces=ns)[0]
+ if not version_name:
+ version_name = doc.xpath('/manifest/@android:versionName', namespaces=ns)[0]
+
+ if not version_code:
+ raise Exception('android:versionCode not set by main manifest nor by '
+ '--version-code')
+ if not version_name:
+ raise Exception('android:versionName not set by main manifest nor by '
+ '--version-name')
+
+ return MANIFEST_TEMPLATE % {
+ 'version_code': version_code,
+ 'version_name': version_name,
+ 'package': package,
+ 'split': split,
+ '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.version_code,
+ options.version_name,
+ options.has_code)
+
+ with file(options.out_manifest, 'w') as f:
+ f.write(split_manifest)
+
+ if options.depfile:
+ build_utils.WriteDepfile(
+ options.depfile,
+ build_utils.GetPythonDependencies())
cjhopman 2015/05/07 00:39:52 This list should include the path to the main mani
agrieve 2015/05/12 17:51:43 Done.
+
+
+if __name__ == '__main__':
+ main()
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('j') | build/config/android/internal_rules.gni » ('J')

Powered by Google App Engine
This is Rietveld 408576698