BUILD.gn 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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/config/chrome_build.gni")
  5. import("//build/config/features.gni")
  6. import("//extensions/buildflags/buildflags.gni")
  7. import("//testing/test.gni")
  8. import("//third_party/protobuf/proto_library.gni")
  9. declare_args() {
  10. # Set the variable 'use_official_google_api_keys' to true
  11. # to use the Google-internal file containing official API keys
  12. # even in a developer build. Setting this variable explicitly to
  13. # true will cause the build to fail if the internal file is missing.
  14. #
  15. # Set the variable to false to not use the internal file, even for
  16. # Chrome-branded builds or when it exists in your checkout.
  17. #
  18. # Leave it unset or set to "" to have the variable
  19. # implicitly set to true if you have
  20. # src/google_apis/internal/google_chrome_api_keys.h in your
  21. # checkout, and implicitly set to false if not.
  22. #
  23. # Note that Chrome-branded builds always behave as if the variable
  24. # was explicitly set to true, i.e. they always use official keys,
  25. # and will fail to build if the internal file is missing.
  26. use_official_google_api_keys = ""
  27. # Set these to bake the specified API keys and OAuth client
  28. # IDs/secrets into your build.
  29. #
  30. # If you create a build without values baked in, you can instead
  31. # set environment variables to provide the keys at runtime (see
  32. # src/google_apis/google_api_keys.h for details). Features that
  33. # require server-side APIs may fail to work if no keys are
  34. # provided.
  35. #
  36. # Note that when building a Chrome-branded build or if
  37. # `use_official_google_api_keys` has been set to `true` (explicitly or
  38. # implicitly), these values will be ignored and the official
  39. # keys will be used instead.
  40. google_api_key = ""
  41. # See google_api_key.
  42. google_default_client_id = ""
  43. # See google_api_key.
  44. google_default_client_secret = ""
  45. }
  46. if (use_official_google_api_keys == "") {
  47. # Default behavior, check if the key file exists.
  48. check_internal_result =
  49. exec_script("build/check_internal.py",
  50. [ rebase_path("internal/google_chrome_api_keys.h",
  51. root_build_dir) ],
  52. "value")
  53. use_official_google_api_keys = check_internal_result == 1
  54. }
  55. config("key_defines") {
  56. defines = []
  57. # TODO(crbug.com/1294915): Refactor so use_official_google_api_keys can be
  58. # used for Fuchsia.
  59. if (!is_fuchsia && (is_chrome_branded || use_official_google_api_keys)) {
  60. defines += [ "USE_OFFICIAL_GOOGLE_API_KEYS=1" ]
  61. }
  62. if (google_api_key != "") {
  63. defines += [ "GOOGLE_API_KEY=\"$google_api_key\"" ]
  64. }
  65. if (google_default_client_id != "") {
  66. defines += [ "GOOGLE_DEFAULT_CLIENT_ID=\"$google_default_client_id\"" ]
  67. }
  68. if (google_default_client_secret != "") {
  69. defines +=
  70. [ "GOOGLE_DEFAULT_CLIENT_SECRET=\"$google_default_client_secret\"" ]
  71. }
  72. }
  73. # Variables:
  74. # deps: Extra dependencies
  75. template("google_apis_tmpl") {
  76. source_set(target_name) {
  77. sources = [
  78. "gaia/core_account_id.cc",
  79. "gaia/core_account_id.h",
  80. "gaia/gaia_access_token_fetcher.cc",
  81. "gaia/gaia_access_token_fetcher.h",
  82. "gaia/gaia_auth_consumer.cc",
  83. "gaia/gaia_auth_consumer.h",
  84. "gaia/gaia_auth_fetcher.cc",
  85. "gaia/gaia_auth_fetcher.h",
  86. "gaia/gaia_auth_util.cc",
  87. "gaia/gaia_auth_util.h",
  88. "gaia/gaia_config.cc",
  89. "gaia/gaia_config.h",
  90. "gaia/gaia_constants.cc",
  91. "gaia/gaia_constants.h",
  92. "gaia/gaia_oauth_client.cc",
  93. "gaia/gaia_oauth_client.h",
  94. "gaia/gaia_switches.cc",
  95. "gaia/gaia_switches.h",
  96. "gaia/gaia_urls.cc",
  97. "gaia/gaia_urls.h",
  98. "gaia/google_service_auth_error.cc",
  99. "gaia/google_service_auth_error.h",
  100. "gaia/oauth2_access_token_consumer.cc",
  101. "gaia/oauth2_access_token_consumer.h",
  102. "gaia/oauth2_access_token_fetcher.cc",
  103. "gaia/oauth2_access_token_fetcher.h",
  104. "gaia/oauth2_access_token_fetcher_immediate_error.cc",
  105. "gaia/oauth2_access_token_fetcher_immediate_error.h",
  106. "gaia/oauth2_access_token_fetcher_impl.cc",
  107. "gaia/oauth2_access_token_fetcher_impl.h",
  108. "gaia/oauth2_access_token_manager.cc",
  109. "gaia/oauth2_access_token_manager.h",
  110. "gaia/oauth2_api_call_flow.cc",
  111. "gaia/oauth2_api_call_flow.h",
  112. "gaia/oauth2_id_token_decoder.cc",
  113. "gaia/oauth2_id_token_decoder.h",
  114. "gaia/oauth2_mint_token_flow.cc",
  115. "gaia/oauth2_mint_token_flow.h",
  116. "gaia/oauth_multilogin_result.cc",
  117. "gaia/oauth_multilogin_result.h",
  118. "gaia/oauth_request_signer.cc",
  119. "gaia/oauth_request_signer.h",
  120. "google_api_keys.cc",
  121. "google_api_keys.h",
  122. ]
  123. configs += [ ":key_defines" ]
  124. deps = [
  125. ":oauth2_mint_token_consent_result_proto",
  126. "//base",
  127. "//base/third_party/dynamic_annotations",
  128. "//build:branding_buildflags",
  129. "//build:chromeos_buildflags",
  130. "//crypto",
  131. "//mojo/public/cpp/bindings:struct_traits",
  132. "//services/network/public/cpp",
  133. ]
  134. if (is_chrome_branded || use_official_google_api_keys) {
  135. deps += [ "internal:generate_metrics_key_header" ]
  136. }
  137. if (defined(invoker.deps)) {
  138. deps += invoker.deps
  139. }
  140. if (is_apple) {
  141. sources += [
  142. "google_api_keys_mac.h",
  143. "google_api_keys_mac.mm",
  144. ]
  145. frameworks = [ "Foundation.framework" ]
  146. }
  147. }
  148. }
  149. google_apis_tmpl("google_apis") {
  150. deps = [
  151. "//net",
  152. "//services/network/public/cpp",
  153. "//services/network/public/mojom",
  154. ]
  155. }
  156. proto_library("oauth2_mint_token_consent_result_proto") {
  157. sources = [ "gaia/oauth2_mint_token_consent_result.proto" ]
  158. }
  159. static_library("test_support") {
  160. testonly = true
  161. sources = [
  162. "gaia/core_account_id_for_testing.cc",
  163. "gaia/fake_gaia.cc",
  164. "gaia/fake_gaia.h",
  165. "gaia/fake_oauth2_access_token_manager.cc",
  166. "gaia/fake_oauth2_access_token_manager.h",
  167. "gaia/oauth2_access_token_manager_test_util.cc",
  168. "gaia/oauth2_access_token_manager_test_util.h",
  169. ]
  170. public_deps = [
  171. ":google_apis",
  172. "//base",
  173. "//base/test:test_support",
  174. "//net:test_support",
  175. "//services/network:network_service",
  176. "//services/network:test_support",
  177. "//services/network/public/cpp",
  178. ]
  179. }
  180. source_set("run_all_unittests") {
  181. testonly = true
  182. sources = [ "run_all_unittests.cc" ]
  183. deps = [
  184. "//base/test:test_support",
  185. "//mojo/core/embedder",
  186. ]
  187. }
  188. test("google_apis_unittests") {
  189. sources = [
  190. "gaia/gaia_auth_fetcher_unittest.cc",
  191. "gaia/gaia_auth_util_unittest.cc",
  192. "gaia/gaia_config_unittest.cc",
  193. "gaia/gaia_oauth_client_unittest.cc",
  194. "gaia/gaia_urls_unittest.cc",
  195. "gaia/google_service_auth_error_unittest.cc",
  196. "gaia/oauth2_access_token_fetcher_impl_unittest.cc",
  197. "gaia/oauth2_access_token_manager_unittest.cc",
  198. "gaia/oauth2_api_call_flow_unittest.cc",
  199. "gaia/oauth2_id_token_decoder_unittest.cc",
  200. "gaia/oauth2_mint_token_flow_unittest.cc",
  201. "gaia/oauth_multilogin_result_unittest.cc",
  202. "gaia/oauth_request_signer_unittest.cc",
  203. "google_api_keys_unittest.cc",
  204. "google_api_keys_unittest.h",
  205. ]
  206. configs += [ ":key_defines" ]
  207. deps = [
  208. ":google_apis",
  209. ":oauth2_mint_token_consent_result_proto",
  210. ":run_all_unittests",
  211. ":test_support",
  212. "//base",
  213. "//base/test:test_support",
  214. "//build:branding_buildflags",
  215. "//build:chromeos_buildflags",
  216. "//google_apis/calendar:calendar_unittests",
  217. "//google_apis/common:common_unittests",
  218. "//testing/gmock",
  219. "//testing/gtest",
  220. ]
  221. if (is_ios) {
  222. deps += [ ":google_apis_unittest_bundle_data" ]
  223. } else {
  224. data = [ "test/" ]
  225. }
  226. if (is_android) {
  227. deps += [ "//net/android:net_java" ]
  228. }
  229. if (is_fuchsia) {
  230. use_cfv1 = false
  231. additional_manifest_fragments =
  232. [ "//build/config/fuchsia/test/network.shard.test-cml" ]
  233. }
  234. if (enable_extensions) {
  235. deps += [ "//google_apis/drive:drive_unittests" ]
  236. }
  237. if (is_apple) {
  238. sources += [ "google_api_keys_mac_unittest.mm" ]
  239. deps += [ "//third_party/ocmock" ]
  240. }
  241. }
  242. bundle_data("google_apis_unittest_bundle_data") {
  243. testonly = true
  244. sources = [
  245. "test/data/calendar/event_self_response_statuses.json",
  246. "test/data/calendar/event_statuses.json",
  247. "test/data/calendar/events.json",
  248. "test/data/calendar/invalid_events.json",
  249. "test/data/gaia/all_base_urls.json",
  250. "test/data/gaia/all_urls.json",
  251. "test/data/gaia/api_keys.json",
  252. "test/data/gaia/bad_url.json",
  253. "test/data/gaia/bad_url_key.json",
  254. "test/data/gaia/bad_urls_key.json",
  255. "test/data/gaia/not_a_json.txt",
  256. "test/data/gaia/one_base_url.json",
  257. "test/data/gaia/one_url.json",
  258. ]
  259. outputs = [ "{{bundle_resources_dir}}/" +
  260. "{{source_root_relative_dir}}/{{source_file_part}}" ]
  261. }