author Mike Hommey <>
Fri, 22 Jan 2016 10:02:48 +0900
changeset 316315 e9996f9ea66f064494ac7f91aacefd142cb6babc
parent 309821 7fb27cc3a41695df71c52db2bf093fdf8cdb43be
child 316553 db7cf2a8fd1107919d7b1affd4e4caea62789ba9
permissions -rw-r--r--
Bug 1239217 - Make the RecursiveMake build system create backend files generically. r=gps The current rule is only for "backend.RecursiveMakeBackend", but, with the current default of generating both the RecursiveMake and FasterMake backends, the command creates/refreshes both backends. This is, in fact, how the FasterMake backend is refreshed in most cases. Moreover, with an hybrid backends, the generated file is not "backend.RecursiveMakeBackend" anymore, so we need a more generic way to handle this. Furthermore, it's not necessarily desirable for all backends to have a dependency file to handle the dependencies to refresh the backend, so generate a plain list instead. This has the side effect of making `mach build-backend --diff` more readable for changes to that file. Finally, make the backend.* files created like any other backend file, such that its diff appears in the `mach build-backend --diff` output.

import java.util.regex.Pattern

allprojects {
    // Expose the per-object-directory configuration to all projects.
    ext {
        mozconfig = gradle.mozconfig
        topsrcdir = gradle.mozconfig.topsrcdir
        topobjdir = gradle.mozconfig.topobjdir

    repositories {

buildDir "${topobjdir}/gradle/build"

buildscript {
    repositories {

        // For spoon-gradle-plugin SNAPSHOT release.  This needs to go before
        // the snapshots repository, otherwise we find a remote 1.0.3-SNAPSHOT
        // that doesn't include nalexander's local changes.
        maven {
            url "file://${gradle.mozconfig.topsrcdir}/mobile/android/gradle/m2repo"
        // For spoon SNAPSHOT releases.
        maven {
            url ''

    dependencies {
        // Unit testing support was added in 1.1.0. IntelliJ 14.1.4 and Android
        // Studio appear to work fine with plugin version 1.3.0.
        classpath ''
        classpath('com.stanfy.spoon:spoon-gradle-plugin:1.0.3-SNAPSHOT') {
            // Without these, we get errors linting.
            exclude module: 'guava'

task generateCodeAndResources(type:Exec) {
    workingDir "${topobjdir}"

    commandLine mozconfig.substs.GMAKE
    args '-C'
    args "${topobjdir}/mobile/android/base"
    args 'gradle-targets'

    // Only show the output if something went wrong.
    ignoreExitValue = true
    standardOutput = new ByteArrayOutputStream()
    errorOutput = standardOutput
    doLast {
        if (execResult.exitValue != 0) {
            throw new GradleException("Process '${commandLine}' finished with non-zero exit value ${execResult.exitValue}:\n\n${standardOutput.toString()}")

// Skip unit test for all build variants, unless if it was specifically requested by user.
// The enabled property for the unit test tasks is reset based on the command line task names just before the task execution.
// I bet there is a easier/cleaner way to do this, but this gets the job done for now.
Pattern pattern = Pattern.compile('.*test(.+UnitTest)?.*')
boolean startTasksIncludeTest = gradle.startParameter.taskNames.any {
    taskName ->
gradle.taskGraph.beforeTask {
    Task task ->
        if ( {
            task.enabled = startTasksIncludeTest

afterEvaluate {
    subprojects {
        if (!hasProperty('android')) {
        android.applicationVariants.all {
            preBuild.dependsOn rootProject.generateCodeAndResources
        android.libraryVariants.all {
            preBuild.dependsOn rootProject.generateCodeAndResources

apply plugin: 'idea'

idea {
    project {
        languageLevel = '1.7'

    module {
        // Object directories take a huge amount of time for IntelliJ to index.
        // Exclude them.  Convention is that object directories start with obj.
        // IntelliJ is clever and will not exclude the parts of the object
        // directory that are referenced, if there are any.  In practice,
        // indexing the entirety of the tree is taking too long, so exclude all
        // but mobile/.
        def topsrcdirURI = file(topsrcdir).toURI()
        excludeDirs += files(file(topsrcdir)
            .listFiles({it.isDirectory()} as FileFilter)
            .collect({topsrcdirURI.relativize(it.toURI()).toString()}) // Relative paths.

        // If topobjdir is below topsrcdir, hide only some portions of that tree.
        def topobjdirURI = file(topobjdir).toURI()
        if (!topsrcdirURI.relativize(topobjdirURI).isAbsolute()) {
            excludeDirs -= file(topobjdir)
            excludeDirs += files(file(topobjdir).listFiles())
            excludeDirs -= file("${topobjdir}/gradle")

        if (!mozconfig.substs.MOZ_INSTALL_TRACKING) {
            excludeDirs += file("${topsrcdir}/mobile/android/thirdparty/com/adjust")

task wrapper(type: Wrapper) {