Bug 1457255 - 1. Translate kotlin warning/error messages for treeherder; r=nalexander
☠☠ backed out by 258fa1eb49c9 ☠ ☠
authorJim Chen <nchen@mozilla.com>
Tue, 01 May 2018 00:22:53 -0400
changeset 472513 4eccde5dfbef9f3c2eb8e274f5a3c55514664d03
parent 472512 232bed10f4d8f36466070a58ae5a37156e24d894
child 472514 a49833bfd519d024618c7c7f1c10c27b63474166
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
@@ -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'