Bug 1882087 - Format build failure messages for treeherder. r=tthibaud,android-reviewers

Co-authored with @tthibaud : We have borrowed from geckoview's reformatting of gradle errors and warnings: https://searchfox.org/mozilla-central/rev/b189986e26a92f749462094e7869771c1a6607c0/mobile/android/geckoview/build.gradle#165-202
...with adaptations as needed for A-C, Focus, and Fenix.

Example: https://treeherder.mozilla.org/jobs?repo=try&revision=221a0bc4bd8040e179735213e49a618fb83bf827

Differential Revision: https://phabricator.services.mozilla.com/D204425
This commit is contained in:
Geoff Brown
2024-03-12 21:03:49 +00:00
parent 43bbbb0609
commit 380a6f69d9
3 changed files with 108 additions and 2 deletions

View File

@@ -244,6 +244,40 @@ subprojects {
}
}
}
tasks.withType(KotlinCompile).configureEach {
// Translate Kotlin messages like "w: ..." and "e: ..." into
// "...: warning: ..." and "...: error: ...", to make Treeherder understand.
def listener = {
if (it.startsWith("e: warnings found")) {
return
}
if (it.startsWith('w: ') || it.startsWith('e: ')) {
def matches = (it =~ /([ew]): (.+):(\d+):(\d+) (.*)/)
if (!matches) {
logger.quiet "kotlinc message format has changed!"
if (it.startsWith('w: ')) {
// For warnings, don't continue because we don't want to throw an
// exception. For errors, we want the exception so that the new error
// message format gets translated properly.
return
}
}
def (_, type, file, line, column, message) = matches[0]
type = (type == 'w') ? 'warning' : 'error'
// Use logger.lifecycle, which does not go through stderr again.
logger.lifecycle "$file:$line:$column: $type: $message"
}
} as StandardOutputListener
doFirst {
logging.addStandardErrorListener(listener)
}
doLast {
logging.removeStandardErrorListener(listener)
}
}
}
if (findProject(":geckoview") == null) {

View File

@@ -79,6 +79,41 @@ subprojects {
jvmToolchain(config.jvmTargetCompatibility)
}
}
tasks.withType(KotlinCompile).configureEach { task ->
// Translate Kotlin messages like "w: ..." and "e: ..." into
// "...: warning: ..." and "...: error: ...", to make Treeherder understand.
def listener = {
if (it.startsWith("e: warnings found")) {
return
}
if (it.startsWith('w: ') || it.startsWith('e: ')) {
def matches = (it =~ /([ew]): (.+):(\d+):(\d+) (.*)/)
if (!matches) {
logger.quiet "kotlinc message format has changed!"
if (it.startsWith('w: ')) {
// For warnings, don't continue because we don't want to throw an
// exception. For errors, we want the exception so that the new error
// message format gets translated properly.
return
}
}
def (_, type, file, line, column, message) = matches[0]
type = (type == 'w') ? 'warning' : 'error'
// Use logger.lifecycle, which does not go through stderr again.
logger.lifecycle "$file:$line:$column: $type: $message"
}
} as StandardOutputListener
doFirst {
logging.addStandardErrorListener(listener)
}
doLast {
logging.removeStandardErrorListener(listener)
}
}
}
tasks.register('clean', Delete) {

View File

@@ -1,5 +1,7 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
// Top-level build file where you can add configuration options common to all sub-projects/modules.
@@ -101,6 +103,41 @@ subprojects {
jvmToolchain(config.jvmTargetCompatibility)
}
}
tasks.withType(KotlinCompile).configureEach { task ->
// Translate Kotlin messages like "w: ..." and "e: ..." into
// "...: warning: ..." and "...: error: ...", to make Treeherder understand.
def listener = {
if (it.startsWith("e: warnings found")) {
return
}
if (it.startsWith('w: ') || it.startsWith('e: ')) {
def matches = (it =~ /([ew]): (.+):(\d+):(\d+) (.*)/)
if (!matches) {
logger.quiet "kotlinc message format has changed!"
if (it.startsWith('w: ')) {
// For warnings, don't continue because we don't want to throw an
// exception. For errors, we want the exception so that the new error
// message format gets translated properly.
return
}
}
def (_, type, file, line, column, message) = matches[0]
type = (type == 'w') ? 'warning' : 'error'
// Use logger.lifecycle, which does not go through stderr again.
logger.lifecycle "$file:$line:$column: $type: $message"
}
} as StandardOutputListener
doFirst {
logging.addStandardErrorListener(listener)
}
doLast {
logging.removeStandardErrorListener(listener)
}
}
}
tasks.register('clean', Delete) {