Revision control
Copy as Markdown
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
// This is based off:
import groovy.json.JsonOutput
plugins {
alias libs.plugins.gradle.python.envs
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'jacoco'
apply plugin: 'kotlinx-serialization'
/*
* This defines the location of the JSON schema used to validate the pings
* created during unit testing. This uses the vendored schema.
*
* Use `bin/update-schema.sh latest` to update it to the latest upstream version.`
*/
File GLEAN_PING_SCHEMA_PATH = file("$rootDir/glean.1.schema.json")
// This will store the uniffi-bindgen generated files for our component
def UNIFFI_OUT_DIR = layout.buildDirectory.dir("generated/uniffi/")
// Set configuration for the glean_parser
ext.allowGleanInternal = true
ext.gleanNamespace = "mozilla.telemetry.glean"
kotlin {
jvmToolchain(rootProject.ext.build.jvmTargetCompatibility)
}
android {
namespace = "mozilla.telemetry.glean"
ndkVersion rootProject.ext.build.ndkVersion
compileSdkVersion rootProject.ext.build.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.build['minSdkVersion']
targetSdkVersion rootProject.ext.build['targetSdkVersion']
// Carefully escape the string here so it will support `\` in
// Windows paths correctly.
buildConfigField("String", "GLEAN_PING_SCHEMA_PATH", JsonOutput.toJson(GLEAN_PING_SCHEMA_PATH.path))
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
// Export our rules in debug, as a consumer might still enable proguard/r8
consumerProguardFiles "$projectDir/proguard-rules-consumer.pro"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles "$projectDir/proguard-rules-consumer.pro"
}
withoutLib {
initWith release
}
}
sourceSets.main.kotlin.srcDirs += UNIFFI_OUT_DIR
// Uncomment to include debug symbols in native library builds.
// packagingOptions { doNotStrip "**/*.so" }
testOptions {
unitTests.all {
testLogging {
showStandardStreams = true
}
maxHeapSize = "1024m"
}
unitTests {
includeAndroidResources = true
}
}
}
kotlin {
jvmToolchain(rootProject.ext.build.jvmTargetCompatibility)
}
afterEvaluate {
android.libraryVariants.all { variant ->
def variantName = variant.name.capitalize();
def testTask = tasks["test${variantName}UnitTest"]
}
def gleanNative = configurations.getByName("gleanNative")
android.libraryVariants.all { variant ->
def variantName = variant.name.capitalize();
def compileTask = tasks["compile${variantName}Kotlin"]
compileTask.dependsOn(generateUniffiBindings)
variant.registerJavaGeneratingTask(generateUniffiBindings, gleanNative.singleFile)
}
if (project.hasProperty("coverage")) {
jacoco {
toolVersion = libs.versions.jacoco
}
task jacocoTestReport(type: JacocoReport) {
reports {
xml.required = true
html.required = true
}
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*',
'**/*Test*.*', 'android/**/*.*', '**/*$[0-9].*']
def kotlinDebugTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
def javaDebugTree = fileTree(dir: "$project.buildDir/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"
sourceDirectories.from = files([mainSrc])
classDirectories.from = files([kotlinDebugTree, javaDebugTree])
executionData.from = fileTree(dir: project.buildDir, includes: [
'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec'
])
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
finalizedBy jacocoTestReport
}
}
}
configurations {
// Configurations are a somewhat mysterious Gradle concept.
// For our purposes, we can treat them sets of files
// produced by one component and consumed by another.
// This configuration can't be consumed from the outside.
gleanNative {
canBeConsumed = false
}
}
dependencies {
// Add a JNA dependency, which is required by UniFFI.
implementation(libs.jna) {
artifact {
type = "aar"
}
}
api project(":glean-native")
gleanNative project("path": ":glean-native", "configuration": "gleanNative")
implementation project("path": ":glean-native", "configuration": "forUnitTests")
implementation libs.androidx.annotation
implementation libs.androidx.lifecycle.common
implementation libs.androidx.lifecycle.process
implementation libs.androidx.work
implementation libs.kotlinx.coroutines
api libs.kotlinx.serialization
// We need a compileOnly dependency on the following block of testing
// libraries in order to expose the GleanTestRule to applications/libraries
// using the Glean SDK.
// We can't simply create a separate package otherwise we would need
// to provide a public API for the testing package to access the
// Glean internals, which is something we would not want to do.
compileOnly libs.junit
compileOnly libs.test.work
testImplementation libs.mockito
testImplementation libs.mockwebserver
testImplementation libs.robolectric
testImplementation libs.test.core
testImplementation libs.test.junit.ext
testImplementation libs.test.work
androidTestImplementation libs.test.espresso.core
androidTestImplementation libs.test.runner
}
apply from: "$rootDir/publish.gradle"
ext.configurePublish()
def generateUniffiBindings = tasks.register("generateUniffiBindings") {
def udlFilePath = "../src/glean.udl"
doFirst {
exec {
workingDir project.rootDir
commandLine 'cargo', 'uniffi-bindgen', 'generate', '--no-format', "${project.projectDir}/${udlFilePath}", '--language', 'kotlin', '--out-dir', UNIFFI_OUT_DIR.get()
}
}
outputs.dir UNIFFI_OUT_DIR
// Re-generate if the interface definition changes.
inputs.file "${project.projectDir}/../src/glean.udl"
// Re-generate if the uniffi config changes.
inputs.file "${project.projectDir}/../uniffi.toml"
// Re-generate if our uniffi-bindgen tooling changes.
inputs.dir "${project.rootDir}/tools/embedded-uniffi-bindgen/"
// Re-generate if our uniffi-bindgen version changes.
inputs.file "${project.rootDir}/Cargo.lock"
}
// Generate markdown docs for the collected metrics.
ext.gleanDocsDirectory = "$rootDir/docs/user/user/collected-metrics"
ext.gleanYamlFiles = [
"$rootDir/glean-core/metrics.yaml",
"$rootDir/glean-core/pings.yaml",
"$rootDir/glean-core/android/metrics.yaml"
]
// Include the glean-gradle-plugin. This is slightly different than what is
// recommended for external users since we are loading it from the same root Gradle
// build.
apply from: '../../gradle-plugin/src/main/groovy/mozilla/telemetry/glean-gradle-plugin/GleanGradlePlugin.groovy'
ext.glean_plugin.apply(project)
// Store the path to the Glean Miniconda installation in a buildConfigField
// so that unit tests can validate JSON schema.
// Note that despite the name of this variable it isn't strictly for Miniconda
// anymore, it's for any sort of Python environment.
android {
defaultConfig {
buildConfigField(
"String",
"GLEAN_MINICONDA_DIR",
// Carefully escape the string here so it will support `\` in
// Windows paths correctly.
JsonOutput.toJson(project.ext.gleanPythonEnvDir.path)
)
}
}