Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2818)

Unified Diff: build/android/gyp/javac.py

Issue 295683002: Make javac.py output colorful (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | build/android/gyp/util/build_utils.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/javac.py
diff --git a/build/android/gyp/javac.py b/build/android/gyp/javac.py
index f51f76c490cce8f24bacda2d8ecdf1a9e8654f82..45b781584a7198c4daf7b7ab0417f4b8485498e7 100755
--- a/build/android/gyp/javac.py
+++ b/build/android/gyp/javac.py
@@ -7,11 +7,48 @@
import fnmatch
import optparse
import os
+import re
import sys
from util import build_utils
from util import md5_check
+sys.path.append(build_utils.COLORAMA_ROOT)
Nico 2015/05/24 23:32:17 FYI, you should always use `sys.path.insert(0, …`.
+import colorama
+
+
+def ColorJavacOutput(output):
+ fileline_prefix = '(?P<fileline>(?P<file>[-.\w/\\]+.java):(?P<line>[0-9]+):)'
+ warning_re = re.compile(
+ fileline_prefix + '(?P<full_message> warning: (?P<message>.*))$')
+ error_re = re.compile(
+ fileline_prefix + '(?P<full_message> (?P<message>.*))$')
+ marker_re = re.compile(r'\s*(?P<marker>\^)\s*$')
+
+ warning_color = ['full_message', colorama.Fore.YELLOW + colorama.Style.DIM]
+ error_color = ['full_message', colorama.Fore.MAGENTA + colorama.Style.BRIGHT]
+ marker_color = ['marker', colorama.Fore.BLUE + colorama.Style.BRIGHT]
+
+ def Colorize(line, regex, color):
+ match = regex.match(line)
+ start = match.start(color[0])
+ end = match.end(color[0])
+ return (line[:start]
+ + color[1] + line[start:end]
+ + colorama.Fore.RESET + colorama.Style.RESET_ALL
+ + line[end:])
+
+ def ApplyColor(line):
+ if warning_re.match(line):
+ line = Colorize(line, warning_re, warning_color)
+ elif error_re.match(line):
+ line = Colorize(line, error_re, error_color)
+ elif marker_re.match(line):
+ line = Colorize(line, marker_re, marker_color)
+ return line
+
+ return '\n'.join(map(ApplyColor, output.split('\n')))
+
def DoJavac(options, args):
output_dir = options.output_dir
@@ -64,7 +101,11 @@ def DoJavac(options, args):
# not contain the corresponding old .class file after running this action.
build_utils.DeleteDirectory(output_dir)
build_utils.MakeDirectory(output_dir)
- build_utils.CheckOutput(javac_cmd, print_stdout=options.chromium_code)
+ build_utils.CheckOutput(
+ javac_cmd,
+ print_stdout=options.chromium_code,
+ stderr_filter=ColorJavacOutput)
+
record_path = '%s/javac.md5.stamp' % options.output_dir
md5_check.CallAndRecordIfStale(
@@ -75,6 +116,8 @@ def DoJavac(options, args):
def main():
+ colorama.init()
+
parser = optparse.OptionParser()
parser.add_option('--src-gendirs',
help='Directories containing generated java files.')
« no previous file with comments | « no previous file | build/android/gyp/util/build_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698