Bug 1457255 - 1. Translate kotlin warning/error messages for treeherder; r=nalexander
authorJim Chen <nchen@mozilla.com>
Tue, 01 May 2018 00:22:53 -0400
changeset 472622 0809a8ffff81aa76ecc57d25764b4fa2d6f241cc
parent 472621 20ee7729dcec477ced97129ac11262aa16b9968d
child 472623 d8eab86052b640012218606a9e704027cc59ff43
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1457255
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1457255 - 1. Translate kotlin warning/error messages for treeherder; r=nalexander kotlinc emits its warning/error messages as "w: <msg>" and "e: <msg>", which Treeherder is unable to pick up. Rather than changing Treeherder, it's best to make the change as close to the source of the message as possible. I looked at changing mach to redirect the output of gradle and make adjustments as necessary, but for some reason gradle doesn't want to work with the pipes that mach sets up. So that leaves changing the gradle build script itself. This patch adds some code to detect the kotlin messages, and output an adjusted version as necessary. It has the benefit of only dealing with kotlinc output, so output from other tools should not be inadvertently changed. However, due to the way it is implemented, it does duplicate every warning/error output; for example, an error would now look like this in the terminal: <file>: error: <msg> e: <file>: <msg> I think this is an acceptable drawback.
mobile/android/geckoview/build.gradle
--- a/mobile/android/geckoview/build.gradle
+++ b/mobile/android/geckoview/build.gradle
@@ -147,16 +147,46 @@ android {
             }
 
             assets {
             }
         }
     }
 }
 
+tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
+    // Translate Kotlin messages like "w: ..." and "e: ..." into
+    // "...: warning: ..." and "...: error: ...", to make Treeherder understand.
+    def listener = {
+        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)
+    }
+}
+
 dependencies {
     implementation "com.android.support:support-v4:$support_library_version"
     implementation "com.android.support:palette-v7:$support_library_version"
 
     testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
     testImplementation 'junit:junit:4.12'
     testImplementation 'org.robolectric:robolectric:3.8'
     testImplementation 'org.mockito:mockito-core:1.10.19'