From c14b256b81d6ea32f66f1bf7e5ec7d077305e348 Mon Sep 17 00:00:00 2001 From: adhingra Date: Mon, 24 Mar 2025 20:24:42 +0000 Subject: [PATCH] Bug 1955358 - Allow Android Studio to read from local mozconfig. r=geckoview-reviewers,saschanaz,nalexander,ohall Differential Revision: https://phabricator.services.mozilla.com/D242463 --- mobile/android/gradle/mach_env.gradle | 5 ++--- mobile/android/gradle/mozconfig.gradle | 4 +++- substitute-local-geckoview.gradle | 28 ++++++++++++++------------ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/mobile/android/gradle/mach_env.gradle b/mobile/android/gradle/mach_env.gradle index 560d7dac225c..5c0a9c460560 100644 --- a/mobile/android/gradle/mach_env.gradle +++ b/mobile/android/gradle/mach_env.gradle @@ -13,13 +13,12 @@ ext.machEnv = { topsrcdir -> } def localMozconfig = localProperties.getProperty("mozilla-central.mozconfig") - - def env = System.env.collect { k, v -> "${k}=${v}" } + def env = new HashMap(System.env) if (localMozconfig) { def envMozconfig = System.env.get('FOUND_MOZCONFIG') if (!envMozconfig || localMozconfig == envMozconfig) { logger.lifecycle("settings.gradle> Setting mozconfig from local.properties: ${localMozconfig}") - env << "MOZCONFIG=${localMozconfig}" + env.MOZCONFIG = localMozconfig } else { logger.lifecycle("settings.gradle> Preferring mozconfig set in mach environment to mozconfig set in local.properties: ${envMozconfig}") } diff --git a/mobile/android/gradle/mozconfig.gradle b/mobile/android/gradle/mozconfig.gradle index 6f25bd2a05f9..2ecb384d27bf 100644 --- a/mobile/android/gradle/mozconfig.gradle +++ b/mobile/android/gradle/mozconfig.gradle @@ -23,7 +23,9 @@ if (System.env.GRADLE_MACH_PYTHON) { } def proc = providers.exec { - commandLine(command) + workingDir = new File(topsrcdir) + environment = machEnv(topsrcdir) + commandLine = command ignoreExitValue = true } diff --git a/substitute-local-geckoview.gradle b/substitute-local-geckoview.gradle index a32dc5ae8a05..8e38fa104b8d 100644 --- a/substitute-local-geckoview.gradle +++ b/substitute-local-geckoview.gradle @@ -49,24 +49,26 @@ def loadMozconfig() { // Cribbed from https://hg.mozilla.org/mozilla-central/file/tip/settings.gradle. When run in // topobjdir, `mach environment` correctly finds the mozconfig corresponding to that object // directory. - def commandLine = ["${topsrcdir}/mach", "environment", "--format", "json", "--verbose"] - def proc = commandLine.execute( - machEnv(topsrcdir), - new File(ext.has('topobjdir') ? ext.get('topobjdir') : topsrcdir)) - def standardOutput = new ByteArrayOutputStream() - def standardError = new ByteArrayOutputStream() - proc.consumeProcessOutput(standardOutput, standardError) - proc.waitFor() + def command = ["${topsrcdir}/mach", "environment", "--format", "json", "--verbose"] + def proc = providers.exec { + workingDir = new File(ext.has('topobjdir') ? ext.get('topobjdir') : topsrcdir) + environment = machEnv(topsrcdir) + commandLine = command + ignoreExitValue = true + } + def result = proc.result.get().exitValue + def standardOutput = proc.standardOutput.asText.get() + def standardError = proc.standardError.asText.get() // Only show the output if something went wrong. - if (proc.exitValue() != 0) { - throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${proc.exitValue()}:\n\n" - + "stdout:\n${standardOutput.toString()}\n\n" - + "stderr:\n${standardError.toString()}") + if (result != 0) { + throw new GradleException("Process '${command}' finished with non-zero exit value ${result}:\n\n" + + "stdout:\n${standardOutput}\n\n" + + "stderr:\n${standardError}") } def slurper = new JsonSlurper() - def mozconfig = slurper.parseText(standardOutput.toString()) + def mozconfig = slurper.parseText(standardOutput) if (topsrcdir != mozconfig.topsrcdir) { throw new GradleException("Specified topsrcdir ('${topsrcdir}') is not mozconfig topsrcdir ('${mozconfig.topsrcdir}')")