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 5import("//build/buildflag_header.gni") 6import("//build/toolchain/toolchain.gni") 7import("//build/util/lastchange.gni") 8import("//build/util/process_version.gni") 9import("//build/util/version.gni") 10import("//components/cronet/native/include/headers.gni") 11import("//components/grpc_support/include/headers.gni") 12import("//testing/test.gni") 13 14declare_args() { 15 # If set to true, this will remove histogram manager to reduce binary size. 16 disable_histogram_support = is_mac || is_win 17} 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 27process_version("cronet_version_header") { 28 template_file = "//components/cronet/version.h.in" 29 sources = [ "//chrome/VERSION" ] 30 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", 43 "cronet_upload_data_stream.cc", 44 "cronet_upload_data_stream.h", 45 "cronet_url_request.cc", 46 "cronet_url_request.h", 47 "cronet_url_request_context.cc", 48 "cronet_url_request_context.h", 49 "host_cache_persistence_manager.cc", 50 "host_cache_persistence_manager.h", 51 "stale_host_resolver.cc", 52 "stale_host_resolver.h", 53 "url_request_context_config.cc", 54 "url_request_context_config.h", 55 ] 56 deps = [ 57 ":cronet_buildflags", 58 ":cronet_version_header", 59 "//base", 60 "//components/prefs:prefs", 61 "//net", 62 "//third_party/metrics_proto", 63 ] 64 65 if (!disable_histogram_support) { 66 public_deps = [ "//components/metrics:library_support" ] 67 } 68} 69 70source_set("metrics_util") { 71 sources = [ 72 "metrics_util.cc", 73 "metrics_util.h", 74 ] 75 deps = [ "//base" ] 76} 77 78# Unit tests for Cronet common implementation. 79source_set("cronet_common_unittests") { 80 testonly = true 81 82 deps = [ 83 ":cronet_common", 84 "//components/prefs:test_support", 85 "//net:test_support", 86 ] 87 88 sources = [ 89 "host_cache_persistence_manager_unittest.cc", 90 "stale_host_resolver_unittest.cc", 91 "url_request_context_config_unittest.cc", 92 ] 93} 94 95# For platforms on which the native Cronet library is used, build the library, 96# a cronet_tests binary that exercises it, and a unit-tests binary. 97# Android and iOS have their own platform-specific rules to build Cronet. 98if (is_android) { 99 group("cronet_package") { 100 testonly = true 101 deps = [ "//components/cronet/android:cronet_package_android" ] 102 } 103} else if (is_ios) { 104 group("cronet_package") { 105 deps = [ "//components/cronet/ios:cronet_package_ios" ] 106 } 107} else { 108 config("shared_library_public_config") { 109 if (is_mac && !is_component_build) { 110 # Executable targets that depend on the shared libraries below need to have 111 # the rpath setup in non-component build configurations. 112 ldflags = [ 113 "-rpath", 114 "@executable_path/", 115 ] 116 } 117 } 118 119 _cronet_shared_lib_name = "cronet.$chrome_version_full" 120 _cronet_shared_lib_file_name = 121 "$shlib_prefix$_cronet_shared_lib_name$shlib_extension" 122 123 shared_library("cronet") { 124 output_name = _cronet_shared_lib_name 125 126 deps = [ 127 "//base", 128 "//components/cronet:cronet_common", 129 "//components/cronet/native:cronet_native_impl", 130 "//net", 131 ] 132 133 sources = [ "cronet_global_state_stubs.cc" ] 134 135 if (is_mac && !is_component_build) { 136 ldflags = [ 137 "-install_name", 138 "@executable_path/$_cronet_shared_lib_file_name", 139 ] 140 public_configs = [ ":shared_library_public_config" ] 141 } 142 } 143 144 test("cronet_tests") { 145 deps = [ 146 ":cronet_common", 147 "//base", 148 "//base/test:test_support", 149 "//components/cronet/native:cronet_native_impl", 150 "//components/cronet/native/test:cronet_native_tests", 151 "//net", 152 ] 153 154 sources = [ 155 "cronet_global_state_stubs.cc", 156 "run_all_unittests.cc", 157 ] 158 159 defines = [ "CRONET_TESTS_IMPLEMENTATION" ] 160 161 if ((is_linux || is_chromeos) && !is_component_build) { 162 public_configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ] 163 } 164 } 165 166 test("cronet_unittests") { 167 deps = [ 168 ":cronet_common", 169 ":cronet_common_unittests", 170 "//base", 171 "//base/test:test_support", 172 "//components/cronet/native:cronet_native_unittests", 173 "//net", 174 ] 175 176 sources = [ 177 "cronet_global_state_stubs.cc", 178 "run_all_unittests.cc", 179 ] 180 } 181 182 _package_dir = "$root_out_dir/cronet" 183 184 # Generate LICENSE file by recursively joining all dependent licenses. 185 action("generate_license") { 186 _license_path = "$_package_dir/LICENSE" 187 188 script = "//tools/licenses.py" 189 inputs = [ lastchange_file ] 190 outputs = [ _license_path ] 191 args = [ 192 "license_file", 193 rebase_path(_license_path, root_build_dir), 194 "--gn-target", 195 "//components/cronet:cronet", 196 "--gn-out-dir", 197 ".", 198 ] 199 } 200 201 # Copy boiler-plate files into the package. 202 copy("cronet_package_copy") { 203 sources = [ 204 "${root_out_dir}${shlib_subdir}/${_cronet_shared_lib_file_name}", 205 "//AUTHORS", 206 "//chrome/VERSION", 207 ] 208 deps = [ ":cronet" ] 209 outputs = [ "$_package_dir/{{source_file_part}}" ] 210 } 211 212 # Copy headers. 213 copy("cronet_package_headers") { 214 sources = cronet_native_public_headers + grpc_public_headers 215 216 outputs = [ "$_package_dir/include/{{source_file_part}}" ] 217 } 218 219 group("cronet_package") { 220 deps = [ 221 ":cronet_package_copy", 222 ":cronet_package_headers", 223 ":generate_license", 224 ] 225 } 226 227 executable("cronet_native_perf_test") { 228 testonly = true 229 sources = [ 230 "native/perftest/main.cc", 231 "native/perftest/perf_test.cc", 232 ] 233 deps = [ 234 "//base", 235 "//components/cronet", 236 "//components/cronet/native:cronet_native_headers", 237 "//components/cronet/native/test:cronet_native_tests", 238 "//components/cronet/native/test:cronet_native_testutil", 239 "//net:test_support", 240 ] 241 } 242 243 executable("cronet_sample") { 244 testonly = true 245 sources = [ 246 "native/sample/main.cc", 247 "native/sample/sample_executor.cc", 248 "native/sample/sample_executor.h", 249 "native/sample/sample_url_request_callback.cc", 250 "native/sample/sample_url_request_callback.h", 251 ] 252 deps = [ 253 "//components/cronet", 254 "//components/cronet/native:cronet_native_headers", 255 ] 256 if ((is_linux || is_chromeos) && !is_component_build) { 257 public_configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ] 258 } 259 } 260 261 test("cronet_sample_test") { 262 sources = [ "native/sample/test/sample_test.cc" ] 263 deps = [ 264 ":cronet_sample", 265 "//testing/gtest:gtest", 266 ] 267 } 268} 269