-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathbuild.gradle
241 lines (200 loc) · 8.31 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This is based off:
// https://github.com/mozilla/application-services/blob/c40e2ccb422cf4af9ffdf095149cec34de1d4bef/components/fxa-client/android/build.gradle
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 {
compileSdkVersion rootProject.ext.build.compileSdkVersion
namespace = "mozilla.telemetry.glean"
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
// See https://github.com/gradle/gradle/issues/5184#issuecomment-457865951
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)
)
}
}