Bug 1670261 - Ensure the Glean versions in the project match. r=agi,chutten

In GeckoView we need to depend on the same Glean version as the included
Glean Rust crate has.
We _could_ let Gradle read that from Cargo.lock directly,
but that complicates the build.

Instead we manually update both versions to the same
and have Gradle ensure we don't forget that.

Differential Revision: https://phabricator.services.mozilla.com/D116602
This commit is contained in:
Jan-Erik Rediger 2021-08-02 16:22:46 +00:00
parent e31efdfb2d
commit d1298df426
3 changed files with 34 additions and 3 deletions

View File

@ -1,3 +1,7 @@
import org.tomlj.Toml
import org.tomlj.TomlParseResult
import org.tomlj.TomlTable
def tryInt = { string ->
if (string == null) {
return string
@ -8,6 +12,23 @@ def tryInt = { string ->
return string
}
// Parses the Cargo.lock and returns the version for the given package name.
def getRustVersionFor(packageName) {
String version = null;
TomlParseResult result = Toml.parse(file("Cargo.lock").getText());
for (object in result.getArray("package").toList()) {
def table = (TomlTable) object
if (table.getString("name") == packageName) {
if (version != null) {
throw new StopExecutionException("Multiple versions for '${packageName}' found." +
" Ensure '${packageName}' is only included once.")
}
version = table.getString("version")
}
}
return version
}
allprojects {
// Expose the per-object-directory configuration to all projects.
ext {
@ -15,6 +36,12 @@ allprojects {
topsrcdir = gradle.mozconfig.topsrcdir
topobjdir = gradle.mozconfig.topobjdir
gleanVersion = "40.0.0"
if (gleanVersion != getRustVersionFor("glean")) {
throw new StopExecutionException("Mismatched Glean version, expected: ${gleanVersion}," +
" found ${getRustVersionFor("glean")}")
}
buildToolsVersion = mozconfig.substs.ANDROID_BUILD_TOOLS_VERSION
compileSdkVersion = tryInt(mozconfig.substs.ANDROID_TARGET_SDK)
targetSdkVersion = tryInt(mozconfig.substs.ANDROID_TARGET_SDK)
@ -78,6 +105,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.8.2'
classpath 'org.apache.commons:commons-exec:1.3'
classpath 'org.tomlj:tomlj:1.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

View File

@ -241,7 +241,9 @@ dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-annotations-jvm:1.3.70"
// The Glean Kotlin, which will be re-exported.
api "org.mozilla.telemetry:glean:36.0.1"
if (!mozconfig.substs.MOZ_ANDROID_GECKOVIEW_LITE) {
api "org.mozilla.telemetry:glean:${project.ext.gleanVersion}"
}
implementation "androidx.annotation:annotation:1.1.0"
implementation "androidx.legacy:legacy-support-v4:1.0.0"

View File

@ -7,10 +7,11 @@ It currently depends on [glean-core] from crates.io.
To update the dependency:
1. Bump the version of the `glean-core` and `glean` crates in
1. Bump the version of the `glean` crate in
`toolkit/components/glean/Cargo.toml` and `toolkit/components/glean/api/Cargo.toml`.
2. Run `mach vendor rust`.
This fetches all dependencies and adds them to `mozilla-central/third_pary/rust`.
This fetches all dependencies and adds them to `third_pary/rust`.
3. Update the version of `gleanVersion` in `build.gradle` to the same version.
## Version mismatches of Rust dependencies