Bug 1955358 - Allow Android Studio to read from local mozconfig. r=geckoview-reviewers,saschanaz,nalexander,ohall

Differential Revision: https://phabricator.services.mozilla.com/D242463
This commit is contained in:
adhingra
2025-03-24 20:24:42 +00:00
parent 4db9267410
commit c14b256b81
3 changed files with 20 additions and 17 deletions

View File

@@ -13,13 +13,12 @@ ext.machEnv = { topsrcdir ->
} }
def localMozconfig = localProperties.getProperty("mozilla-central.mozconfig") def localMozconfig = localProperties.getProperty("mozilla-central.mozconfig")
def env = new HashMap(System.env)
def env = System.env.collect { k, v -> "${k}=${v}" }
if (localMozconfig) { if (localMozconfig) {
def envMozconfig = System.env.get('FOUND_MOZCONFIG') def envMozconfig = System.env.get('FOUND_MOZCONFIG')
if (!envMozconfig || localMozconfig == envMozconfig) { if (!envMozconfig || localMozconfig == envMozconfig) {
logger.lifecycle("settings.gradle> Setting mozconfig from local.properties: ${localMozconfig}") logger.lifecycle("settings.gradle> Setting mozconfig from local.properties: ${localMozconfig}")
env << "MOZCONFIG=${localMozconfig}" env.MOZCONFIG = localMozconfig
} else { } else {
logger.lifecycle("settings.gradle> Preferring mozconfig set in mach environment to mozconfig set in local.properties: ${envMozconfig}") logger.lifecycle("settings.gradle> Preferring mozconfig set in mach environment to mozconfig set in local.properties: ${envMozconfig}")
} }

View File

@@ -23,7 +23,9 @@ if (System.env.GRADLE_MACH_PYTHON) {
} }
def proc = providers.exec { def proc = providers.exec {
commandLine(command) workingDir = new File(topsrcdir)
environment = machEnv(topsrcdir)
commandLine = command
ignoreExitValue = true ignoreExitValue = true
} }

View File

@@ -49,24 +49,26 @@ def loadMozconfig() {
// Cribbed from https://hg.mozilla.org/mozilla-central/file/tip/settings.gradle. When run in // 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 // topobjdir, `mach environment` correctly finds the mozconfig corresponding to that object
// directory. // directory.
def commandLine = ["${topsrcdir}/mach", "environment", "--format", "json", "--verbose"] def command = ["${topsrcdir}/mach", "environment", "--format", "json", "--verbose"]
def proc = commandLine.execute( def proc = providers.exec {
machEnv(topsrcdir), workingDir = new File(ext.has('topobjdir') ? ext.get('topobjdir') : topsrcdir)
new File(ext.has('topobjdir') ? ext.get('topobjdir') : topsrcdir)) environment = machEnv(topsrcdir)
def standardOutput = new ByteArrayOutputStream() commandLine = command
def standardError = new ByteArrayOutputStream() ignoreExitValue = true
proc.consumeProcessOutput(standardOutput, standardError) }
proc.waitFor() 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. // Only show the output if something went wrong.
if (proc.exitValue() != 0) { if (result != 0) {
throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${proc.exitValue()}:\n\n" throw new GradleException("Process '${command}' finished with non-zero exit value ${result}:\n\n"
+ "stdout:\n${standardOutput.toString()}\n\n" + "stdout:\n${standardOutput}\n\n"
+ "stderr:\n${standardError.toString()}") + "stderr:\n${standardError}")
} }
def slurper = new JsonSlurper() def slurper = new JsonSlurper()
def mozconfig = slurper.parseText(standardOutput.toString()) def mozconfig = slurper.parseText(standardOutput)
if (topsrcdir != mozconfig.topsrcdir) { if (topsrcdir != mozconfig.topsrcdir) {
throw new GradleException("Specified topsrcdir ('${topsrcdir}') is not mozconfig topsrcdir ('${mozconfig.topsrcdir}')") throw new GradleException("Specified topsrcdir ('${topsrcdir}') is not mozconfig topsrcdir ('${mozconfig.topsrcdir}')")