-
Notifications
You must be signed in to change notification settings - Fork 230
/
Copy pathsettings.gradle
162 lines (142 loc) · 6.57 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* 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
// We prefer `appServicesRootDir` over `rootDir` to help us on the path to the monorepo.
// (They are the same in app-services but different in moz-central)
def maybeAppServicesRootDir = new File(rootDir, "services/app-services")
def appServicesRootDir = maybeAppServicesRootDir.isDirectory() ? maybeAppServicesRootDir : rootDir;
includeBuild("$appServicesRootDir/tools/nimbus-gradle-plugin") {
dependencySubstitution {
substitute module("org.mozilla.appservices:tooling-nimbus-gradle") using(project(':'))
}
}
buildscript {
dependencies {
classpath 'org.yaml:snakeyaml:2.2'
}
repositories {
mavenCentral()
}
}
rootProject.name = "appservices"
def setupProject(name, projectProps, appServicesRootDir) {
def path = projectProps.path
def description = projectProps.description
def artifactId = projectProps.artifactId
// TODO: Can we remove artifactId?
if (name != artifactId) {
throw new GradleException("Project name should match artifactId: $name != $artifactId")
}
settings.include(":$name")
project(":$name").projectDir = new File(appServicesRootDir, path)
// project(...) gives us a skeleton project that we can't set ext.* on
gradle.beforeProject { project ->
// applying this plugin to our sub-projects here makes life much easier for m-c.
// Once in m-c, we can probably just remove all publishing capabilities from these crates entirely?
project.apply plugin: 'maven-publish'
// 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
project.ext.artifactId = artifactId
// Expose the rest of the project properties, mostly for validation reasons.
project.ext.configProps = projectProps
project.ext.appServicesRootDir = appServicesRootDir
if (gradle.hasProperty("mozconfig")) {
project.buildDir = "${gradle.mozconfig.topobjdir}/gradle/build/app-services/android/$name"
}
}
}
}
def yaml = new Yaml()
def buildconfig = yaml.load(new File(appServicesRootDir, '.buildconfig-android.yml').newInputStream())
buildconfig.projects.each { project ->
setupProject(project.key, project.value, appServicesRootDir)
}
Properties localProperties = new Properties();
if (file('local.properties').canRead()) {
localProperties.load(file('local.properties').newDataInputStream())
localProperties.each { prop ->
gradle.ext.set("localProperties.${prop.key}", prop.value)
}
logger.lifecycle('Local configuration: loaded local.properties')
} else {
logger.lifecycle('Local configuration: absent local.properties; proceeding as normal.')
}
def calcVersion(buildconfig) {
def local = gradle.rootProject.findProperty("local")
if (gradle.hasProperty("mozconfig")) {
// We are in m-c - XXX - this is temporary - once in m-c this will not be called, but this seems sane for now?
def buildid = file("${gradle.mozconfig.topobjdir}/buildid.h").getText('utf-8').split()[2]
return "${gradle.mozconfig.substs.MOZ_APP_VERSION}-${buildid}"
} else if (gradle.rootProject.hasProperty("nightlyVersion")) {
// We are in app-services but building a "nightly" version to be consumed by Fenix.
return gradle.rootProject.nightlyVersion
} else if(local) {
// We are doing a local publish
return '0.0.1-SNAPSHOT'
} else {
// A normal build from app-services.
return new File(rootDir, 'version.txt').getText().trim()
}
}
def calcGroupId(buildconfig) {
if (gradle.rootProject.hasProperty("nightlyVersion")) {
return buildconfig.groupId + ".nightly"
} else {
return buildconfig.groupId
}
}
// This is a copy of the `Config` object used in moz-central (but with the addition of ndkVersion for UniFFI)
// This is only used when not in mozilla-central - on m-c the existing Config class is used.
// In the short term we should keep them in sync.
// Once in moz-central we should remove this.
class Config {
// This "componentsVersion" number is defined in "version.txt" and should follow
// semantic versioning (MAJOR.MINOR.PATCH). See https://semver.org/
public final String componentsVersion
public final String componentsGroupId
public final Integer jvmTargetCompatibility
public final Integer compileSdkVersion
public final Integer minSdkVersion
public final Integer targetSdkVersion
public final String ndkVersion
Config(
String componentsVersion,
String componentsGroupId,
Integer jvmTargetCompatibility,
Integer compileSdkVersion,
Integer minSdkVersion,
Integer targetSdkVersion,
String ndkVersion
) {
this.componentsVersion = componentsVersion
this.componentsGroupId = componentsGroupId
this.jvmTargetCompatibility = jvmTargetCompatibility
this.compileSdkVersion = compileSdkVersion
this.minSdkVersion = minSdkVersion
this.targetSdkVersion = targetSdkVersion
this.ndkVersion = ndkVersion
}
}
gradle.projectsLoaded { ->
// 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
if (!gradle.hasProperty("mozconfig")) {
gradle.rootProject.ext.config = new Config(
// You can use -Plocal=true to help with mavenLocal publishing workflow.
// It makes a fake version number that's smaller than any published version,
// which can be depended on specifically by the ./build-scripts/substitute-local-appservices.gradle
// but which is unlikely to be depended on by accident otherwise.
calcVersion(buildconfig), // version,
calcGroupId(buildconfig), // componentsGroupId
17, // jvmTargetCompatibility,
35, // compileSdkVersion,
21, // minSdkVersion,
35, // targetSdkVersion,
"28.0.13004108", // ndkVersion - Keep it in sync in TC Dockerfile.
)
}
}