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

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

Issue 1141793003: Update from https://crrev.com/329939 (Closed) Base URL: git@github.com:domokit/mojo.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 unified diff | Download patch
« no previous file with comments | « build/android/gyp/util/proguard_util.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
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 if not path in dep_config_cache: 72 if not path in dep_config_cache:
73 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] 73 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info']
74 return dep_config_cache[path] 74 return dep_config_cache[path]
75 75
76 76
77 def DepsOfType(wanted_type, configs): 77 def DepsOfType(wanted_type, configs):
78 return [c for c in configs if c['type'] == wanted_type] 78 return [c for c in configs if c['type'] == wanted_type]
79 79
80 80
81 def GetAllDepsConfigsInOrder(deps_config_paths): 81 def GetAllDepsConfigsInOrder(deps_config_paths):
82 def Deps(path): 82 def GetDeps(path):
83 return set(GetDepConfig(path)['deps_configs']) 83 return set(GetDepConfig(path)['deps_configs'])
84 return build_utils.GetSortedTransitiveDependencies(deps_config_paths, Deps) 84 return build_utils.GetSortedTransitiveDependencies(deps_config_paths, GetDeps)
85
86
87 class Deps(object):
88 def __init__(self, direct_deps_config_paths):
89 self.all_deps_config_paths = GetAllDepsConfigsInOrder(
90 direct_deps_config_paths)
91 self.direct_deps_configs = [
92 GetDepConfig(p) for p in direct_deps_config_paths]
93 self.all_deps_configs = [
94 GetDepConfig(p) for p in self.all_deps_config_paths]
95
96 def All(self, wanted_type=None):
97 if type is None:
98 return self.all_deps_configs
99 return DepsOfType(wanted_type, self.all_deps_configs)
100
101 def Direct(self, wanted_type=None):
102 if wanted_type is None:
103 return self.direct_deps_configs
104 return DepsOfType(wanted_type, self.direct_deps_configs)
105
106 def AllConfigPaths(self):
107 return self.all_deps_config_paths
85 108
86 109
87 def main(argv): 110 def main(argv):
88 parser = optparse.OptionParser() 111 parser = optparse.OptionParser()
89 build_utils.AddDepfileOption(parser) 112 build_utils.AddDepfileOption(parser)
90 parser.add_option('--build-config', help='Path to build_config output.') 113 parser.add_option('--build-config', help='Path to build_config output.')
91 parser.add_option( 114 parser.add_option(
92 '--type', 115 '--type',
93 help='Type of this target (e.g. android_library).') 116 help='Type of this target (e.g. android_library).')
94 parser.add_option( 117 parser.add_option(
95 '--possible-deps-configs', 118 '--possible-deps-configs',
96 help='List of paths for dependency\'s build_config files. Some ' 119 help='List of paths for dependency\'s build_config files. Some '
97 'dependencies may not write build_config files. Missing build_config ' 120 'dependencies may not write build_config files. Missing build_config '
98 'files are handled differently based on the type of this target.') 121 'files are handled differently based on the type of this target.')
99 122
100 # android_resources options 123 # android_resources options
101 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') 124 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
102 parser.add_option('--resources-zip', help='Path to target\'s resources zip.') 125 parser.add_option('--resources-zip', help='Path to target\'s resources zip.')
126 parser.add_option('--r-text', help='Path to target\'s R.txt file.')
103 parser.add_option('--package-name', 127 parser.add_option('--package-name',
104 help='Java package name for these resources.') 128 help='Java package name for these resources.')
105 parser.add_option('--android-manifest', help='Path to android manifest.') 129 parser.add_option('--android-manifest', help='Path to android manifest.')
106 130
107 # java library options 131 # java library options
108 parser.add_option('--jar-path', help='Path to target\'s jar output.') 132 parser.add_option('--jar-path', help='Path to target\'s jar output.')
109 parser.add_option('--supports-android', action='store_true', 133 parser.add_option('--supports-android', action='store_true',
110 help='Whether this library supports running on the Android platform.') 134 help='Whether this library supports running on the Android platform.')
111 parser.add_option('--requires-android', action='store_true', 135 parser.add_option('--requires-android', action='store_true',
112 help='Whether this library requires running on the Android platform.') 136 help='Whether this library requires running on the Android platform.')
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 options.possible_deps_configs) 182 options.possible_deps_configs)
159 183
160 allow_unknown_deps = options.type == 'android_apk' 184 allow_unknown_deps = options.type == 'android_apk'
161 unknown_deps = [ 185 unknown_deps = [
162 c for c in possible_deps_config_paths if not os.path.exists(c)] 186 c for c in possible_deps_config_paths if not os.path.exists(c)]
163 if unknown_deps and not allow_unknown_deps: 187 if unknown_deps and not allow_unknown_deps:
164 raise Exception('Unknown deps: ' + str(unknown_deps)) 188 raise Exception('Unknown deps: ' + str(unknown_deps))
165 189
166 direct_deps_config_paths = [ 190 direct_deps_config_paths = [
167 c for c in possible_deps_config_paths if not c in unknown_deps] 191 c for c in possible_deps_config_paths if not c in unknown_deps]
168 all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths)
169 192
170 direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths] 193 deps = Deps(direct_deps_config_paths)
171 all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths] 194 direct_library_deps = deps.Direct('java_library')
195 all_library_deps = deps.All('java_library')
172 196
173 direct_library_deps = DepsOfType('java_library', direct_deps_configs) 197 direct_resources_deps = deps.Direct('android_resources')
174 all_library_deps = DepsOfType('java_library', all_deps_configs) 198 all_resources_deps = deps.All('android_resources')
175
176 direct_resources_deps = DepsOfType('android_resources', direct_deps_configs)
177 all_resources_deps = DepsOfType('android_resources', all_deps_configs)
178 # Resources should be ordered with the highest-level dependency first so that 199 # Resources should be ordered with the highest-level dependency first so that
179 # overrides are done correctly. 200 # overrides are done correctly.
180 all_resources_deps.reverse() 201 all_resources_deps.reverse()
181 202
203 if options.type == 'android_apk' and options.tested_apk_config:
204 tested_apk_deps = Deps([options.tested_apk_config])
205 tested_apk_resources_deps = tested_apk_deps.All('android_resources')
206 all_resources_deps = [
207 d for d in all_resources_deps if not d in tested_apk_resources_deps]
208
182 # Initialize some common config. 209 # Initialize some common config.
183 config = { 210 config = {
184 'deps_info': { 211 'deps_info': {
185 'name': os.path.basename(options.build_config), 212 'name': os.path.basename(options.build_config),
186 'path': options.build_config, 213 'path': options.build_config,
187 'type': options.type, 214 'type': options.type,
188 'deps_configs': direct_deps_config_paths, 215 'deps_configs': direct_deps_config_paths,
189 } 216 }
190 } 217 }
191 deps_info = config['deps_info'] 218 deps_info = config['deps_info']
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 c['srcjar'] for c in direct_resources_deps if 'srcjar' in c] 257 c['srcjar'] for c in direct_resources_deps if 'srcjar' in c]
231 258
232 if options.type == 'android_apk': 259 if options.type == 'android_apk':
233 # Apks will get their resources srcjar explicitly passed to the java step. 260 # Apks will get their resources srcjar explicitly passed to the java step.
234 config['javac']['srcjars'] = [] 261 config['javac']['srcjars'] = []
235 262
236 if options.type == 'android_resources': 263 if options.type == 'android_resources':
237 deps_info['resources_zip'] = options.resources_zip 264 deps_info['resources_zip'] = options.resources_zip
238 if options.srcjar: 265 if options.srcjar:
239 deps_info['srcjar'] = options.srcjar 266 deps_info['srcjar'] = options.srcjar
267 if options.android_manifest:
268 manifest = AndroidManifest(options.android_manifest)
269 deps_info['package_name'] = manifest.GetPackageName()
240 if options.package_name: 270 if options.package_name:
241 deps_info['package_name'] = options.package_name 271 deps_info['package_name'] = options.package_name
272 if options.r_text:
273 deps_info['r_text'] = options.r_text
242 274
243 if options.type == 'android_resources' or options.type == 'android_apk': 275 if options.type == 'android_resources' or options.type == 'android_apk':
244 config['resources'] = {} 276 config['resources'] = {}
245 config['resources']['dependency_zips'] = [ 277 config['resources']['dependency_zips'] = [
246 c['resources_zip'] for c in all_resources_deps] 278 c['resources_zip'] for c in all_resources_deps]
247 config['resources']['extra_package_names'] = [] 279 config['resources']['extra_package_names'] = []
280 config['resources']['extra_r_text_files'] = []
248 281
249 if options.type == 'android_apk': 282 if options.type == 'android_apk':
250 config['resources']['extra_package_names'] = [ 283 config['resources']['extra_package_names'] = [
251 c['package_name'] for c in all_resources_deps if 'package_name' in c] 284 c['package_name'] for c in all_resources_deps if 'package_name' in c]
285 config['resources']['extra_r_text_files'] = [
286 c['r_text'] for c in all_resources_deps if 'r_text' in c]
252 287
253 if options.type in ['android_apk', 'deps_dex']: 288 if options.type in ['android_apk', 'deps_dex']:
254 deps_dex_files = [c['dex_path'] for c in all_library_deps] 289 deps_dex_files = [c['dex_path'] for c in all_library_deps]
255 290
256 # An instrumentation test apk should exclude the dex files that are in the apk 291 # An instrumentation test apk should exclude the dex files that are in the apk
257 # under test. 292 # under test.
258 if options.type == 'android_apk' and options.tested_apk_config: 293 if options.type == 'android_apk' and options.tested_apk_config:
259 tested_apk_config_paths = GetAllDepsConfigsInOrder( 294 tested_apk_deps = Deps([options.tested_apk_config])
260 [options.tested_apk_config]) 295 tested_apk_library_deps = tested_apk_deps.All('java_library')
261 tested_apk_configs = [GetDepConfig(p) for p in tested_apk_config_paths]
262 tested_apk_library_deps = DepsOfType('java_library', tested_apk_configs)
263 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] 296 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps]
264 deps_dex_files = [ 297 deps_dex_files = [
265 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] 298 p for p in deps_dex_files if not p in tested_apk_deps_dex_files]
266 299
267 tested_apk_config = GetDepConfig(options.tested_apk_config) 300 tested_apk_config = GetDepConfig(options.tested_apk_config)
268 expected_tested_package = tested_apk_config['package_name'] 301 expected_tested_package = tested_apk_config['package_name']
269 AndroidManifest(options.android_manifest).CheckInstrumentation( 302 AndroidManifest(options.android_manifest).CheckInstrumentation(
270 expected_tested_package) 303 expected_tested_package)
271 304
272 # Dependencies for the final dex file of an apk or a 'deps_dex'. 305 # Dependencies for the final dex file of an apk or a 'deps_dex'.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 config['native'] = { 342 config['native'] = {
310 'libraries': library_paths, 343 'libraries': library_paths,
311 'java_libraries_list': java_libraries_list 344 'java_libraries_list': java_libraries_list
312 } 345 }
313 346
314 build_utils.WriteJson(config, options.build_config, only_if_changed=True) 347 build_utils.WriteJson(config, options.build_config, only_if_changed=True)
315 348
316 if options.depfile: 349 if options.depfile:
317 build_utils.WriteDepfile( 350 build_utils.WriteDepfile(
318 options.depfile, 351 options.depfile,
319 all_deps_config_paths + build_utils.GetPythonDependencies()) 352 deps.AllConfigPaths() + build_utils.GetPythonDependencies())
320 353
321 354
322 if __name__ == '__main__': 355 if __name__ == '__main__':
323 sys.exit(main(sys.argv[1:])) 356 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « build/android/gyp/util/proguard_util.py ('k') | build/android/gyp/write_ordered_libraries.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698