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

Side by Side Diff: build/android/gyp/write_build_config.py

Issue 361633002: [Android][gn] Add android resources templates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-java
Patch Set: Fix bad rebase Created 6 years, 5 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 | « build/android/gyp/util/build_utils.py ('k') | build/android/gyp/write_ordered_libraries.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2014 The Chromium Authors. All rights reserved. 3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Writes a build_config file. 7 """Writes a build_config file.
8 8
9 The build_config file for a target is a json file containing information about 9 The build_config file for a target is a json file containing information about
10 how to build that target based on the target's dependencies. This includes 10 how to build that target based on the target's dependencies. This includes
11 things like: the javac classpath, the list of android resources dependencies, 11 things like: the javac classpath, the list of android resources dependencies,
12 etc. It also includes the information needed to create the build_config for 12 etc. It also includes the information needed to create the build_config for
13 other target's that depend on that one. 13 other targets that depend on that one.
14 14
15 There are several different types of build_configs: 15 There are several different types of build_configs:
16 android_library: An android library containing java code. 16 android_library: An android library containing java code.
17 android_resources: A target containing android resources.
17 18
18 Android build scripts should not refer to the build_config directly, and the 19 Android build scripts should not refer to the build_config directly, and the
19 build specification should instead pass information in using the special 20 build specification should instead pass information in using the special
20 file-arg syntax (see build_utils.py:ExpandFileArgs). That syntax allows passing 21 file-arg syntax (see build_utils.py:ExpandFileArgs). That syntax allows passing
21 of values in a json dict in a file and looks like this: 22 of values in a json dict in a file and looks like this:
22 --python-arg=@(build_config_path):javac:classpath 23 --python-arg=@(build_config_path:javac:classpath)
23 24
24 Note: If paths to input files are passed in this way, it is important that: 25 Note: If paths to input files are passed in this way, it is important that:
25 1. inputs/deps of the action ensure that the files are available the first 26 1. inputs/deps of the action ensure that the files are available the first
26 time the action runs. 27 time the action runs.
27 2. Either (a) or (b) 28 2. Either (a) or (b)
28 a. inputs/deps ensure that the action runs whenever one of the files changes 29 a. inputs/deps ensure that the action runs whenever one of the files changes
29 b. the files are added to the action's depfile 30 b. the files are added to the action's depfile
30 """ 31 """
31 32
32 import optparse 33 import optparse
33 import os 34 import os
34 import sys 35 import sys
35 36
36 from util import build_utils 37 from util import build_utils
37 38
39 dep_config_cache = {}
40 def GetDepConfig(path):
41 if not path in dep_config_cache:
42 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info']
43 return dep_config_cache[path]
44
45
46 def DepsOfType(wanted_type, configs):
47 return [c for c in configs if c['type'] == wanted_type]
48
49
50 def GetAllDepsConfigsInOrder(deps_config_paths):
51 def Deps(path):
52 return set(GetDepConfig(path)['deps_configs'])
53 return build_utils.GetSortedTransitiveDependencies(deps_config_paths, Deps)
54
55
38 def main(argv): 56 def main(argv):
39 parser = optparse.OptionParser() 57 parser = optparse.OptionParser()
40 build_utils.AddDepfileOption(parser) 58 build_utils.AddDepfileOption(parser)
41 parser.add_option('--build-config', help='Path to build_config output.') 59 parser.add_option('--build-config', help='Path to build_config output.')
42 parser.add_option('--type', help='Type of this target.') 60 parser.add_option(
61 '--type',
62 help='Type of this target (e.g. android_library).')
43 parser.add_option( 63 parser.add_option(
44 '--possible-deps-configs', 64 '--possible-deps-configs',
45 help='List of paths for dependency\'s build_config files. Some ' 65 help='List of paths for dependency\'s build_config files. Some '
46 'dependencies may not write build_config files. Missing build_config ' 66 'dependencies may not write build_config files. Missing build_config '
47 'files are handled differently based on the type of this target.') 67 'files are handled differently based on the type of this target.')
48 68
69 # android_resources options
70 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
71 parser.add_option('--resources-zip', help='Path to target\'s resources zip.')
72
49 # android_library options 73 # android_library options
50 parser.add_option('--jar-path', help='Path to target\'s jar output.') 74 parser.add_option('--jar-path', help='Path to target\'s jar output.')
51 75
52 options, args = parser.parse_args(argv) 76 options, args = parser.parse_args(argv)
53 77
54 if args: 78 if args:
55 parser.error('No positional arguments should be given.') 79 parser.error('No positional arguments should be given.')
56 80
57 required_options = ('build_config', 'type') 81 required_options = ('build_config', 'type')
58 build_utils.CheckOptions(options, parser, required_options) 82 build_utils.CheckOptions(options, parser, required_options)
59 83
84 if not options.type in [
85 'android_library', 'android_resources']:
86 raise Exception('Unknown type: <%s>' % options.type)
87
60 if options.type == 'android_library': 88 if options.type == 'android_library':
61 required_options = ('jar_path',) 89 required_options = ('jar_path',)
62 build_utils.CheckOptions(options, parser, required_options) 90 build_utils.CheckOptions(options, parser, required_options)
63 91
64 deps_configs = build_utils.ParseGypList(options.possible_deps_configs) 92 possible_deps_configs = build_utils.ParseGypList(
65 for c in deps_configs: 93 options.possible_deps_configs)
94 for c in possible_deps_configs:
66 if not os.path.exists(c): 95 if not os.path.exists(c):
67 # Currently we only allow deps to things that write build_config files. 96 # Currently we only allow deps to things that write build_config files.
68 raise Exception('Unknown dep type: ' + c) 97 raise Exception('Unknown dep type: ' + c)
69 98
70 deps_configs = [build_utils.ReadJson(c) for c in deps_configs] 99 direct_deps_config_paths = possible_deps_configs
100 all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths)
101
102 direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths]
103 all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths]
104
105 direct_library_deps = DepsOfType('android_library', direct_deps_configs)
106 all_resources_deps = DepsOfType('android_resources', all_deps_configs)
107
108 # Initialize some common config.
109 config = {
110 'deps_info': {
111 'path': options.build_config,
112 'type': options.type,
113 'deps_configs': direct_deps_config_paths,
114 }
115 }
116 deps_info = config['deps_info']
71 117
72 if options.type == 'android_library': 118 if options.type == 'android_library':
73 javac_classpath = [c['outputs']['jar_path'] for c in deps_configs] 119 javac_classpath = [c['jar_path'] for c in direct_library_deps]
74 config = { 120 deps_info['jar_path'] = options.jar_path
75 'outputs': { 121 config['javac'] = {
76 'jar_path': options.jar_path 122 'classpath': javac_classpath,
77 },
78 'javac': {
79 'classpath': javac_classpath
80 }
81 } 123 }
82 else: 124 # Only resources might have srcjars (normal srcjar targets are listed in
83 raise Exception('Unknown type: ' + options.type) 125 # srcjar_deps). A resource's srcjar contains the R.java file for those
126 # resources, and (like Android's default build system) we allow a library to
127 # refer to the resources in any of its dependents.
128 config['javac']['srcjars'] = [
129 c['srcjar'] for c in all_resources_deps if 'srcjar' in c]
84 130
85 build_utils.WriteJson(config, options.build_config) 131 if options.type == 'android_resources':
132 deps_info['resources_zip'] = options.resources_zip
133 if options.srcjar:
134 deps_info['srcjar'] = options.srcjar
135 config['resources'] = {}
136 config['resources']['dependency_zips'] = [
137 c['resources_zip'] for c in all_resources_deps]
138
139 build_utils.WriteJson(config, options.build_config, only_if_changed=True)
86 140
87 if options.depfile: 141 if options.depfile:
88 build_utils.WriteDepfile( 142 build_utils.WriteDepfile(
89 options.depfile, 143 options.depfile,
90 build_utils.GetPythonDependencies()) 144 all_deps_config_paths + build_utils.GetPythonDependencies())
91 145
92 146
93 if __name__ == '__main__': 147 if __name__ == '__main__':
94 sys.exit(main(sys.argv[1:])) 148 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « build/android/gyp/util/build_utils.py ('k') | build/android/gyp/write_ordered_libraries.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698