Bug 1256995 - Move --with-gradle to mobile/android/moz.configure. r=glandium
authorNick Alexander <nalexander@mozilla.com>
Thu, 17 Mar 2016 11:04:08 -0700
changeset 289766 1b70e9fe9db0c1829208283251e8edc308eee5f3
parent 289765 ecf81bf18bdf7939aa0e70e698c40dbcb9dcb7b4
child 289767 8ae2e73a7d903b1ba90cb5c77ad89a852ab7f733
push id18309
push usernalexander@mozilla.com
push dateTue, 22 Mar 2016 17:27:53 +0000
treeherderfx-team@45e593e317fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1256995
milestone48.0a1
Bug 1256995 - Move --with-gradle to mobile/android/moz.configure. r=glandium This also adds a GRADLE_FLAGS environment variable for use in automation. Manually tested. MozReview-Commit-ID: 8nDkqz2VnJn
build.gradle
build/moz.configure/init.configure
build/moz.configure/old.configure
mobile/android/gradle.configure
mobile/android/mach_commands.py
mobile/android/moz.configure
old-configure.in
--- a/build.gradle
+++ b/build.gradle
@@ -4,28 +4,32 @@ allprojects {
     // Expose the per-object-directory configuration to all projects.
     ext {
         mozconfig = gradle.mozconfig
         topsrcdir = gradle.mozconfig.topsrcdir
         topobjdir = gradle.mozconfig.topobjdir
     }
 
     repositories {
-        maven {
-            url gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY
+        if (gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY) {
+            maven {
+                url gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY
+            }
         }
     }
 }
 
 buildDir "${topobjdir}/gradle/build"
 
 buildscript {
     repositories {
-        maven {
-            url gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY
+        if (gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY) {
+            maven {
+                url gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY
+            }
         }
         // For android-sdk-manager SNAPSHOT releases.
         maven {
             url "file://${gradle.mozconfig.topsrcdir}/mobile/android/gradle/m2repo"
         }
     }
 
     dependencies {
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -250,21 +250,25 @@ def wanted_mozconfig_variables(help):
          'AUTOCONF',
          'AWK',
          'DISABLE_EXPORT_JS',
          'DISABLE_SHARED_JS',
          'DOXYGEN',
          'DSYMUTIL',
          'EXTERNAL_SOURCE_DIR',
          'GENISOIMAGE',
+         'GRADLE',
+         'GRADLE_FLAGS',
+         'GRADLE_MAVEN_REPOSITORY',
          'JS_STANDALONE',
          'L10NBASEDIR',
          'MOZILLABUILD',
          'MOZ_ARTIFACT_BUILDS',
          'MOZ_BUILD_APP',
+         'MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE',
          'MOZ_CALLGRIND',
          'MOZ_DMD',
          'MOZ_FMP4',
          'MOZ_INSTRUMENT_EVENT_LOOP',
          'MOZ_INSTRUMENTS',
          'MOZ_JPROF',
          'MOZ_PROFILING',
          'MOZ_USE_SYSTRACE',
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -318,17 +318,16 @@ def old_configure_options(*options):
     '--with-doc-include-dirs',
     '--with-doc-input-dirs',
     '--with-doc-output-dir',
     '--with-float-abi',
     '--with-fpu',
     '--with-gonk-toolchain-prefix',
     '--with-google-api-keyfile',
     '--with-google-oauth-api-keyfile',
-    '--with-gradle',
     '--with-intl-api',
     '--with-ios-sdk',
     '--with-java-bin-path',
     '--with-jitreport-granularity',
     '--with-linux-headers',
     '--with-macbundlename-prefix',
     '--with-macos-private-frameworks',
     '--with-macos-sdk',
new file mode 100644
--- /dev/null
+++ b/mobile/android/gradle.configure
@@ -0,0 +1,49 @@
+# -*- Mode: python; c-basic-offset: 4; 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/.
+
+# If --with-gradle is specified, build mobile/android with Gradle.  If no
+# Gradle binary is specified, or if --without-gradle is specified, use the in
+# tree Gradle wrapper.  The wrapper downloads and installs Gradle, which is
+# good for local developers but not good in automation.
+option('--with-gradle', nargs='?',
+       help='Enable building mobile/android with Gradle '
+            '(argument: location of binary or wrapper (gradle/gradlew))')
+
+@depends('--with-gradle', check_build_environment)
+def gradle(value, build_env):
+    if value:
+        set_config('MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE', '1')
+
+    gradle = value[0] if len(value) else \
+        os.path.join(build_env['TOPSRCDIR'], 'gradlew')
+
+    # TODO: verify that $GRADLE is executable.
+    if not os.path.isfile(gradle):
+        error('GRADLE must be executable: %s' % gradle)
+
+    set_config('GRADLE', gradle)
+
+    return gradle
+
+
+# Automation uses this to change log levels, not use the daemon, and use
+# offline mode.
+option(env='GRADLE_FLAGS', default='', help='Flags to pass to Gradle.')
+
+@depends('GRADLE_FLAGS')
+def gradle_flags(value):
+    set_config('GRADLE_FLAGS', value[0] if value else '')
+
+
+# Automation will set this to file:///path/to/local via the mozconfig.
+# Local developer default is jcenter.
+option(env='GRADLE_MAVEN_REPOSITORY', default='https://jcenter.bintray.com/',
+       help='Path to Maven repository containing Gradle dependencies.')
+
+@depends('GRADLE_MAVEN_REPOSITORY')
+def gradle_maven_repository(value):
+    if value:
+        set_config('GRADLE_MAVEN_REPOSITORY', value[0])
--- a/mobile/android/mach_commands.py
+++ b/mobile/android/mach_commands.py
@@ -10,16 +10,20 @@ import os
 
 import mozpack.path as mozpath
 
 from mozbuild.base import (
     MachCommandBase,
     MachCommandConditions as conditions,
 )
 
+from mozbuild.shellutil import (
+    split as shell_split,
+)
+
 from mach.decorators import (
     CommandArgument,
     CommandProvider,
     Command,
 )
 
 
 # NOTE python/mach/mach/commands/commandinfo.py references this function
@@ -58,26 +62,28 @@ class MachCommands(MachCommandBase):
         self.log_manager.terminal_handler.setLevel(logging.CRITICAL)
 
 
         # In automation, JAVA_HOME is set via mozconfig, which needs
         # to be specially handled in each mach command. This turns
         # $JAVA_HOME/bin/java into $JAVA_HOME.
         java_home = os.path.dirname(os.path.dirname(self.substs['JAVA']))
 
+        gradle_flags = shell_split(self.substs.get('GRADLE_FLAGS', ''))
+
         # We force the Gradle JVM to run with the UTF-8 encoding, since we
         # filter strings.xml, which is really UTF-8; the ellipsis character is
         # replaced with ??? in some encodings (including ASCII).  It's not yet
         # possible to filter with encodings in Gradle
         # (https://github.com/gradle/gradle/pull/520) and it's challenging to
         # do our filtering with Gradle's Ant support.  Moreover, all of the
         # Android tools expect UTF-8: see
         # http://tools.android.com/knownissues/encoding.  See
         # http://stackoverflow.com/a/21267635 for discussion of this approach.
-        return self.run_process([self.substs['GRADLE']] + args,
+        return self.run_process([self.substs['GRADLE']] + gradle_flags + args,
             append_env={
                 'GRADLE_OPTS': '-Dfile.encoding=utf-8',
                 'JAVA_HOME': java_home,
             },
             pass_thru=True, # Allow user to run gradle interactively.
             ensure_exit_code=False, # Don't throw on non-zero exit code.
             cwd=mozpath.join(self.topsrcdir))
 
--- a/mobile/android/moz.configure
+++ b/mobile/android/moz.configure
@@ -1,7 +1,8 @@
 # -*- Mode: python; c-basic-offset: 4; 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/.
 
 include('../../toolkit/moz.configure')
+include('gradle.configure')
--- a/old-configure.in
+++ b/old-configure.in
@@ -2808,17 +2808,16 @@ MOZ_PEERCONNECTION=
 MOZ_SRTP=
 MOZ_WEBRTC_SIGNALING=
 MOZ_WEBRTC_ASSERT_ALWAYS=1
 MOZ_WEBRTC_HARDWARE_AEC_NS=
 MOZ_SCTP=
 MOZ_ANDROID_OMX=
 MOZ_MEDIA_NAVIGATOR=
 MOZ_OMX_PLUGIN=
-MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE=
 MOZ_VPX_ERROR_CONCEALMENT=
 MOZ_WEBSPEECH=1
 MOZ_WEBSPEECH_MODELS=
 MOZ_WEBSPEECH_POCKETSPHINX=
 MOZ_WEBSPEECH_TEST_BACKEND=1
 VPX_USE_YASM=
 VPX_ASFLAGS=
 VPX_AS_CONVERSION=
@@ -4135,78 +4134,16 @@ if test -n "$MOZ_OMX_PLUGIN"; then
         dnl Only allow building OMX plugin on Gonk (B2G) or Android
         AC_DEFINE(MOZ_OMX_PLUGIN)
     else
         dnl fail if we're not building on Gonk or Android
         AC_MSG_ERROR([OMX media plugin can only be built on B2G or Android])
     fi
 fi
 
-dnl ========================================================
-dnl Gradle support
-dnl
-dnl If --with-gradle is specified, build mobile/android with Gradle.
-dnl
-dnl If no Gradle binary is specified, use the in tree Gradle wrapper.
-dnl The wrapper downloads and installs Gradle, which is good for local
-dnl developers but not good in automation.
-dnl ========================================================
-
-GRADLE=
-MOZ_ARG_WITH_STRING(gradle,
-[  --with-gradle=/path/to/bin/gradle
-                          Enable building mobile/android with Gradle (argument: location of binary or wrapper (gradle/gradlew))],
-    if test "$withval" = "no" ; then
-        dnl --without-gradle => use the wrapper in |mach gradle|, don't build
-        dnl with Gradle by default.
-        GRADLE=$srcdir/gradlew
-        MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE=
-    elif test "$withval" = "yes" ; then
-        dnl --with-gradle => use the wrapper in |mach gradle|, build with
-        dnl Gradle by default.
-        GRADLE=$srcdir/gradlew
-        MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE=1
-    else
-        dnl --with-gradle=/path/to/gradle => use the given binary in |mach
-        dnl gradle|, build with Gradle by default.
-        GRADLE=$withval
-        MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE=1
-    fi
-    ,
-    dnl No --with{out}-gradle => use the wrapper in |mach gradle|, don't build
-    dnl with Gradle by default.
-    GRADLE=$srcdir/gradlew
-    MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE=
-    )
-
-if test "$OS_TARGET" = Android -a x"$MOZ_WIDGET_TOOLKIT" != x"gonk" ; then
-    if test -z "$GRADLE" -o ! -x "$GRADLE" ; then
-        AC_MSG_ERROR([The program gradlew/gradle was not found.  Use --with-gradle=/path/to/bin/gradle}])
-    fi
-fi
-AC_SUBST(GRADLE)
-
-dnl Path to Maven repository containing Gradle dependencies.  Automation will
-dnl set this to file:///path/to/local via the mozconfig.  Local developer
-dnl default is jcenter.
-if test -z "$GRADLE_MAVEN_REPOSITORY" ; then
-    GRADLE_MAVEN_REPOSITORY=https://jcenter.bintray.com/
-fi
-AC_SUBST(GRADLE_MAVEN_REPOSITORY)
-
-if test -n "$MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE"; then
-    if test "$OS_TARGET" = "Android" -a x"$MOZ_WIDGET_TOOLKIT" != x"gonk"; then
-        dnl Only allow building mobile/android with Gradle.
-        AC_DEFINE(MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE)
-    else
-        dnl fail if we're not building mobile/android.
-        AC_MSG_ERROR([Can only build mobile/android with Gradle])
-    fi
-fi
-
 dnl system libvpx Support
 dnl ========================================================
 MOZ_ARG_WITH_BOOL(system-libvpx,
 [  --with-system-libvpx    Use system libvpx (located with pkgconfig)],
     MOZ_SYSTEM_LIBVPX=1)
 
 MOZ_LIBVPX_CFLAGS=
 MOZ_LIBVPX_LIBS=
@@ -7624,17 +7561,16 @@ AC_SUBST(WIN32_GUI_EXE_LDFLAGS)
 
 AC_SUBST(MOZ_VORBIS)
 AC_SUBST(MOZ_TREMOR)
 AC_SUBST(MOZ_FFVPX)
 AC_SUBST_LIST(FFVPX_ASFLAGS)
 AC_SUBST(MOZ_DIRECTSHOW)
 AC_SUBST(MOZ_ANDROID_OMX)
 AC_SUBST(MOZ_OMX_PLUGIN)
-AC_SUBST(MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE)
 AC_SUBST(MOZ_VPX_ERROR_CONCEALMENT)
 AC_SUBST(VPX_USE_YASM)
 AC_SUBST_LIST(VPX_ASFLAGS)
 AC_SUBST(VPX_AS_CONVERSION)
 AC_SUBST(VPX_X86_ASM)
 AC_SUBST(VPX_ARM_ASM)
 AC_SUBST(VPX_NEED_OBJ_INT_EXTRACT)
 AC_SUBST(MOZ_CODE_COVERAGE)