blob: 794bad117d35e3b3e6378a7593398577ce91a8c5 [file] [log] [blame]
Misha Efimov1770a1b2018-01-11 15:27:271# Copyright 2017 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
Misha Efimova0b0fe612018-10-02 14:23:445import("//build/buildflag_header.gni")
Misha Efimov0edcce32018-10-03 19:09:296import("//build/toolchain/toolchain.gni")
7import("//build/util/lastchange.gni")
Misha Efimov1770a1b2018-01-11 15:27:278import("//build/util/process_version.gni")
9import("//build/util/version.gni")
Misha Efimov0edcce32018-10-03 19:09:2910import("//components/cronet/native/include/headers.gni")
11import("//components/grpc_support/include/headers.gni")
Misha Efimov1770a1b2018-01-11 15:27:2712import("//testing/test.gni")
13
Misha Efimova0b0fe612018-10-02 14:23:4414declare_args() {
15 # If set to true, this will remove histogram manager to reduce binary size.
Misha Efimov0edcce32018-10-03 19:09:2916 disable_histogram_support = is_mac || is_win
Misha Efimova0b0fe612018-10-02 14:23:4417}
18
19# Disable histogram support is not allowed on Android.
20assert(!disable_histogram_support || !is_android)
21
22buildflag_header("cronet_buildflags") {
23 header = "cronet_buildflags.h"
24 flags = [ "DISABLE_HISTOGRAM_SUPPORT=$disable_histogram_support" ]
25}
26
Misha Efimov1770a1b2018-01-11 15:27:2727process_version("cronet_version_header") {
28 template_file = "//components/cronet/version.h.in"
29 sources = [
30 "//chrome/VERSION",
31 ]
32 output = "$target_gen_dir/version.h"
33 extra_args = [
34 "-e",
35 "VERSION_FULL=\"%s.%s.%s.%s\" % (MAJOR,MINOR,BUILD,PATCH)",
36 ]
37}
38
39# Cronet common implementation.
40source_set("cronet_common") {
41 sources = [
42 "cronet_global_state.h",
43 "cronet_prefs_manager.cc",
44 "cronet_prefs_manager.h",
Misha Efimovd16a27a2018-05-29 15:03:4445 "cronet_upload_data_stream.cc",
46 "cronet_upload_data_stream.h",
Misha Efimovc1731b02018-01-16 21:46:5147 "cronet_url_request.cc",
48 "cronet_url_request.h",
Misha Efimov1770a1b2018-01-11 15:27:2749 "cronet_url_request_context.cc",
50 "cronet_url_request_context.h",
51 "histogram_manager.cc",
52 "histogram_manager.h",
53 "host_cache_persistence_manager.cc",
54 "host_cache_persistence_manager.h",
55 "stale_host_resolver.cc",
56 "stale_host_resolver.h",
57 "url_request_context_config.cc",
58 "url_request_context_config.h",
59 ]
60 deps = [
Misha Efimova0b0fe612018-10-02 14:23:4461 ":cronet_buildflags",
Misha Efimov1770a1b2018-01-11 15:27:2762 ":cronet_version_header",
63 "//base",
64 "//components/metrics:metrics",
65 "//components/prefs:prefs",
66 "//net",
67 "//third_party/metrics_proto",
68 ]
Misha Efimova0b0fe612018-10-02 14:23:4469
70 if (disable_histogram_support) {
71 sources -= [
72 "histogram_manager.cc",
73 "histogram_manager.h",
74 ]
75 deps -= [
76 "//components/metrics:metrics",
77 "//third_party/metrics_proto",
78 ]
79 }
Misha Efimov1770a1b2018-01-11 15:27:2780}
81
Caleb Raitto95c93c02019-01-23 17:49:1282source_set("metrics_util") {
83 sources = [
84 "metrics_util.cc",
85 "metrics_util.h",
86 ]
87 deps = [
88 "//base",
89 ]
90}
91
Misha Efimov1770a1b2018-01-11 15:27:2792# Unit tests for Cronet common implementation.
93source_set("cronet_common_unittests") {
94 testonly = true
95
96 deps = [
97 ":cronet_common",
98 "//components/prefs:test_support",
99 "//net:test_support",
100 ]
101
102 sources = [
103 "histogram_manager_unittest.cc",
104 "host_cache_persistence_manager_unittest.cc",
Misha Efimov1770a1b2018-01-11 15:27:27105 "stale_host_resolver_unittest.cc",
106 "url_request_context_config_unittest.cc",
107 ]
Misha Efimova0b0fe612018-10-02 14:23:44108
109 if (disable_histogram_support) {
110 sources -= [ "histogram_manager_unittest.cc" ]
111 }
Misha Efimov1770a1b2018-01-11 15:27:27112}
Wez115d4312018-02-17 04:05:19113
114# For platforms on which the native Cronet library is used, build the library,
115# a cronet_tests binary that exercises it, and a unit-tests binary.
116# Android and iOS have their own platform-specific rules to build Cronet.
Wez12ce94a2018-03-27 03:42:25117if (!is_ios && !is_android) {
Misha Efimovc5cf88e62018-04-04 20:02:33118 config("shared_library_public_config") {
119 if (is_mac && !is_component_build) {
120 # Executable targets that depend on the shared libraries below need to have
121 # the rpath setup in non-component build configurations.
122 ldflags = [
123 "-rpath",
124 "@executable_path/",
125 ]
126 }
127 }
128
Misha Efimov5e6f91c2018-10-12 17:56:27129 _cronet_shared_lib_name = "cronet.$chrome_version_full"
130 _cronet_shared_lib_file_name =
131 "$shlib_prefix$_cronet_shared_lib_name$shlib_extension"
132
Wez115d4312018-02-17 04:05:19133 shared_library("cronet") {
Misha Efimov5e6f91c2018-10-12 17:56:27134 output_name = _cronet_shared_lib_name
135
Wez115d4312018-02-17 04:05:19136 deps = [
137 "//base",
Wez115d4312018-02-17 04:05:19138 "//components/cronet:cronet_common",
139 "//components/cronet/native:cronet_native_impl",
140 "//net",
141 ]
142
143 sources = [
144 "cronet_global_state_stubs.cc",
145 ]
Misha Efimovc5cf88e62018-04-04 20:02:33146
147 if (is_mac && !is_component_build) {
148 ldflags = [
149 "-install_name",
Misha Efimovc79080372018-10-27 19:36:50150 "@executable_path/$_cronet_shared_lib_file_name",
Misha Efimovc5cf88e62018-04-04 20:02:33151 ]
152 public_configs = [ ":shared_library_public_config" ]
153 }
Wez115d4312018-02-17 04:05:19154 }
155
156 test("cronet_tests") {
Wez115d4312018-02-17 04:05:19157 deps = [
Misha Efimov41fba7252018-09-05 17:02:58158 ":cronet_common",
Wez087612362018-02-26 21:37:41159 "//base",
160 "//base/test:test_support",
Misha Efimov41fba7252018-09-05 17:02:58161 "//components/cronet/native:cronet_native_impl",
Wez115d4312018-02-17 04:05:19162 "//components/cronet/native/test:cronet_native_tests",
Misha Efimov41fba7252018-09-05 17:02:58163 "//net",
Wez087612362018-02-26 21:37:41164 ]
165
166 sources = [
Misha Efimov41fba7252018-09-05 17:02:58167 "cronet_global_state_stubs.cc",
Wez087612362018-02-26 21:37:41168 "run_all_unittests.cc",
Wez115d4312018-02-17 04:05:19169 ]
Misha Efimov91c17342018-04-02 21:31:07170
Wez318901082018-08-24 23:57:42171 defines = [ "CRONET_TESTS_IMPLEMENTATION" ]
172
Misha Efimov91c17342018-04-02 21:31:07173 if (is_linux && !is_component_build) {
174 public_configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
175 }
Wez115d4312018-02-17 04:05:19176 }
177
178 test("cronet_unittests") {
Wez115d4312018-02-17 04:05:19179 deps = [
180 ":cronet_common",
181 ":cronet_common_unittests",
182 "//base",
Wez8b25664a2018-08-28 23:51:10183 "//base/test:test_support",
Wez115d4312018-02-17 04:05:19184 "//components/cronet/native:cronet_native_unittests",
185 "//net",
186 ]
187
188 sources = [
189 "cronet_global_state_stubs.cc",
Wez8b25664a2018-08-28 23:51:10190 "run_all_unittests.cc",
Wez115d4312018-02-17 04:05:19191 ]
192 }
Misha Efimov0edcce32018-10-03 19:09:29193
194 _package_dir = "$root_out_dir/cronet"
195
196 # Generate LICENSE file by recursively joining all dependent licenses.
197 action("generate_license") {
198 _license_path = "$_package_dir/LICENSE"
199
200 script = "//tools/licenses.py"
201 inputs = [
202 lastchange_file,
203 ]
204 outputs = [
205 _license_path,
206 ]
207 args = [
208 "license_file",
209 rebase_path(_license_path, root_build_dir),
210 "--gn-target",
211 "//components/cronet:cronet",
212 "--gn-out-dir",
213 ".",
214 ]
215 }
216
217 # Copy boiler-plate files into the package.
218 copy("cronet_package_copy") {
219 sources = [
Misha Efimov5e6f91c2018-10-12 17:56:27220 "$root_out_dir/$_cronet_shared_lib_file_name",
Misha Efimov0edcce32018-10-03 19:09:29221 "//AUTHORS",
222 "//chrome/VERSION",
223 ]
Misha Efimov0edcce32018-10-03 19:09:29224 deps = [
225 ":cronet",
226 ]
Misha Efimov5e6f91c2018-10-12 17:56:27227 outputs = [
228 "$_package_dir/{{source_file_part}}",
229 ]
Misha Efimov0edcce32018-10-03 19:09:29230 }
231
232 # Copy headers.
233 copy("cronet_package_headers") {
234 sources = cronet_native_public_headers + grpc_public_headers
235
236 outputs = [
237 "$_package_dir/include/{{source_file_part}}",
238 ]
239 }
240
241 group("cronet_package") {
242 deps = [
243 ":cronet_package_copy",
244 ":cronet_package_headers",
Misha Efimov0edcce32018-10-03 19:09:29245 ":generate_license",
246 ]
247 }
Paul Jensen608d3512018-10-05 14:54:38248
249 executable("cronet_native_perf_test") {
250 testonly = true
251 sources = [
252 "native/perftest/main.cc",
253 "native/perftest/perf_test.cc",
254 ]
255 deps = [
256 "//base",
257 "//components/cronet",
258 "//components/cronet/native:cronet_native_headers",
259 "//components/cronet/native/test:cronet_native_tests",
260 "//components/cronet/native/test:cronet_native_testutil",
261 "//net:test_support",
262 ]
263 }
Misha Efimova7332e272018-10-18 13:21:26264
265 executable("cronet_sample") {
266 testonly = true
267 sources = [
268 "native/sample/main.cc",
269 "native/sample/sample_executor.cc",
270 "native/sample/sample_executor.h",
271 "native/sample/sample_url_request_callback.cc",
272 "native/sample/sample_url_request_callback.h",
273 ]
274 deps = [
275 "//components/cronet",
276 "//components/cronet/native:cronet_native_headers",
277 ]
278 if (is_linux && !is_component_build) {
279 public_configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
280 }
281 }
282
283 test("cronet_sample_test") {
284 sources = [
285 "native/sample/test/sample_test.cc",
286 ]
287 deps = [
288 ":cronet_sample",
289 "//testing/gtest:gtest",
290 ]
291 }
Wez115d4312018-02-17 04:05:19292}