build.gradle
author L10n Bumper Bot <release+l10nbumper@mozilla.com>
Mon, 17 Dec 2018 05:00:11 -0800
changeset 506261 e8f9d8975d0f9702b320f8cfcd989bd88db6273d
parent 505203 ecb2818bcd055bc5381d0702c955ee78a64dc41c
child 507697 31bf1cd657a32a8cc0127966c4b823bb2365de78
permissions -rw-r--r--
no bug - Bumping Fennec l10n changesets r=release a=l10n-bump DONTBUILD an -> 176758dc0404 dsb -> 4614a05cf396 fy-NL -> 329815f0d288 gd -> 3d6b27ee5e58 hi-IN -> a886e2b55636 hsb -> a1da7baaac2c hy-AM -> 6f231310c387 kab -> 2cbdc076a185 kk -> 1753bd996be6 lo -> 18b2a9d5cd35 mai -> 0de2b15a802b mr -> 69f8bd0a8e45 ru -> 49be174d9b2b sv-SE -> 4eb4d6069f79 tr -> ace765b25800 trs -> ccc0b3063a5b uk -> 4013e6bffec1 ur -> 8df00f58a967 uz -> a36b000cfbb4

def tryInt = { string ->
    if (string == null) {
        return string
    }
    if (string.isInteger()) {
        return string as Integer
    }
    return string
}

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

        compileSdkVersion = tryInt(mozconfig.substs.ANDROID_COMPILE_SDK_VERSION)
        targetSdkVersion = tryInt(mozconfig.substs.ANDROID_TARGET_SDK)
        minSdkVersion = tryInt(mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION)
        manifestPlaceholders = [
            ANDROID_PACKAGE_NAME: mozconfig.substs.ANDROID_PACKAGE_NAME,
            ANDROID_TARGET_SDK: mozconfig.substs.ANDROID_TARGET_SDK,
            MOZ_ANDROID_MIN_SDK_VERSION: mozconfig.substs.MOZ_ANDROID_MIN_SDK_VERSION,
            MOZ_ANDROID_SHARED_ID: "${mozconfig.substs.ANDROID_PACKAGE_NAME}.sharedID",
        ]
    }

    repositories {
        gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
            maven {
                url repository
            }
        }
    }
}

buildDir "${topobjdir}/gradle/build"

buildscript {
    repositories {
        gradle.mozconfig.substs.GRADLE_MAVEN_REPOSITORIES.each { repository ->
            maven {
                url repository
            }
        }
    }

    ext.kotlin_version = '1.2.41'
    ext.support_library_version = '26.1.0'
    ext.jacoco_version = '0.8.1'

    if (gradle.mozconfig.substs.MOZ_ANDROID_GOOGLE_PLAY_SERVICES) {
        ext.google_play_services_version = '15.0.1'
    }

    dependencies {
        classpath 'org.mozilla.apilint:apilint:0.1.4'
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

if ('multi' == System.env.AB_CD) {
    // Multi-l10n builds set `AB_CD=multi`, which isn't a valid locale.  This
    // causes the
    //
    // |mach build| > |mach gradle| > |make gradle-targets| > AndroidManifest.xml > strings.xml > multi/brand.dtd
    //
    // dependency chain to fail, since multi isn't a real locale.  To avoid
    // this, if Gradle is invoked with AB_CD=multi, we don't invoke Make at all.
    task generateCodeAndResources()
} else if (System.env.IS_LANGUAGE_REPACK == '1') {
    // Single-locale l10n repacks set `IS_LANGUAGE_REPACK=1` and handle resource
    // and code generation themselves.
    task generateCodeAndResources()
} else {
    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()}")
            }
        }
    }
}

afterEvaluate {
    subprojects { project ->
        if (project.name != 'thirdparty') {
            tasks.withType(JavaCompile) {
                // Add compiler args for all code except third-party code.
                options.compilerArgs += [
                    // Turn on all warnings, except...
                    "-Xlint:all",
                    // Deprecation, because we do use deprecated API for compatibility.
                    "-Xlint:-deprecation",
                    // Serial, because we don't use Java serialization.
                    "-Xlint:-serial",
                    // Classfile, because javac has a bug with MethodParameters attributes
                    // with Java 7. https://bugs.openjdk.java.net/browse/JDK-8190452
                    "-Xlint:-classfile",
                    // Turn all remaining warnings into errors,
                    // unless marked by @SuppressWarnings.
                    "-Werror"]
            }
            if (project.name == 'app') {
                tasks.withType(JavaCompile) {
                    // Turn off classfile warnings because upon updating to play services 15.0.0
                    // a warning is being thrown from play-services-base which fails the build
                    // (com/google/android/gms/common/api/GoogleApiClient.class):
                    // warning: Cannot find annotation method 'value()' in type 'GuardedBy':
                    // class file for javax.annotation.concurrent.GuardedBy not found
                    options.compilerArgs += ["-Xlint:-classfile"]
                }
            }
        }

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

apply plugin: 'idea'

idea {
    project {
        languageLevel = '1.8'
    }

    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.
            .findAll({!it.equals('mobile/')}))

        // 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) {
}