Bug 1946226 - Don't parse TOML multiple times. r=janerik,tthibaud
We currently parse `Cargo.lock` for every single Gradle project. This is unnecessary: once is enough. Moreover, this can be a parallelizable and build-cache friendly task. This patch places the task in the :geckoview project, since that's where the version of native Glean is most relevant Differential Revision: https://phabricator.services.mozilla.com/D234384
This commit is contained in:
56
build.gradle
56
build.gradle
@@ -55,23 +55,47 @@ def tryInt = { string ->
|
|||||||
return string
|
return string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses the Cargo.lock and returns the version for the given package name.
|
abstract class VerifyGleanVersionTask extends DefaultTask {
|
||||||
def getRustVersionFor(packageName) {
|
@InputFile
|
||||||
String version = null;
|
final RegularFileProperty source = project.objects.fileProperty().convention(project.layout.projectDirectory.file("Cargo.lock"))
|
||||||
TomlParseResult result = Toml.parse(file("Cargo.lock").getText());
|
|
||||||
for (object in result.getArray("package").toList()) {
|
@Input
|
||||||
def table = (TomlTable) object
|
String expectedVersion = Versions.mozilla_glean
|
||||||
if (table.getString("name") == packageName) {
|
|
||||||
if (version != null) {
|
@OutputFiles
|
||||||
throw new StopExecutionException("Multiple versions for '${packageName}' found." +
|
FileCollection outputFiles = project.objects.fileCollection()
|
||||||
" Ensure '${packageName}' is only included once.")
|
|
||||||
}
|
@TaskAction
|
||||||
version = table.getString("version")
|
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 {
|
allprojects {
|
||||||
// Expose the per-object-directory configuration to all projects.
|
// Expose the per-object-directory configuration to all projects.
|
||||||
ext {
|
ext {
|
||||||
@@ -79,11 +103,7 @@ allprojects {
|
|||||||
topsrcdir = gradle.mozconfig.topsrcdir
|
topsrcdir = gradle.mozconfig.topsrcdir
|
||||||
topobjdir = gradle.mozconfig.topobjdir
|
topobjdir = gradle.mozconfig.topobjdir
|
||||||
|
|
||||||
gleanVersion = Versions.mozilla_glean
|
gleanVersion = Versions.mozilla_glean // Verification done in verifyGleanVersion task
|
||||||
if (gleanVersion != getRustVersionFor("glean")) {
|
|
||||||
throw new StopExecutionException("Mismatched Glean version, expected: ${gleanVersion}," +
|
|
||||||
" found ${getRustVersionFor("glean")}")
|
|
||||||
}
|
|
||||||
|
|
||||||
artifactSuffix = getArtifactSuffix()
|
artifactSuffix = getArtifactSuffix()
|
||||||
versionName = getVersionName()
|
versionName = getVersionName()
|
||||||
|
|||||||
@@ -510,6 +510,8 @@ task("generateSDKBindings", type: JavaExec) {
|
|||||||
dependsOn project(':annotations').jar
|
dependsOn project(':annotations').jar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
preBuild.dependsOn(":verifyGleanVersion")
|
||||||
|
|
||||||
apply plugin: 'org.mozilla.apilint'
|
apply plugin: 'org.mozilla.apilint'
|
||||||
|
|
||||||
apiLint {
|
apiLint {
|
||||||
|
|||||||
Reference in New Issue
Block a user