Bug 1492664 - update references in docs; r=froydnj
[gecko.git] / build.gradle
blob3ed83c85323db79e560539d5b67252e5a486ac28
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 = 26
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     }
89     dependencies {
90         classpath 'org.mozilla.apilint:apilint:0.1.5'
91         classpath 'com.android.tools.build:gradle:3.1.4'
92         classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
93         classpath 'org.apache.commons:commons-exec:1.3'
94         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
95     }
98 // A stream that processes bytes line by line, prepending a tag before sending
99 // each line to Gradle's logging.
100 class TaggedLogOutputStream extends org.apache.commons.exec.LogOutputStream {
101     String tag
102     Logger logger
104     TaggedLogOutputStream(tag, logger) {
105         this.tag = tag
106         this.logger = logger
107     }
109     void processLine(String line, int level) {
110         logger.lifecycle("${this.tag} ${line}")
111     }
114 ext.geckoBinariesOnlyIf = { task ->
115     // Never for official builds.
116     if (mozconfig.substs.MOZILLA_OFFICIAL) {
117         rootProject.logger.lifecycle("Skipping task ${task.path} because: MOZILLA_OFFICIAL")
118         return false
119     }
121     // Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale.  This
122     // causes the
123     //
124     // |mach build| > |mach gradle| >
125     // |mach build mobile/android/base/generated_android_code_and_resources| >
126     // AndroidManifest.xml > strings.xml > multi/brand.dtd
127     //
128     // dependency chain to fail, since multi isn't a real locale.  To avoid
129     // this, if Gradle is invoked with AB_CD=multi, we don't invoke Make at all.
130     if ('multi' == System.env.AB_CD) {
131         rootProject.logger.lifecycle("Skipping task ${task.path} because: AB_CD=multi")
132         return false
133     }
135     // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource
136     // and code generation themselves.
137     if ('1' == System.env.IS_LANGUAGE_REPACK) {
138         rootProject.logger.lifecycle("Skipping task ${task.path} because: IS_LANGUAGE_REPACK")
139         return false
140     }
142     rootProject.logger.lifecycle("Executing task ${task.path}")
143     return true
146 task machBuildGeneratedAndroidCodeAndResources(type: Exec) {
147     onlyIf rootProject.ext.geckoBinariesOnlyIf
149     workingDir "${topsrcdir}"
151     commandLine mozconfig.substs.PYTHON
152     args "${topsrcdir}/mach"
153     args 'build'
154     args 'mobile/android/base/generated_android_code_and_resources'
156     // Add `-v` if we're running under `--info` (or `--debug`).
157     if (project.logger.isEnabled(LogLevel.INFO)) {
158         args '-v'
159     }
161     // `path` is like `:machBuildGeneratedAndroidCodeAndResources`.
162     standardOutput = new TaggedLogOutputStream("${path}>", logger)
163     errorOutput = standardOutput
166 // Why |mach build mobile/android/base/...| and |mach build faster|?  |mach
167 // build faster| generates dependentlibs.list, which in turn depends on compiled
168 // code.  That causes a circular dependency between Java compilation/JNI wrapper
169 // generation/native code compilation.  So we have the special target for
170 // Android-specific generated code, and the |mach build faster| target for all
171 // the stuff that goes into the omnijar.
172 task machBuildFaster(type: Exec) {
173     onlyIf rootProject.ext.geckoBinariesOnlyIf
175     workingDir "${topsrcdir}"
177     commandLine mozconfig.substs.PYTHON
178     args "${topsrcdir}/mach"
179     args 'build'
180     args 'faster'
182     // Add `-v` if we're running under `--info` (or `--debug`).
183     if (project.logger.isEnabled(LogLevel.INFO)) {
184         args '-v'
185     }
187     // `path` is like `:machBuildFaster`.
188     standardOutput = new TaggedLogOutputStream("${path}>", logger)
189     errorOutput = standardOutput
192 def createMachStagePackageTask(name) {
193     return task(name, type: Exec) {
194         onlyIf rootProject.ext.geckoBinariesOnlyIf
196         dependsOn rootProject.machBuildFaster
198         // We'd prefer to take these from the :omnijar project directly, but
199         // it's awkward to reach across projects at evaluation time, so we
200         // duplicate the list here.
201         inputs.dir "${topsrcdir}/mobile/android/chrome"
202         inputs.dir "${topsrcdir}/mobile/android/components"
203         inputs.dir "${topsrcdir}/mobile/android/locales"
204         inputs.dir "${topsrcdir}/mobile/android/modules"
205         inputs.dir "${topsrcdir}/mobile/android/themes"
206         inputs.dir "${topsrcdir}/toolkit"
208         workingDir "${topobjdir}"
210         // We'd prefer this to be a `mach` invocation, but `mach build
211         // mobile/android/installer/stage-package` doesn't work as expected.
212         commandLine mozconfig.substs.GMAKE
213         args '-C'
214         args "${topobjdir}/mobile/android/installer"
215         args 'stage-package'
217         outputs.file "${topobjdir}/dist/fennec/assets/${mozconfig.substs.ANDROID_CPU_ARCH}/libxul.so"
218         outputs.file "${topobjdir}/dist/fennec/lib/${mozconfig.substs.ANDROID_CPU_ARCH}/libmozglue.so"
220         // `path` is like `:machStagePackage`.
221         standardOutput = new TaggedLogOutputStream("${path}>", logger)
222         errorOutput = standardOutput
223     }
226 createMachStagePackageTask("machStagePackageForFennec").with {
227     outputs.file "${topobjdir}/dist/fennec/assets/omni.ja"
230 createMachStagePackageTask("machStagePackageForGeckoview").with {
231     args 'MOZ_GECKOVIEW_JAR=1'
232     outputs.file "${topobjdir}/dist/geckoview/assets/omni.ja"
233     // Avoid races between stage-package invocations.
234     mustRunAfter tasks["machStagePackageForFennec"]
237 afterEvaluate {
238     subprojects { project ->
239         if (project.name != 'thirdparty') {
240             tasks.withType(JavaCompile) {
241                 // Add compiler args for all code except third-party code.
242                 options.compilerArgs += [
243                     // Turn on all warnings, except...
244                     "-Xlint:all",
245                     // Deprecation, because we do use deprecated API for compatibility.
246                     "-Xlint:-deprecation",
247                     // Serial, because we don't use Java serialization.
248                     "-Xlint:-serial",
249                     // Classfile, because javac has a bug with MethodParameters attributes
250                     // with Java 7. https://bugs.openjdk.java.net/browse/JDK-8190452
251                     "-Xlint:-classfile",
252                     // Turn all remaining warnings into errors,
253                     // unless marked by @SuppressWarnings.
254                     "-Werror"]
255             }
256             if (project.name == 'app') {
257                 tasks.withType(JavaCompile) {
258                     // Turn off classfile warnings because upon updating to play services 15.0.0
259                     // a warning is being thrown from play-services-base which fails the build
260                     // (com/google/android/gms/common/api/GoogleApiClient.class):
261                     // warning: Cannot find annotation method 'value()' in type 'GuardedBy':
262                     // class file for javax.annotation.concurrent.GuardedBy not found
263                     options.compilerArgs += ["-Xlint:-classfile"]
264                 }
265             }
266         }
268         if (!hasProperty('android')) {
269             return
270         }
271         android.applicationVariants.all {
272             preBuild.dependsOn rootProject.machBuildGeneratedAndroidCodeAndResources
273         }
274         android.libraryVariants.all {
275             preBuild.dependsOn rootProject.machBuildGeneratedAndroidCodeAndResources
276         }
277     }
280 apply plugin: 'idea'
282 idea {
283     project {
284         languageLevel = '1.8'
285     }
287     module {
288         // Object directories take a huge amount of time for IntelliJ to index.
289         // Exclude them.  Convention is that object directories start with obj.
290         // IntelliJ is clever and will not exclude the parts of the object
291         // directory that are referenced, if there are any.  In practice,
292         // indexing the entirety of the tree is taking too long, so exclude all
293         // but mobile/.
294         def topsrcdirURI = file(topsrcdir).toURI()
295         excludeDirs += files(file(topsrcdir)
296             .listFiles({it.isDirectory()} as FileFilter)
297             .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
298             .findAll({!it.equals('mobile/')}))
300         // If topobjdir is below topsrcdir, hide only some portions of that tree.
301         def topobjdirURI = file(topobjdir).toURI()
302         if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
303             excludeDirs -= file(topobjdir)
304             excludeDirs += files(file(topobjdir).listFiles())
305             excludeDirs -= file("${topobjdir}/gradle")
306         }
308         if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
309             excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
310         }
311     }
314 task wrapper(type: Wrapper) {