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.forward_dependent_configs_from)) {
76 forward_dependent_configs_from = invoker.forward_dependent_configs_from
78 if (defined(invoker.include_dirs)) {
79 include_dirs = invoker.include_dirs
81 if (defined(invoker.ldflags)) {
82 ldflags = invoker.ldflags
84 if (defined(invoker.lib_dirs)) {
85 lib_dirs = invoker.lib_dirs
87 if (defined(invoker.libs)) {
90 if (defined(invoker.output_extension)) {
91 output_extension = invoker.output_extension
93 if (defined(invoker.output_name)) {
94 output_name = invoker.output_name
96 if (defined(invoker.public)) {
97 public = invoker.public
99 if (defined(invoker.public_configs)) {
100 public_configs = invoker.public_configs
102 if (defined(invoker.public_deps)) {
103 public_deps = invoker.public_deps
105 if (defined(invoker.sources)) {
106 sources = invoker.sources
108 if (defined(invoker.visibility)) {
109 visibility = invoker.visibility
113 unittest_apk(apk_name) {
114 unittests_dep = ":$library_name"
115 apk_name = main_target_name
116 if (defined(invoker.output_name)) {
117 apk_name = invoker.output_name
118 unittests_binary = "lib${apk_name}.so"
123 if (defined(invoker.apk_deps)) {
124 deps += invoker.apk_deps
126 if (defined(invoker.apk_asset_location)) {
127 asset_location = invoker.apk_asset_location
131 test_name = main_target_name
132 if (defined(invoker.output_name)) {
133 test_name = invoker.output_name
135 test_runner_script_name = "${test_name}__test_runner_script"
136 test_runner_script(test_runner_script_name) {
137 test_name = test_name
139 test_suite = test_name
140 if (defined(invoker.isolate_file)) {
141 isolate_file = invoker.isolate_file
148 ":$test_runner_script_name",
156 executable(target_name) {
158 configs = [] # Prevent list overwriting warning.
159 configs = invoker.configs
162 set_sources_assignment_filter([])
166 if (defined(invoker.all_dependent_configs)) {
167 all_dependent_configs = invoker.all_dependent_configs
169 if (defined(invoker.allow_circular_includes_from)) {
170 allow_circular_includes_from = invoker.allow_circular_includes_from
172 if (defined(invoker.cflags)) {
173 cflags = invoker.cflags
175 if (defined(invoker.cflags_c)) {
176 cflags_c = invoker.cflags_c
178 if (defined(invoker.cflags_cc)) {
179 cflags_cc = invoker.cflags_cc
181 if (defined(invoker.cflags_objc)) {
182 cflags_objc = invoker.cflags_objc
184 if (defined(invoker.cflags_objcc)) {
185 cflags_objcc = invoker.cflags_objcc
187 if (defined(invoker.check_includes)) {
188 check_includes = invoker.check_includes
190 if (defined(invoker.data)) {
193 if (defined(invoker.data_deps)) {
194 data_deps = invoker.data_deps
196 if (defined(invoker.datadeps)) {
197 datadeps = invoker.datadeps
199 if (defined(invoker.defines)) {
200 defines = invoker.defines
203 if (defined(invoker.deps)) {
209 # All shared libraries must have the sanitizer deps to properly link in
210 # asan mode (this target will be empty in other cases).
211 "//build/config/sanitizers:deps",
213 # Give tests the default manifest on Windows (a no-op elsewhere).
214 "//build/win:default_exe_manifest",
217 if (defined(invoker.forward_dependent_configs_from)) {
218 forward_dependent_configs_from = invoker.forward_dependent_configs_from
220 if (defined(invoker.include_dirs)) {
221 include_dirs = invoker.include_dirs
223 if (defined(invoker.ldflags)) {
224 ldflags = invoker.ldflags
226 if (defined(invoker.lib_dirs)) {
227 lib_dirs = invoker.lib_dirs
229 if (defined(invoker.libs)) {
232 if (defined(invoker.output_extension)) {
233 output_extension = invoker.output_extension
235 if (defined(invoker.output_name)) {
236 output_name = invoker.output_name
238 if (defined(invoker.public)) {
239 public = invoker.public
241 if (defined(invoker.public_configs)) {
242 public_configs = invoker.public_configs
244 if (defined(invoker.public_deps)) {
245 public_deps = invoker.public_deps
247 if (defined(invoker.sources)) {
248 sources = invoker.sources
250 if (defined(invoker.visibility)) {
251 visibility = invoker.visibility