From 1764740990d1c4e70494e513a2212782400853cf Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Thu, 9 May 2019 20:39:10 +0000 Subject: [PATCH] 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 --HG-- extra : moz-landing-system : lando --- build.gradle | 6 ++++++ mobile/android/gradle.py | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index bbd1b16e6d5d..ed0b7d3cc73b 100644 --- a/build.gradle +++ b/build.gradle @@ -107,6 +107,12 @@ class TaggedLogOutputStream extends org.apache.commons.exec.LogOutputStream { } 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") diff --git a/mobile/android/gradle.py b/mobile/android/gradle.py index 2c48c9cf0877..fa15c2263f83 100644 --- a/mobile/android/gradle.py +++ b/mobile/android/gradle.py @@ -5,6 +5,7 @@ from __future__ import print_function import buildconfig +import os import subprocess import sys @@ -30,7 +31,11 @@ def android(verb, *args): 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: