fixup! [M108 Migration][API] Bring up autofill
[platform/framework/web/chromium-efl.git] / google_apis / BUILD.gn
1 # Copyright 2014 The Chromium Authors
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import("//build/buildflag_header.gni")
6 import("//build/config/chrome_build.gni")
7 import("//build/config/features.gni")
8 import("//extensions/buildflags/buildflags.gni")
9 import("//testing/test.gni")
10 import("//third_party/protobuf/proto_library.gni")
11
12 declare_args() {
13   # Set the variable 'use_official_google_api_keys' to true
14   # to use the Google-internal file containing official API keys
15   # even in a developer build.  Setting this variable explicitly to
16   # true will cause the build to fail if the internal file is missing.
17   #
18   # Set the variable to false to not use the internal file, even for
19   # Chrome-branded builds or when it exists in your checkout.
20   #
21   # Leave it set to "" to have the variable implicitly set to true for
22   # Chrome-branded builds or if
23   # //src/google_apis/internal/google_chrome_api_keys.h is present and false
24   # otherwise.
25   # This does not apply to iOS builds, which use different mechanisms and always
26   # evaluate to use_official_google_api_keys=false.
27   # See https://crbug.com/1183709.
28   use_official_google_api_keys = ""
29
30   # Set these to bake the specified API keys and OAuth client
31   # IDs/secrets into your build.
32   #
33   # If you create a build without values baked in, you can instead
34   # set environment variables to provide the keys at runtime (see
35   # src/google_apis/google_api_keys.h for details).  Features that
36   # require server-side APIs may fail to work if no keys are
37   # provided.
38   #
39   # Note that if `use_official_google_api_keys` has been set to true
40   # (explicitly or implicitly), these values will be ignored and the official
41   # keys will be used instead.
42   google_api_key = ""
43
44   # See google_api_key.
45   google_default_client_id = ""
46
47   # See google_api_key.
48   google_default_client_secret = ""
49 }
50
51 if (use_official_google_api_keys == "") {
52   # No override set. Determine the default behavior.
53   if (is_chrome_branded) {
54     # Chrome-branded builds default to behaving as if
55     #`use_official_google_api_keys` was explicitly set to true and will fail to
56     # build if the file is missing.
57     use_official_google_api_keys = true
58
59     # TODO(crbug.com/1294931): Remove this override when fixing the issue.
60     if (is_fuchsia) {
61       use_official_google_api_keys = false
62     }
63   } else {
64     # Check if the key file exists.
65     check_internal_result =
66         exec_script("build/check_internal.py",
67                     [ rebase_path("internal/google_chrome_api_keys.h",
68                                   root_build_dir) ],
69                     "value")
70     use_official_google_api_keys = check_internal_result == 1
71   }
72 }
73
74 # Official API keys should always be used for Chrome-branded builds except on
75 # iOS (see https://crbug.com/1183709) and Fuchsia (see the description of
76 # https://crbug.com/1171510 for background).
77 assert(
78     use_official_google_api_keys || !is_chrome_branded || is_ios || is_fuchsia)
79
80 declare_args() {
81   # Whether the SetAPIKey() method is defined.
82   # iOS and Fuchsia builds that do not use the built-in key use this.
83   support_external_google_api_key =
84       is_ios || (is_fuchsia && !use_official_google_api_keys)
85 }
86
87 # internal:generate_metrics_key_header must be a deps when
88 # USE_OFFICIAL_GOOGLE_API_KEYS` is defined. Use this variable for both.
89 # On iOS, Chrome branding had been overriding use_official_google_api_keys.
90 # TODO(crbug.com/1362160): Fix this logic on iOS. Can this variable be replaced
91 # with just use_official_google_api_keys?
92 _use_official_google_keys_and_generate_metrics_key_header =
93     use_official_google_api_keys || (is_ios && is_chrome_branded)
94
95 buildflag_header("buildflags") {
96   header = "buildflags.h"
97   flags = [ "SUPPORT_EXTERNAL_GOOGLE_API_KEY=$support_external_google_api_key" ]
98 }
99
100 config("key_defines") {
101   defines = []
102
103   if (_use_official_google_keys_and_generate_metrics_key_header) {
104     defines += [ "USE_OFFICIAL_GOOGLE_API_KEYS=1" ]
105   }
106   if (google_api_key != "") {
107     defines += [ "GOOGLE_API_KEY=\"$google_api_key\"" ]
108   }
109   if (google_default_client_id != "") {
110     defines += [ "GOOGLE_DEFAULT_CLIENT_ID=\"$google_default_client_id\"" ]
111   }
112   if (google_default_client_secret != "") {
113     defines +=
114         [ "GOOGLE_DEFAULT_CLIENT_SECRET=\"$google_default_client_secret\"" ]
115   }
116 }
117
118 # Variables:
119 #   deps: Extra dependencies
120 template("google_apis_tmpl") {
121   source_set(target_name) {
122     sources = [
123       "gaia/core_account_id.cc",
124       "gaia/core_account_id.h",
125       "gaia/gaia_access_token_fetcher.cc",
126       "gaia/gaia_access_token_fetcher.h",
127       "gaia/gaia_auth_consumer.cc",
128       "gaia/gaia_auth_consumer.h",
129       "gaia/gaia_auth_fetcher.cc",
130       "gaia/gaia_auth_fetcher.h",
131       "gaia/gaia_auth_util.cc",
132       "gaia/gaia_auth_util.h",
133       "gaia/gaia_config.cc",
134       "gaia/gaia_config.h",
135       "gaia/gaia_constants.cc",
136       "gaia/gaia_constants.h",
137       "gaia/gaia_oauth_client.cc",
138       "gaia/gaia_oauth_client.h",
139       "gaia/gaia_switches.cc",
140       "gaia/gaia_switches.h",
141       "gaia/gaia_urls.cc",
142       "gaia/gaia_urls.h",
143       "gaia/google_service_auth_error.cc",
144       "gaia/google_service_auth_error.h",
145       "gaia/oauth2_access_token_consumer.cc",
146       "gaia/oauth2_access_token_consumer.h",
147       "gaia/oauth2_access_token_fetcher.cc",
148       "gaia/oauth2_access_token_fetcher.h",
149       "gaia/oauth2_access_token_fetcher_immediate_error.cc",
150       "gaia/oauth2_access_token_fetcher_immediate_error.h",
151       "gaia/oauth2_access_token_fetcher_impl.cc",
152       "gaia/oauth2_access_token_fetcher_impl.h",
153       "gaia/oauth2_access_token_manager.cc",
154       "gaia/oauth2_access_token_manager.h",
155       "gaia/oauth2_api_call_flow.cc",
156       "gaia/oauth2_api_call_flow.h",
157       "gaia/oauth2_id_token_decoder.cc",
158       "gaia/oauth2_id_token_decoder.h",
159       "gaia/oauth2_mint_token_flow.cc",
160       "gaia/oauth2_mint_token_flow.h",
161       "gaia/oauth_multilogin_result.cc",
162       "gaia/oauth_multilogin_result.h",
163       "gaia/oauth_request_signer.cc",
164       "gaia/oauth_request_signer.h",
165       "google_api_keys.cc",
166       "google_api_keys.h",
167     ]
168
169     configs += [ ":key_defines" ]
170
171     public_deps = [ ":buildflags" ]
172
173     deps = [
174       ":oauth2_mint_token_consent_result_proto",
175       "//base",
176       "//base/third_party/dynamic_annotations",
177       "//build:branding_buildflags",
178       "//build:chromeos_buildflags",
179       "//crypto",
180       "//mojo/public/cpp/bindings:struct_traits",
181       "//services/network/public/cpp",
182     ]
183
184     if (_use_official_google_keys_and_generate_metrics_key_header) {
185       deps += [ "internal:generate_metrics_key_header" ]
186     }
187
188     if (defined(invoker.deps)) {
189       deps += invoker.deps
190     }
191
192     if (is_apple) {
193       sources += [
194         "google_api_keys_mac.h",
195         "google_api_keys_mac.mm",
196       ]
197
198       frameworks = [ "Foundation.framework" ]
199     }
200   }
201 }
202
203 google_apis_tmpl("google_apis") {
204   deps = [
205     "//net",
206     "//services/network/public/cpp",
207     "//services/network/public/mojom",
208   ]
209 }
210
211 proto_library("oauth2_mint_token_consent_result_proto") {
212   sources = [ "gaia/oauth2_mint_token_consent_result.proto" ]
213 }
214
215 static_library("test_support") {
216   testonly = true
217   sources = [
218     "gaia/core_account_id_for_testing.cc",
219     "gaia/fake_gaia.cc",
220     "gaia/fake_gaia.h",
221     "gaia/fake_oauth2_access_token_manager.cc",
222     "gaia/fake_oauth2_access_token_manager.h",
223     "gaia/oauth2_access_token_manager_test_util.cc",
224     "gaia/oauth2_access_token_manager_test_util.h",
225   ]
226
227   public_deps = [
228     ":google_apis",
229     "//base",
230     "//base/test:test_support",
231     "//net:test_support",
232     "//services/network:network_service",
233     "//services/network:test_support",
234     "//services/network/public/cpp",
235   ]
236 }
237
238 source_set("run_all_unittests") {
239   testonly = true
240   sources = [ "run_all_unittests.cc" ]
241
242   deps = [
243     "//base/test:test_support",
244     "//mojo/core/embedder",
245   ]
246 }
247
248 test("google_apis_unittests") {
249   sources = [
250     "gaia/gaia_auth_fetcher_unittest.cc",
251     "gaia/gaia_auth_util_unittest.cc",
252     "gaia/gaia_config_unittest.cc",
253     "gaia/gaia_oauth_client_unittest.cc",
254     "gaia/gaia_urls_unittest.cc",
255     "gaia/google_service_auth_error_unittest.cc",
256     "gaia/oauth2_access_token_fetcher_impl_unittest.cc",
257     "gaia/oauth2_access_token_manager_unittest.cc",
258     "gaia/oauth2_api_call_flow_unittest.cc",
259     "gaia/oauth2_id_token_decoder_unittest.cc",
260     "gaia/oauth2_mint_token_flow_unittest.cc",
261     "gaia/oauth_multilogin_result_unittest.cc",
262     "gaia/oauth_request_signer_unittest.cc",
263     "google_api_keys_unittest.cc",
264     "google_api_keys_unittest.h",
265   ]
266
267   configs += [ ":key_defines" ]
268
269   deps = [
270     ":google_apis",
271     ":oauth2_mint_token_consent_result_proto",
272     ":run_all_unittests",
273     ":test_support",
274     "//base",
275     "//base/test:test_support",
276     "//build:branding_buildflags",
277     "//build:chromeos_buildflags",
278     "//google_apis/calendar:calendar_unittests",
279     "//google_apis/common:common_unittests",
280     "//testing/gmock",
281     "//testing/gtest",
282   ]
283
284   if (is_ios) {
285     deps += [ ":google_apis_unittest_bundle_data" ]
286   } else {
287     data = [ "test/" ]
288   }
289
290   if (is_android) {
291     deps += [ "//net/android:net_java" ]
292   }
293
294   if (is_fuchsia) {
295     additional_manifest_fragments =
296         [ "//build/config/fuchsia/test/network.shard.test-cml" ]
297   }
298
299   if (enable_extensions) {
300     deps += [ "//google_apis/drive:drive_unittests" ]
301   }
302
303   if (is_apple) {
304     sources += [ "google_api_keys_mac_unittest.mm" ]
305
306     deps += [ "//third_party/ocmock" ]
307   }
308 }
309
310 bundle_data("google_apis_unittest_bundle_data") {
311   testonly = true
312   sources = [
313     "test/data/calendar/event_self_response_statuses.json",
314     "test/data/calendar/event_statuses.json",
315     "test/data/calendar/events.json",
316     "test/data/calendar/invalid_events.json",
317     "test/data/gaia/all_base_urls.json",
318     "test/data/gaia/all_urls.json",
319     "test/data/gaia/api_keys.json",
320     "test/data/gaia/bad_url.json",
321     "test/data/gaia/bad_url_key.json",
322     "test/data/gaia/bad_urls_key.json",
323     "test/data/gaia/not_a_json.txt",
324     "test/data/gaia/one_base_url.json",
325     "test/data/gaia/one_url.json",
326   ]
327   outputs = [ "{{bundle_resources_dir}}/" +
328               "{{source_root_relative_dir}}/{{source_file_part}}" ]
329 }