| OLD | NEW |
| (Empty) |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import("//build/module_args/mojo.gni") | |
| 6 import("mojo.gni") | |
| 7 import("mojo_sdk.gni") | |
| 8 | |
| 9 # Generate a binary mojo application.The parameters of this template are those | |
| 10 # of a shared library. | |
| 11 template("mojo_native_application") { | |
| 12 if (defined(invoker.output_name)) { | |
| 13 base_target_name = invoker.output_name | |
| 14 } else { | |
| 15 base_target_name = target_name | |
| 16 } | |
| 17 | |
| 18 if (!is_nacl) { | |
| 19 final_target_name = target_name | |
| 20 output = base_target_name + ".mojo" | |
| 21 library_target_name = base_target_name + "_library" | |
| 22 copy_symbols_target = "__${final_target_name}_copy_symbols" | |
| 23 | |
| 24 if (is_linux || is_android) { | |
| 25 library_name = "lib${library_target_name}.so" | |
| 26 } else if (is_win) { | |
| 27 library_name = "${library_target_name}.dll" | |
| 28 } else if (is_mac || is_ios) { | |
| 29 library_name = "lib${library_target_name}.dylib" | |
| 30 } else { | |
| 31 assert(false, "Platform not supported.") | |
| 32 } | |
| 33 | |
| 34 if (is_android) { | |
| 35 # On android, use the stripped version of the library, because application
s | |
| 36 # are always fetched over the network. | |
| 37 library_dir = "${root_out_dir}/lib.stripped" | |
| 38 } else { | |
| 39 library_dir = root_out_dir | |
| 40 } | |
| 41 | |
| 42 shared_library(library_target_name) { | |
| 43 data_deps = [] | |
| 44 forward_variables_from(invoker, | |
| 45 [ | |
| 46 "cflags", | |
| 47 "cflags_c", | |
| 48 "cflags_cc", | |
| 49 "cflags_objc", | |
| 50 "cflags_objcc", | |
| 51 "defines", | |
| 52 "include_dirs", | |
| 53 "ldflags", | |
| 54 "lib_dirs", | |
| 55 "libs", | |
| 56 ]) | |
| 57 if (defined(invoker.data_deps)) { | |
| 58 data_deps += invoker.data_deps | |
| 59 } | |
| 60 | |
| 61 # Copy any necessary prebuilt artifacts. | |
| 62 if (mojo_use_prebuilt_mojo_shell) { | |
| 63 data_deps += | |
| 64 [ rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) ] | |
| 65 } | |
| 66 if (mojo_use_prebuilt_network_service) { | |
| 67 data_deps += [ rebase_path("mojo/public/tools:copy_network_service", | |
| 68 ".", | |
| 69 mojo_root) ] | |
| 70 } | |
| 71 | |
| 72 deps = rebase_path([ "mojo/public/platform/native:system_thunks" ], | |
| 73 ".", | |
| 74 mojo_root) | |
| 75 if (defined(invoker.deps)) { | |
| 76 deps += invoker.deps | |
| 77 } | |
| 78 if (defined(invoker.configs)) { | |
| 79 configs += invoker.configs | |
| 80 } | |
| 81 forward_variables_from(invoker, | |
| 82 [ | |
| 83 "public_deps", | |
| 84 "all_dependent_configs", | |
| 85 "public_configs", | |
| 86 "check_includes", | |
| 87 "data", | |
| 88 "inputs", | |
| 89 "public", | |
| 90 "sources", | |
| 91 "testonly", | |
| 92 ]) | |
| 93 | |
| 94 visibility = [ | |
| 95 ":${final_target_name}", | |
| 96 ":${copy_symbols_target}", | |
| 97 ] | |
| 98 } | |
| 99 | |
| 100 copy(copy_symbols_target) { | |
| 101 if (defined(invoker.testonly)) { | |
| 102 testonly = invoker.testonly | |
| 103 } | |
| 104 visibility = [ ":${final_target_name}" ] | |
| 105 deps = [ | |
| 106 ":${library_target_name}", | |
| 107 ] | |
| 108 | |
| 109 sources = [ | |
| 110 "${root_out_dir}/${library_name}", | |
| 111 ] | |
| 112 outputs = [ | |
| 113 "${root_out_dir}/symbols/${library_name}", | |
| 114 ] | |
| 115 } | |
| 116 | |
| 117 copy(final_target_name) { | |
| 118 forward_variables_from(invoker, | |
| 119 [ | |
| 120 "testonly", | |
| 121 "visibility", | |
| 122 ]) | |
| 123 | |
| 124 public_deps = [ | |
| 125 # We want to allow rules to depend on symbol libraries. | |
| 126 ":${copy_symbols_target}", | |
| 127 ] | |
| 128 | |
| 129 deps = [ | |
| 130 ":${library_target_name}", | |
| 131 ] | |
| 132 | |
| 133 sources = [ | |
| 134 "${library_dir}/${library_name}", | |
| 135 ] | |
| 136 outputs = [ | |
| 137 "${root_out_dir}/${output}", | |
| 138 ] | |
| 139 } | |
| 140 } else { | |
| 141 nexe_target_name = base_target_name + "_nexe" | |
| 142 executable_target_name = base_target_name + "_exe" | |
| 143 | |
| 144 executable(nexe_target_name) { | |
| 145 output_name = base_target_name | |
| 146 data_deps = [] | |
| 147 forward_variables_from(invoker, | |
| 148 [ | |
| 149 "cflags", | |
| 150 "cflags_c", | |
| 151 "cflags_cc", | |
| 152 "cflags_objc", | |
| 153 "cflags_objcc", | |
| 154 "defines", | |
| 155 "include_dirs", | |
| 156 "ldflags", | |
| 157 "lib_dirs", | |
| 158 "libs", | |
| 159 ]) | |
| 160 if (defined(invoker.data_deps)) { | |
| 161 data_deps += invoker.data_deps | |
| 162 } | |
| 163 | |
| 164 # Copy any necessary prebuilt artifacts. | |
| 165 if (mojo_use_prebuilt_mojo_shell) { | |
| 166 data_deps += | |
| 167 [ rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) ] | |
| 168 } | |
| 169 if (mojo_use_prebuilt_network_service) { | |
| 170 data_deps += [ rebase_path("mojo/public/tools:copy_network_service", | |
| 171 ".", | |
| 172 mojo_root) ] | |
| 173 } | |
| 174 | |
| 175 deps = rebase_path([ | |
| 176 "mojo/public/c:system", | |
| 177 "mojo/public/platform/nacl:system", | |
| 178 ], | |
| 179 ".", | |
| 180 mojo_root) | |
| 181 if (defined(invoker.deps)) { | |
| 182 deps += invoker.deps | |
| 183 } | |
| 184 if (defined(invoker.configs)) { | |
| 185 configs += invoker.configs | |
| 186 } | |
| 187 | |
| 188 forward_variables_from(invoker, | |
| 189 [ | |
| 190 "forward_dependent_configs_from", | |
| 191 "public_deps", | |
| 192 "all_dependent_configs", | |
| 193 "public_configs", | |
| 194 "check_includes", | |
| 195 "data", | |
| 196 "inputs", | |
| 197 "public", | |
| 198 "sources", | |
| 199 "testonly", | |
| 200 ]) | |
| 201 | |
| 202 visibility = [ ":*" ] | |
| 203 } | |
| 204 | |
| 205 group(target_name) { | |
| 206 # This group specifies two targets: first, it requests that the | |
| 207 # pexe be built, and secondly (if the toolchain is not requesting | |
| 208 # a pexe implicitly), it creates a nexe. | |
| 209 forward_variables_from(invoker, [ "testonly" ]) | |
| 210 deps = [ | |
| 211 ":${executable_target_name}(//build/toolchain/nacl:newlib_pnacl)", | |
| 212 ] | |
| 213 if (current_cpu != "pnacl") { | |
| 214 deps += [ ":${executable_target_name}" ] | |
| 215 } | |
| 216 } | |
| 217 | |
| 218 action(executable_target_name) { | |
| 219 if (current_cpu == "pnacl") { | |
| 220 input_file_extension = ".pexe" | |
| 221 output_file_extension = ".pexe.mojo" | |
| 222 content_handler = "content_handler_nonsfi_pexe" | |
| 223 } else { | |
| 224 input_file_extension = ".nexe" | |
| 225 output_file_extension = "_${target_cpu}.nexe.mojo" | |
| 226 content_handler = "content_handler_sfi_nexe" | |
| 227 } | |
| 228 input_file = "${base_target_name}${input_file_extension}" | |
| 229 output_file = "${base_target_name}${output_file_extension}" | |
| 230 | |
| 231 forward_variables_from(invoker, | |
| 232 [ | |
| 233 "testonly", | |
| 234 "visibility", | |
| 235 ]) | |
| 236 | |
| 237 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root) | |
| 238 | |
| 239 input_path = "${root_out_dir}/${input_file}" | |
| 240 inputs = [ | |
| 241 input_path, | |
| 242 ] | |
| 243 | |
| 244 output_path = "${root_build_dir}/${output_file}" | |
| 245 outputs = [ | |
| 246 output_path, | |
| 247 ] | |
| 248 | |
| 249 deps = [ | |
| 250 ":${nexe_target_name}", | |
| 251 ] | |
| 252 | |
| 253 rebase_input = rebase_path(input_path, root_build_dir) | |
| 254 rebase_output = rebase_path(output_path, root_build_dir) | |
| 255 args = [ | |
| 256 "--input=$rebase_input", | |
| 257 "--output=$rebase_output", | |
| 258 "--line=#!mojo mojo:$content_handler", | |
| 259 ] | |
| 260 } | |
| 261 } | |
| 262 } | |
| 263 | |
| 264 if (is_android) { | |
| 265 import("//build/config/android/rules.gni") | |
| 266 | |
| 267 # Declares an Android Mojo application consisting of an .so file and a | |
| 268 # corresponding .dex.jar file. | |
| 269 # | |
| 270 # Variables: | |
| 271 # sources (optional): The c++ sources. | |
| 272 # deps (optional): The c++ dependencies. | |
| 273 # java_sources (optional): The java sources. | |
| 274 # java_deps (optional): The java dependencies. | |
| 275 # jni_package (optional): The c++ package for the generated jni headers. | |
| 276 # output_name (optional): override for the output file name | |
| 277 # public_deps / data_deps (optional): Dependencies. | |
| 278 template("mojo_android_application") { | |
| 279 shared_library_name = "__${target_name}_lib" | |
| 280 library_basename = "lib${shared_library_name}.so" | |
| 281 if (defined(invoker.jni_package)) { | |
| 282 assert(defined(invoker.java_sources)) | |
| 283 generate_jni_name = "__${target_name}_jni" | |
| 284 } | |
| 285 if (defined(invoker.java_sources)) { | |
| 286 java_library_name = "__${target_name}_java" | |
| 287 } | |
| 288 android_standalone_library_name = "__${target_name}_java_lib" | |
| 289 dex_output_path = "${target_gen_dir}/${target_name}.dex.jar" | |
| 290 zip_action_name = "__${target_name}_zip" | |
| 291 zip_action_output = "${target_gen_dir}/${target_name}.zip" | |
| 292 copy_symbols_target = "__${target_name}_copy_symbols" | |
| 293 final_target_name = target_name | |
| 294 | |
| 295 if (defined(invoker.jni_package)) { | |
| 296 generate_jni(generate_jni_name) { | |
| 297 visibility = [ ":${shared_library_name}" ] | |
| 298 | |
| 299 sources = invoker.java_sources | |
| 300 jni_package = invoker.jni_package | |
| 301 } | |
| 302 } | |
| 303 | |
| 304 shared_library(shared_library_name) { | |
| 305 visibility = [ | |
| 306 ":${copy_symbols_target}", | |
| 307 ":${zip_action_name}", | |
| 308 ] | |
| 309 | |
| 310 if (defined(invoker.sources)) { | |
| 311 sources = invoker.sources | |
| 312 } | |
| 313 | |
| 314 deps = rebase_path([ "mojo/public/platform/native:system_thunks" ], | |
| 315 ".", | |
| 316 mojo_root) | |
| 317 if (defined(invoker.jni_package)) { | |
| 318 deps += [ ":${generate_jni_name}" ] | |
| 319 } | |
| 320 if (defined(invoker.deps)) { | |
| 321 deps += invoker.deps | |
| 322 } | |
| 323 } | |
| 324 | |
| 325 copy(copy_symbols_target) { | |
| 326 visibility = [ ":${final_target_name}" ] | |
| 327 deps = [ | |
| 328 ":${shared_library_name}", | |
| 329 ] | |
| 330 | |
| 331 sources = [ | |
| 332 "${root_out_dir}/${library_basename}", | |
| 333 ] | |
| 334 outputs = [ | |
| 335 "${root_out_dir}/symbols/${library_basename}", | |
| 336 ] | |
| 337 } | |
| 338 | |
| 339 if (defined(invoker.java_sources)) { | |
| 340 android_library(java_library_name) { | |
| 341 visibility = [ ":*" ] | |
| 342 | |
| 343 java_files = invoker.java_sources | |
| 344 | |
| 345 if (defined(invoker.java_deps)) { | |
| 346 deps = invoker.java_deps | |
| 347 } | |
| 348 } | |
| 349 } | |
| 350 | |
| 351 android_standalone_library(android_standalone_library_name) { | |
| 352 deps = [] | |
| 353 | |
| 354 if (defined(invoker.java_sources)) { | |
| 355 deps += [ ":${java_library_name}" ] | |
| 356 } | |
| 357 | |
| 358 if (defined(invoker.java_deps)) { | |
| 359 deps += invoker.java_deps | |
| 360 } | |
| 361 | |
| 362 dex_path = dex_output_path | |
| 363 } | |
| 364 | |
| 365 action(zip_action_name) { | |
| 366 visibility = [ ":${final_target_name}" ] | |
| 367 script = "//build/android/gn/zip.py" | |
| 368 | |
| 369 inputs = [ | |
| 370 "${root_out_dir}/lib.stripped/${library_basename}", | |
| 371 dex_output_path, | |
| 372 ] | |
| 373 | |
| 374 output = zip_action_output | |
| 375 outputs = [ | |
| 376 output, | |
| 377 ] | |
| 378 | |
| 379 rebase_inputs = rebase_path(inputs, root_build_dir) | |
| 380 rebase_output = rebase_path(output, root_build_dir) | |
| 381 args = [ | |
| 382 "--inputs=${rebase_inputs}", | |
| 383 "--output=${rebase_output}", | |
| 384 ] | |
| 385 | |
| 386 deps = [ | |
| 387 ":${android_standalone_library_name}", | |
| 388 ":${shared_library_name}", | |
| 389 ] | |
| 390 | |
| 391 if (defined(invoker.deps)) { | |
| 392 deps += invoker.deps | |
| 393 } | |
| 394 if (defined(invoker.public_deps)) { | |
| 395 public_deps = invoker.public_deps | |
| 396 } | |
| 397 if (defined(invoker.data_deps)) { | |
| 398 data_deps = invoker.data_deps | |
| 399 } | |
| 400 } | |
| 401 | |
| 402 if (defined(invoker.output_name)) { | |
| 403 mojo_output = "${root_out_dir}/" + invoker.output_name + ".mojo" | |
| 404 } else { | |
| 405 mojo_output = "${root_out_dir}/" + target_name + ".mojo" | |
| 406 } | |
| 407 | |
| 408 action(final_target_name) { | |
| 409 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root) | |
| 410 | |
| 411 input = zip_action_output | |
| 412 inputs = [ | |
| 413 input, | |
| 414 ] | |
| 415 | |
| 416 output = mojo_output | |
| 417 outputs = [ | |
| 418 output, | |
| 419 ] | |
| 420 | |
| 421 rebase_input = rebase_path(input, root_build_dir) | |
| 422 rebase_output = rebase_path(output, root_build_dir) | |
| 423 args = [ | |
| 424 "--input=${rebase_input}", | |
| 425 "--output=${rebase_output}", | |
| 426 "--line=#!mojo mojo:android_handler", | |
| 427 ] | |
| 428 | |
| 429 deps = [ | |
| 430 ":${copy_symbols_target}", | |
| 431 ] | |
| 432 | |
| 433 public_deps = [ | |
| 434 ":${zip_action_name}", | |
| 435 ] | |
| 436 } | |
| 437 } | |
| 438 } | |
| OLD | NEW |