BUILD.gn 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. # Copyright 2014 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. import("//build/buildflag_header.gni")
  5. import("//build/config/chromecast_build.gni")
  6. import("//mojo/public/tools/bindings/mojom.gni")
  7. import("//testing/libfuzzer/fuzzer_test.gni")
  8. import("//testing/test.gni")
  9. mojom("variations_mojom") {
  10. sources = [ "variations.mojom" ]
  11. }
  12. if (is_android) {
  13. import("//build/config/android/rules.gni")
  14. }
  15. large_variation_key_size_enabled =
  16. is_castos || is_cast_android || is_chromeos_lacros
  17. buildflag_header("buildflags") {
  18. header = "buildflags.h"
  19. flags = [ "LARGE_VARIATION_KEY_SIZE=$large_variation_key_size_enabled" ]
  20. }
  21. component("variations_features") {
  22. output_name = "variations_features"
  23. defines = [ "IS_VARIATIONS_FEATURES_IMPL" ]
  24. sources = [
  25. "variations_features.cc",
  26. "variations_features.h",
  27. ]
  28. deps = [ "//base" ]
  29. }
  30. component("variations") {
  31. sources = [
  32. "active_field_trials.cc",
  33. "active_field_trials.h",
  34. "child_process_field_trial_syncer.cc",
  35. "child_process_field_trial_syncer.h",
  36. "client_filterable_state.cc",
  37. "client_filterable_state.h",
  38. "entropy_provider.cc",
  39. "entropy_provider.h",
  40. "fake_crash.cc",
  41. "fake_crash.h",
  42. "hashing.cc",
  43. "hashing.h",
  44. "metrics.cc",
  45. "metrics.h",
  46. "platform_field_trials.h",
  47. "pref_names.cc",
  48. "pref_names.h",
  49. "processed_study.cc",
  50. "processed_study.h",
  51. "seed_response.cc",
  52. "seed_response.h",
  53. "study_filtering.cc",
  54. "study_filtering.h",
  55. "synthetic_trial_registry.cc",
  56. "synthetic_trial_registry.h",
  57. "synthetic_trials.cc",
  58. "synthetic_trials.h",
  59. "synthetic_trials_active_group_id_provider.cc",
  60. "synthetic_trials_active_group_id_provider.h",
  61. "variations_associated_data.cc",
  62. "variations_associated_data.h",
  63. "variations_client.h",
  64. "variations_crash_keys.cc",
  65. "variations_crash_keys.h",
  66. "variations_ids_provider.cc",
  67. "variations_ids_provider.h",
  68. "variations_layers.cc",
  69. "variations_layers.h",
  70. "variations_murmur_hash.cc",
  71. "variations_murmur_hash.h",
  72. "variations_request_scheduler.cc",
  73. "variations_request_scheduler.h",
  74. "variations_seed_processor.cc",
  75. "variations_seed_processor.h",
  76. "variations_seed_simulator.cc",
  77. "variations_seed_simulator.h",
  78. "variations_seed_store.cc",
  79. "variations_seed_store.h",
  80. "variations_switches.cc",
  81. "variations_switches.h",
  82. "variations_url_constants.cc",
  83. "variations_url_constants.h",
  84. ]
  85. # Needed for exporting functions (because the target type is a component).
  86. defines = [ "IS_VARIATIONS_IMPL" ]
  87. if (is_android || is_ios) {
  88. sources += [
  89. "variations_request_scheduler_mobile.cc",
  90. "variations_request_scheduler_mobile.h",
  91. ]
  92. }
  93. if (is_android) {
  94. sources += [
  95. "android/variations_associated_data_android.cc",
  96. "android/variations_seed_bridge.cc",
  97. "android/variations_seed_bridge.h",
  98. ]
  99. }
  100. if (is_chromeos_ash) {
  101. sources += [
  102. "variations_crash_keys_chromeos.cc",
  103. "variations_crash_keys_chromeos.h",
  104. ]
  105. }
  106. public_deps = [
  107. ":variations_features",
  108. "proto",
  109. "//base",
  110. ]
  111. deps = [
  112. ":buildflags",
  113. ":variations_mojom",
  114. "proto",
  115. "//build:chromeos_buildflags",
  116. "//components/crash/core/common:crash_key",
  117. "//components/prefs",
  118. "//components/version_info",
  119. "//crypto",
  120. "//third_party/protobuf:protobuf_lite",
  121. "//third_party/zlib/google:compression_utils",
  122. ]
  123. if (is_android) {
  124. deps += [ ":jni" ]
  125. }
  126. }
  127. if (is_android) {
  128. generate_jni("jni") {
  129. sources = [
  130. "android/java/src/org/chromium/components/variations/VariationsAssociatedData.java",
  131. "android/java/src/org/chromium/components/variations/firstrun/VariationsSeedBridge.java",
  132. ]
  133. }
  134. java_cpp_strings("java_switches_srcjar") {
  135. # External code should depend on ":variations_java" instead.
  136. visibility = [ ":*" ]
  137. sources = [ "variations_switches.cc" ]
  138. template = "//components/variations/android/java_templates/VariationsSwitches.java.tmpl"
  139. }
  140. android_library("variations_java") {
  141. srcjar_deps = [
  142. ":java_switches_srcjar",
  143. ":variations_enum_srcjar",
  144. ]
  145. deps = [ "//third_party/androidx:androidx_annotation_annotation_java" ]
  146. }
  147. java_cpp_enum("variations_enum_srcjar") {
  148. # External code should depend on ":variations_java" instead.
  149. visibility = [ ":*" ]
  150. sources = [
  151. "metrics.h",
  152. "synthetic_trials.h",
  153. ]
  154. }
  155. }
  156. static_library("test_support") {
  157. testonly = true
  158. sources = [
  159. "scoped_variations_ids_provider.cc",
  160. "scoped_variations_ids_provider.h",
  161. "variations_params_manager.cc",
  162. "variations_params_manager.h",
  163. "variations_test_utils.cc",
  164. "variations_test_utils.h",
  165. ]
  166. public_deps = [
  167. ":variations",
  168. ":variations_mojom",
  169. ]
  170. deps = [
  171. "field_trial_config:field_trial_config",
  172. "proto",
  173. "//base/test:test_support",
  174. "//components/metrics",
  175. "//components/prefs:prefs",
  176. "//third_party/zlib/google:compression_utils",
  177. ]
  178. }
  179. source_set("unit_tests") {
  180. testonly = true
  181. sources = [
  182. "active_field_trials_unittest.cc",
  183. "child_process_field_trial_syncer_unittest.cc",
  184. "client_filterable_state_unittest.cc",
  185. "entropy_provider_unittest.cc",
  186. "hashing_unittest.cc",
  187. "net/variations_command_line_unittest.cc",
  188. "net/variations_http_headers_unittest.cc",
  189. "processed_study_unittest.cc",
  190. "simulate_for_crosstalk_unittest.cc",
  191. "study_filtering_unittest.cc",
  192. "synthetic_trial_registry_unittest.cc",
  193. "variations_associated_data_unittest.cc",
  194. "variations_ids_provider_unittest.cc",
  195. "variations_murmur_hash_unittest.cc",
  196. "variations_request_scheduler_unittest.cc",
  197. "variations_seed_processor_unittest.cc",
  198. "variations_seed_simulator_unittest.cc",
  199. "variations_seed_store_unittest.cc",
  200. "variations_test_utils_unittest.cc",
  201. ]
  202. if (is_android || is_ios) {
  203. sources += [ "variations_request_scheduler_mobile_unittest.cc" ]
  204. }
  205. if (is_chromeos_ash) {
  206. sources += [ "variations_crash_keys_chromeos_unittest.cc" ]
  207. }
  208. # This test uses crash_reporter::GetCrashKeyValue(), which in a component
  209. # build returns the crash keys in the unit-test, not the "variations"
  210. # target. The test verifies the keys in the "variations" target, not the
  211. # test. As such, it fails in component builds.
  212. # TODO(crbug.com/1186718): Enable this unittest for is_fuchsia when crash keys
  213. # are supported on Fuchsia.
  214. if (!is_component_build && !is_fuchsia) {
  215. sources += [ "variations_crash_keys_unittest.cc" ]
  216. }
  217. deps = [
  218. ":test_support",
  219. ":variations",
  220. ":variations_features",
  221. ":variations_mojom",
  222. "net",
  223. "proto",
  224. "//base/test:test_support",
  225. "//components/crash/core/common:crash_key",
  226. "//components/prefs:test_support",
  227. "//components/variations/field_trial_config:field_trial_config",
  228. "//services/network/public/cpp:cpp_base",
  229. "//testing/gmock",
  230. "//testing/gtest",
  231. "//third_party/smhasher:murmurhash3",
  232. "//third_party/zlib/google:compression_utils",
  233. "//url",
  234. ]
  235. }
  236. # Convenience testing target
  237. test("variations_unittests") {
  238. sources = [ "//components/test/run_all_unittests.cc" ]
  239. deps = [
  240. ":unit_tests",
  241. "//components/test:test_support",
  242. "//components/variations/field_trial_config:unit_tests",
  243. "//components/variations/service:unit_tests",
  244. ]
  245. }
  246. if (use_libfuzzer) {
  247. fuzzer_test("create_trial_from_study_fuzzer") {
  248. sources = [ "fuzzers/create_trial_from_study_fuzzer.cc" ]
  249. deps = [
  250. ":variations",
  251. "proto",
  252. "//base/test:test_support",
  253. "//third_party/libprotobuf-mutator",
  254. ]
  255. }
  256. }