2018-08-03 21:12:41 +03:00
|
|
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
|
|
|
|
|
|
|
buildscript {
|
2018-12-19 03:46:42 +03:00
|
|
|
ext.kotlin_version = '1.3.10'
|
2019-04-02 23:18:15 +03:00
|
|
|
ext.android_components_version = '0.49.0'
|
2019-04-20 00:56:36 +03:00
|
|
|
ext.jna_version = '5.2.0'
|
2018-08-20 20:41:04 +03:00
|
|
|
|
|
|
|
ext.build = [
|
|
|
|
compileSdkVersion: 27,
|
|
|
|
targetSdkVersion: 27,
|
|
|
|
minSdkVersion: 21, // So that we can publish for aarch64.
|
|
|
|
]
|
|
|
|
|
2018-08-03 21:12:41 +03:00
|
|
|
repositories {
|
|
|
|
google()
|
|
|
|
jcenter()
|
2018-08-20 20:41:04 +03:00
|
|
|
maven {
|
|
|
|
url "https://plugins.gradle.org/m2/"
|
|
|
|
}
|
2018-08-03 21:12:41 +03:00
|
|
|
}
|
|
|
|
dependencies {
|
2019-03-27 00:35:50 +03:00
|
|
|
classpath "com.android.tools.build:gradle:$properties.androidGradlePluginVersion"
|
2018-08-03 21:12:41 +03:00
|
|
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
|
|
|
2018-08-20 20:41:04 +03:00
|
|
|
// Publish.
|
2018-11-15 08:13:33 +03:00
|
|
|
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
|
|
|
|
classpath 'digital.wup:android-maven-publish:3.6.2'
|
2018-08-20 20:41:04 +03:00
|
|
|
|
2019-04-19 22:16:41 +03:00
|
|
|
classpath 'gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.1'
|
2018-08-20 20:41:04 +03:00
|
|
|
|
2018-09-19 02:49:44 +03:00
|
|
|
// Yes, this is unusual. We want to access some host-specific
|
|
|
|
// computation at build time.
|
2019-04-20 00:56:36 +03:00
|
|
|
classpath "net.java.dev.jna:jna:$jna_version"
|
2018-09-19 02:49:44 +03:00
|
|
|
|
2018-11-06 02:03:20 +03:00
|
|
|
// Downloading libs/ archives from Taskcluster.
|
|
|
|
classpath 'de.undercouch:gradle-download-task:3.4.3'
|
|
|
|
|
2019-02-06 00:44:51 +03:00
|
|
|
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.8'
|
|
|
|
|
2018-08-03 21:12:41 +03:00
|
|
|
// NOTE: Do not place your application dependencies here; they belong
|
|
|
|
// in the individual module build.gradle files
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:05:47 +03:00
|
|
|
plugins {
|
|
|
|
id("io.gitlab.arturbosch.detekt").version("1.0.0-RC14")
|
|
|
|
}
|
|
|
|
|
2018-11-06 02:03:20 +03:00
|
|
|
apply plugin: 'de.undercouch.download'
|
|
|
|
|
2018-08-03 21:12:41 +03:00
|
|
|
allprojects {
|
|
|
|
repositories {
|
|
|
|
google()
|
|
|
|
jcenter()
|
2019-03-21 20:43:12 +03:00
|
|
|
maven {
|
|
|
|
url "https://maven.mozilla.org/maven2"
|
|
|
|
}
|
2018-08-03 21:12:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 08:13:33 +03:00
|
|
|
subprojects {
|
|
|
|
apply plugin: 'digital.wup.android-maven-publish'
|
|
|
|
|
|
|
|
// This allows to invoke Gradle like `./gradlew publishToRootProjectBuildDir` (equivalent to
|
|
|
|
// `./gradlew publish`) and also `./gradlew publishToProjectBuildDir`.
|
|
|
|
publishing {
|
|
|
|
repositories {
|
|
|
|
maven {
|
|
|
|
name = "rootProjectBuildDir"
|
|
|
|
url "file://${project.rootProject.buildDir}/maven"
|
|
|
|
}
|
|
|
|
maven {
|
|
|
|
name = "projectBuildDir"
|
|
|
|
url "file://${project.buildDir}/maven"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-27 00:35:50 +03:00
|
|
|
|
|
|
|
apply plugin: NativeLibsPlugin
|
|
|
|
nativeLibs {
|
|
|
|
nss {
|
|
|
|
lib "libplc4.*"
|
|
|
|
lib "libplds4.*"
|
|
|
|
lib "libnspr4.*"
|
|
|
|
lib "*freebl3.*"
|
|
|
|
lib "*nss3.*"
|
|
|
|
lib "*nssckbi.*"
|
|
|
|
lib "*nssutil3.*"
|
|
|
|
lib "*softokn3.*"
|
|
|
|
lib "*smime3.*"
|
2019-04-19 05:18:02 +03:00
|
|
|
lib "*sqlite3.*"
|
2019-03-27 00:35:50 +03:00
|
|
|
// We don't need SSL so we might as well save space.
|
|
|
|
// lib "libssl3.*"
|
|
|
|
}
|
|
|
|
}
|
2018-11-15 08:13:33 +03:00
|
|
|
}
|
|
|
|
|
2018-08-03 21:12:41 +03:00
|
|
|
task clean(type: Delete) {
|
|
|
|
delete rootProject.buildDir
|
|
|
|
}
|
2018-11-06 01:16:40 +03:00
|
|
|
|
|
|
|
// Avoid Gradle namespace collision. This is here, rather than in `buildscript
|
|
|
|
// { ... }`, to avoid issues with importing.
|
|
|
|
import com.sun.jna.Platform as DefaultPlatform
|
|
|
|
|
2019-03-14 22:51:01 +03:00
|
|
|
// If this is `null`, we use libs from the source directory.
|
|
|
|
// Check if there are any changes to `libs` since `master`, and if not,
|
|
|
|
// use the sha to download the artifacts from taskcluster.
|
2019-03-18 23:17:50 +03:00
|
|
|
//
|
|
|
|
// Note we pass the path to the git-dir so that this still works when
|
|
|
|
// used as a dependency substitution from e.g. android-components.
|
|
|
|
ext.libsGitSha = "git --git-dir=${rootProject.rootDir}/.git diff --name-only master -- :/libs".execute().text.allWhitespace ?
|
|
|
|
"git --git-dir=${rootProject.rootDir}/.git rev-parse HEAD:libs".execute().text.trim() : null
|
|
|
|
|
2018-11-06 02:03:20 +03:00
|
|
|
|
|
|
|
if (rootProject.ext.libsGitSha != null) {
|
|
|
|
task downloadAndroidLibs(type: Download) {
|
|
|
|
src "https://index.taskcluster.net/v1/task/project.application-services.application-services.build.libs.android.${rootProject.ext.libsGitSha}/artifacts/public/target.tar.gz"
|
|
|
|
dest new File(buildDir, "libs.android.${rootProject.ext.libsGitSha}.tar.gz")
|
|
|
|
|
|
|
|
doFirst {
|
|
|
|
if (it.dest.exists()) {
|
|
|
|
throw new StopExecutionException("File to download already exists: ${it.dest.path}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
overwrite true
|
|
|
|
}
|
|
|
|
|
|
|
|
task untarAndroidLibs(dependsOn: downloadAndroidLibs, type: Copy) {
|
|
|
|
from tarTree(downloadAndroidLibs.dest)
|
|
|
|
into rootProject.buildDir
|
|
|
|
}
|
|
|
|
|
|
|
|
task downloadDesktopLibs(type: Download) {
|
|
|
|
src {
|
|
|
|
switch (DefaultPlatform.RESOURCE_PREFIX) {
|
|
|
|
case 'darwin':
|
|
|
|
return "https://index.taskcluster.net/v1/task/project.application-services.application-services.build.libs.desktop.macos.${rootProject.ext.libsGitSha}/artifacts/public/target.tar.gz"
|
|
|
|
case 'linux-x86-64':
|
|
|
|
return "https://index.taskcluster.net/v1/task/project.application-services.application-services.build.libs.desktop.linux.${rootProject.ext.libsGitSha}/artifacts/public/target.tar.gz"
|
2018-11-07 22:17:29 +03:00
|
|
|
case 'win32-x86-64':
|
|
|
|
return "https://index.taskcluster.net/v1/task/project.application-services.application-services.build.libs.desktop.win32-x86-64.${rootProject.ext.libsGitSha}/artifacts/public/target.tar.gz"
|
2018-11-06 02:03:20 +03:00
|
|
|
default:
|
|
|
|
throw new GradleException("Unknown host platform '${DefaultPlatform.RESOURCE_PREFIX}'. " +
|
|
|
|
"Set `ext.libsGitSha = null` in ${rootProject.rootDir}/build.gradle and build your own libs. " +
|
|
|
|
"If you don't want to build your own libs for Android, you can untar\n\n${downloadAndroidLibs.src}\n\nat top-level to populate `libs/android/`. " +
|
|
|
|
"You'll need build your own libs for your host platform in order to be able to build and run unit tests.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dest {
|
|
|
|
switch (DefaultPlatform.RESOURCE_PREFIX) {
|
|
|
|
case 'darwin':
|
|
|
|
return new File(buildDir, "libs.desktop.macos.${rootProject.ext.libsGitSha}.tar.gz")
|
|
|
|
case 'linux-x86-64':
|
|
|
|
return new File(buildDir, "libs.desktop.linux.${rootProject.ext.libsGitSha}.tar.gz")
|
2018-11-07 22:17:29 +03:00
|
|
|
case 'win32-x86-64':
|
|
|
|
return new File(buildDir, "libs.desktop.win32-x86-64.${rootProject.ext.libsGitSha}.tar.gz")
|
2018-11-06 02:03:20 +03:00
|
|
|
default:
|
|
|
|
throw new GradleException("Unknown host platform '${DefaultPlatform.RESOURCE_PREFIX}'. " +
|
|
|
|
"Set `ext.libsGitSha = null` in ${rootProject.rootDir}/build.gradle and build your own libs.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
doFirst {
|
|
|
|
if (it.dest.exists()) {
|
|
|
|
throw new StopExecutionException("File to download already exists: ${it.dest.path}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
overwrite true
|
|
|
|
}
|
|
|
|
|
|
|
|
task untarDesktopLibs(dependsOn: downloadDesktopLibs, type: Copy) {
|
|
|
|
from tarTree(downloadDesktopLibs.dest)
|
|
|
|
into rootProject.buildDir
|
|
|
|
}
|
|
|
|
|
|
|
|
subprojects { project ->
|
|
|
|
afterEvaluate {
|
|
|
|
android.libraryVariants.all { v ->
|
|
|
|
def task = v.preBuild
|
|
|
|
task.dependsOn(rootProject.untarAndroidLibs)
|
|
|
|
task.dependsOn(rootProject.untarDesktopLibs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-15 22:09:50 +03:00
|
|
|
Properties localProperties = null;
|
|
|
|
if (file('local.properties').canRead()) {
|
|
|
|
localProperties = new Properties();
|
|
|
|
localProperties.load(file('local.properties').newDataInputStream())
|
|
|
|
logger.lifecycle('Local configuration: loaded local.properties')
|
|
|
|
}
|
|
|
|
|
|
|
|
// For non-megazord builds, don't do a release build unless we explicitly want
|
|
|
|
// it (e.g. in CI, or if specified in local.properties). This avoids some cases
|
|
|
|
// where two builds of some crates are required when they wouldn't otherwise be,
|
|
|
|
// as well as improving build times for local development.
|
|
|
|
ext.nonMegazordProfile = "debug"
|
2019-04-19 22:16:41 +03:00
|
|
|
// Additionally, we require `--locked` in CI, but not for local builds.
|
|
|
|
// Unlike the above, this can't be overridden by `local.properties` (mainly
|
|
|
|
// because doing so seems pointless, not for any security reason)
|
|
|
|
ext.extraCargoBuildArguments = []
|
2019-03-15 22:09:50 +03:00
|
|
|
|
|
|
|
if (System.getenv("CI")) {
|
2019-04-12 00:55:53 +03:00
|
|
|
// Note: CI can still override this (and does for PRs), this
|
|
|
|
// is just the default
|
2019-03-15 22:09:50 +03:00
|
|
|
ext.nonMegazordProfile = "release"
|
2019-04-19 22:16:41 +03:00
|
|
|
ext.extraCargoBuildArguments = ["--locked"]
|
2019-04-12 00:55:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (localProperties != null) {
|
2019-03-15 22:09:50 +03:00
|
|
|
String localNonMegazordProfile = localProperties.getProperty(
|
|
|
|
"application-services.nonmegazord-profile");
|
|
|
|
if (localNonMegazordProfile != null) {
|
|
|
|
ext.nonMegazordProfile = localNonMegazordProfile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 09:54:06 +03:00
|
|
|
// The Cargo targets to invoke. The mapping from short name to target
|
|
|
|
// triple is defined by the `rust-android-gradle` plugin.
|
2019-04-18 03:57:47 +03:00
|
|
|
// They can be overwritten in `local.properties` by the `rust.targets`
|
|
|
|
// attribute.
|
2019-03-18 09:54:06 +03:00
|
|
|
ext.rustTargets = [
|
|
|
|
'arm',
|
|
|
|
'arm64',
|
|
|
|
'x86_64',
|
|
|
|
'x86',
|
|
|
|
]
|
2019-04-18 03:57:47 +03:00
|
|
|
|
|
|
|
// Generate libs for our current platform so we can run unit tests.
|
|
|
|
switch (DefaultPlatform.RESOURCE_PREFIX) {
|
|
|
|
case 'darwin':
|
|
|
|
ext.rustTargets += 'darwin'
|
|
|
|
break
|
|
|
|
case 'linux-x86-64':
|
|
|
|
ext.rustTargets += 'linux-x86-64'
|
|
|
|
break
|
|
|
|
case 'win32-x86-64':
|
|
|
|
ext.rustTargets += 'win32-x86-64-gnu'
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2019-04-19 21:38:57 +03:00
|
|
|
// Use in-tree libs from the source directory in CI or if the git SHA is unset; otherwise use
|
|
|
|
// downloaded libs.
|
|
|
|
def libsRootDir = (System.getenv('CI') || ext.libsGitSha == null) ? rootProject.rootDir : rootProject.buildDir
|
|
|
|
|
2018-11-06 01:16:40 +03:00
|
|
|
// Configure some environment variables, per toolchain, that will apply during
|
|
|
|
// the Cargo build. We assume that the `libs/` directory has been populated
|
|
|
|
// before invoking Gradle (or Cargo).
|
|
|
|
ext.cargoExec = { spec, toolchain ->
|
|
|
|
spec.environment("OPENSSL_STATIC", "1")
|
2019-04-15 23:29:05 +03:00
|
|
|
spec.environment("NSS_DIR", new File(libsRootDir, "libs/${toolchain.folder}/nss").absolutePath)
|
2018-11-27 23:43:01 +03:00
|
|
|
spec.environment("OPENSSL_DIR", new File(libsRootDir, "libs/${toolchain.folder}/openssl").absolutePath)
|
2019-04-19 21:38:57 +03:00
|
|
|
}
|
|
|
|
// Strictly speaking, we could always specify `SQLCIPHER_LIB_DIR` and
|
|
|
|
// `SQLCIPHER_INCLUDE_DIR`, and so long as everything else is configured right,
|
|
|
|
// we wouldn't bring it in. That said, by only specifying it when we expect it
|
|
|
|
// to be needed, we force a compilation (well, linking) failure if the
|
|
|
|
// configuration is otherwise wrong.
|
|
|
|
ext.cargoExecWithSQLCipher = { spec, toolchain ->
|
|
|
|
ext.cargoExec(spec, toolchain)
|
2018-11-27 23:43:01 +03:00
|
|
|
spec.environment("SQLCIPHER_LIB_DIR", new File(libsRootDir, "libs/${toolchain.folder}/sqlcipher/lib").absolutePath)
|
|
|
|
spec.environment("SQLCIPHER_INCLUDE_DIR", new File(libsRootDir, "libs/${toolchain.folder}/sqlcipher/include").absolutePath)
|
|
|
|
}
|
2019-03-22 23:05:47 +03:00
|
|
|
|
|
|
|
detekt {
|
|
|
|
// The version number is duplicated, please refer to plugins block for more details
|
|
|
|
toolVersion = "1.0.0-RC14"
|
2019-03-27 00:35:50 +03:00
|
|
|
input = files("${projectDir}/components", "${projectDir}/gradle-plugin", "buildSrc")
|
2019-03-22 23:05:47 +03:00
|
|
|
filters = ".*test.*,.*/resources/.*,.*/tmp/.*,.*/build/.*"
|
|
|
|
config = files("${projectDir}/.detekt.yml")
|
|
|
|
failFast = false
|
|
|
|
reports {
|
|
|
|
xml.enabled = false
|
|
|
|
}
|
|
|
|
}
|
2019-03-22 23:06:00 +03:00
|
|
|
|
|
|
|
configurations {
|
|
|
|
ktlint
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
ktlint "com.github.shyiko:ktlint:0.31.0"
|
|
|
|
}
|
|
|
|
|
|
|
|
task ktlint(type: JavaExec, group: "verification") {
|
|
|
|
description = "Check Kotlin code style."
|
|
|
|
classpath = configurations.ktlint
|
|
|
|
main = "com.github.shyiko.ktlint.Main"
|
2019-03-27 00:35:50 +03:00
|
|
|
args "${projectDir}/components/**/*.kt", "${projectDir}/gradle-plugin/**/*.kt", "buildSrc/**/*.kt", "!**/build"
|
2019-03-22 23:06:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
task ktlintFormat(type: JavaExec, group: "formatting") {
|
|
|
|
description = "Fix Kotlin code style deviations."
|
|
|
|
classpath = configurations.ktlint
|
|
|
|
main = "com.github.shyiko.ktlint.Main"
|
2019-03-27 00:35:50 +03:00
|
|
|
args "-F", "${projectDir}/components/**/*.kt", "${projectDir}/gradle-plugin/**/*.kt", "buildSrc/**/*.kt", "!**/build"
|
2019-03-22 23:06:00 +03:00
|
|
|
}
|