| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 # ============================================================================== | 5 # ============================================================================== |
| 6 # TEST SETUP | 6 # TEST SETUP |
| 7 # ============================================================================== | 7 # ============================================================================== |
| 8 | 8 |
| 9 template("_gen_isolate") { | |
| 10 testonly = true | |
| 11 _runtime_deps_file = "$target_gen_dir/$target_name.runtime_deps" | |
| 12 group("${target_name}__write_deps") { | |
| 13 forward_variables_from(invoker, | |
| 14 [ | |
| 15 "data", | |
| 16 "data_deps", | |
| 17 "deps", | |
| 18 "public_deps", | |
| 19 ]) | |
| 20 write_runtime_deps = _runtime_deps_file | |
| 21 } | |
| 22 | |
| 23 action(target_name) { | |
| 24 script = "//testing/generate_isolate.py" | |
| 25 inputs = [ | |
| 26 _runtime_deps_file, | |
| 27 ] | |
| 28 outputs = [ | |
| 29 invoker.output, | |
| 30 ] | |
| 31 args = [ | |
| 32 "--output-directory=.", | |
| 33 "--out-file", | |
| 34 rebase_path(invoker.output, root_build_dir), | |
| 35 "--runtime-deps-file", | |
| 36 rebase_path(_runtime_deps_file, root_build_dir), | |
| 37 ] | |
| 38 if (is_android) { | |
| 39 args += [ "--apply-android-filters" ] | |
| 40 } | |
| 41 if (defined(invoker.apply_device_filters) && invoker.apply_device_filters) { | |
| 42 args += [ "--apply-device-filters" ] | |
| 43 } | |
| 44 _assert_no_odd_data = | |
| 45 defined(invoker.assert_no_odd_data) && invoker.assert_no_odd_data | |
| 46 if (_assert_no_odd_data) { | |
| 47 args += [ "--assert-no-odd-data" ] | |
| 48 } | |
| 49 if (defined(invoker.command)) { | |
| 50 _isolate_dir = get_path_info(invoker.output, "dir") | |
| 51 args += [ | |
| 52 "--command", | |
| 53 rebase_path(invoker.command, _isolate_dir), | |
| 54 ] | |
| 55 } | |
| 56 deps = [ | |
| 57 ":${invoker.target_name}__write_deps", | |
| 58 ] | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 # Define a test as an executable (or apk on Android) with the "testonly" flag | 9 # Define a test as an executable (or apk on Android) with the "testonly" flag |
| 63 # set. | 10 # set. |
| 64 # Variable: | 11 # Variable: |
| 65 # use_raw_android_executable: Use executable() rather than android_apk(). | 12 # use_raw_android_executable: Use executable() rather than android_apk(). |
| 66 # use_native_activity: Test implements ANativeActivity_onCreate(). | 13 # use_native_activity: Test implements ANativeActivity_onCreate(). |
| 67 template("test") { | 14 template("test") { |
| 68 if (is_android) { | 15 if (is_android) { |
| 69 import("//build/config/android/config.gni") | 16 import("//build/config/android/config.gni") |
| 70 import("//build/config/android/rules.gni") | 17 import("//build/config/android/rules.gni") |
| 71 import("//build/config/sanitizers/sanitizers.gni") | 18 import("//build/config/sanitizers/sanitizers.gni") |
| 72 | 19 |
| 73 _use_raw_android_executable = defined(invoker.use_raw_android_executable) && | 20 _use_raw_android_executable = defined(invoker.use_raw_android_executable) && |
| 74 invoker.use_raw_android_executable | 21 invoker.use_raw_android_executable |
| 75 | 22 |
| 76 # output_name is used to allow targets with the same name but in different | 23 # output_name is used to allow targets with the same name but in different |
| 77 # packages to still produce unique runner scripts. | 24 # packages to still produce unique runner scripts. |
| 78 _output_name = invoker.target_name | 25 _output_name = invoker.target_name |
| 79 if (defined(invoker.output_name)) { | 26 if (defined(invoker.output_name)) { |
| 80 _output_name = invoker.output_name | 27 _output_name = invoker.output_name |
| 81 } | 28 } |
| 82 | 29 |
| 83 _test_runner_target = "${_output_name}__test_runner_script" | 30 _test_runner_target = "${_output_name}__test_runner_script" |
| 84 _wrapper_script_vars = [ "shard_timeout" ] | 31 _wrapper_script_vars = [ |
| 85 _gen_isolate_vars = [ | |
| 86 "allow_odd_runtime_deps", | |
| 87 "ignore_all_data_deps", | 32 "ignore_all_data_deps", |
| 33 "shard_timeout", |
| 88 ] | 34 ] |
| 89 _generate_device_isolate = | |
| 90 !defined(invoker.ignore_all_data_deps) || !invoker.ignore_all_data_deps | |
| 91 | |
| 92 if (_generate_device_isolate) { | |
| 93 _allow_odd_runtime_deps = defined(invoker.allow_odd_runtime_deps) && | |
| 94 invoker.allow_odd_runtime_deps | |
| 95 | |
| 96 # The device isolate is needed at runtime, so it cannot go in | |
| 97 # target_gen_dir, as builder/tester configurations do not include it. | |
| 98 _target_dir_name = get_label_info(":$target_name", "dir") | |
| 99 _device_isolate_path = "$root_out_dir/gen.runtime/$_target_dir_name/$targe
t_name.device.isolate" | |
| 100 _gen_isolate_target_name = "${target_name}__isolate" | |
| 101 _gen_isolate(_gen_isolate_target_name) { | |
| 102 forward_variables_from(invoker, | |
| 103 [ | |
| 104 "data", | |
| 105 "data_deps", | |
| 106 "deps", | |
| 107 "public_deps", | |
| 108 ]) | |
| 109 assert_no_odd_data = !_allow_odd_runtime_deps | |
| 110 output = _device_isolate_path | |
| 111 apply_device_filters = true | |
| 112 } | |
| 113 } | |
| 114 | 35 |
| 115 assert(_use_raw_android_executable || enable_java_templates) | 36 assert(_use_raw_android_executable || enable_java_templates) |
| 116 | 37 |
| 117 if (_use_raw_android_executable) { | 38 if (_use_raw_android_executable) { |
| 118 _exec_target = "${target_name}__exec" | 39 _exec_target = "${target_name}__exec" |
| 119 _dist_target = "${target_name}__dist" | 40 _dist_target = "${target_name}__dist" |
| 120 _exec_output = | 41 _exec_output = |
| 121 "$target_out_dir/${invoker.target_name}/${invoker.target_name}" | 42 "$target_out_dir/${invoker.target_name}/${invoker.target_name}" |
| 122 | 43 |
| 123 executable(_exec_target) { | 44 executable(_exec_target) { |
| 124 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn
. | 45 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn
. |
| 125 configs = [] | 46 configs = [] |
| 126 data_deps = [] | 47 data_deps = [] |
| 127 forward_variables_from( | 48 forward_variables_from(invoker, |
| 128 invoker, | 49 "*", |
| 129 "*", | 50 _wrapper_script_vars + [ "extra_dist_files" ]) |
| 130 _wrapper_script_vars + _gen_isolate_vars + [ "extra_dist_files" ]) | |
| 131 testonly = true | 51 testonly = true |
| 132 | 52 |
| 133 # Thanks to the set_defaults() for test(), configs are initialized with | 53 # Thanks to the set_defaults() for test(), configs are initialized with |
| 134 # the default shared_library configs rather than executable configs. | 54 # the default shared_library configs rather than executable configs. |
| 135 configs -= [ | 55 configs -= [ |
| 136 "//build/config:shared_library_config", | 56 "//build/config:shared_library_config", |
| 137 "//build/config/android:hide_native_jni_exports", | 57 "//build/config/android:hide_native_jni_exports", |
| 138 ] | 58 ] |
| 139 configs += [ "//build/config:executable_config" ] | 59 configs += [ "//build/config:executable_config" ] |
| 140 | 60 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 154 ] | 74 ] |
| 155 if (defined(invoker.extra_dist_files)) { | 75 if (defined(invoker.extra_dist_files)) { |
| 156 extra_files = invoker.extra_dist_files | 76 extra_files = invoker.extra_dist_files |
| 157 } | 77 } |
| 158 } | 78 } |
| 159 } else { | 79 } else { |
| 160 _library_target = "_${target_name}__library" | 80 _library_target = "_${target_name}__library" |
| 161 _apk_target = "${target_name}_apk" | 81 _apk_target = "${target_name}_apk" |
| 162 _apk_specific_vars = [ | 82 _apk_specific_vars = [ |
| 163 "android_manifest", | 83 "android_manifest", |
| 84 "android_manifest_dep", |
| 164 "enable_multidex", | 85 "enable_multidex", |
| 165 "proguard_configs", | 86 "proguard_configs", |
| 166 "proguard_enabled", | 87 "proguard_enabled", |
| 167 "use_default_launcher", | 88 "use_default_launcher", |
| 168 "write_asset_list", | 89 "write_asset_list", |
| 169 "use_native_activity", | 90 "use_native_activity", |
| 170 ] | 91 ] |
| 171 shared_library(_library_target) { | 92 shared_library(_library_target) { |
| 172 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn
. | 93 # Configs will always be defined since we set_defaults in BUILDCONFIG.gn
. |
| 173 configs = [] # Prevent list overwriting warning. | 94 configs = [] # Prevent list overwriting warning. |
| 174 configs = invoker.configs | 95 configs = invoker.configs |
| 175 testonly = true | 96 testonly = true |
| 176 | 97 |
| 177 deps = [] | 98 deps = [] |
| 178 forward_variables_from(invoker, | 99 forward_variables_from( |
| 179 "*", | 100 invoker, |
| 180 _apk_specific_vars + _wrapper_script_vars + | 101 "*", |
| 181 _gen_isolate_vars + [ "visibility" ]) | 102 _apk_specific_vars + _wrapper_script_vars + [ "visibility" ]) |
| 182 | 103 |
| 183 if (!defined(invoker.use_default_launcher) || | 104 if (!defined(invoker.use_default_launcher) || |
| 184 invoker.use_default_launcher) { | 105 invoker.use_default_launcher) { |
| 185 deps += [ "//testing/android/native_test:native_test_native_code" ] | 106 deps += [ "//testing/android/native_test:native_test_native_code" ] |
| 186 } | 107 } |
| 187 } | 108 } |
| 188 unittest_apk(_apk_target) { | 109 unittest_apk(_apk_target) { |
| 189 forward_variables_from(invoker, _apk_specific_vars + [ "deps" ]) | 110 forward_variables_from(invoker, _apk_specific_vars + [ "deps" ]) |
| 190 unittests_dep = ":$_library_target" | 111 shared_library = ":$_library_target" |
| 191 apk_name = invoker.target_name | 112 apk_name = invoker.target_name |
| 192 if (defined(invoker.output_name)) { | 113 if (defined(invoker.output_name)) { |
| 193 apk_name = invoker.output_name | 114 apk_name = invoker.output_name |
| 194 unittests_binary = "lib${apk_name}.so" | |
| 195 install_script_name = "install_${invoker.output_name}" | 115 install_script_name = "install_${invoker.output_name}" |
| 196 } | 116 } |
| 197 deps += [ ":$_library_target" ] | |
| 198 | 117 |
| 199 # TODO(agrieve): Remove this data_dep once bots don't build the _apk | 118 # TODO(agrieve): Remove this data_dep once bots don't build the _apk |
| 200 # target (post-GYP). | 119 # target (post-GYP). |
| 201 # It's a bit backwards for the apk to depend on the runner script, since | 120 # It's a bit backwards for the apk to depend on the runner script, since |
| 202 # the apk is conceptually a runtime_dep of the script. However, it is | 121 # the apk is conceptually a runtime_dep of the script. However, it is |
| 203 # currently necessary because the bots build this _apk target directly | 122 # currently necessary because the bots build this _apk target directly |
| 204 # rather than the group() below. | 123 # rather than the group() below. |
| 205 data_deps = [ | 124 data_deps = [ |
| 206 ":$_test_runner_target", | 125 ":$_test_runner_target", |
| 207 ] | 126 ] |
| 208 } | 127 } |
| 209 | 128 |
| 210 # Incremental test targets work only for .apks. | 129 # Incremental test targets work only for .apks. |
| 211 _incremental_test_runner_target = | 130 _incremental_test_runner_target = |
| 212 "${_output_name}_incremental__test_runner_script" | 131 "${_output_name}_incremental__test_runner_script" |
| 213 test_runner_script(_incremental_test_runner_target) { | 132 test_runner_script(_incremental_test_runner_target) { |
| 214 forward_variables_from(invoker, _wrapper_script_vars) | 133 forward_variables_from(invoker, |
| 215 if (_generate_device_isolate) { | 134 _wrapper_script_vars + [ |
| 216 isolate_file = _device_isolate_path | 135 "data", |
| 217 deps = [ | 136 "data_deps", |
| 218 ":$_gen_isolate_target_name", | 137 "deps", |
| 219 ] | 138 "public_deps", |
| 220 } | 139 ]) |
| 221 apk_target = ":$_apk_target" | 140 apk_target = ":$_apk_target" |
| 222 test_name = "${_output_name}_incremental" | 141 test_name = "${_output_name}_incremental" |
| 223 test_type = "gtest" | 142 test_type = "gtest" |
| 224 test_suite = _output_name | 143 test_suite = _output_name |
| 225 incremental_install = true | 144 incremental_install = true |
| 226 } | 145 } |
| 227 group("${target_name}_incremental") { | 146 group("${target_name}_incremental") { |
| 228 testonly = true | 147 testonly = true |
| 229 datadeps = [ | 148 datadeps = [ |
| 230 ":$_incremental_test_runner_target", | 149 ":$_incremental_test_runner_target", |
| 231 ] | 150 ] |
| 232 deps = [ | 151 deps = [ |
| 233 ":${_apk_target}_incremental", | 152 ":${_apk_target}_incremental", |
| 234 ] | 153 ] |
| 235 } | 154 } |
| 236 } | 155 } |
| 237 | 156 |
| 238 _test_runner_target = "${_output_name}__test_runner_script" | 157 _test_runner_target = "${_output_name}__test_runner_script" |
| 239 test_runner_script(_test_runner_target) { | 158 test_runner_script(_test_runner_target) { |
| 240 forward_variables_from(invoker, _wrapper_script_vars) | 159 forward_variables_from(invoker, |
| 241 if (_generate_device_isolate) { | 160 _wrapper_script_vars + [ |
| 242 isolate_file = _device_isolate_path | 161 "data", |
| 243 deps = [ | 162 "data_deps", |
| 244 ":$_gen_isolate_target_name", | 163 "deps", |
| 245 ] | 164 "public_deps", |
| 246 } | 165 ]) |
| 247 | 166 |
| 248 if (_use_raw_android_executable) { | 167 if (_use_raw_android_executable) { |
| 249 executable_dist_dir = "$root_out_dir/$_dist_target" | 168 executable_dist_dir = "$root_out_dir/$_dist_target" |
| 250 } else { | 169 } else { |
| 251 apk_target = ":$_apk_target" | 170 apk_target = ":$_apk_target" |
| 252 } | 171 } |
| 253 test_name = _output_name | 172 test_name = _output_name |
| 254 test_type = "gtest" | 173 test_type = "gtest" |
| 255 test_suite = _output_name | 174 test_suite = _output_name |
| 256 } | 175 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 275 ":${invoker.target_name}", | 194 ":${invoker.target_name}", |
| 276 ] | 195 ] |
| 277 } | 196 } |
| 278 } else if (is_ios) { | 197 } else if (is_ios) { |
| 279 import("//build/config/ios/rules.gni") | 198 import("//build/config/ios/rules.gni") |
| 280 | 199 |
| 281 _test_target = target_name | 200 _test_target = target_name |
| 282 _resources_bundle_data = target_name + "_resources_bundle_data" | 201 _resources_bundle_data = target_name + "_resources_bundle_data" |
| 283 | 202 |
| 284 bundle_data(_resources_bundle_data) { | 203 bundle_data(_resources_bundle_data) { |
| 285 visibility = [ | 204 visibility = [ ":$_test_target" ] |
| 286 ":${_test_target}", | |
| 287 ":${_test_target}_generate_executable", | |
| 288 ] | |
| 289 sources = [ | 205 sources = [ |
| 290 "//testing/gtest_ios/Default.png", | 206 "//testing/gtest_ios/Default.png", |
| 291 ] | 207 ] |
| 292 outputs = [ | 208 outputs = [ |
| 293 "{{bundle_resources_dir}}/{{source_file_part}}", | 209 "{{bundle_resources_dir}}/{{source_file_part}}", |
| 294 ] | 210 ] |
| 295 } | 211 } |
| 296 | 212 |
| 297 ios_app_bundle(_test_target) { | 213 ios_app_bundle(_test_target) { |
| 298 testonly = true | 214 testonly = true |
| 299 | 215 |
| 300 # See above call. | 216 # See above call. |
| 301 set_sources_assignment_filter([]) | 217 set_sources_assignment_filter([]) |
| 302 forward_variables_from(invoker, "*", [ "testonly" ]) | 218 forward_variables_from(invoker, "*", [ "testonly" ]) |
| 303 | 219 |
| 304 # Provide sensible defaults in case invoker did not define any of those | 220 # Provide sensible defaults in case invoker did not define any of those |
| 305 # required variables. | 221 # required variables. |
| 306 if (!defined(info_plist) && !defined(info_plist_target)) { | 222 if (!defined(info_plist) && !defined(info_plist_target)) { |
| 307 info_plist = "//testing/gtest_ios/unittest-Info.plist" | 223 info_plist = "//testing/gtest_ios/unittest-Info.plist" |
| 308 } | 224 } |
| 309 if (!defined(entitlements_path)) { | 225 |
| 310 entitlements_path = "//testing/gtest_ios" | 226 _bundle_id_suffix = target_name |
| 227 if (ios_automatically_manage_certs) { |
| 228 # Use the same bundle identifier for all unit tests when managing |
| 229 # certificates automatically as the number of free certs is limited. |
| 230 _bundle_id_suffix = "generic-unit-test" |
| 311 } | 231 } |
| 312 if (!defined(code_signing_identity)) { | |
| 313 code_signing_identity = "" | |
| 314 } | |
| 315 | |
| 316 # TODO(crbug.com/603102): remove this once gyp support is dropped and all | |
| 317 # application uses the target name as value for BUNDLE_ID_TEST_NAME. | |
| 318 if (defined(invoker.app_name)) { | |
| 319 app_name = invoker.app_name | |
| 320 } else { | |
| 321 app_name = target_name | |
| 322 } | |
| 323 | |
| 324 if (!defined(extra_substitutions)) { | 232 if (!defined(extra_substitutions)) { |
| 325 extra_substitutions = [] | 233 extra_substitutions = [] |
| 326 } | 234 } |
| 327 extra_substitutions += [ "BUNDLE_ID_TEST_NAME=$app_name" ] | 235 extra_substitutions += [ "GTEST_BUNDLE_ID_SUFFIX=$_bundle_id_suffix" ] |
| 328 | 236 |
| 329 if (!defined(deps)) { | 237 if (!defined(deps)) { |
| 330 deps = [] | 238 deps = [] |
| 331 } | 239 } |
| 332 deps += [ | 240 deps += [ |
| 333 ":$_resources_bundle_data", | |
| 334 | |
| 335 # All shared libraries must have the sanitizer deps to properly link in | 241 # All shared libraries must have the sanitizer deps to properly link in |
| 336 # asan mode (this target will be empty in other cases). | 242 # asan mode (this target will be empty in other cases). |
| 337 "//build/config/sanitizers:deps", | 243 "//build/config/sanitizers:deps", |
| 338 ] | 244 ] |
| 245 if (!defined(bundle_deps)) { |
| 246 bundle_deps = [] |
| 247 } |
| 248 bundle_deps += [ ":$_resources_bundle_data" ] |
| 339 } | 249 } |
| 340 } else { | 250 } else { |
| 341 executable(target_name) { | 251 executable(target_name) { |
| 342 deps = [] | 252 deps = [] |
| 343 forward_variables_from(invoker, "*") | 253 forward_variables_from(invoker, "*") |
| 344 | 254 |
| 345 testonly = true | 255 testonly = true |
| 346 deps += [ | 256 deps += [ |
| 347 # All shared libraries must have the sanitizer deps to properly link in | 257 # All shared libraries must have the sanitizer deps to properly link in |
| 348 # asan mode (this target will be empty in other cases). | 258 # asan mode (this target will be empty in other cases). |
| (...skipping 25 matching lines...) Expand all Loading... |
| 374 } | 284 } |
| 375 | 285 |
| 376 # Test defaults. | 286 # Test defaults. |
| 377 set_defaults("test") { | 287 set_defaults("test") { |
| 378 if (is_android) { | 288 if (is_android) { |
| 379 configs = default_shared_library_configs | 289 configs = default_shared_library_configs |
| 380 } else { | 290 } else { |
| 381 configs = default_executable_configs | 291 configs = default_executable_configs |
| 382 } | 292 } |
| 383 } | 293 } |
| OLD | NEW |