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

Side by Side 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: Tweaked generate_split_manifest GN template so that action is at top 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 unified diff | Download patch
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 APK split.
7
8 Given the manifest file for the main APK, generates an AndroidManifest.xml with
9 the value required for a Split APK (package, versionCode, etc).
10 """
11
12 import lxml.etree
13 import optparse
14
15 from util import build_utils
16
17 MANIFEST_TEMPLATE = """<?xml version="1.0" encoding="utf-8"?>
18 <manifest
19 xmlns:android="http://schemas.android.com/apk/res/android"
20 package="%(package)s"
21 split="%(split)s">
22 <application android:hasCode="%(has_code)s">
23 </application>
24 </manifest>
25 """
26
27 def ParseArgs():
28 """Parses command line options.
29
30 Returns:
31 An options object as from optparse.OptionsParser.parse_args()
32 """
33 parser = optparse.OptionParser()
34 build_utils.AddDepfileOption(parser)
35 parser.add_option('--main-manifest', help='The main manifest of the app')
36 parser.add_option('--out-manifest', help='The output manifest')
37 parser.add_option('--split', help='The name of the split')
38 parser.add_option(
39 '--has-code',
40 action='store_true',
41 default=False,
42 help='Whether the split will contain a .dex file')
43
44 (options, args) = parser.parse_args()
45
46 if args:
47 parser.error('No positional arguments should be given.')
48
49 # Check that required options have been provided.
50 required_options = ('main_manifest', 'out_manifest', 'split')
51 build_utils.CheckOptions(options, parser, required=required_options)
52
53 return options
54
55
56 def Build(main_manifest, split, has_code):
57 """Builds a split manifest based on the manifest of the main APK.
58
59 Args:
60 main_manifest: the XML manifest of the main APK as a string
61 split: the name of the split as a string
62 has_code: whether this split APK will contain .dex files
63
64 Returns:
65 The XML split manifest as a string
66 """
67
68 doc = lxml.etree.fromstring(main_manifest)
69 package = doc.xpath('/manifest/@package')[0]
70
71 return MANIFEST_TEMPLATE % {
72 'package': package,
73 'split': split.replace('-', '_'),
74 'has_code': str(has_code).lower()
75 }
76
77
78 def main():
79 options = ParseArgs()
80 main_manifest = file(options.main_manifest).read()
81 split_manifest = Build(
82 main_manifest,
83 options.split,
84 options.has_code)
85
86 with file(options.out_manifest, 'w') as f:
87 f.write(split_manifest)
88
89 if options.depfile:
90 build_utils.WriteDepfile(
91 options.depfile,
92 [main_manifest] + build_utils.GetPythonDependencies())
93
94
95 if __name__ == '__main__':
96 main()
OLDNEW
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698