Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 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 | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 """Writes a build_config file. | |
| 8 | |
| 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 | |
| 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 | |
| 13 other target's that depend on that one. | |
| 14 | |
| 15 There are several different types of build_configs: | |
| 16 android_library: An android library containing java code. | |
| 17 | |
| 18 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 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 --python-arg=@(build_config_path):javac:classpath | |
| 23 | |
| 24 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 time the action runs. | |
| 27 2. Either (a) or (b) | |
| 28 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 """ | |
| 31 | |
| 32 import optparse | |
| 33 import os | |
| 34 import sys | |
| 35 | |
| 36 from util import build_utils | |
| 37 | |
| 38 def main(argv): | |
| 39 parser = optparse.OptionParser() | |
| 40 build_utils.AddDepfileOption(parser) | |
| 41 parser.add_option('--build-config', help='Path to build_config output.') | |
| 42 parser.add_option('--type', help='Type of this target.') | |
| 43 parser.add_option( | |
| 44 '--possible-deps-configs', | |
| 45 help='List of paths for dependency\'s build_config files. Some ' | |
| 46 'dependencies may not write build_config files. Missing build_config ' | |
| 47 'files are handled differently based on the type of this target.') | |
| 48 | |
| 49 # android_library options | |
| 50 parser.add_option('--jar-path', help='Path to target\'s jar output.') | |
| 51 | |
| 52 options, _ = parser.parse_args(argv) | |
|
Nico
2014/07/01 18:24:51
nit: I'd do `options, args =` and then error out i
cjhopman
2014/07/01 22:14:01
Done.
| |
| 53 | |
| 54 required_options = ('build_config', 'type') | |
| 55 build_utils.CheckOptions(options, parser, required_options) | |
| 56 | |
| 57 if options.type == 'android_library': | |
| 58 required_options = ('jar_path',) | |
| 59 build_utils.CheckOptions(options, parser, required_options) | |
| 60 | |
| 61 deps_configs = build_utils.ParseGypList(options.possible_deps_configs) | |
| 62 for c in deps_configs: | |
| 63 if not os.path.exists(c): | |
| 64 # Currently we only allow deps to things that write build_config files. | |
| 65 raise Exception('Unknown dep type: ' + c) | |
| 66 | |
| 67 deps_configs = [build_utils.ReadJson(c) for c in deps_configs] | |
| 68 | |
| 69 if options.type == 'android_library': | |
| 70 javac_classpath = [c['outputs']['jar_path'] for c in deps_configs] | |
| 71 config = { | |
| 72 'outputs': { | |
| 73 'jar_path': options.jar_path | |
| 74 }, | |
| 75 'javac': { | |
| 76 'classpath': javac_classpath | |
| 77 } | |
| 78 } | |
| 79 else: | |
| 80 raise Exception('Unknown type: ' + options.type) | |
| 81 | |
| 82 build_utils.WriteJson(config, options.build_config) | |
| 83 | |
| 84 if options.depfile: | |
| 85 build_utils.WriteDepfile( | |
| 86 options.depfile, | |
| 87 build_utils.GetPythonDependencies()) | |
| 88 | |
| 89 | |
| 90 if __name__ == '__main__': | |
| 91 sys.exit(main(sys.argv[1:])) | |
| OLD | NEW |