Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 target's that depend on that one. |
|
newt (away)
2014/07/07 21:47:12
s/target's/targets
cjhopman
2014/07/08 00:16:27
Done.
| |
| 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. |
|
newt (away)
2014/07/07 21:47:12
mention new types here
cjhopman
2014/07/08 00:16:27
Done.
| |
| 17 | 17 |
| 18 Android build scripts should not refer to the build_config directly, and the | 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 | 19 build specification should instead pass information in using the special |
| 20 file-arg syntax (see build_utils.py:ExpandFileArgs). That syntax allows passing | 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: | 21 of values in a json dict in a file and looks like this: |
| 22 --python-arg=@(build_config_path):javac:classpath | 22 --python-arg=@(build_config_path):javac:classpath |
|
newt (away)
2014/07/07 21:47:12
Is this syntax correct? Also, if usage of this is
cjhopman
2014/07/08 00:16:27
No, it wasn't. Now it is.
| |
| 23 | 23 |
| 24 Note: If paths to input files are passed in this way, it is important that: | 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 | 25 1. inputs/deps of the action ensure that the files are available the first |
| 26 time the action runs. | 26 time the action runs. |
| 27 2. Either (a) or (b) | 27 2. Either (a) or (b) |
| 28 a. inputs/deps ensure that the action runs whenever one of the files changes | 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 | 29 b. the files are added to the action's depfile |
| 30 """ | 30 """ |
| 31 | 31 |
| 32 import optparse | 32 import optparse |
| 33 import os | 33 import os |
| 34 import sys | 34 import sys |
| 35 | 35 |
| 36 from util import build_utils | 36 from util import build_utils |
| 37 | 37 |
| 38 dep_config_cache = {} | |
| 39 def GetDepConfig(path): | |
| 40 if not path in dep_config_cache: | |
| 41 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] | |
| 42 return dep_config_cache[path] | |
| 43 | |
| 44 | |
| 45 def DepsOfType(wanted_type, configs): | |
| 46 return [c for c in configs if c['type'] == wanted_type] | |
| 47 | |
| 48 | |
| 49 def GetAllDepsConfigsInOrder(deps_config_paths): | |
| 50 def Deps(path): | |
| 51 return set(GetDepConfig(path)['deps_configs']) | |
| 52 return build_utils.GetSortedTransitiveDependencies(deps_config_paths, Deps) | |
| 53 | |
| 54 | |
| 38 def main(argv): | 55 def main(argv): |
| 39 parser = optparse.OptionParser() | 56 parser = optparse.OptionParser() |
| 40 build_utils.AddDepfileOption(parser) | 57 build_utils.AddDepfileOption(parser) |
| 41 parser.add_option('--build-config', help='Path to build_config output.') | 58 parser.add_option('--build-config', help='Path to build_config output.') |
| 42 parser.add_option('--type', help='Type of this target.') | 59 parser.add_option('--type', help='Type of this target.') |
|
newt (away)
2014/07/07 21:47:11
"e.g. android_library"
cjhopman
2014/07/08 00:16:27
Done.
| |
| 43 parser.add_option( | 60 parser.add_option( |
| 44 '--possible-deps-configs', | 61 '--possible-deps-configs', |
| 45 help='List of paths for dependency\'s build_config files. Some ' | 62 help='List of paths for dependency\'s build_config files. Some ' |
| 46 'dependencies may not write build_config files. Missing build_config ' | 63 'dependencies may not write build_config files. Missing build_config ' |
| 47 'files are handled differently based on the type of this target.') | 64 'files are handled differently based on the type of this target.') |
| 48 | 65 |
| 66 # android_resources options | |
| 67 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') | |
| 68 parser.add_option('--resources-zip', help='Path to target\'s resources zip.') | |
| 69 | |
| 49 # android_library options | 70 # android_library options |
| 50 parser.add_option('--jar-path', help='Path to target\'s jar output.') | 71 parser.add_option('--jar-path', help='Path to target\'s jar output.') |
| 51 | 72 |
| 52 options, args = parser.parse_args(argv) | 73 options, args = parser.parse_args(argv) |
| 53 | 74 |
| 54 if args: | 75 if args: |
| 55 parser.error('No positional arguments should be given.') | 76 parser.error('No positional arguments should be given.') |
| 56 | 77 |
| 57 required_options = ('build_config', 'type') | 78 required_options = ('build_config', 'type') |
| 58 build_utils.CheckOptions(options, parser, required_options) | 79 build_utils.CheckOptions(options, parser, required_options) |
| 59 | 80 |
| 81 if not options.type in [ | |
| 82 'android_library', 'android_resources']: | |
| 83 raise Exception('Unknown type: <%s>' % options.type) | |
| 84 | |
| 60 if options.type == 'android_library': | 85 if options.type == 'android_library': |
| 61 required_options = ('jar_path',) | 86 required_options = ('jar_path',) |
| 62 build_utils.CheckOptions(options, parser, required_options) | 87 build_utils.CheckOptions(options, parser, required_options) |
| 63 | 88 |
| 64 deps_configs = build_utils.ParseGypList(options.possible_deps_configs) | 89 possible_deps_configs = build_utils.ParseGypList( |
| 65 for c in deps_configs: | 90 options.possible_deps_configs) |
| 91 for c in possible_deps_configs: | |
| 66 if not os.path.exists(c): | 92 if not os.path.exists(c): |
| 67 # Currently we only allow deps to things that write build_config files. | 93 # Currently we only allow deps to things that write build_config files. |
| 68 raise Exception('Unknown dep type: ' + c) | 94 raise Exception('Unknown dep type: ' + c) |
| 69 | 95 |
| 70 deps_configs = [build_utils.ReadJson(c) for c in deps_configs] | 96 direct_deps_config_paths = possible_deps_configs |
| 97 all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths) | |
| 98 | |
| 99 direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths] | |
| 100 all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths] | |
| 101 | |
| 102 direct_library_deps = DepsOfType('android_library', direct_deps_configs) | |
| 103 all_resources_deps = DepsOfType('android_resources', all_deps_configs) | |
|
newt (away)
2014/07/07 21:47:12
all_resources_deps contains only android_resources
cjhopman
2014/07/08 00:16:27
It is. I added a comment below about it.
| |
| 104 | |
| 105 # Initialize some common config. | |
| 106 config = { | |
| 107 'deps_info': { | |
| 108 'path': options.build_config, | |
| 109 'type': options.type, | |
| 110 'deps_configs': direct_deps_config_paths, | |
| 111 } | |
| 112 } | |
| 113 deps_info = config['deps_info'] | |
| 71 | 114 |
| 72 if options.type == 'android_library': | 115 if options.type == 'android_library': |
| 73 javac_classpath = [c['outputs']['jar_path'] for c in deps_configs] | 116 javac_classpath = [c['jar_path'] for c in direct_library_deps] |
| 74 config = { | 117 deps_info['jar_path'] = options.jar_path |
| 75 'outputs': { | 118 config['javac'] = { |
| 76 'jar_path': options.jar_path | 119 'classpath': javac_classpath, |
| 77 }, | 120 'srcjars': [c['srcjar'] for c in all_resources_deps if 'srcjar' in c], |
| 78 'javac': { | |
| 79 'classpath': javac_classpath | |
| 80 } | |
| 81 } | 121 } |
| 82 else: | |
| 83 raise Exception('Unknown type: ' + options.type) | |
| 84 | 122 |
| 85 build_utils.WriteJson(config, options.build_config) | 123 if options.type == 'android_resources': |
| 124 deps_info['resources_zip'] = options.resources_zip | |
| 125 if options.srcjar: | |
| 126 deps_info['srcjar'] = options.srcjar | |
| 127 config['resources'] = {} | |
| 128 config['resources']['dependency_zips'] = [ | |
| 129 c['resources_zip'] for c in all_resources_deps] | |
| 130 | |
| 131 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | |
| 86 | 132 |
| 87 if options.depfile: | 133 if options.depfile: |
| 88 build_utils.WriteDepfile( | 134 build_utils.WriteDepfile( |
| 89 options.depfile, | 135 options.depfile, |
| 90 build_utils.GetPythonDependencies()) | 136 all_deps_config_paths + build_utils.GetPythonDependencies()) |
| 91 | 137 |
| 92 | 138 |
| 93 if __name__ == '__main__': | 139 if __name__ == '__main__': |
| 94 sys.exit(main(sys.argv[1:])) | 140 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |