| 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 | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 59   parser.add_option('--build-config', help='Path to build_config output.') | 59   parser.add_option('--build-config', help='Path to build_config output.') | 
| 60   parser.add_option( | 60   parser.add_option( | 
| 61       '--type', | 61       '--type', | 
| 62       help='Type of this target (e.g. android_library).') | 62       help='Type of this target (e.g. android_library).') | 
| 63   parser.add_option( | 63   parser.add_option( | 
| 64       '--possible-deps-configs', | 64       '--possible-deps-configs', | 
| 65       help='List of paths for dependency\'s build_config files. Some ' | 65       help='List of paths for dependency\'s build_config files. Some ' | 
| 66       'dependencies may not write build_config files. Missing build_config ' | 66       'dependencies may not write build_config files. Missing build_config ' | 
| 67       'files are handled differently based on the type of this target.') | 67       'files are handled differently based on the type of this target.') | 
| 68 | 68 | 
| 69   # android_resources options | 69   # android_resources/apk options | 
| 70   parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') | 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.') | 71   parser.add_option('--resources-zip', help='Path to target\'s resources zip.') | 
| 72 | 72 | 
| 73   # android_library options | 73   # android_library/apk options | 
| 74   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.') | 
| 75 | 75 | 
| 76   options, args = parser.parse_args(argv) | 76   options, args = parser.parse_args(argv) | 
| 77 | 77 | 
| 78   if args: | 78   if args: | 
| 79     parser.error('No positional arguments should be given.') | 79     parser.error('No positional arguments should be given.') | 
| 80 | 80 | 
| 81   required_options = ('build_config', 'type') | 81 | 
|  | 82   if not options.type in [ | 
|  | 83       'android_library', 'android_resources', 'android_apk']: | 
|  | 84     raise Exception('Unknown type: <%s>' % options.type) | 
|  | 85 | 
|  | 86 | 
|  | 87   required_options = ['build_config'] + { | 
|  | 88       'android_library': ['jar_path'], | 
|  | 89       'android_resources': ['resources_zip'], | 
|  | 90       'android_apk': ['jar_path', 'resources_zip'] | 
|  | 91     }[options.type] | 
|  | 92 | 
| 82   build_utils.CheckOptions(options, parser, required_options) | 93   build_utils.CheckOptions(options, parser, required_options) | 
| 83 | 94 | 
| 84   if not options.type in [ | 95   possible_deps_config_paths = build_utils.ParseGypList( | 
| 85       'android_library', 'android_resources']: | 96       options.possible_deps_configs) | 
| 86     raise Exception('Unknown type: <%s>' % options.type) |  | 
| 87 | 97 | 
| 88   if options.type == 'android_library': |  | 
| 89     required_options = ('jar_path',) |  | 
| 90     build_utils.CheckOptions(options, parser, required_options) |  | 
| 91 | 98 | 
| 92   possible_deps_configs = build_utils.ParseGypList( |  | 
| 93       options.possible_deps_configs) |  | 
| 94   for c in possible_deps_configs: |  | 
| 95     if not os.path.exists(c): |  | 
| 96       # Currently we only allow deps to things that write build_config files. |  | 
| 97       raise Exception('Unknown dep type: ' + c) |  | 
| 98 | 99 | 
| 99   direct_deps_config_paths = possible_deps_configs | 100 | 
|  | 101   allow_unknown_deps = options.type == 'android_apk' | 
|  | 102   unknown_deps = [ | 
|  | 103       c for c in possible_deps_config_paths if not os.path.exists(c)] | 
|  | 104   if unknown_deps and not allow_unknown_deps: | 
|  | 105     raise Exception('Unknown deps: ' + unknown_deps) | 
|  | 106 | 
|  | 107   direct_deps_config_paths = [ | 
|  | 108       c for c in possible_deps_config_paths if not c in unknown_deps] | 
| 100   all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths) | 109   all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths) | 
| 101 | 110 | 
| 102   direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths] | 111   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] | 112   all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths] | 
| 104 | 113 | 
| 105   direct_library_deps = DepsOfType('android_library', direct_deps_configs) | 114   direct_library_deps = DepsOfType('android_library', direct_deps_configs) | 
| 106   all_resources_deps = DepsOfType('android_resources', all_deps_configs) | 115   all_resources_deps = DepsOfType('android_resources', all_deps_configs) | 
| 107 | 116 | 
| 108   # Initialize some common config. | 117   # Initialize some common config. | 
| 109   config = { | 118   config = { | 
| 110     'deps_info': { | 119     'deps_info': { | 
| 111       'path': options.build_config, | 120       'path': options.build_config, | 
| 112       'type': options.type, | 121       'type': options.type, | 
| 113       'deps_configs': direct_deps_config_paths, | 122       'deps_configs': direct_deps_config_paths, | 
| 114     } | 123     } | 
| 115   } | 124   } | 
| 116   deps_info = config['deps_info'] | 125   deps_info = config['deps_info'] | 
| 117 | 126 | 
| 118   if options.type == 'android_library': | 127   if options.type in ['android_library', 'android_apk']: | 
| 119     javac_classpath = [c['jar_path'] for c in direct_library_deps] | 128     javac_classpath = [c['jar_path'] for c in direct_library_deps] | 
|  | 129     deps_info['resources_deps'] = [c['path'] for c in all_resources_deps] | 
| 120     deps_info['jar_path'] = options.jar_path | 130     deps_info['jar_path'] = options.jar_path | 
| 121     config['javac'] = { | 131     config['javac'] = { | 
| 122       'classpath': javac_classpath, | 132       'classpath': javac_classpath, | 
| 123     } | 133     } | 
| 124     # Only resources might have srcjars (normal srcjar targets are listed in | 134     # Only resources might have srcjars (normal srcjar targets are listed in | 
| 125     # srcjar_deps). A resource's srcjar contains the R.java file for those | 135     # 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 | 136     # resources, and (like Android's default build system) we allow a library to | 
| 127     # refer to the resources in any of its dependents. | 137     # refer to the resources in any of its dependents. | 
| 128     config['javac']['srcjars'] = [ | 138     config['javac']['srcjars'] = [ | 
| 129         c['srcjar'] for c in all_resources_deps if 'srcjar' in c] | 139         c['srcjar'] for c in all_resources_deps if 'srcjar' in c] | 
| 130 | 140 | 
| 131   if options.type == 'android_resources': | 141   if options.type == 'android_resources' or options.type == 'android_apk': | 
| 132     deps_info['resources_zip'] = options.resources_zip | 142     deps_info['resources_zip'] = options.resources_zip | 
| 133     if options.srcjar: | 143     if options.srcjar: | 
| 134       deps_info['srcjar'] = options.srcjar | 144       deps_info['srcjar'] = options.srcjar | 
|  | 145 | 
| 135     config['resources'] = {} | 146     config['resources'] = {} | 
| 136     config['resources']['dependency_zips'] = [ | 147     config['resources']['dependency_zips'] = [ | 
| 137         c['resources_zip'] for c in all_resources_deps] | 148         c['resources_zip'] for c in all_resources_deps] | 
| 138 | 149 | 
| 139   build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 150   build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 
| 140 | 151 | 
| 141   if options.depfile: | 152   if options.depfile: | 
| 142     build_utils.WriteDepfile( | 153     build_utils.WriteDepfile( | 
| 143         options.depfile, | 154         options.depfile, | 
| 144         all_deps_config_paths + build_utils.GetPythonDependencies()) | 155         all_deps_config_paths + build_utils.GetPythonDependencies()) | 
| 145 | 156 | 
| 146 | 157 | 
| 147 if __name__ == '__main__': | 158 if __name__ == '__main__': | 
| 148   sys.exit(main(sys.argv[1:])) | 159   sys.exit(main(sys.argv[1:])) | 
| OLD | NEW | 
|---|