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
|
||||
}
|
||||
|
||||
// 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()
|
||||
|
||||
@@ -510,6 +510,8 @@ task("generateSDKBindings", type: JavaExec) {
|
||||
dependsOn project(':annotations').jar
|
||||
}
|
||||
|
||||
preBuild.dependsOn(":verifyGleanVersion")
|
||||
|
||||
apply plugin: 'org.mozilla.apilint'
|
||||
|
||||
apiLint {
|
||||
|
||||
Reference in New Issue
Block a user