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

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

Issue 687633003: Greatly improve (non-android) java support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: junit_unittests -> java_binary Created 6 years, 1 month 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
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
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 targets that depend on that one. 13 other targets that depend on that one.
14 14
15 There are several different types of build_configs: 15 There are several different types of build_configs:
newt (away) 2014/11/03 22:12:44 there are now several more...
cjhopman 2014/11/15 03:37:59 Done. lol.
16 android_library: An android library containing java code. 16 android_library: An android library containing java code.
17 android_resources: A target containing android resources. 17 android_resources: A target containing android resources.
18 18
19 Android build scripts should not refer to the build_config directly, and the 19 Android build scripts should not refer to the build_config directly, and the
20 build specification should instead pass information in using the special 20 build specification should instead pass information in using the special
21 file-arg syntax (see build_utils.py:ExpandFileArgs). That syntax allows passing 21 file-arg syntax (see build_utils.py:ExpandFileArgs). That syntax allows passing
22 of values in a json dict in a file and looks like this: 22 of values in a json dict in a file and looks like this:
23 --python-arg=@FileArg(build_config_path:javac:classpath) 23 --python-arg=@FileArg(build_config_path:javac:classpath)
24 24
25 Note: If paths to input files are passed in this way, it is important that: 25 Note: If paths to input files are passed in this way, it is important that:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 'dependencies may not write build_config files. Missing build_config ' 69 'dependencies may not write build_config files. Missing build_config '
70 'files are handled differently based on the type of this target.') 70 'files are handled differently based on the type of this target.')
71 71
72 # android_resources options 72 # android_resources options
73 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') 73 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
74 parser.add_option('--resources-zip', help='Path to target\'s resources zip.') 74 parser.add_option('--resources-zip', help='Path to target\'s resources zip.')
75 parser.add_option('--package-name', 75 parser.add_option('--package-name',
76 help='Java package name for these resources.') 76 help='Java package name for these resources.')
77 parser.add_option('--android-manifest', help='Path to android manifest.') 77 parser.add_option('--android-manifest', help='Path to android manifest.')
78 78
79 # android_library/apk options 79 # java library options
80 parser.add_option('--jar-path', help='Path to target\'s jar output.') 80 parser.add_option('--jar-path', help='Path to target\'s jar output.')
81 parser.add_option('--supports-android', action='store_true',
82 help='Whether this library supports running on the Android platform.')
83 parser.add_option('--requires-android', action='store_true',
84 help='Whether this library requires running on the Android platform.')
85
86 # android library options
81 parser.add_option('--dex-path', help='Path to target\'s dex output.') 87 parser.add_option('--dex-path', help='Path to target\'s dex output.')
82 88
83 # apk native library options 89 # native library options
84 parser.add_option('--native-libs', help='List of top-level native libs.') 90 parser.add_option('--native-libs', help='List of top-level native libs.')
85 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.') 91 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.')
86 92
87 options, args = parser.parse_args(argv) 93 options, args = parser.parse_args(argv)
88 94
89 if args: 95 if args:
90 parser.error('No positional arguments should be given.') 96 parser.error('No positional arguments should be given.')
91 97
92 98
93 if not options.type in [ 99 if not options.type in [
94 'android_library', 'android_resources', 'android_apk']: 100 'java_library', 'android_resources', 'android_apk']:
95 raise Exception('Unknown type: <%s>' % options.type) 101 raise Exception('Unknown type: <%s>' % options.type)
96 102
97
98 required_options = ['build_config'] + { 103 required_options = ['build_config'] + {
99 'android_library': ['jar_path', 'dex_path'], 104 'java_library': ['jar_path'],
100 'android_resources': ['resources_zip'], 105 'android_resources': ['resources_zip'],
101 'android_apk': ['jar_path', 'dex_path', 'resources_zip'] 106 'android_apk': ['jar_path', 'dex_path', 'resources_zip']
102 }[options.type] 107 }[options.type]
103 108
104 if options.native_libs: 109 if options.native_libs:
105 required_options += ['readelf_path'] 110 required_options.append('readelf_path')
106 111
107 build_utils.CheckOptions(options, parser, required_options) 112 build_utils.CheckOptions(options, parser, required_options)
108 113
114 if options.type == 'java_library':
115 if options.supports_android and not options.dex_path:
116 raise Exception('java_library that supports Android requires a dex path.')
117
118 if options.requires_android and not options.supports_android:
119 raise Exception(
120 '--supports-android is required when using --requires-android')
121
109 possible_deps_config_paths = build_utils.ParseGypList( 122 possible_deps_config_paths = build_utils.ParseGypList(
110 options.possible_deps_configs) 123 options.possible_deps_configs)
111 124
112
113 allow_unknown_deps = options.type == 'android_apk' 125 allow_unknown_deps = options.type == 'android_apk'
114 unknown_deps = [ 126 unknown_deps = [
115 c for c in possible_deps_config_paths if not os.path.exists(c)] 127 c for c in possible_deps_config_paths if not os.path.exists(c)]
116 if unknown_deps and not allow_unknown_deps: 128 if unknown_deps and not allow_unknown_deps:
117 raise Exception('Unknown deps: ' + str(unknown_deps)) 129 raise Exception('Unknown deps: ' + str(unknown_deps))
118 130
119 direct_deps_config_paths = [ 131 direct_deps_config_paths = [
120 c for c in possible_deps_config_paths if not c in unknown_deps] 132 c for c in possible_deps_config_paths if not c in unknown_deps]
121 all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths) 133 all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths)
122 134
123 direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths] 135 direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths]
124 all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths] 136 all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths]
125 137
126 direct_library_deps = DepsOfType('android_library', direct_deps_configs) 138 direct_library_deps = DepsOfType('java_library', direct_deps_configs)
127 all_library_deps = DepsOfType('android_library', all_deps_configs) 139 all_library_deps = DepsOfType('java_library', all_deps_configs)
128 140
129 direct_resources_deps = DepsOfType('android_resources', direct_deps_configs) 141 direct_resources_deps = DepsOfType('android_resources', direct_deps_configs)
130 all_resources_deps = DepsOfType('android_resources', all_deps_configs) 142 all_resources_deps = DepsOfType('android_resources', all_deps_configs)
131 143
132 # Initialize some common config. 144 # Initialize some common config.
133 config = { 145 config = {
134 'deps_info': { 146 'deps_info': {
147 'name': os.path.basename(options.build_config),
135 'path': options.build_config, 148 'path': options.build_config,
136 'type': options.type, 149 'type': options.type,
137 'deps_configs': direct_deps_config_paths, 150 'deps_configs': direct_deps_config_paths,
138 } 151 }
139 } 152 }
140 deps_info = config['deps_info'] 153 deps_info = config['deps_info']
141 154
142 if options.type in ['android_library', 'android_apk']: 155
156 if options.type == 'java_library':
157 deps_info['requires_android'] = options.requires_android
158 deps_info['supports_android'] = options.requires_android
newt (away) 2014/11/03 22:12:44 Should this be deps_info['supports_android']
cjhopman 2014/11/15 03:37:59 Done.
159
160 deps_require_android = (all_resources_deps +
161 [d['name'] for d in direct_library_deps if d['requires_android']])
162 deps_not_support_android = (
163 [d['name'] for d in direct_library_deps if not d['supports_android']])
164
165 if deps_require_android and not options.requires_android:
166 raise Exception('Some deps require building for the Android platform: ' +
167 str(deps_require_android))
168
169 if deps_not_support_android and options.supports_android:
170 raise Exception('Not all deps support the Android platform: ' +
171 str(deps_not_support_android))
172
173
174 if options.type in ['java_library', 'android_apk']:
143 javac_classpath = [c['jar_path'] for c in direct_library_deps] 175 javac_classpath = [c['jar_path'] for c in direct_library_deps]
176 java_full_classpath = [c['jar_path'] for c in all_library_deps]
144 deps_info['resources_deps'] = [c['path'] for c in all_resources_deps] 177 deps_info['resources_deps'] = [c['path'] for c in all_resources_deps]
145 deps_info['jar_path'] = options.jar_path 178 deps_info['jar_path'] = options.jar_path
146 deps_info['dex_path'] = options.dex_path 179 if options.type == 'android_apk' or options.supports_android:
180 deps_info['dex_path'] = options.dex_path
147 config['javac'] = { 181 config['javac'] = {
148 'classpath': javac_classpath, 182 'classpath': javac_classpath,
149 } 183 }
184 config['java'] = {
185 'full_classpath': java_full_classpath
186 }
150 187
151 if options.type == 'android_library': 188 if options.type == 'java_library':
152 # Only resources might have srcjars (normal srcjar targets are listed in 189 # Only resources might have srcjars (normal srcjar targets are listed in
153 # srcjar_deps). A resource's srcjar contains the R.java file for those 190 # srcjar_deps). A resource's srcjar contains the R.java file for those
154 # resources, and (like Android's default build system) we allow a library to 191 # resources, and (like Android's default build system) we allow a library to
155 # refer to the resources in any of its dependents. 192 # refer to the resources in any of its dependents.
156 config['javac']['srcjars'] = [ 193 config['javac']['srcjars'] = [
157 c['srcjar'] for c in direct_resources_deps if 'srcjar' in c] 194 c['srcjar'] for c in direct_resources_deps if 'srcjar' in c]
158 195
159 if options.type == 'android_apk': 196 if options.type == 'android_apk':
197 # Apks will get their resources srcjar explicitly passed to the java step.
160 config['javac']['srcjars'] = [] 198 config['javac']['srcjars'] = []
161 199
162
163 if options.type == 'android_resources': 200 if options.type == 'android_resources':
164 deps_info['resources_zip'] = options.resources_zip 201 deps_info['resources_zip'] = options.resources_zip
165 if options.srcjar: 202 if options.srcjar:
166 deps_info['srcjar'] = options.srcjar 203 deps_info['srcjar'] = options.srcjar
167 if options.package_name: 204 if options.package_name:
168 deps_info['package_name'] = options.package_name 205 deps_info['package_name'] = options.package_name
169 206
170 if options.type == 'android_resources' or options.type == 'android_apk': 207 if options.type == 'android_resources' or options.type == 'android_apk':
171 config['resources'] = {} 208 config['resources'] = {}
172 config['resources']['dependency_zips'] = [ 209 config['resources']['dependency_zips'] = [
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 build_utils.WriteJson(config, options.build_config, only_if_changed=True) 254 build_utils.WriteJson(config, options.build_config, only_if_changed=True)
218 255
219 if options.depfile: 256 if options.depfile:
220 build_utils.WriteDepfile( 257 build_utils.WriteDepfile(
221 options.depfile, 258 options.depfile,
222 all_deps_config_paths + build_utils.GetPythonDependencies()) 259 all_deps_config_paths + build_utils.GetPythonDependencies())
223 260
224 261
225 if __name__ == '__main__': 262 if __name__ == '__main__':
226 sys.exit(main(sys.argv[1:])) 263 sys.exit(main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698