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
3 # found in the LICENSE file.
5 # ==============================================================================
7 # ==============================================================================
9 # Define a test as an executable (or apk on Android) with the "testonly" flag
13 import("//build/config/android/config.gni")
14 import("//build/config/android/rules.gni")
16 main_target_name = target_name
17 library_name = "_${target_name}__library"
18 apk_name = "${target_name}_apk"
20 shared_library(library_name) {
21 # Configs will always be defined since we set_defaults for a component
22 # in the main config. We want to use those rather than whatever came with
23 # the nested shared/static library inside the component.
24 configs = [] # Prevent list overwriting warning.
25 configs = invoker.configs
28 set_sources_assignment_filter([])
32 if (defined(invoker.all_dependent_configs)) {
33 all_dependent_configs = invoker.all_dependent_configs
35 if (defined(invoker.allow_circular_includes_from)) {
36 allow_circular_includes_from = invoker.allow_circular_includes_from
38 if (defined(invoker.cflags)) {
39 cflags = invoker.cflags
41 if (defined(invoker.cflags_c)) {
42 cflags_c = invoker.cflags_c
44 if (defined(invoker.cflags_cc)) {
45 cflags_cc = invoker.cflags_cc
47 if (defined(invoker.cflags_objc)) {
48 cflags_objc = invoker.cflags_objc
50 if (defined(invoker.cflags_objcc)) {
51 cflags_objcc = invoker.cflags_objcc
53 if (defined(invoker.check_includes)) {
54 check_includes = invoker.check_includes
56 if (defined(invoker.data)) {
59 if (defined(invoker.data_deps)) {
60 data_deps = invoker.data_deps
62 if (defined(invoker.datadeps)) {
63 datadeps = invoker.datadeps
65 if (defined(invoker.defines)) {
66 defines = invoker.defines
69 if (!defined(invoker.use_launcher) || invoker.use_launcher) {
70 deps += [ "//testing/android/native_test:native_test_native_code" ]
72 if (defined(invoker.deps)) {
75 if (defined(invoker.direct_dependent_configs)) {
76 direct_dependent_configs = invoker.direct_dependent_configs
78 if (defined(invoker.forward_dependent_configs_from)) {
79 forward_dependent_configs_from = invoker.forward_dependent_configs_from
81 if (defined(invoker.include_dirs)) {
82 include_dirs = invoker.include_dirs
84 if (defined(invoker.ldflags)) {
85 ldflags = invoker.ldflags
87 if (defined(invoker.lib_dirs)) {
88 lib_dirs = invoker.lib_dirs
90 if (defined(invoker.libs)) {
93 if (defined(invoker.output_extension)) {
94 output_extension = invoker.output_extension
96 if (defined(invoker.output_name)) {
97 output_name = invoker.output_name
99 if (defined(invoker.public)) {
100 public = invoker.public
102 if (defined(invoker.public_configs)) {
103 public_configs = invoker.public_configs
105 if (defined(invoker.public_deps)) {
106 public_deps = invoker.public_deps
108 if (defined(invoker.sources)) {
109 sources = invoker.sources
111 if (defined(invoker.visibility)) {
112 visibility = invoker.visibility
116 unittest_apk(apk_name) {
117 unittests_dep = ":$library_name"
118 apk_name = main_target_name
119 if (defined(invoker.output_name)) {
120 apk_name = invoker.output_name
121 unittests_binary = "lib${apk_name}.so"
126 if (defined(invoker.apk_deps)) {
127 deps += invoker.apk_deps
129 if (defined(invoker.apk_asset_location)) {
130 asset_location = invoker.apk_asset_location
134 test_name = main_target_name
135 if (defined(invoker.output_name)) {
136 test_name = invoker.output_name
138 test_runner_script_name = "${test_name}__test_runner_script"
139 test_runner_script(test_runner_script_name) {
140 test_name = test_name
142 test_suite = test_name
143 if (defined(invoker.isolate_file)) {
144 isolate_file = invoker.isolate_file
151 ":$test_runner_script_name",
159 executable(target_name) {
161 configs = [] # Prevent list overwriting warning.
162 configs = invoker.configs
165 set_sources_assignment_filter([])
169 if (defined(invoker.all_dependent_configs)) {
170 all_dependent_configs = invoker.all_dependent_configs
172 if (defined(invoker.allow_circular_includes_from)) {
173 allow_circular_includes_from = invoker.allow_circular_includes_from
175 if (defined(invoker.cflags)) {
176 cflags = invoker.cflags
178 if (defined(invoker.cflags_c)) {
179 cflags_c = invoker.cflags_c
181 if (defined(invoker.cflags_cc)) {
182 cflags_cc = invoker.cflags_cc
184 if (defined(invoker.cflags_objc)) {
185 cflags_objc = invoker.cflags_objc
187 if (defined(invoker.cflags_objcc)) {
188 cflags_objcc = invoker.cflags_objcc
190 if (defined(invoker.check_includes)) {
191 check_includes = invoker.check_includes
193 if (defined(invoker.data)) {
196 if (defined(invoker.data_deps)) {
197 data_deps = invoker.data_deps
199 if (defined(invoker.datadeps)) {
200 datadeps = invoker.datadeps
202 if (defined(invoker.defines)) {
203 defines = invoker.defines
206 # All shared libraries must have the sanitizer deps to properly link in
207 # asan mode (this target will be empty in other cases).
208 if (defined(invoker.deps)) {
209 deps = invoker.deps + [ "//build/config/sanitizers:deps" ]
212 "//build/config/sanitizers:deps",
215 if (defined(invoker.direct_dependent_configs)) {
216 direct_dependent_configs = invoker.direct_dependent_configs
218 if (defined(invoker.forward_dependent_configs_from)) {
219 forward_dependent_configs_from = invoker.forward_dependent_configs_from
221 if (defined(invoker.include_dirs)) {
222 include_dirs = invoker.include_dirs
224 if (defined(invoker.ldflags)) {
225 ldflags = invoker.ldflags
227 if (defined(invoker.lib_dirs)) {
228 lib_dirs = invoker.lib_dirs
230 if (defined(invoker.libs)) {
233 if (defined(invoker.output_extension)) {
234 output_extension = invoker.output_extension
236 if (defined(invoker.output_name)) {
237 output_name = invoker.output_name
239 if (defined(invoker.public)) {
240 public = invoker.public
242 if (defined(invoker.public_configs)) {
243 public_configs = invoker.public_configs
245 if (defined(invoker.public_deps)) {
246 public_deps = invoker.public_deps
248 if (defined(invoker.sources)) {
249 sources = invoker.sources
251 if (defined(invoker.visibility)) {
252 visibility = invoker.visibility