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 # 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 |
10 # set. | 10 # set. |
11 # Variable: | |
12 # use_raw_android_executable: Use executable() rather than android_apk(). | |
13 template("test") { | 11 template("test") { |
14 if (is_android) { | 12 if (is_android) { |
15 import("//build/config/android/config.gni") | 13 import("//build/config/android/config.gni") |
16 import("//build/config/android/rules.gni") | 14 import("//build/config/android/rules.gni") |
17 | 15 |
18 _use_raw_android_executable = defined(invoker.use_raw_android_executable) && | 16 _library_target = "_${target_name}__library" |
19 invoker.use_raw_android_executable | 17 _apk_target = "${target_name}_apk" |
| 18 |
| 19 shared_library(_library_target) { |
| 20 # Configs will always be defined since we set_defaults for a component |
| 21 # in the main config. We want to use those rather than whatever came with |
| 22 # the nested shared/static library inside the component. |
| 23 configs = [] # Prevent list overwriting warning. |
| 24 configs = invoker.configs |
| 25 |
| 26 testonly = true |
| 27 |
| 28 # Don't use "*" to forward all variables since some (like output_name |
| 29 # and isolate_file) apply only to the APK below. |
| 30 deps = [] |
| 31 forward_variables_from(invoker, |
| 32 [ |
| 33 "all_dependent_configs", |
| 34 "allow_circular_includes_from", |
| 35 "cflags", |
| 36 "cflags_c", |
| 37 "cflags_cc", |
| 38 "check_includes", |
| 39 "data", |
| 40 "data_deps", |
| 41 "datadeps", |
| 42 "defines", |
| 43 "deps", |
| 44 "include_dirs", |
| 45 "ldflags", |
| 46 "lib_dirs", |
| 47 "libs", |
| 48 "output_extension", |
| 49 "output_name", |
| 50 "public", |
| 51 "public_configs", |
| 52 "public_deps", |
| 53 "sources", |
| 54 "visibility", |
| 55 ]) |
| 56 |
| 57 if (!defined(invoker.use_default_launcher) || |
| 58 invoker.use_default_launcher) { |
| 59 deps += [ "//testing/android/native_test:native_test_native_code" ] |
| 60 } |
| 61 } |
| 62 |
| 63 unittest_apk(_apk_target) { |
| 64 forward_variables_from(invoker, |
| 65 [ |
| 66 "android_manifest", |
| 67 "deps", |
| 68 "enable_multidex", |
| 69 "use_default_launcher", |
| 70 "write_asset_list", |
| 71 ]) |
| 72 unittests_dep = ":$_library_target" |
| 73 apk_name = invoker.target_name |
| 74 if (defined(invoker.output_name)) { |
| 75 apk_name = invoker.output_name |
| 76 unittests_binary = "lib${apk_name}.so" |
| 77 install_script_name = "install_${invoker.output_name}" |
| 78 } |
| 79 deps += [ ":$_library_target" ] |
| 80 } |
20 | 81 |
21 # output_name is used to allow targets with the same name but in different | 82 # output_name is used to allow targets with the same name but in different |
22 # packages to still produce unique runner scripts. | 83 # packages to still produce unique runner scripts. |
23 _output_name = invoker.target_name | 84 _output_name = invoker.target_name |
24 if (defined(invoker.output_name)) { | 85 if (defined(invoker.output_name)) { |
25 _output_name = invoker.output_name | 86 _output_name = invoker.output_name |
26 } | 87 } |
27 | |
28 if (_use_raw_android_executable) { | |
29 _exec_target = "${target_name}__exec" | |
30 _dist_target = "${target_name}__dist" | |
31 _exec_output = | |
32 "$target_out_dir/${invoker.target_name}/${invoker.target_name}" | |
33 | |
34 executable(_exec_target) { | |
35 data_deps = [] | |
36 forward_variables_from(invoker, "*") | |
37 testonly = true | |
38 | |
39 # Don't output to the root or else conflict with the group() below. | |
40 output_name = rebase_path(_exec_output, root_out_dir) | |
41 if (is_component_build || is_asan) { | |
42 data_deps += [ "//build/android:cpplib_stripped" ] | |
43 } | |
44 } | |
45 | |
46 # TODO(agrieve): This is required for component builds, but it's not | |
47 # currently used by test_runner.py (and so doesn't work in component | |
48 # builds). | |
49 create_native_executable_dist(_dist_target) { | |
50 testonly = true | |
51 include_main_binary = true | |
52 dist_dir = "$root_out_dir/$target_name" | |
53 binary = _exec_output | |
54 deps = [ | |
55 ":$_exec_target", | |
56 ] | |
57 } | |
58 } else { | |
59 _library_target = "_${target_name}__library" | |
60 _apk_target = "${target_name}_apk" | |
61 _apk_specific_vars = [ | |
62 "android_manifest", | |
63 "enable_multidex", | |
64 "use_default_launcher", | |
65 "write_asset_list", | |
66 ] | |
67 shared_library(_library_target) { | |
68 # Configs will always be defined since we set_defaults for a component | |
69 # in the main config. We want to use those rather than whatever came | |
70 # with the nested shared/static library inside the component. | |
71 configs = [] # Prevent list overwriting warning. | |
72 configs = invoker.configs | |
73 testonly = true | |
74 | |
75 deps = [] | |
76 forward_variables_from(invoker, | |
77 "*", | |
78 _apk_specific_vars + [ | |
79 "isolate_file", | |
80 "visibility", | |
81 ]) | |
82 | |
83 if (!defined(invoker.use_default_launcher) || | |
84 invoker.use_default_launcher) { | |
85 deps += [ "//testing/android/native_test:native_test_native_code" ] | |
86 } | |
87 } | |
88 unittest_apk(_apk_target) { | |
89 forward_variables_from(invoker, _apk_specific_vars + [ "deps" ]) | |
90 unittests_dep = ":$_library_target" | |
91 apk_name = invoker.target_name | |
92 if (defined(invoker.output_name)) { | |
93 apk_name = invoker.output_name | |
94 unittests_binary = "lib${apk_name}.so" | |
95 install_script_name = "install_${invoker.output_name}" | |
96 } | |
97 deps += [ ":$_library_target" ] | |
98 } | |
99 | |
100 # Incremental test targets work only for .apks. | |
101 _incremental_test_runner_target = | |
102 "${_output_name}_incremental__test_runner_script" | |
103 test_runner_script(_incremental_test_runner_target) { | |
104 forward_variables_from(invoker, [ "isolate_file" ]) | |
105 apk_target = ":$_apk_target" | |
106 test_name = "${_output_name}_incremental" | |
107 test_type = "gtest" | |
108 test_suite = _output_name | |
109 incremental_install = true | |
110 } | |
111 group("${target_name}_incremental") { | |
112 testonly = true | |
113 datadeps = [ | |
114 ":$_incremental_test_runner_target", | |
115 ] | |
116 deps = [ | |
117 ":${_apk_target}_incremental", | |
118 ] | |
119 } | |
120 } | |
121 | |
122 _test_runner_target = "${_output_name}__test_runner_script" | 88 _test_runner_target = "${_output_name}__test_runner_script" |
123 test_runner_script(_test_runner_target) { | 89 test_runner_script(_test_runner_target) { |
124 forward_variables_from(invoker, [ "isolate_file" ]) | 90 apk_target = ":$_apk_target" |
125 if (_use_raw_android_executable) { | |
126 executable = "$root_out_dir/$_dist_target/${invoker.target_name}" | |
127 } else { | |
128 apk_target = ":$_apk_target" | |
129 } | |
130 test_name = _output_name | 91 test_name = _output_name |
131 test_type = "gtest" | 92 test_type = "gtest" |
132 test_suite = _output_name | 93 test_suite = _output_name |
| 94 if (defined(invoker.isolate_file)) { |
| 95 isolate_file = invoker.isolate_file |
| 96 } |
| 97 } |
| 98 _incremental_test_runner_target = |
| 99 "${_output_name}_incremental__test_runner_script" |
| 100 test_runner_script(_incremental_test_runner_target) { |
| 101 apk_target = ":$_apk_target" |
| 102 test_name = "${_output_name}_incremental" |
| 103 test_type = "gtest" |
| 104 test_suite = _output_name |
| 105 incremental_install = true |
| 106 if (defined(invoker.isolate_file)) { |
| 107 isolate_file = invoker.isolate_file |
| 108 } |
133 } | 109 } |
134 | 110 |
135 group(target_name) { | 111 group(target_name) { |
136 testonly = true | 112 testonly = true |
137 deps = [ | 113 datadeps = [ |
138 ":$_test_runner_target", | 114 ":$_test_runner_target", |
139 ] | 115 ] |
140 if (_use_raw_android_executable) { | 116 deps = [ |
141 deps += [ ":$_dist_target" ] | 117 ":$_apk_target", |
142 } else { | 118 ] |
143 deps += [ ":$_apk_target" ] | 119 } |
144 } | 120 group("${target_name}_incremental") { |
| 121 testonly = true |
| 122 datadeps = [ |
| 123 ":$_incremental_test_runner_target", |
| 124 ] |
| 125 deps = [ |
| 126 ":${_apk_target}_incremental", |
| 127 ] |
145 } | 128 } |
146 | 129 |
147 # TODO(GYP): Delete this after we've converted everything to GN. | 130 # TODO(GYP): Delete this after we've converted everything to GN. |
148 # The _run targets exist only for compatibility w/ GYP. | 131 # The _run targets exist only for compatibility w/ GYP. |
149 group("${target_name}_apk_run") { | 132 group("${target_name}_apk_run") { |
150 testonly = true | 133 testonly = true |
151 deps = [ | 134 deps = [ |
152 ":${invoker.target_name}", | 135 ":${invoker.target_name}", |
153 ] | 136 ] |
154 } | 137 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 # TODO(GYP): Delete this after we've converted everything to GN. | 199 # TODO(GYP): Delete this after we've converted everything to GN. |
217 # The _run targets exist only for compatibility with GYP. | 200 # The _run targets exist only for compatibility with GYP. |
218 group("${target_name}_run") { | 201 group("${target_name}_run") { |
219 testonly = true | 202 testonly = true |
220 deps = [ | 203 deps = [ |
221 ":${invoker.target_name}", | 204 ":${invoker.target_name}", |
222 ] | 205 ] |
223 } | 206 } |
224 } | 207 } |
225 } | 208 } |
OLD | NEW |