diff --git a/build.gradle b/build.gradle index 596477c4f462..44c9adf36180 100644 --- a/build.gradle +++ b/build.gradle @@ -55,23 +55,47 @@ 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") +abstract class VerifyGleanVersionTask extends DefaultTask { + @InputFile + final RegularFileProperty source = project.objects.fileProperty().convention(project.layout.projectDirectory.file("Cargo.lock")) + + @Input + String expectedVersion = Versions.mozilla_glean + + @OutputFiles + FileCollection outputFiles = project.objects.fileCollection() + + @TaskAction + void verifyGleanVersion() { + def foundVersion = getRustVersionFor(source.get().asFile, "glean") + if (expectedVersion != foundVersion) { + throw new GradleException("Mismatched Glean version, expected: '${expectedVersion}'," + + " found '${foundVersion}'") + } else { + logger.lifecycle("verifyGleanVersion> expected version matches found version '${foundVersion}'") } } - return version + + // Parses the Cargo.lock and returns the version for the given package name. + static String getRustVersionFor(file, packageName) { + String version = null; + TomlParseResult result = Toml.parse(file.getText()); + for (object in result.getArray("package").toList()) { + def table = (TomlTable) object + if (table.getString("name") == packageName) { + if (version != null) { + throw new GradleException("Multiple versions for '${packageName}' found." + + " Ensure '${packageName}' is only included once.") + } + version = table.getString("version") + } + } + return version + } } +tasks.register("verifyGleanVersion", VerifyGleanVersionTask) + allprojects { // Expose the per-object-directory configuration to all projects. ext { @@ -79,11 +103,7 @@ allprojects { topsrcdir = gradle.mozconfig.topsrcdir topobjdir = gradle.mozconfig.topobjdir - gleanVersion = Versions.mozilla_glean - if (gleanVersion != getRustVersionFor("glean")) { - throw new StopExecutionException("Mismatched Glean version, expected: ${gleanVersion}," + - " found ${getRustVersionFor("glean")}") - } + gleanVersion = Versions.mozilla_glean // Verification done in verifyGleanVersion task artifactSuffix = getArtifactSuffix() versionName = getVersionName() diff --git a/mobile/android/geckoview/build.gradle b/mobile/android/geckoview/build.gradle index 85d1e04fd5d3..3523ab96a3ee 100644 --- a/mobile/android/geckoview/build.gradle +++ b/mobile/android/geckoview/build.gradle @@ -510,6 +510,8 @@ task("generateSDKBindings", type: JavaExec) { dependsOn project(':annotations').jar } +preBuild.dependsOn(":verifyGleanVersion") + apply plugin: 'org.mozilla.apilint' apiLint {