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

Side by Side Diff: build/config/android/internal_rules.gni

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 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import("//build/config/android/config.gni") 5 import("//build/config/android/config.gni")
6 6
7 assert(is_android) 7 assert(is_android)
8 8
9 9
10 rebased_android_sdk = rebase_path(android_sdk, root_build_dir) 10 rebased_android_sdk = rebase_path(android_sdk, root_build_dir)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 "--jar-path", rebase_path(jar_path, root_build_dir), 48 "--jar-path", rebase_path(jar_path, root_build_dir),
49 "--processed-config-path", rebase_path(config_path, root_build_dir), 49 "--processed-config-path", rebase_path(config_path, root_build_dir),
50 "--result-path", rebase_path(result_path, root_build_dir), 50 "--result-path", rebase_path(result_path, root_build_dir),
51 "--java-files=$rebased_java_files", 51 "--java-files=$rebased_java_files",
52 "--enable", 52 "--enable",
53 ] 53 ]
54 } 54 }
55 } 55 }
56 56
57 57
58 template("dex") {
59 if (defined(invoker.testonly)) { testonly = invoker.testonly }
60
61 assert(defined(invoker.sources))
62 assert(defined(invoker.output))
63 action(target_name) {
64 script = "//build/android/gyp/dex.py"
65 depfile = "$target_gen_dir/$target_name.d"
66 sources = invoker.sources
67 outputs = [depfile, invoker.output]
68 if (defined(invoker.inputs)) {
69 inputs = invoker.inputs
70 }
71
72 if (defined(invoker.deps)) {
73 deps = invoker.deps
74 }
75
76 rebased_output = rebase_path(invoker.output, root_build_dir)
77
78 args = [
79 "--depfile", rebase_path(depfile, root_build_dir),
80 "--android-sdk-tools", rebased_android_sdk_build_tools,
81 "--dex-path", rebased_output,
82 ]
83
84 if (defined(invoker.no_locals) && invoker.no_locals) {
85 args += [
86 "--no-locals=1"
87 ]
88 }
89
90 if (defined(invoker.args)) {
91 args += invoker.args
92 }
93
94 args += rebase_path(invoker.sources, root_build_dir)
95 }
96 }
97
98
58 # Write the target's .build_config file. This is a json file that contains a 99 # Write the target's .build_config file. This is a json file that contains a
59 # dictionary of information about how to build this target (things that 100 # dictionary of information about how to build this target (things that
60 # require knowledge about this target's dependencies and cannot be calculated 101 # require knowledge about this target's dependencies and cannot be calculated
61 # at gn-time). There is a special syntax to add a value in that dictionary to 102 # at gn-time). There is a special syntax to add a value in that dictionary to
62 # an action/action_foreachs args: 103 # an action/action_foreachs args:
63 # --python-arg=@FileArg($rebased_build_config_path:key0:key1) 104 # --python-arg=@FileArg($rebased_build_config_path:key0:key1)
64 # At runtime, such an arg will be replaced by the value in the build_config. 105 # At runtime, such an arg will be replaced by the value in the build_config.
65 # See build/android/gyp/write_build_config.py and 106 # See build/android/gyp/write_build_config.py and
66 # build/android/gyp/util/build_utils.py:ExpandFileArgs 107 # build/android/gyp/util/build_utils.py:ExpandFileArgs
67 template("write_build_config") { 108 template("write_build_config") {
68 if (defined(invoker.testonly)) { testonly = invoker.testonly } 109 if (defined(invoker.testonly)) { testonly = invoker.testonly }
69 110
70 assert(defined(invoker.type)) 111 assert(defined(invoker.type))
71 assert(defined(invoker.build_config)) 112 assert(defined(invoker.build_config))
72 113
73 type = invoker.type 114 type = invoker.type
74 build_config = invoker.build_config 115 build_config = invoker.build_config
75 116
76 assert(type == "android_apk" || type == "android_library" || type == "android_ resources") 117 assert(type == "android_apk" || type == "java_library" || type == "android_res ources")
77 118
78 action(target_name) { 119 action(target_name) {
79 script = "//build/android/gyp/write_build_config.py" 120 script = "//build/android/gyp/write_build_config.py"
80 depfile = "$target_gen_dir/$target_name.d" 121 depfile = "$target_gen_dir/$target_name.d"
81 inputs = [] 122 inputs = []
82 123
83 deps = [] 124 deps = []
84 if (defined(invoker.deps)) { 125 if (defined(invoker.deps)) {
85 deps += invoker.deps 126 deps += invoker.deps
86 } 127 }
(...skipping 11 matching lines...) Expand all
98 build_config 139 build_config
99 ] 140 ]
100 141
101 args = [ 142 args = [
102 "--type", type, 143 "--type", type,
103 "--depfile", rebase_path(depfile, root_build_dir), 144 "--depfile", rebase_path(depfile, root_build_dir),
104 "--possible-deps-configs=$rebase_possible_deps_configs", 145 "--possible-deps-configs=$rebase_possible_deps_configs",
105 "--build-config", rebase_path(build_config, root_build_dir), 146 "--build-config", rebase_path(build_config, root_build_dir),
106 ] 147 ]
107 148
108 if (type == "android_library" || type == "android_apk") { 149 is_java_library = type == "java_library"
150 is_apk = type == "android_apk"
151 is_android_resources = type == "android_resources"
152
153 supports_android = (is_apk || is_android_resources ||
154 (is_java_library && defined(invoker.supports_android) &&
155 invoker.supports_android))
156 requires_android = (is_apk || is_android_resources ||
157 (is_java_library && defined(invoker.requires_android) &&
158 invoker.requires_android))
159
160 assert(!requires_android || supports_android, "requires_android requires" +
161 " supports_android")
162 assert(is_java_library || true)
newt (away) 2014/11/03 22:12:44 why this assert?
cjhopman 2014/11/15 03:37:59 Added comment about why.
163 assert(is_apk || true)
164 assert(is_android_resources || true)
165
166 if (is_java_library || is_apk) {
109 args += [ 167 args += [
110 "--jar-path", rebase_path(invoker.jar_path, root_build_dir), 168 "--jar-path", rebase_path(invoker.jar_path, root_build_dir),
169 ]
170 }
171
172 if (is_apk || (is_java_library && supports_android)) {
173 args += [
111 "--dex-path", rebase_path(invoker.dex_path, root_build_dir), 174 "--dex-path", rebase_path(invoker.dex_path, root_build_dir),
112 ] 175 ]
113 } 176 }
177 if (supports_android) {
178 args += [ "--supports-android" ]
179 }
180 if (requires_android) {
181 args += [ "--requires-android" ]
182 }
114 183
115 if (type == "android_resources" || type == "android_apk") { 184 if (is_android_resources || is_apk) {
116 assert(defined(invoker.resources_zip)) 185 assert(defined(invoker.resources_zip))
117 args += [ 186 args += [
118 "--resources-zip", rebase_path(invoker.resources_zip, root_build_dir), 187 "--resources-zip", rebase_path(invoker.resources_zip, root_build_dir),
119 ] 188 ]
120 if (defined(invoker.android_manifest)) { 189 if (defined(invoker.android_manifest)) {
121 inputs += [ 190 inputs += [
122 invoker.android_manifest 191 invoker.android_manifest
123 ] 192 ]
124 args += [ 193 args += [
125 "--android-manifest", rebase_path(invoker.android_manifest, root_build _dir), 194 "--android-manifest", rebase_path(invoker.android_manifest, root_build _dir),
126 ] 195 ]
127 } 196 }
128 if (defined(invoker.custom_package)) { 197 if (defined(invoker.custom_package)) {
129 args += [ 198 args += [
130 "--package-name", invoker.custom_package 199 "--package-name", invoker.custom_package
131 ] 200 ]
132 } 201 }
133 } 202 }
134 203
135 if (type == "android_apk") { 204 if (is_apk) {
136 if (defined(invoker.native_libs)) { 205 if (defined(invoker.native_libs)) {
137 rebased_native_libs = rebase_path(invoker.native_libs, root_build_dir) 206 rebased_native_libs = rebase_path(invoker.native_libs, root_build_dir)
138 rebased_android_readelf = rebase_path(android_readelf, root_build_dir) 207 rebased_android_readelf = rebase_path(android_readelf, root_build_dir)
139 args += [ 208 args += [
140 "--native-libs=$rebased_native_libs", 209 "--native-libs=$rebased_native_libs",
141 "--readelf-path=$rebased_android_readelf", 210 "--readelf-path=$rebased_android_readelf",
142 ] 211 ]
143 } 212 }
144 } 213 }
145 214
146 if (defined(invoker.srcjar)) { 215 if (defined(invoker.srcjar)) {
147 args += [ 216 args += [
148 "--srcjar", rebase_path(invoker.srcjar, root_build_dir) 217 "--srcjar", rebase_path(invoker.srcjar, root_build_dir)
149 ] 218 ]
150 } 219 }
151 } 220 }
152 } 221 }
153 222
154 223
155 # Creates a zip archive of the inputs. 224 template("process_java_prebuilt") {
156 # If base_dir is provided, the archive paths will be relative to it.
157 template("zip") {
158 if (defined(invoker.testonly)) { testonly = invoker.testonly }
159
160 assert(defined(invoker.inputs))
161 assert(defined(invoker.output))
162
163 rebase_inputs = rebase_path(invoker.inputs, root_build_dir)
164 rebase_output = rebase_path(invoker.output, root_build_dir)
165 action(target_name) {
166 script = "//build/android/gn/zip.py"
167 depfile = "$target_gen_dir/$target_name.d"
168 inputs = invoker.inputs
169 outputs = [
170 depfile,
171 invoker.output
172 ]
173 args = [
174 "--depfile", rebase_path(depfile, root_build_dir),
175 "--inputs=$rebase_inputs",
176 "--output=$rebase_output",
177 ]
178 if (defined(invoker.base_dir)) {
179 args += [
180 "--base-dir", rebase_path(invoker.base_dir, root_build_dir)
181 ]
182 }
183 }
184 }
185
186 template("dex") {
187 if (defined(invoker.testonly)) { testonly = invoker.testonly }
188
189 assert(defined(invoker.sources))
190 assert(defined(invoker.output))
191 action(target_name) {
192 script = "//build/android/gyp/dex.py"
193 depfile = "$target_gen_dir/$target_name.d"
194 sources = invoker.sources
195 outputs = [depfile, invoker.output]
196 if (defined(invoker.inputs)) {
197 inputs = invoker.inputs
198 }
199
200 if (defined(invoker.deps)) {
201 deps = invoker.deps
202 }
203
204 rebased_output = rebase_path(invoker.output, root_build_dir)
205
206 args = [
207 "--depfile", rebase_path(depfile, root_build_dir),
208 "--android-sdk-tools", rebased_android_sdk_build_tools,
209 "--dex-path", rebased_output,
210 ]
211
212 if (defined(invoker.no_locals) && invoker.no_locals) {
213 args += [
214 "--no-locals=1"
215 ]
216 }
217
218 if (defined(invoker.args)) {
219 args += invoker.args
220 }
221
222 args += rebase_path(invoker.sources, root_build_dir)
223 }
224 }
225
226 # Packages resources, assets, dex, and native libraries into an apk. Signs and
227 # zipaligns the apk.
228 template("create_apk") {
229 if (defined(invoker.testonly)) { testonly = invoker.testonly }
230
231 _android_manifest = invoker.android_manifest
232 _base_path = invoker.base_path
233 _final_apk_path = invoker.apk_path
234 _resources_zip = invoker.resources_zip
235 _dex_path = invoker.dex_path
236 _keystore_path = invoker.keystore_path
237 _keystore_name = invoker.keystore_name
238 _keystore_password = invoker.keystore_password
239 _load_library_from_apk = invoker.load_library_from_apk
240
241 _deps = []
242 if (defined(invoker.deps)) {
243 _deps = invoker.deps
244 }
245
246 _native_libs_dir = "//build/android/empty/res"
247 if (defined(invoker.native_libs_dir)) {
248 _native_libs_dir = invoker.native_libs_dir
249 }
250
251 _asset_location = "//build/android/empty/res"
252 if (defined(invoker.asset_location)) {
253 _asset_location = invoker.asset_location
254 }
255
256 _version_code = invoker.version_code
257 _version_name = invoker.version_name
258
259 _base_apk_path = _base_path + ".apk_intermediates"
260
261 _resource_packaged_apk_path = _base_apk_path + ".ap_"
262 _packaged_apk_path = _base_apk_path + ".unfinished.apk"
263
264
265 _configuration_name = "Release"
266 if (is_debug) {
267 _configuration_name = "Debug"
268 }
269
270 action("${target_name}__package_resources") {
271 deps = _deps
272
273 script = "//build/android/gyp/package_resources.py"
274 depfile = "${target_gen_dir}/${target_name}.d"
275 inputs = [
276 _android_manifest,
277 _resources_zip,
278 ]
279 outputs = [depfile, _resource_packaged_apk_path]
280
281 _rebased_resources_zips = [rebase_path(_resources_zip, root_build_dir)]
282 args = [
283 "--depfile", rebase_path(depfile, root_build_dir),
284 "--android-sdk", rebased_android_sdk,
285 "--android-sdk-tools", rebased_android_sdk_build_tools,
286
287 "--configuration-name=$_configuration_name",
288
289 "--android-manifest", rebase_path(_android_manifest, root_build_dir),
290 "--version-code", _version_code,
291 "--version-name", _version_name,
292
293 "--asset-dir", rebase_path(_asset_location, root_build_dir),
294 "--resource-zips=$_rebased_resources_zips",
295
296 "--apk-path", rebase_path(_resource_packaged_apk_path, root_build_dir),
297 ]
298 }
299
300 action("${target_name}__package") {
301 script = "//build/android/gyp/ant.py"
302 _ant_script = "//build/android/ant/apk-package.xml"
303
304 depfile = "$target_gen_dir/$target_name.d"
305
306 inputs = [
307 _dex_path,
308 _resource_packaged_apk_path,
309 _ant_script
310 ]
311
312 outputs = [
313 depfile,
314 _packaged_apk_path,
315 ]
316
317 _rebased_emma_jar = ""
318 _rebased_resource_packaged_apk_path = rebase_path(
319 _resource_packaged_apk_path, root_build_dir)
320 _rebased_packaged_apk_path = rebase_path(_packaged_apk_path, root_build_dir)
321 _rebased_native_libs_dir = rebase_path(_native_libs_dir, root_build_dir)
322 _rebased_dex_path = rebase_path(_dex_path, root_build_dir)
323 args = [
324 "--depfile", rebase_path(depfile, root_build_dir),
325 "--",
326 "-quiet",
327 "-DANDROID_SDK_ROOT=$rebased_android_sdk_root",
328 "-DANDROID_SDK_TOOLS=$rebased_android_sdk_build_tools",
329 "-DRESOURCE_PACKAGED_APK_NAME=$_rebased_resource_packaged_apk_path",
330 "-DCONFIGURATION_NAME=$_configuration_name",
331 "-DNATIVE_LIBS_DIR=$_rebased_native_libs_dir",
332 "-DOUT_DIR=",
333 "-DUNSIGNED_APK_PATH=$_rebased_packaged_apk_path",
334 "-DEMMA_INSTRUMENT=0",
335 "-DEMMA_DEVICE_JAR=$_rebased_emma_jar",
336 "-DDEX_FILE_PATH=$_rebased_dex_path",
337
338 "-Dbasedir=.",
339 "-buildfile", rebase_path(_ant_script, root_build_dir)
340 ]
341 }
342
343 action("${target_name}__finalize") {
344 script = "//build/android/gyp/finalize_apk.py"
345 depfile = "$target_gen_dir/$target_name.d"
346
347 sources = [_packaged_apk_path]
348 inputs = [_keystore_path]
349 outputs = [depfile, _final_apk_path]
350
351 args = [
352 "--depfile", rebase_path(depfile, root_build_dir),
353 "--zipalign-path", rebase_path(zipalign_path, root_build_dir),
354 "--unsigned-apk-path", rebase_path(_packaged_apk_path, root_build_dir),
355 "--final-apk-path", rebase_path(_final_apk_path, root_build_dir),
356 "--key-path", rebase_path(_keystore_path, root_build_dir),
357 "--key-name", _keystore_name,
358 "--key-passwd", _keystore_password,
359 ]
360 if (_load_library_from_apk) {
361 _rezip_jar_path = "$root_build_dir/lib.java/rezip_apk.jar"
362 inputs += [
363 _rezip_jar_path
364 ]
365 args += [
366 "--load-library-from-zip-file=1",
367 "--rezip-apk-jar-path", rebase_path(_rezip_jar_path, root_build_dir)
368 ]
369 }
370 }
371
372 group(target_name) {
373 deps = [":${target_name}__finalize"]
374 }
375 }
376
377 template("java_prebuilt") {
378 if (defined(invoker.testonly)) { testonly = invoker.testonly } 225 if (defined(invoker.testonly)) { testonly = invoker.testonly }
379 226
380 _input_jar_path = invoker.input_jar_path 227 _input_jar_path = invoker.input_jar_path
381 _output_jar_path = invoker.output_jar_path 228 _output_jar_path = invoker.output_jar_path
382 _jar_toc_path = _output_jar_path + ".TOC" 229 _jar_toc_path = _output_jar_path + ".TOC"
383 230
384 assert(invoker.build_config != "") 231 assert(invoker.build_config != "")
385 232
386 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) { 233 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
387 _proguard_jar_path = "$android_sdk_root/tools/proguard/lib/proguard.jar" 234 _proguard_jar_path = "$android_sdk_root/tools/proguard/lib/proguard.jar"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 ] 282 ]
436 } 283 }
437 284
438 group(target_name) { 285 group(target_name) {
439 deps = [ 286 deps = [
440 ":${target_name}__jar_toc" 287 ":${target_name}__jar_toc"
441 ] 288 ]
442 } 289 }
443 } 290 }
444 291
292
293 template("java_prebuilt_impl") {
294 if (defined(invoker.testonly)) { testonly = invoker.testonly }
295 _supports_android = (
296 defined(invoker.supports_android) && invoker.supports_android)
297
298 assert(defined(invoker.jar_path))
299 _base_path = "${target_gen_dir}/$target_name"
300 _jar_path = _base_path + ".jar"
301 _build_config = _base_path + ".build_config"
302
303 if (_supports_android) {
304 _dex_path = _base_path + ".dex.jar"
305 }
306
307 _final_deps = []
308 _template_name = target_name
309
310
311 _final_deps += [ ":${_template_name}__build_config" ]
312 write_build_config("${_template_name}__build_config") {
313 type = "java_library"
314 supports_android = _supports_android
315 requires_android = (defined(invoker.requires_android) &&
316 invoker.requires_android)
317
318 deps = []
319 if (defined(invoker.deps)) {
320 deps += invoker.deps
321 }
322 build_config = _build_config
323 jar_path = _jar_path
324 if (_supports_android) {
325 dex_path = _dex_path
326 }
327 }
328
329 _final_deps += [ ":${_template_name}__process_jar" ]
330 process_java_prebuilt("${_template_name}__process_jar") {
331 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
332 proguard_preprocess = true
333 proguard_config = invoker.proguard_config
334 }
335
336 build_config = _build_config
337 input_jar_path = invoker.jar_path
338 output_jar_path = _jar_path
339 }
340
341 if (_supports_android) {
342 _final_deps += [ ":${_template_name}__dex" ]
343 dex("${_template_name}__dex") {
344 sources = [_jar_path]
345 output = _dex_path
346 }
347 }
348
349 group(target_name) {
350 deps = _final_deps
351 }
352 }
353
354
445 # Compiles and jars a set of java files. 355 # Compiles and jars a set of java files.
446 # 356 #
447 # Outputs: 357 # Outputs:
448 # $jar_path.jar 358 # $jar_path.jar
449 # $jar_path.jar.TOC 359 # $jar_path.jar.TOC
450 # 360 #
451 # Variables 361 # Variables
452 # java_files: List of .java files to compile. 362 # java_files: List of .java files to compile.
453 # java_deps: List of java dependencies. These should all have a .jar output 363 # java_deps: List of java dependencies. These should all have a .jar output
454 # at "${target_gen_dir}/${target_name}.jar. 364 # at "${target_gen_dir}/${target_name}.jar.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 _java_srcjars = invoker.srcjars 400 _java_srcjars = invoker.srcjars
491 } 401 }
492 foreach(dep, _srcjar_deps) { 402 foreach(dep, _srcjar_deps) {
493 _dep_gen_dir = get_label_info(dep, "target_gen_dir") 403 _dep_gen_dir = get_label_info(dep, "target_gen_dir")
494 _dep_name = get_label_info(dep, "name") 404 _dep_name = get_label_info(dep, "name")
495 _java_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ] 405 _java_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ]
496 } 406 }
497 # Mark srcjar_deps as used. 407 # Mark srcjar_deps as used.
498 assert(_srcjar_deps == [] || true) 408 assert(_srcjar_deps == [] || true)
499 409
500 _system_jars = [ android_sdk_jar ] 410 _system_jars = []
501 action("${target_name}__javac") { 411 if (defined(invoker.android) && invoker.android) {
412 _system_jars += [ android_sdk_jar ]
413 }
414
415 _rebased_build_config = rebase_path(_build_config, root_build_dir)
416 _rebased_jar_path = rebase_path(_intermediate_jar_path, root_build_dir)
417
418 _template_name = target_name
419 _final_deps = [ ":${_template_name}__javac" ]
420 action("${_template_name}__javac") {
502 script = "//build/android/gyp/javac.py" 421 script = "//build/android/gyp/javac.py"
503 depfile = "$target_gen_dir/$target_name.d" 422 depfile = "$target_gen_dir/$target_name.d"
423 deps = []
504 outputs = [ 424 outputs = [
505 depfile, 425 depfile,
506 _intermediate_jar_path, 426 _intermediate_jar_path,
507 _intermediate_jar_path + ".md5.stamp" 427 _intermediate_jar_path + ".md5.stamp"
508 ] 428 ]
509 sources = _java_files + _java_srcjars 429 sources = _java_files + _java_srcjars
510 inputs = _system_jars + [ _build_config ] 430 inputs = _system_jars + [ _build_config ]
511 431
512 _rebased_system_jars = rebase_path(_system_jars, root_build_dir) 432 _rebased_system_jars = rebase_path(_system_jars, root_build_dir)
513 _rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir) 433 _rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir)
514 _rebased_build_config = rebase_path(_build_config, root_build_dir)
515 _rebased_depfile = rebase_path(depfile, root_build_dir) 434 _rebased_depfile = rebase_path(depfile, root_build_dir)
516 _rebased_jar_path = rebase_path(_intermediate_jar_path, root_build_dir)
517 args = [ 435 args = [
518 "--depfile=$_rebased_depfile", 436 "--depfile=$_rebased_depfile",
519 "--classpath=$_rebased_system_jars", 437 "--classpath=$_rebased_system_jars",
520 "--classpath=@FileArg($_rebased_build_config:javac:classpath)", 438 "--classpath=@FileArg($_rebased_build_config:javac:classpath)",
521 "--jar-path=$_rebased_jar_path", 439 "--jar-path=$_rebased_jar_path",
522 "--java-srcjars=$_rebased_java_srcjars", 440 "--java-srcjars=$_rebased_java_srcjars",
523 "--java-srcjars=@FileArg($_rebased_build_config:javac:srcjars)", 441 "--java-srcjars=@FileArg($_rebased_build_config:javac:srcjars)",
524 "--jar-excluded-classes=$_jar_excluded_patterns", 442 "--jar-excluded-classes=$_jar_excluded_patterns",
525 ] 443 ]
526 if (_chromium_code) { 444 if (_chromium_code) {
527 args += [ "--chromium-code" ] 445 args += [ "--chromium-code=1" ]
446 }
447
448 if (defined(invoker.main_class)) {
449 args += [
450 "--main-class", invoker.main_class
451 ]
528 } 452 }
529 453
530 args += rebase_path(_java_files, root_build_dir) 454 args += rebase_path(_java_files, root_build_dir)
531 } 455 }
532 456
533 java_prebuilt("${target_name}__finish") { 457 _final_deps += [ ":${_template_name}__finish" ]
458 process_java_prebuilt("${_template_name}__finish") {
534 build_config = _build_config 459 build_config = _build_config
535 input_jar_path = _intermediate_jar_path 460 input_jar_path = _intermediate_jar_path
536 output_jar_path = _final_jar_path 461 output_jar_path = _final_jar_path
537 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) { 462 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
538 proguard_preprocess = invoker.proguard_preprocess 463 proguard_preprocess = invoker.proguard_preprocess
539 proguard_config = invoker.proguard_config 464 proguard_config = invoker.proguard_config
540 } 465 }
541 } 466 }
542 467
543 group(target_name) { 468 group(target_name) {
544 deps = [ 469 deps = _final_deps
545 ":${target_name}__javac",
546 ":${target_name}__finish",
547 ]
548 } 470 }
549 } 471 }
550 472
551 473
552 # This adds Android-specific parts to the java_library template. 474 template("java_library_impl") {
553 #
554 # Runs Android lint against the compiled java files.
555 # Dexes the output jar for inclusion in an APK.
556 template("android_java_library") {
557 if (defined(invoker.testonly)) { testonly = invoker.testonly } 475 if (defined(invoker.testonly)) { testonly = invoker.testonly }
558 476
559 assert(defined(invoker.java_files) || defined(invoker.DEPRECATED_java_in_dir) 477 assert(defined(invoker.java_files) || defined(invoker.DEPRECATED_java_in_dir)
560 || defined(invoker.srcjars) || defined(invoker.srcjar_deps)) 478 || defined(invoker.srcjars) || defined(invoker.srcjar_deps))
561 assert(defined(invoker.build_config)) 479 _base_path = "$target_gen_dir/$target_name"
562 assert(defined(invoker.jar_path)) 480 _jar_path = _base_path + ".jar"
563 assert(defined(invoker.dex_path)) 481 if (defined(invoker.jar_path)) {
482 _jar_path = invoker.jar_path
483 }
484 _template_name = target_name
485
486 _final_deps = []
487 _final_datadeps = []
488 if (defined(invoker.datadeps)) {
489 _final_datadeps = invoker.datadeps
490 }
491
492 _supports_android = (defined(invoker.supports_android) &&
493 invoker.supports_android)
494 _requires_android = (defined(invoker.requires_android) &&
495 invoker.requires_android)
496
497 if (_supports_android) {
498 _dex_path = _base_path + ".dex.jar"
499 if (defined(invoker.dex_path)) {
500 _dex_path = invoker.dex_path
501 }
502 }
503
504 if (defined(invoker.override_build_config)) {
505 _build_config = invoker.override_build_config
506 } else {
507 _build_config = _base_path + ".build_config"
508 _final_deps += [ ":${_template_name}__build_config" ]
509 write_build_config("${_template_name}__build_config") {
510 type = "java_library"
511 supports_android = _supports_android
512 requires_android = _requires_android
513
514 deps = []
515 if (defined(invoker.deps)) {
516 deps += invoker.deps
517 }
518
519 build_config = _build_config
520 jar_path = _jar_path
521 if (_supports_android) {
522 dex_path = _dex_path
523 }
524 }
525 }
526
527 _chromium_code = true
528 if (defined(invoker.chromium_code)) {
529 _chromium_code = invoker.chromium_code
530 }
564 531
565 _srcjar_deps = [] 532 _srcjar_deps = []
566 if (defined(invoker.srcjar_deps)) { 533 if (defined(invoker.srcjar_deps)) {
567 _srcjar_deps = invoker.srcjar_deps 534 _srcjar_deps = invoker.srcjar_deps
568 } 535 }
569 536
570 _srcjars = [] 537 _srcjars = []
571 if (defined(invoker.srcjars)) { 538 if (defined(invoker.srcjars)) {
572 _srcjars = invoker.srcjars 539 _srcjars = invoker.srcjars
573 } 540 }
(...skipping 16 matching lines...) Expand all
590 "--pattern", 557 "--pattern",
591 "*.java", 558 "*.java",
592 rebase_path(invoker.DEPRECATED_java_in_dir, root_build_dir) 559 rebase_path(invoker.DEPRECATED_java_in_dir, root_build_dir)
593 ], 560 ],
594 "list lines" 561 "list lines"
595 ) 562 )
596 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir) 563 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
597 } 564 }
598 assert(_java_files != [] || _srcjar_deps != [] || _srcjars != []) 565 assert(_java_files != [] || _srcjar_deps != [] || _srcjars != [])
599 566
600 _jar_path = invoker.jar_path 567 _final_deps += [ ":${_template_name}__compile_java" ]
601 _dex_path = invoker.dex_path 568 compile_java("${_template_name}__compile_java") {
602
603 _android_manifest = "//build/android/AndroidManifest.xml"
604 if (defined(invoker.android_manifest)) {
605 _android_manifest = invoker.android_manifest
606 }
607 assert(_android_manifest != "")
608
609 _final_deps = []
610 _final_datadeps = []
611
612 compile_java("${target_name}__compile_java") {
613 jar_path = _jar_path 569 jar_path = _jar_path
614 if (defined(invoker.jar_excluded_patterns)) { 570 build_config = _build_config
615 jar_excluded_patterns = invoker.jar_excluded_patterns
616 }
617 build_config = invoker.build_config
618 java_files = _java_files 571 java_files = _java_files
619 srcjar_deps = _srcjar_deps 572 srcjar_deps = _srcjar_deps
620 srcjars = _srcjars 573 srcjars = _srcjars
621 574 chromium_code = _chromium_code
622 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) { 575 android = _requires_android
623 proguard_preprocess = invoker.proguard_preprocess 576
624 proguard_config = invoker.proguard_config 577 if (defined(invoker.jar_excluded_patterns)) { jar_excluded_patterns = invoke r.jar_excluded_patterns }
625 } 578 if (defined(invoker.main_class)) { main_class = invoker.main_class }
626 579 if (defined(invoker.proguard_preprocess)) { proguard_preprocess = invoker.pr oguard_preprocess }
627 if (defined(invoker.dist_jar_path)) { 580 if (defined(invoker.proguard_config)) { proguard_config = invoker.proguard_c onfig }
628 dist_jar_path = invoker.dist_jar_path 581 if (defined(invoker.dist_jar_path)) { dist_jar_path = invoker.dist_jar_path }
629 } 582 }
630 } 583
631 584 if (defined(invoker.main_class)) {
632 if (defined(invoker.chromium_code) && invoker.chromium_code) { 585 _final_deps += [ ":${_template_name}__binary_script" ]
633 _final_datadeps += [ ":${target_name}__lint" ] 586 action("${_template_name}__binary_script") {
634 android_lint("${target_name}__lint") { 587 script = "//build/android/gyp/create_java_binary_script.py"
635 android_manifest = _android_manifest 588 depfile = "$target_gen_dir/$target_name.d"
636 jar_path = _jar_path 589 java_script = "$root_build_dir/bin/$_template_name"
637 java_files = _java_files 590 inputs = [ _build_config ]
638 } 591 outputs = [
639 } 592 depfile,
640 593 java_script,
641 dex("${target_name}__dex") { 594 ]
642 sources = [_jar_path] 595 _rebased_build_config = rebase_path(_build_config, root_build_dir)
643 output = _dex_path 596 args = [
597 "--depfile", rebase_path(depfile, root_build_dir),
598 "--output", rebase_path(java_script, root_build_dir),
599 "--classpath=@FileArg($_rebased_build_config:java:full_classpath)",
600 "--jar-path", rebase_path(_jar_path, root_build_dir),
601 "--main-class", invoker.main_class,
602 ]
603 }
604 }
605
606 if (_requires_android) {
607 if (defined(invoker.chromium_code) && invoker.chromium_code) {
608 _android_manifest = "//build/android/AndroidManifest.xml"
609 if (defined(invoker.android_manifest)) {
610 _android_manifest = invoker.android_manifest
611 }
612
613 _final_datadeps += [ ":${_template_name}__lint" ]
614 android_lint("${_template_name}__lint") {
615 android_manifest = _android_manifest
616 jar_path = _jar_path
617 java_files = _java_files
618 }
619 }
620
621 _final_deps += [ ":${_template_name}__dex" ]
622 dex("${_template_name}__dex") {
newt (away) 2014/11/03 22:12:45 shouldn't we also run dex when supports_android is
cjhopman 2014/11/15 03:37:59 Done.
623 sources = [_jar_path]
624 output = _dex_path
625 }
644 } 626 }
645 627
646 group(target_name) { 628 group(target_name) {
647 deps = [ 629 deps = _final_deps
648 ":${target_name}__compile_java", 630 datadeps = _final_datadeps
649 ":${target_name}__dex",
650 ] + _final_deps + _final_datadeps
651 } 631 }
652 } 632 }
653 633
634 # Creates a zip archive of the inputs.
635 # If base_dir is provided, the archive paths will be relative to it.
636 template("zip") {
637 if (defined(invoker.testonly)) { testonly = invoker.testonly }
638
639 assert(defined(invoker.inputs))
640 assert(defined(invoker.output))
641
642 rebase_inputs = rebase_path(invoker.inputs, root_build_dir)
643 rebase_output = rebase_path(invoker.output, root_build_dir)
644 action(target_name) {
645 script = "//build/android/gn/zip.py"
646 depfile = "$target_gen_dir/$target_name.d"
647 inputs = invoker.inputs
648 outputs = [
649 depfile,
650 invoker.output
651 ]
652 args = [
653 "--depfile", rebase_path(depfile, root_build_dir),
654 "--inputs=$rebase_inputs",
655 "--output=$rebase_output",
656 ]
657 if (defined(invoker.base_dir)) {
658 args += [
659 "--base-dir", rebase_path(invoker.base_dir, root_build_dir)
660 ]
661 }
662 }
663 }
664
665 # Packages resources, assets, dex, and native libraries into an apk. Signs and
666 # zipaligns the apk.
667 template("create_apk") {
668 if (defined(invoker.testonly)) { testonly = invoker.testonly }
669
670 _android_manifest = invoker.android_manifest
671 _base_path = invoker.base_path
672 _final_apk_path = invoker.apk_path
673 _resources_zip = invoker.resources_zip
674 _dex_path = invoker.dex_path
675 _keystore_path = invoker.keystore_path
676 _keystore_name = invoker.keystore_name
677 _keystore_password = invoker.keystore_password
678 _load_library_from_apk = invoker.load_library_from_apk
679
680 _deps = []
681 if (defined(invoker.deps)) {
682 _deps = invoker.deps
683 }
684
685 _native_libs_dir = "//build/android/empty/res"
686 if (defined(invoker.native_libs_dir)) {
687 _native_libs_dir = invoker.native_libs_dir
688 }
689
690 _asset_location = "//build/android/empty/res"
691 if (defined(invoker.asset_location)) {
692 _asset_location = invoker.asset_location
693 }
694
695 _version_code = invoker.version_code
696 _version_name = invoker.version_name
697
698 _base_apk_path = _base_path + ".apk_intermediates"
699
700 _resource_packaged_apk_path = _base_apk_path + ".ap_"
701 _packaged_apk_path = _base_apk_path + ".unfinished.apk"
702
703
704 _configuration_name = "Release"
705 if (is_debug) {
706 _configuration_name = "Debug"
707 }
708
709 action("${target_name}__package_resources") {
710 deps = _deps
711
712 script = "//build/android/gyp/package_resources.py"
713 depfile = "${target_gen_dir}/${target_name}.d"
714 inputs = [
715 _android_manifest,
716 _resources_zip,
717 ]
718 outputs = [depfile, _resource_packaged_apk_path]
719
720 _rebased_resources_zips = [rebase_path(_resources_zip, root_build_dir)]
721 args = [
722 "--depfile", rebase_path(depfile, root_build_dir),
723 "--android-sdk", rebased_android_sdk,
724 "--android-sdk-tools", rebased_android_sdk_build_tools,
725
726 "--configuration-name=$_configuration_name",
727
728 "--android-manifest", rebase_path(_android_manifest, root_build_dir),
729 "--version-code", _version_code,
730 "--version-name", _version_name,
731
732 "--asset-dir", rebase_path(_asset_location, root_build_dir),
733 "--resource-zips=$_rebased_resources_zips",
734
735 "--apk-path", rebase_path(_resource_packaged_apk_path, root_build_dir),
736 ]
737 }
738
739 action("${target_name}__package") {
740 script = "//build/android/gyp/ant.py"
741 _ant_script = "//build/android/ant/apk-package.xml"
742
743 depfile = "$target_gen_dir/$target_name.d"
744
745 inputs = [
746 _dex_path,
747 _resource_packaged_apk_path,
748 _ant_script
749 ]
750
751 outputs = [
752 depfile,
753 _packaged_apk_path,
754 ]
755
756 _rebased_emma_jar = ""
757 _rebased_resource_packaged_apk_path = rebase_path(
758 _resource_packaged_apk_path, root_build_dir)
759 _rebased_packaged_apk_path = rebase_path(_packaged_apk_path, root_build_dir)
760 _rebased_native_libs_dir = rebase_path(_native_libs_dir, root_build_dir)
761 _rebased_dex_path = rebase_path(_dex_path, root_build_dir)
762 args = [
763 "--depfile", rebase_path(depfile, root_build_dir),
764 "--",
765 "-quiet",
766 "-DANDROID_SDK_ROOT=$rebased_android_sdk_root",
767 "-DANDROID_SDK_TOOLS=$rebased_android_sdk_build_tools",
768 "-DRESOURCE_PACKAGED_APK_NAME=$_rebased_resource_packaged_apk_path",
769 "-DCONFIGURATION_NAME=$_configuration_name",
770 "-DNATIVE_LIBS_DIR=$_rebased_native_libs_dir",
771 "-DOUT_DIR=",
772 "-DUNSIGNED_APK_PATH=$_rebased_packaged_apk_path",
773 "-DEMMA_INSTRUMENT=0",
774 "-DEMMA_DEVICE_JAR=$_rebased_emma_jar",
775 "-DDEX_FILE_PATH=$_rebased_dex_path",
776
777 "-Dbasedir=.",
778 "-buildfile", rebase_path(_ant_script, root_build_dir)
779 ]
780 }
781
782 action("${target_name}__finalize") {
783 script = "//build/android/gyp/finalize_apk.py"
784 depfile = "$target_gen_dir/$target_name.d"
785
786 sources = [_packaged_apk_path]
787 inputs = [_keystore_path]
788 outputs = [depfile, _final_apk_path]
789
790 args = [
791 "--depfile", rebase_path(depfile, root_build_dir),
792 "--zipalign-path", rebase_path(zipalign_path, root_build_dir),
793 "--unsigned-apk-path", rebase_path(_packaged_apk_path, root_build_dir),
794 "--final-apk-path", rebase_path(_final_apk_path, root_build_dir),
795 "--key-path", rebase_path(_keystore_path, root_build_dir),
796 "--key-name", _keystore_name,
797 "--key-passwd", _keystore_password,
798 ]
799 if (_load_library_from_apk) {
800 _rezip_jar_path = "$root_build_dir/lib.java/rezip_apk.jar"
801 inputs += [
802 _rezip_jar_path
803 ]
804 args += [
805 "--load-library-from-zip-file=1",
806 "--rezip-apk-jar-path", rebase_path(_rezip_jar_path, root_build_dir)
807 ]
808 }
809 }
810
811 group(target_name) {
812 deps = [":${target_name}__finalize"]
813 }
814 }
815
654 # Runs process_resources.py 816 # Runs process_resources.py
655 template("process_resources") { 817 template("process_resources") {
656 if (defined(invoker.testonly)) { testonly = invoker.testonly } 818 if (defined(invoker.testonly)) { testonly = invoker.testonly }
657 819
658 zip_path = invoker.zip_path 820 zip_path = invoker.zip_path
659 srcjar_path = invoker.srcjar_path 821 srcjar_path = invoker.srcjar_path
660 build_config = invoker.build_config 822 build_config = invoker.build_config
661 resource_dirs = invoker.resource_dirs 823 resource_dirs = invoker.resource_dirs
662 android_manifest = invoker.android_manifest 824 android_manifest = invoker.android_manifest
663 825
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 926
765 if (defined(invoker.clear_dir) && invoker.clear_dir) { 927 if (defined(invoker.clear_dir) && invoker.clear_dir) {
766 args += ["--clear"] 928 args += ["--clear"]
767 } 929 }
768 930
769 if (defined(invoker.args)) { 931 if (defined(invoker.args)) {
770 args += invoker.args 932 args += invoker.args
771 } 933 }
772 } 934 }
773 } 935 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698