Misha Efimov | 1770a1b | 2018-01-11 15:27:27 | [diff] [blame] | 1 | # 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 Efimov | a0b0fe61 | 2018-10-02 14:23:44 | [diff] [blame] | 5 | import("//build/buildflag_header.gni") |
Misha Efimov | 0edcce3 | 2018-10-03 19:09:29 | [diff] [blame] | 6 | import("//build/toolchain/toolchain.gni") |
| 7 | import("//build/util/lastchange.gni") |
Misha Efimov | 1770a1b | 2018-01-11 15:27:27 | [diff] [blame] | 8 | import("//build/util/process_version.gni") |
| 9 | import("//build/util/version.gni") |
Misha Efimov | 0edcce3 | 2018-10-03 19:09:29 | [diff] [blame] | 10 | import("//components/cronet/native/include/headers.gni") |
| 11 | import("//components/grpc_support/include/headers.gni") |
Misha Efimov | 1770a1b | 2018-01-11 15:27:27 | [diff] [blame] | 12 | import("//testing/test.gni") |
| 13 | |
Misha Efimov | a0b0fe61 | 2018-10-02 14:23:44 | [diff] [blame] | 14 | declare_args() { |
| 15 | # If set to true, this will remove histogram manager to reduce binary size. |
Misha Efimov | 0edcce3 | 2018-10-03 19:09:29 | [diff] [blame] | 16 | disable_histogram_support = is_mac || is_win |
Misha Efimov | a0b0fe61 | 2018-10-02 14:23:44 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | # Disable histogram support is not allowed on Android. |
| 20 | assert(!disable_histogram_support || !is_android) |
| 21 | |
| 22 | buildflag_header("cronet_buildflags") { |
| 23 | header = "cronet_buildflags.h" |
| 24 | flags = [ "DISABLE_HISTOGRAM_SUPPORT=$disable_histogram_support" ] |
| 25 | } |
| 26 | |
Misha Efimov | 1770a1b | 2018-01-11 15:27:27 | [diff] [blame] | 27 | process_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. |
| 40 | source_set("cronet_common") { |
| 41 | sources = [ |
| 42 | "cronet_global_state.h", |
| 43 | "cronet_prefs_manager.cc", |
| 44 | "cronet_prefs_manager.h", |
Misha Efimov | d16a27a | 2018-05-29 15:03:44 | [diff] [blame] | 45 | "cronet_upload_data_stream.cc", |
| 46 | "cronet_upload_data_stream.h", |
Misha Efimov | c1731b0 | 2018-01-16 21:46:51 | [diff] [blame] | 47 | "cronet_url_request.cc", |
| 48 | "cronet_url_request.h", |
Misha Efimov | 1770a1b | 2018-01-11 15:27:27 | [diff] [blame] | 49 | "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 Efimov | a0b0fe61 | 2018-10-02 14:23:44 | [diff] [blame] | 61 | ":cronet_buildflags", |
Misha Efimov | 1770a1b | 2018-01-11 15:27:27 | [diff] [blame] | 62 | ":cronet_version_header", |
| 63 | "//base", |
| 64 | "//components/metrics:metrics", |
| 65 | "//components/prefs:prefs", |
| 66 | "//net", |
| 67 | "//third_party/metrics_proto", |
| 68 | ] |
Misha Efimov | a0b0fe61 | 2018-10-02 14:23:44 | [diff] [blame] | 69 | |
| 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 Efimov | 1770a1b | 2018-01-11 15:27:27 | [diff] [blame] | 80 | } |
| 81 | |
Caleb Raitto | 95c93c0 | 2019-01-23 17:49:12 | [diff] [blame] | 82 | source_set("metrics_util") { |
| 83 | sources = [ |
| 84 | "metrics_util.cc", |
| 85 | "metrics_util.h", |
| 86 | ] |
| 87 | deps = [ |
| 88 | "//base", |
| 89 | ] |
| 90 | } |
| 91 | |
Misha Efimov | 1770a1b | 2018-01-11 15:27:27 | [diff] [blame] | 92 | # Unit tests for Cronet common implementation. |
| 93 | source_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 Efimov | 1770a1b | 2018-01-11 15:27:27 | [diff] [blame] | 105 | "stale_host_resolver_unittest.cc", |
| 106 | "url_request_context_config_unittest.cc", |
| 107 | ] |
Misha Efimov | a0b0fe61 | 2018-10-02 14:23:44 | [diff] [blame] | 108 | |
| 109 | if (disable_histogram_support) { |
| 110 | sources -= [ "histogram_manager_unittest.cc" ] |
| 111 | } |
Misha Efimov | 1770a1b | 2018-01-11 15:27:27 | [diff] [blame] | 112 | } |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 113 | |
| 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. |
John Budorick | bc3571aa | 2019-04-25 02:20:06 | [diff] [blame^] | 117 | if (is_android) { |
| 118 | group("cronet_package") { |
| 119 | testonly = true |
| 120 | deps = [ |
| 121 | "//components/cronet/android:cronet_package_android", |
| 122 | ] |
| 123 | } |
| 124 | } else if (is_ios) { |
| 125 | group("cronet_package") { |
| 126 | deps = [ |
| 127 | "//components/cronet/ios:cronet_package_ios", |
| 128 | ] |
| 129 | } |
| 130 | } else { |
Misha Efimov | c5cf88e6 | 2018-04-04 20:02:33 | [diff] [blame] | 131 | config("shared_library_public_config") { |
| 132 | if (is_mac && !is_component_build) { |
| 133 | # Executable targets that depend on the shared libraries below need to have |
| 134 | # the rpath setup in non-component build configurations. |
| 135 | ldflags = [ |
| 136 | "-rpath", |
| 137 | "@executable_path/", |
| 138 | ] |
| 139 | } |
| 140 | } |
| 141 | |
Misha Efimov | 5e6f91c | 2018-10-12 17:56:27 | [diff] [blame] | 142 | _cronet_shared_lib_name = "cronet.$chrome_version_full" |
| 143 | _cronet_shared_lib_file_name = |
| 144 | "$shlib_prefix$_cronet_shared_lib_name$shlib_extension" |
| 145 | |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 146 | shared_library("cronet") { |
Misha Efimov | 5e6f91c | 2018-10-12 17:56:27 | [diff] [blame] | 147 | output_name = _cronet_shared_lib_name |
| 148 | |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 149 | deps = [ |
| 150 | "//base", |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 151 | "//components/cronet:cronet_common", |
| 152 | "//components/cronet/native:cronet_native_impl", |
| 153 | "//net", |
| 154 | ] |
| 155 | |
| 156 | sources = [ |
| 157 | "cronet_global_state_stubs.cc", |
| 158 | ] |
Misha Efimov | c5cf88e6 | 2018-04-04 20:02:33 | [diff] [blame] | 159 | |
| 160 | if (is_mac && !is_component_build) { |
| 161 | ldflags = [ |
| 162 | "-install_name", |
Misha Efimov | c7908037 | 2018-10-27 19:36:50 | [diff] [blame] | 163 | "@executable_path/$_cronet_shared_lib_file_name", |
Misha Efimov | c5cf88e6 | 2018-04-04 20:02:33 | [diff] [blame] | 164 | ] |
| 165 | public_configs = [ ":shared_library_public_config" ] |
| 166 | } |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | test("cronet_tests") { |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 170 | deps = [ |
Misha Efimov | 41fba725 | 2018-09-05 17:02:58 | [diff] [blame] | 171 | ":cronet_common", |
Wez | 08761236 | 2018-02-26 21:37:41 | [diff] [blame] | 172 | "//base", |
| 173 | "//base/test:test_support", |
Misha Efimov | 41fba725 | 2018-09-05 17:02:58 | [diff] [blame] | 174 | "//components/cronet/native:cronet_native_impl", |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 175 | "//components/cronet/native/test:cronet_native_tests", |
Misha Efimov | 41fba725 | 2018-09-05 17:02:58 | [diff] [blame] | 176 | "//net", |
Wez | 08761236 | 2018-02-26 21:37:41 | [diff] [blame] | 177 | ] |
| 178 | |
| 179 | sources = [ |
Misha Efimov | 41fba725 | 2018-09-05 17:02:58 | [diff] [blame] | 180 | "cronet_global_state_stubs.cc", |
Wez | 08761236 | 2018-02-26 21:37:41 | [diff] [blame] | 181 | "run_all_unittests.cc", |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 182 | ] |
Misha Efimov | 91c1734 | 2018-04-02 21:31:07 | [diff] [blame] | 183 | |
Wez | 31890108 | 2018-08-24 23:57:42 | [diff] [blame] | 184 | defines = [ "CRONET_TESTS_IMPLEMENTATION" ] |
| 185 | |
Misha Efimov | 91c1734 | 2018-04-02 21:31:07 | [diff] [blame] | 186 | if (is_linux && !is_component_build) { |
| 187 | public_configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ] |
| 188 | } |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | test("cronet_unittests") { |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 192 | deps = [ |
| 193 | ":cronet_common", |
| 194 | ":cronet_common_unittests", |
| 195 | "//base", |
Wez | 8b25664a | 2018-08-28 23:51:10 | [diff] [blame] | 196 | "//base/test:test_support", |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 197 | "//components/cronet/native:cronet_native_unittests", |
| 198 | "//net", |
| 199 | ] |
| 200 | |
| 201 | sources = [ |
| 202 | "cronet_global_state_stubs.cc", |
Wez | 8b25664a | 2018-08-28 23:51:10 | [diff] [blame] | 203 | "run_all_unittests.cc", |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 204 | ] |
| 205 | } |
Misha Efimov | 0edcce3 | 2018-10-03 19:09:29 | [diff] [blame] | 206 | |
| 207 | _package_dir = "$root_out_dir/cronet" |
| 208 | |
| 209 | # Generate LICENSE file by recursively joining all dependent licenses. |
| 210 | action("generate_license") { |
| 211 | _license_path = "$_package_dir/LICENSE" |
| 212 | |
| 213 | script = "//tools/licenses.py" |
| 214 | inputs = [ |
| 215 | lastchange_file, |
| 216 | ] |
| 217 | outputs = [ |
| 218 | _license_path, |
| 219 | ] |
| 220 | args = [ |
| 221 | "license_file", |
| 222 | rebase_path(_license_path, root_build_dir), |
| 223 | "--gn-target", |
| 224 | "//components/cronet:cronet", |
| 225 | "--gn-out-dir", |
| 226 | ".", |
| 227 | ] |
| 228 | } |
| 229 | |
| 230 | # Copy boiler-plate files into the package. |
| 231 | copy("cronet_package_copy") { |
| 232 | sources = [ |
Michael Spang | 8803d94 | 2019-01-29 03:33:47 | [diff] [blame] | 233 | "${root_out_dir}${shlib_subdir}/${_cronet_shared_lib_file_name}", |
Misha Efimov | 0edcce3 | 2018-10-03 19:09:29 | [diff] [blame] | 234 | "//AUTHORS", |
| 235 | "//chrome/VERSION", |
| 236 | ] |
Misha Efimov | 0edcce3 | 2018-10-03 19:09:29 | [diff] [blame] | 237 | deps = [ |
| 238 | ":cronet", |
| 239 | ] |
Misha Efimov | 5e6f91c | 2018-10-12 17:56:27 | [diff] [blame] | 240 | outputs = [ |
| 241 | "$_package_dir/{{source_file_part}}", |
| 242 | ] |
Misha Efimov | 0edcce3 | 2018-10-03 19:09:29 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | # Copy headers. |
| 246 | copy("cronet_package_headers") { |
| 247 | sources = cronet_native_public_headers + grpc_public_headers |
| 248 | |
| 249 | outputs = [ |
| 250 | "$_package_dir/include/{{source_file_part}}", |
| 251 | ] |
| 252 | } |
| 253 | |
| 254 | group("cronet_package") { |
| 255 | deps = [ |
| 256 | ":cronet_package_copy", |
| 257 | ":cronet_package_headers", |
Misha Efimov | 0edcce3 | 2018-10-03 19:09:29 | [diff] [blame] | 258 | ":generate_license", |
| 259 | ] |
| 260 | } |
Paul Jensen | 608d351 | 2018-10-05 14:54:38 | [diff] [blame] | 261 | |
| 262 | executable("cronet_native_perf_test") { |
| 263 | testonly = true |
| 264 | sources = [ |
| 265 | "native/perftest/main.cc", |
| 266 | "native/perftest/perf_test.cc", |
| 267 | ] |
| 268 | deps = [ |
| 269 | "//base", |
| 270 | "//components/cronet", |
| 271 | "//components/cronet/native:cronet_native_headers", |
| 272 | "//components/cronet/native/test:cronet_native_tests", |
| 273 | "//components/cronet/native/test:cronet_native_testutil", |
| 274 | "//net:test_support", |
| 275 | ] |
| 276 | } |
Misha Efimov | a7332e27 | 2018-10-18 13:21:26 | [diff] [blame] | 277 | |
| 278 | executable("cronet_sample") { |
| 279 | testonly = true |
| 280 | sources = [ |
| 281 | "native/sample/main.cc", |
| 282 | "native/sample/sample_executor.cc", |
| 283 | "native/sample/sample_executor.h", |
| 284 | "native/sample/sample_url_request_callback.cc", |
| 285 | "native/sample/sample_url_request_callback.h", |
| 286 | ] |
| 287 | deps = [ |
| 288 | "//components/cronet", |
| 289 | "//components/cronet/native:cronet_native_headers", |
| 290 | ] |
| 291 | if (is_linux && !is_component_build) { |
| 292 | public_configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ] |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | test("cronet_sample_test") { |
| 297 | sources = [ |
| 298 | "native/sample/test/sample_test.cc", |
| 299 | ] |
| 300 | deps = [ |
| 301 | ":cronet_sample", |
| 302 | "//testing/gtest:gtest", |
| 303 | ] |
| 304 | } |
Wez | 115d431 | 2018-02-17 04:05:19 | [diff] [blame] | 305 | } |