Bug 1529208 [wpt PR 15469] - [Code Health] Fix incorrect test name, a=testonly
[gecko.git] / build.gradle
blob7b2dd0673418cb6e7007f5f7a00b781c9d0d5598
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     }
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     }
63 buildDir "${topobjdir}/gradle/build"
65 buildscript {
66     repositories {
67         gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
68             maven {
69                 url repository
70             }
71         }
72     }
74     ext.kotlin_version = '1.2.41'
75     ext.support_library_version = '26.1.0'
76     ext.jacoco_version = '0.8.1'
78     if (gradle.mozconfig.substs.MOZ_ANDROID_GOOGLE_PLAY_SERVICES) {
79         ext.google_play_services_version = '15.0.1'
80         ext.google_play_services_cast_version = '16.0.0'
81     }
83     dependencies {
84         classpath 'org.mozilla.apilint:apilint:0.1.8'
85         classpath 'com.android.tools.build:gradle:3.1.4'
86         classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
87         classpath 'org.apache.commons:commons-exec:1.3'
88         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
89     }
92 // A stream that processes bytes line by line, prepending a tag before sending
93 // each line to Gradle's logging.
94 class TaggedLogOutputStream extends org.apache.commons.exec.LogOutputStream {
95     String tag
96     Logger logger
98     TaggedLogOutputStream(tag, logger) {
99         this.tag = tag
100         this.logger = logger
101     }
103     void processLine(String line, int level) {
104         logger.lifecycle("${this.tag} ${line}")
105     }
108 ext.geckoBinariesOnlyIf = { task ->
109     // Never for official builds.
110     if (mozconfig.substs.MOZILLA_OFFICIAL) {
111         rootProject.logger.lifecycle("Skipping task ${task.path} because: MOZILLA_OFFICIAL")
112         return false
113     }
115     // Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale.  This
116     // causes the
117     //
118     // |mach build| > |mach gradle| >
119     // |mach build mobile/android/base/generated_android_code_and_resources| >
120     // AndroidManifest.xml > strings.xml > multi/brand.dtd
121     //
122     // dependency chain to fail, since multi isn't a real locale.  To avoid
123     // this, if Gradle is invoked with AB_CD=multi, we don't invoke Make at all.
124     if ('multi' == System.env.AB_CD) {
125         rootProject.logger.lifecycle("Skipping task ${task.path} because: AB_CD=multi")
126         return false
127     }
129     // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource
130     // and code generation themselves.
131     if ('1' == System.env.IS_LANGUAGE_REPACK) {
132         rootProject.logger.lifecycle("Skipping task ${task.path} because: IS_LANGUAGE_REPACK")
133         return false
134     }
136     rootProject.logger.lifecycle("Executing task ${task.path}")
137     return true
140 task machBuildGeneratedAndroidCodeAndResources(type: Exec) {
141     onlyIf rootProject.ext.geckoBinariesOnlyIf
143     workingDir "${topsrcdir}"
145     commandLine mozconfig.substs.PYTHON
146     args "${topsrcdir}/mach"
147     args 'build'
148     args 'mobile/android/base/generated_android_code_and_resources'
150     // Add `-v` if we're running under `--info` (or `--debug`).
151     if (project.logger.isEnabled(LogLevel.INFO)) {
152         args '-v'
153     }
155     // `path` is like `:machBuildGeneratedAndroidCodeAndResources`.
156     standardOutput = new TaggedLogOutputStream("${path}>", logger)
157     errorOutput = standardOutput
160 // Why |mach build mobile/android/base/...| and |mach build faster|?  |mach
161 // build faster| generates dependentlibs.list, which in turn depends on compiled
162 // code.  That causes a circular dependency between Java compilation/JNI wrapper
163 // generation/native code compilation.  So we have the special target for
164 // Android-specific generated code, and the |mach build faster| target for all
165 // the stuff that goes into the omnijar.
166 task machBuildFaster(type: Exec) {
167     onlyIf rootProject.ext.geckoBinariesOnlyIf
169     workingDir "${topsrcdir}"
171     commandLine mozconfig.substs.PYTHON
172     args "${topsrcdir}/mach"
173     args 'build'
174     args 'faster'
176     // Add `-v` if we're running under `--info` (or `--debug`).
177     if (project.logger.isEnabled(LogLevel.INFO)) {
178         args '-v'
179     }
181     // `path` is like `:machBuildFaster`.
182     standardOutput = new TaggedLogOutputStream("${path}>", logger)
183     errorOutput = standardOutput
186 def createMachStagePackageTask(name) {
187     return task(name, type: Exec) {
188         onlyIf rootProject.ext.geckoBinariesOnlyIf
190         dependsOn rootProject.machBuildFaster
192         // We'd prefer to take these from the :omnijar project directly, but
193         // it's awkward to reach across projects at evaluation time, so we
194         // duplicate the list here.
195         inputs.dir "${topsrcdir}/mobile/android/chrome"
196         inputs.dir "${topsrcdir}/mobile/android/components"
197         inputs.dir "${topsrcdir}/mobile/android/locales"
198         inputs.dir "${topsrcdir}/mobile/android/modules"
199         inputs.dir "${topsrcdir}/mobile/android/themes"
200         inputs.dir "${topsrcdir}/toolkit"
202         workingDir "${topobjdir}"
204         // We'd prefer this to be a `mach` invocation, but `mach build
205         // mobile/android/installer/stage-package` doesn't work as expected.
206         commandLine mozconfig.substs.GMAKE
207         args '-C'
208         args "${topobjdir}/mobile/android/installer"
209         args 'stage-package'
211         outputs.file "${topobjdir}/dist/fennec/assets/${mozconfig.substs.ANDROID_CPU_ARCH}/libxul.so"
212         outputs.file "${topobjdir}/dist/fennec/lib/${mozconfig.substs.ANDROID_CPU_ARCH}/libmozglue.so"
214         // `path` is like `:machStagePackage`.
215         standardOutput = new TaggedLogOutputStream("${path}>", logger)
216         errorOutput = standardOutput
217     }
220 createMachStagePackageTask("machStagePackageForFennec").with {
221     outputs.file "${topobjdir}/dist/fennec/assets/omni.ja"
224 createMachStagePackageTask("machStagePackageForGeckoview").with {
225     args 'MOZ_GECKOVIEW_JAR=1'
226     outputs.file "${topobjdir}/dist/geckoview/assets/omni.ja"
227     // Avoid races between stage-package invocations.
228     mustRunAfter tasks["machStagePackageForFennec"]
231 afterEvaluate {
232     subprojects { project ->
233         if (project.name != 'thirdparty') {
234             tasks.withType(JavaCompile) {
235                 // Add compiler args for all code except third-party code.
236                 options.compilerArgs += [
237                     // Turn on all warnings, except...
238                     "-Xlint:all",
239                     // Deprecation, because we do use deprecated API for compatibility.
240                     "-Xlint:-deprecation",
241                     // Serial, because we don't use Java serialization.
242                     "-Xlint:-serial",
243                     // Classfile, because javac has a bug with MethodParameters attributes
244                     // with Java 7. https://bugs.openjdk.java.net/browse/JDK-8190452
245                     "-Xlint:-classfile",
246                     // Turn all remaining warnings into errors,
247                     // unless marked by @SuppressWarnings.
248                     "-Werror"]
249             }
250             if (project.name == 'app') {
251                 tasks.withType(JavaCompile) {
252                     // Turn off classfile warnings because upon updating to play services 15.0.0
253                     // a warning is being thrown from play-services-base which fails the build
254                     // (com/google/android/gms/common/api/GoogleApiClient.class):
255                     // warning: Cannot find annotation method 'value()' in type 'GuardedBy':
256                     // class file for javax.annotation.concurrent.GuardedBy not found
257                     options.compilerArgs += ["-Xlint:-classfile"]
258                 }
259             }
260         }
262         if (!hasProperty('android')) {
263             return
264         }
265         android.applicationVariants.all {
266             preBuild.dependsOn rootProject.machBuildGeneratedAndroidCodeAndResources
267         }
268         android.libraryVariants.all {
269             preBuild.dependsOn rootProject.machBuildGeneratedAndroidCodeAndResources
270         }
271     }
274 apply plugin: 'idea'
276 idea {
277     project {
278         languageLevel = '1.8'
279     }
281     module {
282         // Object directories take a huge amount of time for IntelliJ to index.
283         // Exclude them.  Convention is that object directories start with obj.
284         // IntelliJ is clever and will not exclude the parts of the object
285         // directory that are referenced, if there are any.  In practice,
286         // indexing the entirety of the tree is taking too long, so exclude all
287         // but mobile/.
288         def topsrcdirURI = file(topsrcdir).toURI()
289         excludeDirs += files(file(topsrcdir)
290             .listFiles({it.isDirectory()} as FileFilter)
291             .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
292             .findAll({!it.equals('mobile/')}))
294         // If topobjdir is below topsrcdir, hide only some portions of that tree.
295         def topobjdirURI = file(topobjdir).toURI()
296         if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
297             excludeDirs -= file(topobjdir)
298             excludeDirs += files(file(topobjdir).listFiles())
299             excludeDirs -= file("${topobjdir}/gradle")
300         }
302         if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
303             excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
304         }
305     }
308 task wrapper(type: Wrapper) {