Bug 1658791: enable "dom/base/test/test_setting_opener.html" for xorigin iframes...
[gecko.git] / build.gradle
blob4a18fdfcd651503f173492eadf4499a648d9e17d
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         buildToolsVersion = mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION
19         compileSdkVersion = tryInt(mozconfig.substs.ANDROID_TARGET_SDK)
20         targetSdkVersion = tryInt(mozconfig.substs.ANDROID_TARGET_SDK)
21         minSdkVersion = tryInt(mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION)
22         manifestPlaceholders = [
23             ANDROID_PACKAGE_NAME: mozconfig.substs.ANDROID_PACKAGE_NAME,
24             ANDROID_TARGET_SDK: mozconfig.substs.ANDROID_TARGET_SDK,
25             MOZ_ANDROID_MIN_SDK_VERSION: mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION,
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.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'
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     }
85     dependencies {
86         classpath 'org.mozilla.apilint:apilint:0.3.0'
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     }
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
100     TaggedLogOutputStream(tag, logger) {
101         this.tag = tag
102         this.logger = logger
103     }
105     void processLine(String line, int level) {
106         logger.lifecycle("${this.tag} ${line}")
107     }
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     }
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     }
123     // Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale.  To
124     // avoid failures, if Gradle is invoked with AB_CD=multi, we don't invoke
125     // Make at all.
126     if ('multi' == System.env.AB_CD) {
127         rootProject.logger.lifecycle("Skipping task ${task.path} because: AB_CD=multi")
128         return false
129     }
131     // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource
132     // and code generation themselves.
133     if ('1' == System.env.IS_LANGUAGE_REPACK) {
134         rootProject.logger.lifecycle("Skipping task ${task.path} because: IS_LANGUAGE_REPACK")
135         return false
136     }
138     rootProject.logger.lifecycle("Executing task ${task.path}")
139     return true
142 class MachExec extends Exec {
143     def MachExec() {
144         // Bug 1543982: When invoking `mach build` recursively, the outer `mach
145         // build` itself modifies the environment, causing configure to run
146         // again.  This tries to restore the environment that the outer `mach
147         // build` was invoked in.  See the comment in
148         // $topsrcdir/settings.gradle.
149         project.ext.mozconfig.mozconfig.env.unmodified.each { k, v -> environment.remove(k) }
150         environment project.ext.mozconfig.orig_mozconfig.env.unmodified
151     }
154 task machBuildFaster(type: MachExec) {
155     onlyIf rootProject.ext.geckoBinariesOnlyIf
157     workingDir "${topsrcdir}"
159     commandLine mozconfig.substs.PYTHON3
160     args "${topsrcdir}/mach"
161     args 'build'
162     args 'faster'
164     // Add `-v` if we're running under `--info` (or `--debug`).
165     if (project.logger.isEnabled(LogLevel.INFO)) {
166         args '-v'
167     }
169     // `path` is like `:machBuildFaster`.
170     standardOutput = new TaggedLogOutputStream("${path}>", logger)
171     errorOutput = standardOutput
174 task machStagePackage(type: MachExec) {
175     onlyIf rootProject.ext.geckoBinariesOnlyIf
177     dependsOn rootProject.machBuildFaster
179     workingDir "${topobjdir}"
181     // We'd prefer this to be a `mach` invocation, but `mach build
182     // mobile/android/installer/stage-package` doesn't work as expected.
183     commandLine mozconfig.substs.GMAKE
184     args '-C'
185     args "${topobjdir}/mobile/android/installer"
186     args 'stage-package'
188     outputs.file "${topobjdir}/dist/geckoview/assets/omni.ja"
190     outputs.file "${topobjdir}/dist/geckoview/assets/${mozconfig.substs.ANDROID_CPU_ARCH}/libxul.so"
191     outputs.file "${topobjdir}/dist/geckoview/lib/${mozconfig.substs.ANDROID_CPU_ARCH}/libmozglue.so"
193     // Force running `stage-package`.
194     outputs.upToDateWhen { false }
196     // `path` is like `:machStagePackage`.
197     standardOutput = new TaggedLogOutputStream("${path}>", logger)
198     errorOutput = standardOutput
201 afterEvaluate {
202     subprojects { project ->
203         tasks.withType(JavaCompile) {
204             // Add compiler args for all code except third-party code.
205             options.compilerArgs += [
206                 // Turn on all warnings, except...
207                 "-Xlint:all",
208                 // Deprecation, because we do use deprecated API for compatibility.
209                 "-Xlint:-deprecation",
210                 // Serial, because we don't use Java serialization.
211                 "-Xlint:-serial",
212                 // Classfile, because javac has a bug with MethodParameters attributes
213                 // with Java 7. https://bugs.openjdk.java.net/browse/JDK-8190452
214                 "-Xlint:-classfile",
215                 // Turn all remaining warnings into errors,
216                 // unless marked by @SuppressWarnings.
217                 "-Werror"]
218         }
219     }
222 apply plugin: 'idea'
224 idea {
225     project {
226         languageLevel = '1.8'
227     }
229     module {
230         // Object directories take a huge amount of time for IntelliJ to index.
231         // Exclude them.  Convention is that object directories start with obj.
232         // IntelliJ is clever and will not exclude the parts of the object
233         // directory that are referenced, if there are any.  In practice,
234         // indexing the entirety of the tree is taking too long, so exclude all
235         // but mobile/.
236         def topsrcdirURI = file(topsrcdir).toURI()
237         excludeDirs += files(file(topsrcdir)
238             .listFiles({it.isDirectory()} as FileFilter)
239             .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
240             .findAll({!it.equals('mobile/')}))
242         // If topobjdir is below topsrcdir, hide only some portions of that tree.
243         def topobjdirURI = file(topobjdir).toURI()
244         if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
245             excludeDirs -= file(topobjdir)
246             excludeDirs += files(file(topobjdir).listFiles())
247             excludeDirs -= file("${topobjdir}/gradle")
248         }
249     }