Source code

Revision control

Other Tools

1
def tryInt = { string ->
2
if (string == null) {
3
return string
4
}
5
if (string.isInteger()) {
6
return string as Integer
7
}
8
return string
9
}
10
11
allprojects {
12
// Expose the per-object-directory configuration to all projects.
13
ext {
14
mozconfig = gradle.mozconfig
15
topsrcdir = gradle.mozconfig.topsrcdir
16
topobjdir = gradle.mozconfig.topobjdir
17
18
compileSdkVersion = 28
19
targetSdkVersion = tryInt(mozconfig.substs.ANDROID_TARGET_SDK)
20
minSdkVersion = tryInt(mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION)
21
manifestPlaceholders = [
22
ANDROID_PACKAGE_NAME: mozconfig.substs.ANDROID_PACKAGE_NAME,
23
ANDROID_TARGET_SDK: mozconfig.substs.ANDROID_TARGET_SDK,
24
MOZ_ANDROID_MIN_SDK_VERSION: mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION,
25
MOZ_ANDROID_SHARED_ID: "${mozconfig.substs.ANDROID_PACKAGE_NAME}.sharedID",
26
]
27
}
28
29
repositories {
30
gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
31
maven {
32
url repository
33
}
34
}
35
}
36
37
task downloadDependencies() {
38
description 'Download all dependencies to the Gradle cache'
39
doLast {
40
configurations.each { configuration ->
41
if (configuration.canBeResolved) {
42
configuration.allDependencies.each { dependency ->
43
try {
44
configuration.files(dependency)
45
} catch(e) {
46
println("Could not resolve ${configuration.name} -> ${dependency.name}")
47
println(" > ${e.message}")
48
if (e.cause) {
49
println(" >> ${e.cause}")
50
if (e.cause.cause) {
51
println(" >> ${e.cause.cause}")
52
}
53
}
54
println("")
55
}
56
}
57
}
58
}
59
}
60
}
61
}
62
63
buildDir "${topobjdir}/gradle/build"
64
65
buildscript {
66
repositories {
67
gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
68
maven {
69
url repository
70
}
71
}
72
}
73
74
ext.kotlin_version = '1.3.41'
75
ext.support_library_version = '28.0.0'
76
ext.jacoco_version = '0.8.1'
77
ext.lifecycle_library_version = '1.1.1'
78
79
if (gradle.mozconfig.substs.MOZ_ANDROID_GOOGLE_PLAY_SERVICES) {
80
ext.google_play_services_version = '15.0.1'
81
ext.google_play_services_cast_version = '16.0.0'
82
ext.google_play_services_fido_version = '17.0.0'
83
}
84
85
dependencies {
86
classpath 'org.mozilla.apilint:apilint:0.2.6'
87
classpath 'com.android.tools.build:gradle:3.4.2'
88
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
89
classpath 'org.apache.commons:commons-exec:1.3'
90
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
91
}
92
}
93
94
// A stream that processes bytes line by line, prepending a tag before sending
95
// each line to Gradle's logging.
96
class TaggedLogOutputStream extends org.apache.commons.exec.LogOutputStream {
97
String tag
98
Logger logger
99
100
TaggedLogOutputStream(tag, logger) {
101
this.tag = tag
102
this.logger = logger
103
}
104
105
void processLine(String line, int level) {
106
logger.lifecycle("${this.tag} ${line}")
107
}
108
}
109
110
ext.geckoBinariesOnlyIf = { task ->
111
// Never when Gradle was invoked within `mach build`.
112
if ('1' == System.env.GRADLE_INVOKED_WITHIN_MACH_BUILD) {
113
rootProject.logger.lifecycle("Skipping task ${task.path} because: within `mach build`")
114
return false
115
}
116
117
// Never for official builds.
118
if (mozconfig.substs.MOZILLA_OFFICIAL) {
119
rootProject.logger.lifecycle("Skipping task ${task.path} because: MOZILLA_OFFICIAL")
120
return false
121
}
122
123
// Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale. This
124
// causes the
125
//
126
// |mach build| > |mach gradle| >
127
// |mach build mobile/android/base/generated_android_code_and_resources| >
128
// AndroidManifest.xml > strings.xml > multi/brand.dtd
129
//
130
// dependency chain to fail, since multi isn't a real locale. To avoid
131
// this, if Gradle is invoked with AB_CD=multi, we don't invoke Make at all.
132
if ('multi' == System.env.AB_CD) {
133
rootProject.logger.lifecycle("Skipping task ${task.path} because: AB_CD=multi")
134
return false
135
}
136
137
// Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource
138
// and code generation themselves.
139
if ('1' == System.env.IS_LANGUAGE_REPACK) {
140
rootProject.logger.lifecycle("Skipping task ${task.path} because: IS_LANGUAGE_REPACK")
141
return false
142
}
143
144
rootProject.logger.lifecycle("Executing task ${task.path}")
145
return true
146
}
147
148
class MachExec extends Exec {
149
def MachExec() {
150
// Bug 1543982: When invoking `mach build` recursively, the outer `mach
151
// build` itself modifies the environment, causing configure to run
152
// again. This tries to restore the environment that the outer `mach
153
// build` was invoked in. See the comment in
154
// $topsrcdir/settings.gradle.
155
project.ext.mozconfig.mozconfig.env.unmodified.each { k, v -> environment.remove(k) }
156
environment project.ext.mozconfig.orig_mozconfig.env.unmodified
157
}
158
}
159
160
task machBuildGeneratedAndroidCodeAndResources(type: MachExec) {
161
onlyIf rootProject.ext.geckoBinariesOnlyIf
162
163
workingDir "${topsrcdir}"
164
165
commandLine mozconfig.substs.PYTHON
166
args "${topsrcdir}/mach"
167
args 'build'
168
args 'mobile/android/base/generated_android_code_and_resources'
169
170
// Add `-v` if we're running under `--info` (or `--debug`).
171
if (project.logger.isEnabled(LogLevel.INFO)) {
172
args '-v'
173
}
174
175
// `path` is like `:machBuildGeneratedAndroidCodeAndResources`.
176
standardOutput = new TaggedLogOutputStream("${path}>", logger)
177
errorOutput = standardOutput
178
}
179
180
// Why |mach build mobile/android/base/...| and |mach build faster|? |mach
181
// build faster| generates dependentlibs.list, which in turn depends on compiled
182
// code. That causes a circular dependency between Java compilation/JNI wrapper
183
// generation/native code compilation. So we have the special target for
184
// Android-specific generated code, and the |mach build faster| target for all
185
// the stuff that goes into the omnijar.
186
task machBuildFaster(type: MachExec) {
187
onlyIf rootProject.ext.geckoBinariesOnlyIf
188
189
workingDir "${topsrcdir}"
190
191
commandLine mozconfig.substs.PYTHON
192
args "${topsrcdir}/mach"
193
args 'build'
194
args 'faster'
195
196
// Add `-v` if we're running under `--info` (or `--debug`).
197
if (project.logger.isEnabled(LogLevel.INFO)) {
198
args '-v'
199
}
200
201
// `path` is like `:machBuildFaster`.
202
standardOutput = new TaggedLogOutputStream("${path}>", logger)
203
errorOutput = standardOutput
204
}
205
206
def createMachStagePackageTask(name) {
207
return task(name, type: MachExec) {
208
onlyIf rootProject.ext.geckoBinariesOnlyIf
209
210
dependsOn rootProject.machBuildFaster
211
212
workingDir "${topobjdir}"
213
214
// We'd prefer this to be a `mach` invocation, but `mach build
215
// mobile/android/installer/stage-package` doesn't work as expected.
216
commandLine mozconfig.substs.GMAKE
217
args '-C'
218
args "${topobjdir}/mobile/android/installer"
219
args 'stage-package'
220
221
outputs.file "${topobjdir}/dist/fennec/assets/${mozconfig.substs.ANDROID_CPU_ARCH}/libxul.so"
222
outputs.file "${topobjdir}/dist/fennec/lib/${mozconfig.substs.ANDROID_CPU_ARCH}/libmozglue.so"
223
224
// Force running `stage-package`.
225
outputs.upToDateWhen { false }
226
227
// `path` is like `:machStagePackage`.
228
standardOutput = new TaggedLogOutputStream("${path}>", logger)
229
errorOutput = standardOutput
230
}
231
}
232
233
createMachStagePackageTask("machStagePackageForFennec").with {
234
outputs.file "${topobjdir}/dist/fennec/assets/omni.ja"
235
}
236
237
createMachStagePackageTask("machStagePackageForGeckoview").with {
238
args 'MOZ_GECKOVIEW_JAR=1'
239
outputs.file "${topobjdir}/dist/geckoview/assets/omni.ja"
240
// Avoid races between stage-package invocations.
241
mustRunAfter tasks["machStagePackageForFennec"]
242
}
243
244
afterEvaluate {
245
subprojects { project ->
246
if (project.name != 'thirdparty') {
247
tasks.withType(JavaCompile) {
248
// Add compiler args for all code except third-party code.
249
options.compilerArgs += [
250
// Turn on all warnings, except...
251
"-Xlint:all",
252
// Deprecation, because we do use deprecated API for compatibility.
253
"-Xlint:-deprecation",
254
// Serial, because we don't use Java serialization.
255
"-Xlint:-serial",
256
// Classfile, because javac has a bug with MethodParameters attributes
258
"-Xlint:-classfile",
259
// Turn all remaining warnings into errors,
260
// unless marked by @SuppressWarnings.
261
"-Werror"]
262
}
263
if (project.name == 'app') {
264
tasks.withType(JavaCompile) {
265
// Turn off classfile warnings because upon updating to play services 15.0.0
266
// a warning is being thrown from play-services-base which fails the build
267
// (com/google/android/gms/common/api/GoogleApiClient.class):
268
// warning: Cannot find annotation method 'value()' in type 'GuardedBy':
269
// class file for javax.annotation.concurrent.GuardedBy not found
270
options.compilerArgs += ["-Xlint:-classfile"]
271
}
272
}
273
}
274
275
if (!hasProperty('android')) {
276
return
277
}
278
android.applicationVariants.all {
279
preBuild.dependsOn rootProject.machBuildGeneratedAndroidCodeAndResources
280
}
281
android.libraryVariants.all {
282
preBuild.dependsOn rootProject.machBuildGeneratedAndroidCodeAndResources
283
}
284
}
285
}
286
287
apply plugin: 'idea'
288
289
idea {
290
project {
291
languageLevel = '1.8'
292
}
293
294
module {
295
// Object directories take a huge amount of time for IntelliJ to index.
296
// Exclude them. Convention is that object directories start with obj.
297
// IntelliJ is clever and will not exclude the parts of the object
298
// directory that are referenced, if there are any. In practice,
299
// indexing the entirety of the tree is taking too long, so exclude all
300
// but mobile/.
301
def topsrcdirURI = file(topsrcdir).toURI()
302
excludeDirs += files(file(topsrcdir)
303
.listFiles({it.isDirectory()} as FileFilter)
304
.collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
305
.findAll({!it.equals('mobile/')}))
306
307
// If topobjdir is below topsrcdir, hide only some portions of that tree.
308
def topobjdirURI = file(topobjdir).toURI()
309
if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
310
excludeDirs -= file(topobjdir)
311
excludeDirs += files(file(topobjdir).listFiles())
312
excludeDirs -= file("${topobjdir}/gradle")
313
}
314
315
if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
316
excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
317
}
318
}
319
}