diff options
author | cjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-11 01:59:37 +0000 |
---|---|---|
committer | cjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-11 01:59:37 +0000 |
commit | c812a8af9afb33f247eafa2372bf78844ca377f2 (patch) | |
tree | 6bc6dfbf7dcf432f11a7fa713fd49f96b3efa5c8 /build | |
parent | 459556d1c0afcfc6a82fd932e0ffcc1c81719bdf (diff) | |
download | chromium_src-c812a8af9afb33f247eafa2372bf78844ca377f2.zip chromium_src-c812a8af9afb33f247eafa2372bf78844ca377f2.tar.gz chromium_src-c812a8af9afb33f247eafa2372bf78844ca377f2.tar.bz2 |
Make javac.py output colorful
This highlights warnings in yellow, errors in red(ish), and the ^ marker
in blue.
Adds stdout_filter and stderr_filter to build_utils.CheckOutput. If the
caller handled this themselves they would need to print stdout/stderr
themselves and modify the value stored in the ProcessCalledException.
NOTRY=true
Review URL: https://codereview.chromium.org/295683002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276231 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rwxr-xr-x | build/android/gyp/javac.py | 45 | ||||
-rw-r--r-- | build/android/gyp/util/build_utils.py | 16 |
2 files changed, 59 insertions, 2 deletions
diff --git a/build/android/gyp/javac.py b/build/android/gyp/javac.py index f51f76c..45b7815 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) +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.') diff --git a/build/android/gyp/util/build_utils.py b/build/android/gyp/util/build_utils.py index 2a53312..fa8592b 100644 --- a/build/android/gyp/util/build_utils.py +++ b/build/android/gyp/util/build_utils.py @@ -14,6 +14,11 @@ import sys import tempfile import zipfile +CHROMIUM_SRC = os.path.join(os.path.dirname(__file__), + os.pardir, os.pardir, os.pardir, os.pardir) +COLORAMA_ROOT = os.path.join(CHROMIUM_SRC, + 'third_party', 'colorama', 'src') + @contextlib.contextmanager def TempDir(): @@ -112,7 +117,10 @@ class CalledProcessError(Exception): # This can be used in most cases like subprocess.check_output(). The output, # particularly when the command fails, better highlights the command's failure. # If the command fails, raises a build_utils.CalledProcessError. -def CheckOutput(args, cwd=None, print_stdout=False, print_stderr=True, +def CheckOutput(args, cwd=None, + print_stdout=False, print_stderr=True, + stdout_filter=None, + stderr_filter=None, fail_func=lambda returncode, stderr: returncode != 0): if not cwd: cwd = os.getcwd() @@ -121,6 +129,12 @@ def CheckOutput(args, cwd=None, print_stdout=False, print_stderr=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) stdout, stderr = child.communicate() + if stdout_filter is not None: + stdout = stdout_filter(stdout) + + if stderr_filter is not None: + stderr = stderr_filter(stderr) + if fail_func(child.returncode, stderr): raise CalledProcessError(cwd, args, stdout + stderr) |