Bug 1247375 - Part 2: Add build system Gradle defines for Fennec. r=glandium
authorNick Alexander <nalexander@mozilla.com>
Wed, 10 Feb 2016 19:29:27 -0800
changeset 320831 ad70e483142cae1aa2b63450191deb044fd65f3b
parent 320830 e653c3abf85464619509ec911d56affee89a7700
child 320832 495bca66e5bb8aee6e03584d852f90b4214dc8b0
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1247375
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1247375 - Part 2: Add build system Gradle defines for Fennec. r=glandium Enable building with Gradle using --with-gradle. Configure the location of Gradle with --with-gradle=/path/to/gradle. For local developers, this is always the in tree Gradle wrapper, which downloads and installs the correct Gradle version automatically. In automation, this will be a version of Gradle fetched from tooltool. Configure the location to use to download Gradle Maven dependencies (including the Android-Gradle plugin) by setting GRADLE_MAVEN_REPOSITORY in your mozconfig. For local developers, this defaults to the jcenter repository. In automation, this will be an archived directory fetched from tooltool. Android-specific Maven dependencies are shipped as "extras" with the Android SDK, and should be found automatically by the Android-Gradle plugin. MozReview-Commit-ID: Hrkn88Vig5H
build.gradle
configure.in
mobile/android/mach_commands.py
--- a/build.gradle
+++ b/build.gradle
@@ -4,26 +4,29 @@ allprojects {
     // Expose the per-object-directory configuration to all projects.
     ext {
         mozconfig = gradle.mozconfig
         topsrcdir = gradle.mozconfig.topsrcdir
         topobjdir = gradle.mozconfig.topobjdir
     }
 
     repositories {
-        jcenter()
+        maven {
+            url gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY
+        }
     }
 }
 
 buildDir "${topobjdir}/gradle/build"
 
 buildscript {
     repositories {
-        jcenter()
-
+        maven {
+            url gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY
+        }
     }
 
     dependencies {
         classpath 'com.android.tools.build:gradle:1.3.0'
         classpath('com.stanfy.spoon:spoon-gradle-plugin:1.0.4') {
             // Without these, we get errors linting.
             exclude module: 'guava'
         }
--- a/configure.in
+++ b/configure.in
@@ -5369,22 +5369,66 @@ if test -n "$MOZ_OMX_PLUGIN"; then
         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 = Enable building mobile/android with Gradle
-dnl ========================================================
-MOZ_ARG_ENABLE_BOOL(gradle-mobile-android-builds,
-[  --enable-gradle-mobile-android-builds      Enable building mobile/android with Gradle],
-    MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE=1,
-    MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE=)
+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])
--- a/mobile/android/mach_commands.py
+++ b/mobile/android/mach_commands.py
@@ -52,17 +52,17 @@ class MachCommands(MachCommandBase):
     @Command('gradle', category='devenv',
         description='Run gradle.',
         conditions=[conditions.is_android])
     @CommandArgument('args', nargs=argparse.REMAINDER)
     def gradle(self, args):
         # Avoid logging the command
         self.log_manager.terminal_handler.setLevel(logging.CRITICAL)
 
-        return self.run_process(['./gradlew'] + args,
+        return self.run_process([self.substs['GRADLE']] + args,
             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))
 
     @Command('gradle-install', category='devenv',
         conditions=[REMOVED])
     def gradle_install(self):
         pass