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, args = parser.parse_args(argv) |
| 53 |
| 54 if args: |
| 55 parser.error('No positional arguments should be given.') |
| 56 |
| 57 required_options = ('build_config', 'type') |
| 58 build_utils.CheckOptions(options, parser, required_options) |
| 59 |
| 60 if options.type == 'android_library': |
| 61 required_options = ('jar_path',) |
| 62 build_utils.CheckOptions(options, parser, required_options) |
| 63 |
| 64 deps_configs = build_utils.ParseGypList(options.possible_deps_configs) |
| 65 for c in deps_configs: |
| 66 if not os.path.exists(c): |
| 67 # Currently we only allow deps to things that write build_config files. |
| 68 raise Exception('Unknown dep type: ' + c) |
| 69 |
| 70 deps_configs = [build_utils.ReadJson(c) for c in deps_configs] |
| 71 |
| 72 if options.type == 'android_library': |
| 73 javac_classpath = [c['outputs']['jar_path'] for c in deps_configs] |
| 74 config = { |
| 75 'outputs': { |
| 76 'jar_path': options.jar_path |
| 77 }, |
| 78 'javac': { |
| 79 'classpath': javac_classpath |
| 80 } |
| 81 } |
| 82 else: |
| 83 raise Exception('Unknown type: ' + options.type) |
| 84 |
| 85 build_utils.WriteJson(config, options.build_config) |
| 86 |
| 87 if options.depfile: |
| 88 build_utils.WriteDepfile( |
| 89 options.depfile, |
| 90 build_utils.GetPythonDependencies()) |
| 91 |
| 92 |
| 93 if __name__ == '__main__': |
| 94 sys.exit(main(sys.argv[1:])) |
OLD | NEW |