1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import org.yaml.snakeyaml.Yaml
13 classpath 'org.yaml:snakeyaml:1.23'
19 directory = new File(rootDir, '.build-cache')
20 removeUnusedEntriesAfterDays = 30
24 def setupProject(name, path, description) {
25 settings.include(":$name")
27 project(":$name").projectDir = new File(rootDir, path)
29 // project(...) gives us a skeleton project that we can't set ext.* on
30 gradle.beforeProject { project ->
31 // However, the "afterProject" listener iterates over every project and gives us the actual project
32 // So, once we filter for the project we care about, we can set whatever we want
33 if (project.name == name) {
34 project.ext.description = description
40 def buildconfig = yaml.load(new File(rootDir, '.buildconfig.yml').newInputStream())
41 buildconfig.projects.each { project ->
42 setupProject(project.key, project.value.path, project.value.description)
45 gradle.projectsLoaded { ->
46 String version = buildconfig.componentsVersion
48 if (gradle.rootProject.hasProperty("nightlyVersion")) {
49 version = gradle.rootProject.nightlyVersion
51 // To support local auto-publication workflow, we use a version prefix we wouldn't normally encounter.
52 if (gradle.rootProject.hasProperty("local")) {
55 // Wait until root project is "loaded" before we set "config"
56 // Note that since this is set on "rootProject.ext", it will be "in scope" during the evaluation of all projects'
57 // gradle files. This means that they can just access "config.<value>", and it'll function properly
58 gradle.rootProject.ext.config = new Config(version)
59 gradle.rootProject.ext.buildConfig = buildconfig
62 def runCmd(cmd, workingDir, successMessage) {
63 def proc = cmd.execute(null, new File(workingDir))
64 proc.consumeProcessOutput(System.out, System.err)
66 if (proc.exitValue() != 0) {
67 throw new GradleException("Process '${cmd}' finished with non-zero exit value ${proc.exitValue()}")
69 logger.lifecycle(successMessage)
73 //////////////////////////////////////////////////////////////////////////
74 // Local Development overrides
75 //////////////////////////////////////////////////////////////////////////
77 Properties localProperties = null;
78 String settingAppServicesPath = "autoPublish.application-services.dir"
79 String settingGleanPath = "substitutions.glean.dir";
81 if (file('local.properties').canRead()) {
82 localProperties = new Properties()
83 localProperties.load(file('local.properties').newDataInputStream())
84 logger.lifecycle('Local configuration: loaded local.properties')
86 logger.lifecycle('Local configuration: absent local.properties; proceeding as normal.')
89 if (localProperties != null) {
90 localProperties.each { prop ->
91 gradle.ext.set("localProperties.${prop.key}", prop.value)
94 String appServicesLocalPath = localProperties.getProperty(settingAppServicesPath);
96 if (appServicesLocalPath != null) {
97 logger.lifecycle("Enabling automatic publication of application-services from: $appServicesLocalPath")
98 def publishAppServicesCmd = ["./automation/publish_to_maven_local_if_modified.py"]
99 runCmd(publishAppServicesCmd, appServicesLocalPath, "Published application-services for local development.")
101 logger.lifecycle("Disabled auto-publication of application-services. Enable it by settings '$settingAppServicesPath' in local.properties")
104 String gleanLocalPath = localProperties.getProperty(settingGleanPath);
106 if (gleanLocalPath != null) {
107 logger.lifecycle("Local configuration: substituting glean module from path: $gleanLocalPath")
109 includeBuild(gleanLocalPath) {
110 dependencySubstitution {
111 substitute module('org.mozilla.telemetry:glean') with project(':glean')
112 substitute module('org.mozilla.telemetry:glean-forUnitTests') with project(':glean')
116 logger.lifecycle("Local configuration: glean substitution path missing. You may specify it via '$settingGleanPath' setting.")