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

Side by Side Diff: build/android/incremental_install/generate_android_manifest.py

Issue 1338813003: GN: Side-load dex files as well as native code in incremental installs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self review style nits Created 5 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6 """Creates an AndroidManifest.xml for an incremental APK.
7
8 Given the manifest file for the real APK, generates an AndroidManifest.xml with
9 the application class changed to IncrementalApplication.
10 """
11
12 import argparse
13 import os
14 import sys
15 from xml.etree import ElementTree
16
17 sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir, 'gyp'))
18 from util import build_utils
19
20 _ANDROID_NAMESPACE = 'http://schemas.android.com/apk/res/android'
21 ElementTree.register_namespace('android', _ANDROID_NAMESPACE)
22
23 _INCREMENTAL_APP_NAME = 'org.chromium.incrementalinstall.BootstrapApplication'
24 _META_DATA_NAME = 'incremental-install-real-app'
25
26
27 def _AddNamespace(name):
28 """Adds the android namespace prefix to the given identifier."""
29 return '{%s}%s' % (_ANDROID_NAMESPACE, name)
30
31 def _ParseArgs():
32 parser = argparse.ArgumentParser()
33 build_utils.AddDepfileOption(parser)
34 parser.add_argument('--src-manifest',
35 help='The main manifest of the app',
36 required=True)
37 parser.add_argument('--out-manifest',
38 help='The output manifest',
39 required=True)
40 parser.add_argument('--disable-isolated-processes',
jbudorick 2015/09/15 18:36:41 When would we use this?
agrieve 2015/09/15 19:30:05 Required for Android M (added to help text).
41 help='Changes all android:isolatedProcess to false',
42 action='store_true')
43 return parser.parse_args()
44
45
46 def _ProcessManifest(main_manifest, main_manifest_path,
47 disable_isolated_processes):
jbudorick 2015/09/15 18:36:41 nit: indentation
agrieve 2015/09/15 19:30:05 Done.
48 """Returns a transformed AndroidManifest.xml for use with _incremental apks.
49
50 Args:
51 main_manifest: Manifest contents to transform.
52 main_manifest_path: Path to main_manifest (used for error messages).
53 disable_isolated_processes: Whether to set all isolatedProcess attributes to
54 false
55
56 Returns:
57 The transformed AndroidManifest.xml.
58 """
59 if disable_isolated_processes:
60 main_manifest = main_manifest.replace('isolatedProcess="true"',
61 'isolatedProcess="false"')
62
63 doc = ElementTree.fromstring(main_manifest)
64 app_node = doc.find('application')
65 if app_node is None:
66 raise Exception('Could not find <application> in %s' % main_manifest_path)
67 real_app_class = app_node.get(_AddNamespace('name'))
68 if real_app_class is None:
69 raise Exception('Could not find android:name in <application> in %s' %
70 main_manifest_path)
71 app_node.set(_AddNamespace('name'), _INCREMENTAL_APP_NAME)
72
73 meta_data_node = ElementTree.SubElement(app_node, 'meta-data')
74 meta_data_node.set(_AddNamespace('name'), _META_DATA_NAME)
75 meta_data_node.set(_AddNamespace('value'), real_app_class)
76 return ElementTree.tostring(doc, encoding='UTF-8')
77
78
79 def main():
80 options = _ParseArgs()
81 with open(options.src_manifest) as f:
82 main_manifest_data = f.read()
83 new_manifest_data = _ProcessManifest(main_manifest_data, options.src_manifest,
84 options.disable_isolated_processes)
85 with open(options.out_manifest, 'w') as f:
86 f.write(new_manifest_data)
87
88 if options.depfile:
89 build_utils.WriteDepfile(
90 options.depfile,
91 [options.src_manifest] + build_utils.GetPythonDependencies())
92
93
94 if __name__ == '__main__':
95 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698