forked from mozilla-mobile/android-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.gradle
124 lines (104 loc) · 4.77 KB
/
settings.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import org.yaml.snakeyaml.Yaml
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.yaml:snakeyaml:1.23'
}
}
buildCache {
local {
directory = new File(rootDir, '.build-cache')
removeUnusedEntriesAfterDays = 30
}
}
def setupProject(name, path, description) {
settings.include(":$name")
project(":$name").projectDir = new File(rootDir, path)
// project(...) gives us a skeleton project that we can't set ext.* on
gradle.beforeProject { project ->
// However, the "afterProject" listener iterates over every project and gives us the actual project
// So, once we filter for the project we care about, we can set whatever we want
if (project.name == name) {
project.ext.description = description
}
}
}
def yaml = new Yaml()
def buildconfig = yaml.load(new File(rootDir, '.buildconfig.yml').newInputStream())
buildconfig.projects.each { project ->
setupProject(project.key, project.value.path, project.value.description)
}
gradle.projectsLoaded { ->
String version = buildconfig.componentsVersion
if (gradle.rootProject.hasProperty("nightlyVersion")) {
version = gradle.rootProject.nightlyVersion
}
// To support local auto-publication workflow, we use a version prefix we wouldn't normally encounter.
if (gradle.rootProject.hasProperty("local")) {
version = "0.0.1"
}
// Wait until root project is "loaded" before we set "config"
// Note that since this is set on "rootProject.ext", it will be "in scope" during the evaluation of all projects'
// gradle files. This means that they can just access "config.<value>", and it'll function properly
gradle.rootProject.ext.config = new Config(version)
gradle.rootProject.ext.buildConfig = buildconfig
}
def runCmd(cmd, workingDir, successMessage) {
def proc = cmd.execute(null, new File(workingDir))
proc.consumeProcessOutput(System.out, System.err)
proc.waitFor()
if (proc.exitValue() != 0) {
throw new GradleException("Process '${cmd}' finished with non-zero exit value ${proc.exitValue()}")
} else {
logger.lifecycle(successMessage)
}
}
//////////////////////////////////////////////////////////////////////////
// Local Development overrides
//////////////////////////////////////////////////////////////////////////
Properties localProperties = null;
String settingAppServicesPath = "autoPublish.application-services.dir"
String settingGleanPath = "substitutions.glean.dir";
if (file('local.properties').canRead()) {
localProperties = new Properties()
localProperties.load(file('local.properties').newDataInputStream())
logger.lifecycle('Local configuration: loaded local.properties')
} else {
logger.lifecycle('Local configuration: absent local.properties; proceeding as normal.')
}
if (localProperties != null) {
localProperties.each { prop ->
gradle.ext.set("localProperties.${prop.key}", prop.value)
}
String appServicesLocalPath = localProperties.getProperty(settingAppServicesPath);
if (appServicesLocalPath != null) {
logger.lifecycle("Enabling automatic publication of application-services from: $appServicesLocalPath")
// Windows can't execute .py files directly, so we assume a "manually installed" python,
// which comes with a "py" launcher and respects the shebang line to specify the version.
def publishAppServicesCmd = [];
if (System.properties['os.name'].toLowerCase().contains('windows')) {
publishAppServicesCmd << "py";
}
publishAppServicesCmd << "./automation/publish_to_maven_local_if_modified.py";
runCmd(publishAppServicesCmd, appServicesLocalPath, "Published application-services for local development.")
} else {
logger.lifecycle("Disabled auto-publication of application-services. Enable it by settings '$settingAppServicesPath' in local.properties")
}
String gleanLocalPath = localProperties.getProperty(settingGleanPath);
if (gleanLocalPath != null) {
logger.lifecycle("Local configuration: substituting glean module from path: $gleanLocalPath")
includeBuild(gleanLocalPath) {
dependencySubstitution {
substitute module('org.mozilla.telemetry:glean') with project(':glean')
substitute module('org.mozilla.telemetry:glean-forUnitTests') with project(':glean')
}
}
} else {
logger.lifecycle("Local configuration: glean substitution path missing. You may specify it via '$settingGleanPath' setting.")
}
}