Bug 1543982 - Part 2: Don't invoke `mach build ...` recursively. r=emilio
authorNick Alexander <nalexander@mozilla.com>
Thu, 09 May 2019 20:39:10 +0000
changeset 532143 17c76d081a9a78e20e52dbfe7b89f072e110c471
parent 532142 55b7de7850bebd08d85caeb719de711a32f71369
child 532144 d87eef05591be2cb8b211a2ca26ef41e7b042f99
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1543982
milestone68.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 1543982 - Part 2: Don't invoke `mach build ...` recursively. r=emilio This commit avoids moz.build tasks when we're already within `mach build`. This is belt-and-braces: from within `mach build`, we want the main moz.build dependency graph to arrange for the Gradle invocations to be in the right state. It's only in other situations, like `mach android ...` or invocation from Android Studio, that we want Gradle to arrange to be in the right state vis. moz.build. Differential Revision: https://phabricator.services.mozilla.com/D30426
build.gradle
mobile/android/gradle.py
--- a/build.gradle
+++ b/build.gradle
@@ -102,16 +102,22 @@ class TaggedLogOutputStream extends org.
     }
 
     void processLine(String line, int level) {
         logger.lifecycle("${this.tag} ${line}")
     }
 }
 
 ext.geckoBinariesOnlyIf = { task ->
+    // Never when Gradle was invoked within `mach build`.
+    if ('1' == System.env.GRADLE_INVOKED_WITHIN_MACH_BUILD) {
+        rootProject.logger.lifecycle("Skipping task ${task.path} because: within `mach build`")
+        return false
+    }
+
     // Never for official builds.
     if (mozconfig.substs.MOZILLA_OFFICIAL) {
         rootProject.logger.lifecycle("Skipping task ${task.path} because: MOZILLA_OFFICIAL")
         return false
     }
 
     // Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale.  This
     // causes the
--- a/mobile/android/gradle.py
+++ b/mobile/android/gradle.py
@@ -1,15 +1,16 @@
 # 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/.
 
 from __future__ import print_function
 
 import buildconfig
+import os
 import subprocess
 import sys
 
 from mozbuild.util import (
     ensureParentDir,
     lock_file,
 )
 import mozpack.path as mozpath
@@ -25,17 +26,21 @@ def android(verb, *args):
     try:
         cmd = [
             sys.executable,
             mozpath.join(buildconfig.topsrcdir, 'mach'),
             'android',
             verb,
         ]
         cmd.extend(args)
-        subprocess.check_call(cmd)
+        env = dict(os.environ)
+        # Confusingly, `MACH` is set only within `mach build`.
+        if env.get('MACH'):
+            env['GRADLE_INVOKED_WITHIN_MACH_BUILD'] = '1'
+        subprocess.check_call(cmd, env=env)
 
         return 0
     finally:
         del lock_instance
 
 
 def assemble_app(dummy_output_file, *inputs):
     return android('assemble-app')