Bug 1378239 - Change mozinfo 'coverage' flag to 'ccov' to avoid ambiguity. r=ahal
[gecko.git] / build.gradle
blob2d3ff0dbe3de52868dae831359619b3b9b2dfde9
1 import java.util.regex.Pattern
3 allprojects {
4     // Expose the per-object-directory configuration to all projects.
5     ext {
6         mozconfig = gradle.mozconfig
7         topsrcdir = gradle.mozconfig.topsrcdir
8         topobjdir = gradle.mozconfig.topobjdir
9     }
11     repositories {
12         if (gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY) {
13             maven {
14                 url gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY
15             }
16         }
17     }
20 buildDir "${topobjdir}/gradle/build"
22 buildscript {
23     repositories {
24         if (gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY) {
25             maven {
26                 url gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORY
27             }
28         }
29         // For android-sdk-manager SNAPSHOT releases.
30         maven {
31             url "file://${gradle.mozconfig.topsrcdir}/mobile/android/gradle/m2repo"
32         }
33     }
35     dependencies {
36         classpath 'com.android.tools.build:gradle:2.1.3'
37         classpath('com.stanfy.spoon:spoon-gradle-plugin:1.0.4') {
38             // Without these, we get errors linting.
39             exclude module: 'guava'
40         }
41         // Provided in tree.
42         classpath 'com.jakewharton.sdkmanager:gradle-plugin:1.5.0-SNAPSHOT'
43         classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.1'
44     }
47 task generateCodeAndResources(type:Exec) {
48     workingDir "${topobjdir}"
50     commandLine mozconfig.substs.GMAKE
51     args '-C'
52     args "${topobjdir}/mobile/android/base"
53     args 'gradle-targets'
55     // Only show the output if something went wrong.
56     ignoreExitValue = true
57     standardOutput = new ByteArrayOutputStream()
58     errorOutput = standardOutput
59     doLast {
60         if (execResult.exitValue != 0) {
61             throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${execResult.exitValue}:\n\n${standardOutput.toString()}")
62         }
63     }
66 // Skip unit test for all build variants, unless if it was specifically requested by user.
67 // The enabled property for the unit test tasks is reset based on the command line task names just before the task execution.
68 // I bet there is a easier/cleaner way to do this, but this gets the job done for now.
69 Pattern pattern = Pattern.compile('.*test(.+UnitTest)?.*')
70 boolean startTasksIncludeTest = gradle.startParameter.taskNames.any {
71     taskName ->
72         taskName.matches(pattern)
74 gradle.taskGraph.beforeTask {
75     Task task ->
76         if (task.name.matches(pattern)) {
77             task.enabled = startTasksIncludeTest
78         }
81 afterEvaluate {
82     subprojects {
83         if (!hasProperty('android')) {
84             return
85         }
86         android.applicationVariants.all {
87             preBuild.dependsOn rootProject.generateCodeAndResources
88         }
89         android.libraryVariants.all {
90             preBuild.dependsOn rootProject.generateCodeAndResources
91         }
92     }
95 apply plugin: 'idea'
97 idea {
98     project {
99         languageLevel = '1.7'
100     }
102     module {
103         // Object directories take a huge amount of time for IntelliJ to index.
104         // Exclude them.  Convention is that object directories start with obj.
105         // IntelliJ is clever and will not exclude the parts of the object
106         // directory that are referenced, if there are any.  In practice,
107         // indexing the entirety of the tree is taking too long, so exclude all
108         // but mobile/.
109         def topsrcdirURI = file(topsrcdir).toURI()
110         excludeDirs += files(file(topsrcdir)
111             .listFiles({it.isDirectory()} as FileFilter)
112             .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.
113             .findAll({!it.equals('mobile/')}))
115         // If topobjdir is below topsrcdir, hide only some portions of that tree.
116         def topobjdirURI = file(topobjdir).toURI()
117         if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
118             excludeDirs -= file(topobjdir)
119             excludeDirs += files(file(topobjdir).listFiles())
120             excludeDirs -= file("${topobjdir}/gradle")
121         }
123         if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
124             excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")
125         }
126     }
129 task wrapper(type: Wrapper) {