Bug 1516135 [wpt PR 14649] - Produce a valid report when no tests are affected, a...
[gecko.git] / build.gradle
blob0e5b4ec1727d4ac436b4146cf92d4579bef80793
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
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
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     }
29     repositories {
30         gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
31             maven {
32                 url repository
33             }
34         }
35         // For in tree dependencies.
36         // TODO: remove this once
37         // https://issuetracker.google.com/issues/120951637 is resolved. See
38         // also Bug 1514374.
39         maven {
40             url "file://${gradle.mozconfig.topsrcdir}/mobile/android/gradle/m2repo"
41         }
42     }
44     task downloadDependencies() {
45         description 'Download all dependencies to the Gradle cache'
46         doLast {
47             configurations.each { configuration ->
48                 if (configuration.canBeResolved) {
49                     configuration.allDependencies.each { dependency ->
50                         try {
51                             configuration.files(dependency)
52                         } catch(e) {
53                             println("Could not resolve ${configuration.name} -> ${dependency.name}")
54                             println(" > ${e.message}")
55                             if (e.cause) {
56                                 println(" >> ${e.cause}")
57                                 if (e.cause.cause) {
58                                     println(" >> ${e.cause.cause}")
59                                 }
60                             }
61                             println("")
62                         }
63                     }
64                 }
65             }
66         }
67     }
70 buildDir "${topobjdir}/gradle/build"
72 buildscript {
73     repositories {
74         gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
75             maven {
76                 url repository
77             }
78         }
79     }
81     ext.kotlin_version = '1.2.41'
82     ext.support_library_version = '26.1.0'
83     ext.jacoco_version = '0.8.1'
85     if (gradle.mozconfig.substs.MOZ_ANDROID_GOOGLE_PLAY_SERVICES) {
86         ext.google_play_services_version = '15.0.1'
87         ext.google_play_services_cast_version = '16.0.0'
88     }
90     dependencies {
91         classpath 'org.mozilla.apilint:apilint:0.1.7'
92         classpath 'com.android.tools.build:gradle:3.1.4'
93         classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
94         classpath 'org.apache.commons:commons-exec:1.3'
95         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
96     }
99 // A stream that processes bytes line by line, prepending a tag before sending
100 // each line to Gradle's logging.
101 class TaggedLogOutputStream extends org.apache.commons.exec.LogOutputStream {
102     String tag
103     Logger logger
105     TaggedLogOutputStream(tag, logger) {
106         this.tag = tag
107         this.logger = logger
108     }
110     void processLine(String line, int level) {
111         logger.lifecycle("${this.tag} ${line}")
112     }
115 ext.geckoBinariesOnlyIf = { task ->
116     // Never for official builds.
117     if (mozconfig.substs.MOZILLA_OFFICIAL) {
118         rootProject.logger.lifecycle("Skipping task ${task.path} because: MOZILLA_OFFICIAL")
119         return false
120     }
122     // Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale.  This
123     // causes the
124     //
125     // |mach build| > |mach gradle| >
126     // |mach build mobile/android/base/generated_android_code_and_resources| >
127     // AndroidManifest.xml > strings.xml > multi/brand.dtd
128     //
129     // dependency chain to fail, since multi isn't a real locale.  To avoid
130     // this, if Gradle is invoked with AB_CD=multi, we don't invoke Make at all.
131     if ('multi' == System.env.AB_CD) {
132         rootProject.logger.lifecycle("Skipping task ${task.path} because: AB_CD=multi")
133         return false
134     }
136     // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource
137     // and code generation themselves.
138     if ('1' == System.env.IS_LANGUAGE_REPACK) {
139         rootProject.logger.lifecycle("Skipping task ${task.path} because: IS_LANGUAGE_REPACK")
140         return false
141     }
143     rootProject.logger.lifecycle("Executing task ${task.path}")
144     return true
147 task machBuildGeneratedAndroidCodeAndResources(type: Exec) {
148     onlyIf rootProject.ext.geckoBinariesOnlyIf
150     workingDir "${topsrcdir}"
152     commandLine mozconfig.substs.PYTHON
153     args "${topsrcdir}/mach"
154     args 'build'
155     args 'mobile/android/base/generated_android_code_and_resources'
157     // Add `-v` if we're running under `--info` (or `--debug`).
158     if (project.logger.isEnabled(LogLevel.INFO)) {
159         args '-v'
160     }
162     // `path` is like `:machBuildGeneratedAndroidCodeAndResources`.
163     standardOutput = new TaggedLogOutputStream("${path}>", logger)
164     errorOutput = standardOutput
167 // Why |mach build mobile/android/base/...| and |mach build faster|?  |mach
168 // build faster| generates dependentlibs.list, which in turn depends on compiled
169 // code.  That causes a circular dependency between Java compilation/JNI wrapper
170 // generation/native code compilation.  So we have the special target for
171 // Android-specific generated code, and the |mach build faster| target for all
172 // the stuff that goes into the omnijar.
173 task machBuildFaster(type: Exec) {
174     onlyIf rootProject.ext.geckoBinariesOnlyIf
176     workingDir "${topsrcdir}"
178     commandLine mozconfig.substs.PYTHON
179     args "${topsrcdir}/mach"
180     args 'build'
181     args 'faster'
183     // Add `-v` if we're running under `--info` (or `--debug`).
184     if (project.logger.isEnabled(LogLevel.INFO)) {
185         args '-v'
186     }
188     // `path` is like `:machBuildFaster`.
189     standardOutput = new TaggedLogOutputStream("${path}>", logger)
190     errorOutput = standardOutput
193 def createMachStagePackageTask(name) {
194     return task(name, type: Exec) {
195         onlyIf rootProject.ext.geckoBinariesOnlyIf
197         dependsOn rootProject.machBuildFaster
199         // We'd prefer to take these from the :omnijar project directly, but
200         // it's awkward to reach across projects at evaluation time, so we
201         // duplicate the list here.
202         inputs.dir "${topsrcdir}/mobile/android/chrome"
203         inputs.dir "${topsrcdir}/mobile/android/components"
204         inputs.dir "${topsrcdir}/mobile/android/locales"
205         inputs.dir "${topsrcdir}/mobile/android/modules"
206         inputs.dir "${topsrcdir}/mobile/android/themes"
207         inputs.dir "${topsrcdir}/toolkit"
209         workingDir "${topobjdir}"
211         // We'd prefer this to be a `mach` invocation, but `mach build
212         // mobile/android/installer/stage-package` doesn't work as expected.
213         commandLine mozconfig.substs.GMAKE
214         args '-C'
215         args "${topobjdir}/mobile/android/installer"
216         args 'stage-package'
218         outputs.file "${topobjdir}/dist/fennec/assets/${mozconfig.substs.ANDROID_CPU_ARCH}/libxul.so"
219         outputs.file "${topobjdir}/dist/fennec/lib/${mozconfig.substs.ANDROID_CPU_ARCH}/libmozglue.so"
221         // `path` is like `:machStagePackage`.
222         standardOutput = new TaggedLogOutputStream("${path}>", logger)
223         errorOutput = standardOutput
224     }
227 createMachStagePackageTask("machStagePackageForFennec").with {
228     outputs.file "${topobjdir}/dist/fennec/assets/omni.ja"
231 createMachStagePackageTask("machStagePackageForGeckoview").with {
232     args 'MOZ_GECKOVIEW_JAR=1'
233     outputs.file "${topobjdir}/dist/geckoview/assets/omni.ja"
234     // Avoid races between stage-package invocations.
235     mustRunAfter tasks["machStagePackageForFennec"]
238 afterEvaluate {
239     subprojects { project ->
240         if (project.name != 'thirdparty') {
241             tasks.withType(JavaCompile) {
242                 // Add compiler args for all code except third-party code.
243                 options.compilerArgs += [
244                     // Turn on all warnings, except...
245                     "-Xlint:all",
246                     // Deprecation, because we do use deprecated API for compatibility.
247                     "-Xlint:-deprecation",
248                     // Serial, because we don't use Java serialization.
249                     "-Xlint:-serial",
250                     // Classfile, because javac has a bug with MethodParameters attributes
251                     // with Java 7. https://bugs.openjdk.java.net/browse/JDK-8190452
252                     "-Xlint:-classfile",
253                     // Turn all remaining warnings into errors,
254                     // unless marked by @SuppressWarnings.
255                     "-Werror"]
256             }
257             if (project.name == 'app') {
258                 tasks.withType(JavaCompile) {
259                     // Turn off classfile warnings because upon updating to play services 15.0.0
260                     // a warning is being thrown from play-services-base which fails the build
261                     // (com/google/android/gms/common/api/GoogleApiClient.class):
262                     // warning: Cannot find annotation method 'value()' in type 'GuardedBy':
263                     // class file for javax.annotation.concurrent.GuardedBy not found
264                     options.compilerArgs += ["-Xlint:-classfile"]
265                 }
266             }
267         }
269         if (!hasProperty('android')) {
270             return
271         }
272         android.applicationVariants.all {
273             preBuild.dependsOn rootProject.machBuildGeneratedAndroidCodeAndResources
274         }
275         android.libraryVariants.all {
276             preBuild.dependsOn rootProject.machBuildGeneratedAndroidCodeAndResources
277         }
278     }
281 apply plugin: 'idea'
283 idea {
284     project {
285         languageLevel = '1.8'
286     }
288     module {
289         // Object directories take a huge amount of time for IntelliJ to index.
290         // Exclude them.  Convention is that object directories start with obj.
291         // IntelliJ is clever and will not exclude the parts of the object
292         // directory that are referenced, if there are any.  In practice,
293         // indexing the entirety of the tree is taking too long, so exclude all
294         // but mobile/.
295         def topsrcdirURI = file(topsrcdir).toURI()
296         excludeDirs += files(file(topsrcdir)
297             .listFiles({it.isDirectory()} as FileFilter)
298             .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
299             .findAll({!it.equals('mobile/')}))
301         // If topobjdir is below topsrcdir, hide only some portions of that tree.
302         def topobjdirURI = file(topobjdir).toURI()
303         if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
304             excludeDirs -= file(topobjdir)
305             excludeDirs += files(file(topobjdir).listFiles())
306             excludeDirs -= file("${topobjdir}/gradle")
307         }
309         if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
310             excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
311         }
312     }
315 task wrapper(type: Wrapper) {