Bug 1876335 - use GRADLE_MAVEN_REPOSITORIES in more places. r=owlish,geckoview-review...
[gecko.git] / mobile / android / gradle / mozconfig.gradle
blob005c2718c3265b495bf78e3d52c300668981ee4c
1 /* -*- Mode: Groovy; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 import groovy.json.JsonSlurper
8 // Loads the mach environment configurations into a gradle extension property.
10 apply from: file('./mach_env.gradle')
12 logger.lifecycle("mozconfig.gradle> Loading mach environment into a gradle extension property")
14 if (!ext.hasProperty("topsrcdir")) {
15     ext.topsrcdir = file(buildscript.getSourceFile()).getParentFile().getParentFile().getParentFile().getParentFile().absolutePath
18 def commandLine = ["${topsrcdir}/mach", "environment", "--format", "json", "--verbose"]
19 if (System.env.GRADLE_MACH_PYTHON) {
20     commandLine.addAll(0, [System.env.GRADLE_MACH_PYTHON])
21 } else if (System.properties["os.name"].contains("Windows")) {
22     commandLine.addAll(0, ["python"])
25 def proc = commandLine.execute(machEnv(topsrcdir), new File(topsrcdir))
26 def standardOutput = new ByteArrayOutputStream()
27 def standardError = new ByteArrayOutputStream()
28 proc.consumeProcessOutput(standardOutput, standardError)
29 proc.waitFor()
31 // Only show the output if something went wrong.
32 if (proc.exitValue() != 0) {
33     logger.info("mozconfig.gradle> Error running ./mach environment: \n\n"
34             + "Process '${commandLine}' finished with non-zero exit value ${proc.exitValue()}:\n\n"
35             + "stdout:\n"
36             + "${standardOutput.toString()}\n\n"
37             + "stderr:\n"
38             + "${standardError.toString()}")
39     throw new StopExecutionException(
40             "Could not run ./mach environment. Try running ./mach build first.")
43 def slurper = new JsonSlurper()
44 def json = slurper.parseText(standardOutput.toString())
46 if (json.substs.MOZ_BUILD_APP != 'mobile/android') {
47     throw new GradleException("Building with Gradle is only supported for Firefox for Android, i.e., MOZ_BUILD_APP == 'mobile/android'.")
50 // The Gradle instance is shared between settings.gradle and all the
51 // other build.gradle files (see
52 // http://forums.gradle.org/gradle/topics/define_extension_properties_from_settings_xml).
53 // We use this ext property to pass the per-object-directory mozconfig
54 // between scripts.  This lets us execute set-up code before we gradle
55 // tries to configure the project even once, and as a side benefit
56 // saves invoking |mach environment| multiple times.
57 gradle.ext.mozconfig = json
59 // Produced by `mach build`.  Bug 1543982: the mozconfig determined by `mach
60 // environment` above can be different because `mach build` itself sets certain
61 // critical environment variables including MOZ_OBJDIR, CC, and CXX.  We use
62 // this record to patch up the environment when we recursively invoke `mach
63 // build ...` commands from within Gradle.  This avoids invalidating configure
64 // based on the changed environment variables.
65 def orig = slurper.parse(new File(json.topobjdir, '.mozconfig.json'))
66 gradle.ext.mozconfig.orig_mozconfig = orig.mozconfig