Bug 1622408 [wpt PR 22244] - Restore the event delegate for a CSSTransition after...
[gecko.git] / build.gradle
blob182b3f62d63591ae8d9c134fa2d5542b5c17afad
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         ]
26     }
28     repositories {
29         gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
30             maven {
31                 url repository
32             }
33         }
34     }
36     task downloadDependencies() {
37         description 'Download all dependencies to the Gradle cache'
38         doLast {
39             configurations.each { configuration ->
40                 if (configuration.canBeResolved) {
41                     configuration.allDependencies.each { dependency ->
42                         try {
43                             configuration.files(dependency)
44                         } catch(e) {
45                             println("Could not resolve ${configuration.name} -> ${dependency.name}")
46                             println(" > ${e.message}")
47                             if (e.cause) {
48                                 println(" >> ${e.cause}")
49                                 if (e.cause.cause) {
50                                     println(" >> ${e.cause.cause}")
51                                 }
52                             }
53                             println("")
54                         }
55                     }
56                 }
57             }
58         }
59     }
62 buildDir "${topobjdir}/gradle/build"
64 buildscript {
65     repositories {
66         gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
67             maven {
68                 url repository
69             }
70         }
71     }
73     ext.kotlin_version = '1.3.41'
74     ext.support_library_version = '28.0.0'
75     ext.jacoco_version = '0.8.1'
76     ext.lifecycle_library_version = '1.1.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         ext.google_play_services_fido_version = '17.0.0'
82     }
84     dependencies {
85         classpath 'org.mozilla.apilint:apilint:0.2.6'
86         classpath 'com.android.tools.build:gradle:3.4.2'
87         classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
88         classpath 'org.apache.commons:commons-exec:1.3'
89         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
90     }
93 // A stream that processes bytes line by line, prepending a tag before sending
94 // each line to Gradle's logging.
95 class TaggedLogOutputStream extends org.apache.commons.exec.LogOutputStream {
96     String tag
97     Logger logger
99     TaggedLogOutputStream(tag, logger) {
100         this.tag = tag
101         this.logger = logger
102     }
104     void processLine(String line, int level) {
105         logger.lifecycle("${this.tag} ${line}")
106     }
109 ext.geckoBinariesOnlyIf = { task ->
110     // Never when Gradle was invoked within `mach build`.
111     if ('1' == System.env.GRADLE_INVOKED_WITHIN_MACH_BUILD) {
112         rootProject.logger.lifecycle("Skipping task ${task.path} because: within `mach build`")
113         return false
114     }
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 class MachExec extends Exec {
148     def MachExec() {
149         // Bug 1543982: When invoking `mach build` recursively, the outer `mach
150         // build` itself modifies the environment, causing configure to run
151         // again.  This tries to restore the environment that the outer `mach
152         // build` was invoked in.  See the comment in
153         // $topsrcdir/settings.gradle.
154         project.ext.mozconfig.mozconfig.env.unmodified.each { k, v -> environment.remove(k) }
155         environment project.ext.mozconfig.orig_mozconfig.env.unmodified
156     }
159 // Why |mach build mobile/android/base/...| and |mach build faster|?  |mach
160 // build faster| generates dependentlibs.list, which in turn depends on compiled
161 // code.  That causes a circular dependency between Java compilation/JNI wrapper
162 // generation/native code compilation.  So we have the special target for
163 // Android-specific generated code, and the |mach build faster| target for all
164 // the stuff that goes into the omnijar.
165 task machBuildFaster(type: MachExec) {
166     onlyIf rootProject.ext.geckoBinariesOnlyIf
168     workingDir "${topsrcdir}"
170     commandLine mozconfig.substs.PYTHON
171     args "${topsrcdir}/mach"
172     args 'build'
173     args 'faster'
175     // Add `-v` if we're running under `--info` (or `--debug`).
176     if (project.logger.isEnabled(LogLevel.INFO)) {
177         args '-v'
178     }
180     // `path` is like `:machBuildFaster`.
181     standardOutput = new TaggedLogOutputStream("${path}>", logger)
182     errorOutput = standardOutput
185 def createMachStagePackageTask(name) {
186     return task(name, type: MachExec) {
187         onlyIf rootProject.ext.geckoBinariesOnlyIf
189         dependsOn rootProject.machBuildFaster
191         workingDir "${topobjdir}"
193         // We'd prefer this to be a `mach` invocation, but `mach build
194         // mobile/android/installer/stage-package` doesn't work as expected.
195         commandLine mozconfig.substs.GMAKE
196         args '-C'
197         args "${topobjdir}/mobile/android/installer"
198         args 'stage-package'
200         outputs.file "${topobjdir}/dist/fennec/assets/${mozconfig.substs.ANDROID_CPU_ARCH}/libxul.so"
201         outputs.file "${topobjdir}/dist/fennec/lib/${mozconfig.substs.ANDROID_CPU_ARCH}/libmozglue.so"
203         // Force running `stage-package`.
204         outputs.upToDateWhen { false }
206         // `path` is like `:machStagePackage`.
207         standardOutput = new TaggedLogOutputStream("${path}>", logger)
208         errorOutput = standardOutput
209     }
212 createMachStagePackageTask("machStagePackageForFennec").with {
213     outputs.file "${topobjdir}/dist/fennec/assets/omni.ja"
216 createMachStagePackageTask("machStagePackageForGeckoview").with {
217     args 'MOZ_GECKOVIEW_JAR=1'
218     outputs.file "${topobjdir}/dist/geckoview/assets/omni.ja"
219     // Avoid races between stage-package invocations.
220     mustRunAfter tasks["machStagePackageForFennec"]
223 afterEvaluate {
224     subprojects { project ->
225         tasks.withType(JavaCompile) {
226             // Add compiler args for all code except third-party code.
227             options.compilerArgs += [
228                 // Turn on all warnings, except...
229                 "-Xlint:all",
230                 // Deprecation, because we do use deprecated API for compatibility.
231                 "-Xlint:-deprecation",
232                 // Serial, because we don't use Java serialization.
233                 "-Xlint:-serial",
234                 // Classfile, because javac has a bug with MethodParameters attributes
235                 // with Java 7. https://bugs.openjdk.java.net/browse/JDK-8190452
236                 "-Xlint:-classfile",
237                 // Turn all remaining warnings into errors,
238                 // unless marked by @SuppressWarnings.
239                 "-Werror"]
240         }
241     }
244 apply plugin: 'idea'
246 idea {
247     project {
248         languageLevel = '1.8'
249     }
251     module {
252         // Object directories take a huge amount of time for IntelliJ to index.
253         // Exclude them.  Convention is that object directories start with obj.
254         // IntelliJ is clever and will not exclude the parts of the object
255         // directory that are referenced, if there are any.  In practice,
256         // indexing the entirety of the tree is taking too long, so exclude all
257         // but mobile/.
258         def topsrcdirURI = file(topsrcdir).toURI()
259         excludeDirs += files(file(topsrcdir)
260             .listFiles({it.isDirectory()} as FileFilter)
261             .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
262             .findAll({!it.equals('mobile/')}))
264         // If topobjdir is below topsrcdir, hide only some portions of that tree.
265         def topobjdirURI = file(topobjdir).toURI()
266         if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
267             excludeDirs -= file(topobjdir)
268             excludeDirs += files(file(topobjdir).listFiles())
269             excludeDirs -= file("${topobjdir}/gradle")
270         }
271     }