Bug 1457255 - 1. Translate kotlin warning/error messages for treeherder; r=nalexander
☠☠ backed out by 076e2b910839 ☠ ☠
authorJim Chen <nchen@mozilla.com>
Mon, 30 Apr 2018 08:40:21 -0400
changeset 472424 f179720d3440eec20ab72e35bb7c4fc479fe4b51
parent 472423 9cf25c9e5c4608f716998c0ab4b71c3ee40b6301
child 472425 ed06c8833608c41c9962e11af663f852c4f20833
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. MozReview-Commit-ID: 2T0lGsIAcPF
mobile/android/geckoview/build.gradle
--- a/mobile/android/geckoview/build.gradle
+++ b/mobile/android/geckoview/build.gradle
@@ -143,16 +143,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'