Skip to content

Commit 2b11365

Browse files
author
joi@chromium.org
committed
Auto-detect whether internal keys should be used.
Allow overriding to explicitly use or not use internal keys, regardless of what is auto-detected. Fix a bug in the implementation, where the default value was not being used for unset tokens. BUG=145584 Review URL: https://codereview.chromium.org/10933126 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157130 0039d316-1c4b-4281-b951-d872f2087c98
1 parent 72a911a commit 2b11365

File tree

3 files changed

+93
-25
lines changed

3 files changed

+93
-25
lines changed

build/common.gypi

+47-18
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,40 @@
547547
'use_system_libjpeg%': '<(android_build_type)',
548548
}],
549549
],
550+
551+
# Set this to 1 to use the Google-internal file containing
552+
# official API keys for Google Chrome even in a developer build.
553+
# Setting this variable explicitly to 1 will cause your build to
554+
# fail if the internal file is missing.
555+
#
556+
# Set this to 0 to not use the internal file, even when it
557+
# exists in your checkout.
558+
#
559+
# Leave set to 2 to have this variable implicitly set to 1 if
560+
# you have src/google_apis/internal/google_chrome_api_keys.h in
561+
# your checkout, and implicitly set to 0 if not.
562+
#
563+
# Note that official builds always behave as if this variable
564+
# was explicitly set to 1, i.e. they always use official keys,
565+
# and will fail to build if the internal file is missing.
566+
'use_official_google_api_keys%': 2,
567+
568+
# Set these to bake the specified API keys and OAuth client
569+
# IDs/secrets into your build.
570+
#
571+
# If you create a build without values baked in, you can instead
572+
# set environment variables to provide the keys at runtime (see
573+
# src/google_apis/google_api_keys.h for details). Features that
574+
# require server-side APIs may fail to work if no keys are
575+
# provided.
576+
#
577+
# Note that if you are building an official build or if
578+
# use_official_google_api_keys has been set to 1 (explicitly or
579+
# implicitly), these values will be ignored and the official
580+
# keys will be used instead.
581+
'google_api_key%': '',
582+
'google_default_client_id%': '',
583+
'google_default_client_secret%': '',
550584
},
551585

552586
# Copy conditionally-set variables out one scope.
@@ -629,6 +663,10 @@
629663
'use_libjpeg_turbo%': '<(use_libjpeg_turbo)',
630664
'use_system_libjpeg%': '<(use_system_libjpeg)',
631665
'android_build_type%': '<(android_build_type)',
666+
'use_official_google_api_keys%': '<(use_official_google_api_keys)',
667+
'google_api_key%': '<(google_api_key)',
668+
'google_default_client_id%': '<(google_default_client_id)',
669+
'google_default_client_secret%': '<(google_default_client_secret)',
632670

633671
# Use system yasm instead of bundled one.
634672
'use_system_yasm%': 0,
@@ -891,24 +929,6 @@
891929
'windows_sdk_default_path': '<(DEPTH)/third_party/platformsdk_win8/files',
892930
'directx_sdk_default_path': '<(DEPTH)/third_party/directxsdk/files',
893931

894-
# Set these to bake API keys and OAuth client IDs/secrets into
895-
# your build. If they are not baked in, you can instead set
896-
# environment variables to provide the keys at runtime (see
897-
# src/google_apis/google_api_keys.h for details). Features that
898-
# require server-side APIs may fail to work if no keys are
899-
# provided.
900-
#
901-
# Note that if you are building an official build or if you set
902-
# use_official_google_api_keys to 1, these values will be ignored
903-
# and the official keys will be used instead.
904-
'google_api_key%': '',
905-
'google_default_client_id%': '',
906-
'google_default_client_secret%': '',
907-
908-
# Set this to 1 to use the Google-internal file containing
909-
# official API keys for Google Chrome even in a developer build.
910-
'use_official_google_api_keys%': 0,
911-
912932
'conditions': [
913933
['OS=="win" and "<!(python <(DEPTH)/build/dir_exists.py <(windows_sdk_default_path))"=="True"', {
914934
'windows_sdk_path%': '<(windows_sdk_default_path)',
@@ -920,6 +940,15 @@
920940
}, {
921941
'directx_sdk_path%': '$(DXSDK_DIR)',
922942
}],
943+
# If use_official_google_api_keys is already set (to 0 or 1), we
944+
# do none of the implicit checking. If it is set to 1 and the
945+
# internal keys file is missing, the build will fail at compile
946+
# time. If it is set to 0 and keys are not provided by other
947+
# means, a warning will be printed at compile time.
948+
['use_official_google_api_keys==2', {
949+
'use_official_google_api_keys%':
950+
'<!(python <(DEPTH)/google_apis/build/check_internal.py <(DEPTH)/google_apis/internal/google_chrome_api_keys.h)',
951+
}],
923952
['os_posix==1 and OS!="mac" and OS!="ios"', {
924953
# Figure out the python architecture to decide if we build pyauto.
925954
'python_arch%': '<!(<(DEPTH)/build/linux/python_arch.sh <(sysroot)/usr/<(system_libdir)/libpython<(python_ver).so.1.0)',

google_apis/build/check_internal.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
"""google_api's auto-internal gyp integration.
7+
8+
Takes one argument, a path. Prints 1 if the path exists, 0 if not.
9+
"""
10+
11+
12+
import os
13+
import sys
14+
15+
16+
if __name__ == '__main__':
17+
if os.path.exists(sys.argv[1]):
18+
print 1
19+
else:
20+
print 0

google_apis/google_api_keys.cc

+26-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@
1515
#include "google_apis/internal/google_chrome_api_keys.h"
1616
#endif
1717

18+
// TODO(joi): Can we enable this warning without having it treated as
19+
// an error? We don't want to fail builds, just warn, but all warnings
20+
// from the preprocessor are currently treated as errors, at least in
21+
// Linux builds.
22+
#if 0
23+
#if !defined(GOOGLE_API_KEY) && ( \
24+
(!defined(GOOGLE_DEFAULT_CLIENT_ID) && \
25+
!defined(GOOGLE_DEFAULT_CLIENT_SECRET)) \
26+
|| \
27+
(!defined(GOOGLE_CLIENT_ID_MAIN) && \
28+
!defined(GOOGLE_CLIENT_SECRET_MAIN)))
29+
#warning You have not specified API keys; some features may not work.
30+
#warning See www.chromium.org/developers/how-tos/api-keys for details.
31+
#endif // (API keys unset)
32+
#endif // 0
33+
1834
// Used to indicate an unset key/id/secret. This works better with
1935
// various unit tests than leaving the token empty.
2036
#define DUMMY_API_TOKEN "dummytoken"
@@ -196,15 +212,18 @@ class APIKeyCache {
196212
<< " with value " << key_value << " from command-line switch.";
197213
}
198214

199-
if (key_value.size() == 0) {
215+
if (key_value == DUMMY_API_TOKEN) {
200216
#if defined(GOOGLE_CHROME_BUILD)
201-
// No key should be empty in an official build, except the
202-
// default keys themselves, which will have an empty default.
203-
CHECK(default_if_unset.size() == 0);
217+
// No key should be unset in an official build except the
218+
// GOOGLE_DEFAULT_* keys. The default keys don't trigger this
219+
// check as their "unset" value is not DUMMY_API_TOKEN.
220+
CHECK(false);
204221
#endif
205-
LOG(INFO) << "Using default value \"" << default_if_unset
206-
<< "\" for API key " << environment_variable_name;
207-
key_value = default_if_unset;
222+
if (default_if_unset.size() > 0) {
223+
LOG(INFO) << "Using default value \"" << default_if_unset
224+
<< "\" for API key " << environment_variable_name;
225+
key_value = default_if_unset;
226+
}
208227
}
209228

210229
// This should remain a debug-only log.

0 commit comments

Comments
 (0)