Bug 1256730 - Move --with-*-keyfile options to python configure. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 09 Aug 2016 18:15:53 +0900
changeset 398545 da330599f99b2a821a561295640a5a06b97a9518
parent 398544 88313d0658beb9720f43e9310d2a48ebf0ffc93d
child 398546 a1c7bc22de8db9cc9d18ceb1e75e227ffc5fc6d1
push id25567
push userbmo:mh+mozilla@glandium.org
push dateTue, 09 Aug 2016 10:49:59 +0000
reviewerschmanchester
bugs1256730
milestone51.0a1
Bug 1256730 - Move --with-*-keyfile options to python configure. r?chmanchester
build/moz.configure/keyfiles.configure
build/moz.configure/old.configure
moz.configure
old-configure.in
new file mode 100644
--- /dev/null
+++ b/build/moz.configure/keyfiles.configure
@@ -0,0 +1,66 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+@template
+def keyfile(desc, help=None):
+    help = help or ('Use the secret key contained in the given keyfile '
+                    'for %s requests' % desc)
+    name = desc.lower().replace(' ', '-')
+    option('--with-%s-keyfile' % name, nargs=1, help=help)
+
+    @depends('--with-%s-keyfile' % name)
+    @checking('for the %s key file' % name, lambda x: bool(x))
+    @imports(_from='__builtin__', _import='open')
+    def keyfile(value):
+        if value:
+            try:
+                with open(value[0]) as fh:
+                    result = fh.read().strip()
+                    if result:
+                        return result
+            except:
+                pass
+        return 'no-%s-key' % name
+
+    return keyfile
+
+
+@template
+def simple_keyfile(desc):
+    set_config('MOZ_%s_KEY' % desc.upper().replace(' ', '_'),
+               keyfile(desc))
+
+
+@template
+def id_and_secret_keyfile(desc):
+    content = keyfile(desc, help='Use the client id and secret key contained '
+                                 'in the given keyfile for %s requests' % desc)
+
+    @depends(content)
+    def id_and_secret(value):
+        if value.startswith('no-') and value.endswith('-key'):
+            id = value[:-3] + 'clientid'
+            secret = value
+        else:
+            id, secret = value[0].split(' ', 1)
+        return namespace(
+            id=id,
+            secret=secret,
+        )
+
+    name = desc.upper().replace(' ', '_')
+    set_config('MOZ_%s_CLIENTID' % name, delayed_getattr(id_and_secret, 'id'))
+    set_config('MOZ_%s_KEY' % name, delayed_getattr(id_and_secret, 'secret'))
+
+
+simple_keyfile('Mozilla API')
+
+simple_keyfile('Google API')
+
+id_and_secret_keyfile('Bing API')
+
+simple_keyfile('Adjust SDK')
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -260,46 +260,42 @@ def old_configure_options(*options):
     '--enable-webrtc',
     '--enable-websms-backend',
     '--enable-webspeech',
     '--enable-webspeechtestbackend',
     '--enable-xul',
     '--enable-zipwriter',
     '--no-create',
     '--prefix',
-    '--with-adjust-sdk-keyfile',
     '--with-android-cxx-stl',
     '--with-android-distribution-directory',
     '--with-android-max-sdk',
     '--with-android-min-sdk',
     '--with-android-sdk',
     '--with-app-basename',
     '--with-app-name',
     '--with-arch',
-    '--with-bing-api-keyfile',
     '--with-branding',
     '--with-crashreporter-enable-percent',
     '--with-cross-lib',
     '--with-debug-label',
     '--with-default-mozilla-five-home',
     '--with-distribution-id',
     '--with-doc-include-dirs',
     '--with-doc-input-dirs',
     '--with-doc-output-dir',
     '--with-float-abi',
     '--with-fpu',
-    '--with-google-api-keyfile',
     '--with-intl-api',
     '--with-ios-sdk',
     '--with-jitreport-granularity',
     '--with-linux-headers',
     '--with-macbundlename-prefix',
     '--with-macos-private-frameworks',
     '--with-macos-sdk',
-    '--with-mozilla-api-keyfile',
     '--with-nspr-cflags',
     '--with-nspr-exec-prefix',
     '--with-nspr-libs',
     '--with-nspr-prefix',
     '--with-nss-exec-prefix',
     '--with-nss-prefix',
     '--with-pthreads',
     '--with-qemu-exe',
--- a/moz.configure
+++ b/moz.configure
@@ -88,16 +88,17 @@ set_define('GTEST_HAS_CLONE',
 js_option('--enable-debug',
           nargs='?',
           help='Enable building with developer debug info '
                '(using the given compiler flags).')
 
 add_old_configure_assignment('MOZ_DEBUG',
                              depends('--enable-debug')(lambda v: bool(v)))
 
+include('build/moz.configure/keyfiles.configure')
 include_when('build/moz.configure/toolchain.configure',
              when='--enable-compile-environment')
 include_when('build/moz.configure/memory.configure',
              when='--enable-compile-environment')
 include_when('build/moz.configure/headers.configure',
              when='--enable-compile-environment')
 include_when('build/moz.configure/warnings.configure',
              when='--enable-compile-environment')
--- a/old-configure.in
+++ b/old-configure.in
@@ -2476,56 +2476,16 @@ case "${target}" in
         NSS_DISABLE_DBM=1
         MOZ_THEME_FASTSTRIPE=1
         MOZ_TREE_FREETYPE=1
         MOZ_RAW=1
         ;;
 
 esac
 
-# Allow to specify a Mozilla API key file that contains the secret key to be
-# used for various Mozilla API requests.
-MOZ_ARG_WITH_STRING(mozilla-api-keyfile,
-[  --with-mozilla-api-keyfile=file   Use the secret key contained in the given keyfile for Mozilla API requests],
-  MOZ_MOZILLA_API_KEY=`cat $withval`)
-if test -z "$MOZ_MOZILLA_API_KEY"; then
-    MOZ_MOZILLA_API_KEY=no-mozilla-api-key
-fi
-AC_SUBST(MOZ_MOZILLA_API_KEY)
-
-# Allow to specify a Google API key file that contains the secret key to be
-# used for various Google API requests.
-MOZ_ARG_WITH_STRING(google-api-keyfile,
-[  --with-google-api-keyfile=file   Use the secret key contained in the given keyfile for Google API requests],
-  MOZ_GOOGLE_API_KEY=`cat $withval`)
-if test -z "$MOZ_GOOGLE_API_KEY"; then
-    MOZ_GOOGLE_API_KEY=no-google-api-key
-fi
-AC_SUBST(MOZ_GOOGLE_API_KEY)
-
-# Allow specifying a Bing API key file that contains the client ID and the
-# secret key to be used for the Bing Translation API requests.
-MOZ_ARG_WITH_STRING(bing-api-keyfile,
-[  --with-bing-api-keyfile=file   Use the client id and secret key contained in the given keyfile for Bing API requests],
- [MOZ_BING_API_CLIENTID=`cat $withval | cut -f 1 -d " "`
-  MOZ_BING_API_KEY=`cat $withval | cut -f 2 -d " "`])
-if test -z "$MOZ_BING_API_CLIENTID"; then
-    MOZ_BING_API_CLIENTID=no-bing-api-clientid
-    MOZ_BING_API_KEY=no-bing-api-key
-fi
-AC_SUBST(MOZ_BING_API_CLIENTID)
-AC_SUBST(MOZ_BING_API_KEY)
-
-# Allow specifying an Adjust SDK key file that contains the app token used for
-# Adjust SDK requests.
-MOZ_ARG_WITH_STRING(adjust-sdk-keyfile,
-[  --with-adjust-sdk-keyfile=file   Use the app token contained in the given keyfile for Adjust SDK requests],
-  MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN=`cat $withval`)
-AC_SUBST(MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN)
-
 # Optional Firefox for Android partner distribution directory.
 MOZ_ARG_WITH_STRING(android-distribution-directory,
 [  --with-android-distribution-directory=dir
                           Optional Firefox for Android partner distribution directory.],
   MOZ_ANDROID_DISTRIBUTION_DIRECTORY=$withval)
 
 if test -n "$MOZ_ANDROID_DISTRIBUTION_DIRECTORY"; then
   # A distribution directory must have an assets/distribution directory.