blob: 82867a5c0a5461730e1a37aeeb493f18e12ae5b3 [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"
Nico Webere9e4be882020-01-13 22:41:5829 sources = [ "//chrome/VERSION" ]
Misha Efimov1770a1b2018-01-11 15:27:2730 output = "$target_gen_dir/version.h"
31 extra_args = [
32 "-e",
33 "VERSION_FULL=\"%s.%s.%s.%s\" % (MAJOR,MINOR,BUILD,PATCH)",
34 ]
35}
36
37# Cronet common implementation.
38source_set("cronet_common") {
39 sources = [
40 "cronet_global_state.h",
41 "cronet_prefs_manager.cc",
42 "cronet_prefs_manager.h",
Misha Efimovd16a27a2018-05-29 15:03:4443 "cronet_upload_data_stream.cc",
44 "cronet_upload_data_stream.h",
Misha Efimovc1731b02018-01-16 21:46:5145 "cronet_url_request.cc",
46 "cronet_url_request.h",
Misha Efimov1770a1b2018-01-11 15:27:2747 "cronet_url_request_context.cc",
48 "cronet_url_request_context.h",
49 "histogram_manager.cc",
50 "histogram_manager.h",
51 "host_cache_persistence_manager.cc",
52 "host_cache_persistence_manager.h",
53 "stale_host_resolver.cc",
54 "stale_host_resolver.h",
55 "url_request_context_config.cc",
56 "url_request_context_config.h",
57 ]
58 deps = [
Misha Efimova0b0fe612018-10-02 14:23:4459 ":cronet_buildflags",
Misha Efimov1770a1b2018-01-11 15:27:2760 ":cronet_version_header",
61 "//base",
62 "//components/metrics:metrics",
63 "//components/prefs:prefs",
64 "//net",
65 "//third_party/metrics_proto",
66 ]
Misha Efimova0b0fe612018-10-02 14:23:4467
68 if (disable_histogram_support) {
69 sources -= [
70 "histogram_manager.cc",
71 "histogram_manager.h",
72 ]
73 deps -= [
74 "//components/metrics:metrics",
75 "//third_party/metrics_proto",
76 ]
77 }
Misha Efimov1770a1b2018-01-11 15:27:2778}
79
Caleb Raitto95c93c02019-01-23 17:49:1280source_set("metrics_util") {
81 sources = [
82 "metrics_util.cc",
83 "metrics_util.h",
84 ]
Nico Webere9e4be882020-01-13 22:41:5885 deps = [ "//base" ]
Caleb Raitto95c93c02019-01-23 17:49:1286}
87
Misha Efimov1770a1b2018-01-11 15:27:2788# Unit tests for Cronet common implementation.
89source_set("cronet_common_unittests") {
90 testonly = true
91
92 deps = [
93 ":cronet_common",
94 "//components/prefs:test_support",
95 "//net:test_support",
96 ]
97
98 sources = [
99 "histogram_manager_unittest.cc",
100 "host_cache_persistence_manager_unittest.cc",
Misha Efimov1770a1b2018-01-11 15:27:27101 "stale_host_resolver_unittest.cc",
102 "url_request_context_config_unittest.cc",
103 ]
Misha Efimova0b0fe612018-10-02 14:23:44104
105 if (disable_histogram_support) {
106 sources -= [ "histogram_manager_unittest.cc" ]
107 }
Misha Efimov1770a1b2018-01-11 15:27:27108}
Wez115d4312018-02-17 04:05:19109
110# For platforms on which the native Cronet library is used, build the library,
111# a cronet_tests binary that exercises it, and a unit-tests binary.
112# Android and iOS have their own platform-specific rules to build Cronet.
John Budorickbc3571aa2019-04-25 02:20:06113if (is_android) {
114 group("cronet_package") {
115 testonly = true
Nico Webere9e4be882020-01-13 22:41:58116 deps = [ "//components/cronet/android:cronet_package_android" ]
John Budorickbc3571aa2019-04-25 02:20:06117 }
118} else if (is_ios) {
119 group("cronet_package") {
Nico Webere9e4be882020-01-13 22:41:58120 deps = [ "//components/cronet/ios:cronet_package_ios" ]
John Budorickbc3571aa2019-04-25 02:20:06121 }
122} else {
Misha Efimovc5cf88e62018-04-04 20:02:33123 config("shared_library_public_config") {
124 if (is_mac && !is_component_build) {
125 # Executable targets that depend on the shared libraries below need to have
126 # the rpath setup in non-component build configurations.
127 ldflags = [
128 "-rpath",
129 "@executable_path/",
130 ]
131 }
132 }
133
Misha Efimov5e6f91c2018-10-12 17:56:27134 _cronet_shared_lib_name = "cronet.$chrome_version_full"
135 _cronet_shared_lib_file_name =
136 "$shlib_prefix$_cronet_shared_lib_name$shlib_extension"
137
Wez115d4312018-02-17 04:05:19138 shared_library("cronet") {
Misha Efimov5e6f91c2018-10-12 17:56:27139 output_name = _cronet_shared_lib_name
140
Wez115d4312018-02-17 04:05:19141 deps = [
142 "//base",
Wez115d4312018-02-17 04:05:19143 "//components/cronet:cronet_common",
144 "//components/cronet/native:cronet_native_impl",
145 "//net",
146 ]
147
Nico Webere9e4be882020-01-13 22:41:58148 sources = [ "cronet_global_state_stubs.cc" ]
Misha Efimovc5cf88e62018-04-04 20:02:33149
150 if (is_mac && !is_component_build) {
151 ldflags = [
152 "-install_name",
Misha Efimovc79080372018-10-27 19:36:50153 "@executable_path/$_cronet_shared_lib_file_name",
Misha Efimovc5cf88e62018-04-04 20:02:33154 ]
155 public_configs = [ ":shared_library_public_config" ]
156 }
Wez115d4312018-02-17 04:05:19157 }
158
159 test("cronet_tests") {
Wez115d4312018-02-17 04:05:19160 deps = [
Misha Efimov41fba7252018-09-05 17:02:58161 ":cronet_common",
Wez087612362018-02-26 21:37:41162 "//base",
163 "//base/test:test_support",
Misha Efimov41fba7252018-09-05 17:02:58164 "//components/cronet/native:cronet_native_impl",
Wez115d4312018-02-17 04:05:19165 "//components/cronet/native/test:cronet_native_tests",
Misha Efimov41fba7252018-09-05 17:02:58166 "//net",
Wez087612362018-02-26 21:37:41167 ]
168
169 sources = [
Misha Efimov41fba7252018-09-05 17:02:58170 "cronet_global_state_stubs.cc",
Wez087612362018-02-26 21:37:41171 "run_all_unittests.cc",
Wez115d4312018-02-17 04:05:19172 ]
Misha Efimov91c17342018-04-02 21:31:07173
Wez318901082018-08-24 23:57:42174 defines = [ "CRONET_TESTS_IMPLEMENTATION" ]
175
Misha Efimov91c17342018-04-02 21:31:07176 if (is_linux && !is_component_build) {
177 public_configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
178 }
Wez115d4312018-02-17 04:05:19179 }
180
181 test("cronet_unittests") {
Wez115d4312018-02-17 04:05:19182 deps = [
183 ":cronet_common",
184 ":cronet_common_unittests",
185 "//base",
Wez8b25664a2018-08-28 23:51:10186 "//base/test:test_support",
Wez115d4312018-02-17 04:05:19187 "//components/cronet/native:cronet_native_unittests",
188 "//net",
189 ]
190
191 sources = [
192 "cronet_global_state_stubs.cc",
Wez8b25664a2018-08-28 23:51:10193 "run_all_unittests.cc",
Wez115d4312018-02-17 04:05:19194 ]
195 }
Misha Efimov0edcce32018-10-03 19:09:29196
197 _package_dir = "$root_out_dir/cronet"
198
199 # Generate LICENSE file by recursively joining all dependent licenses.
200 action("generate_license") {
201 _license_path = "$_package_dir/LICENSE"
202
203 script = "//tools/licenses.py"
Nico Webere9e4be882020-01-13 22:41:58204 inputs = [ lastchange_file ]
205 outputs = [ _license_path ]
Misha Efimov0edcce32018-10-03 19:09:29206 args = [
207 "license_file",
208 rebase_path(_license_path, root_build_dir),
209 "--gn-target",
210 "//components/cronet:cronet",
211 "--gn-out-dir",
212 ".",
213 ]
214 }
215
216 # Copy boiler-plate files into the package.
217 copy("cronet_package_copy") {
218 sources = [
Michael Spang8803d942019-01-29 03:33:47219 "${root_out_dir}${shlib_subdir}/${_cronet_shared_lib_file_name}",
Misha Efimov0edcce32018-10-03 19:09:29220 "//AUTHORS",
221 "//chrome/VERSION",
222 ]
Nico Webere9e4be882020-01-13 22:41:58223 deps = [ ":cronet" ]
224 outputs = [ "$_package_dir/{{source_file_part}}" ]
Misha Efimov0edcce32018-10-03 19:09:29225 }
226
227 # Copy headers.
228 copy("cronet_package_headers") {
229 sources = cronet_native_public_headers + grpc_public_headers
230
Nico Webere9e4be882020-01-13 22:41:58231 outputs = [ "$_package_dir/include/{{source_file_part}}" ]
Misha Efimov0edcce32018-10-03 19:09:29232 }
233
234 group("cronet_package") {
235 deps = [
236 ":cronet_package_copy",
237 ":cronet_package_headers",
Misha Efimov0edcce32018-10-03 19:09:29238 ":generate_license",
239 ]
240 }
Paul Jensen608d3512018-10-05 14:54:38241
242 executable("cronet_native_perf_test") {
243 testonly = true
244 sources = [
245 "native/perftest/main.cc",
246 "native/perftest/perf_test.cc",
247 ]
248 deps = [
249 "//base",
250 "//components/cronet",
251 "//components/cronet/native:cronet_native_headers",
252 "//components/cronet/native/test:cronet_native_tests",
253 "//components/cronet/native/test:cronet_native_testutil",
254 "//net:test_support",
255 ]
256 }
Misha Efimova7332e272018-10-18 13:21:26257
258 executable("cronet_sample") {
259 testonly = true
260 sources = [
261 "native/sample/main.cc",
262 "native/sample/sample_executor.cc",
263 "native/sample/sample_executor.h",
264 "native/sample/sample_url_request_callback.cc",
265 "native/sample/sample_url_request_callback.h",
266 ]
267 deps = [
268 "//components/cronet",
269 "//components/cronet/native:cronet_native_headers",
270 ]
271 if (is_linux && !is_component_build) {
272 public_configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
273 }
274 }
275
276 test("cronet_sample_test") {
Nico Webere9e4be882020-01-13 22:41:58277 sources = [ "native/sample/test/sample_test.cc" ]
Misha Efimova7332e272018-10-18 13:21:26278 deps = [
279 ":cronet_sample",
280 "//testing/gtest:gtest",
281 ]
282 }
Wez115d4312018-02-17 04:05:19283}