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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | build/android/gyp/util/build_utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2013 The Chromium Authors. All rights reserved. 3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import fnmatch 7 import fnmatch
8 import optparse 8 import optparse
9 import os 9 import os
10 import re
10 import sys 11 import sys
11 12
12 from util import build_utils 13 from util import build_utils
13 from util import md5_check 14 from util import md5_check
14 15
16 sys.path.append(build_utils.COLORAMA_ROOT)
Nico 2015/05/24 23:32:17 FYI, you should always use `sys.path.insert(0, …`.
17 import colorama
18
19
20 def ColorJavacOutput(output):
21 fileline_prefix = '(?P<fileline>(?P<file>[-.\w/\\]+.java):(?P<line>[0-9]+):)'
22 warning_re = re.compile(
23 fileline_prefix + '(?P<full_message> warning: (?P<message>.*))$')
24 error_re = re.compile(
25 fileline_prefix + '(?P<full_message> (?P<message>.*))$')
26 marker_re = re.compile(r'\s*(?P<marker>\^)\s*$')
27
28 warning_color = ['full_message', colorama.Fore.YELLOW + colorama.Style.DIM]
29 error_color = ['full_message', colorama.Fore.MAGENTA + colorama.Style.BRIGHT]
30 marker_color = ['marker', colorama.Fore.BLUE + colorama.Style.BRIGHT]
31
32 def Colorize(line, regex, color):
33 match = regex.match(line)
34 start = match.start(color[0])
35 end = match.end(color[0])
36 return (line[:start]
37 + color[1] + line[start:end]
38 + colorama.Fore.RESET + colorama.Style.RESET_ALL
39 + line[end:])
40
41 def ApplyColor(line):
42 if warning_re.match(line):
43 line = Colorize(line, warning_re, warning_color)
44 elif error_re.match(line):
45 line = Colorize(line, error_re, error_color)
46 elif marker_re.match(line):
47 line = Colorize(line, marker_re, marker_color)
48 return line
49
50 return '\n'.join(map(ApplyColor, output.split('\n')))
51
15 52
16 def DoJavac(options, args): 53 def DoJavac(options, args):
17 output_dir = options.output_dir 54 output_dir = options.output_dir
18 55
19 src_gendirs = build_utils.ParseGypList(options.src_gendirs) 56 src_gendirs = build_utils.ParseGypList(options.src_gendirs)
20 java_files = args + build_utils.FindInDirectories(src_gendirs, '*.java') 57 java_files = args + build_utils.FindInDirectories(src_gendirs, '*.java')
21 if options.javac_includes: 58 if options.javac_includes:
22 javac_includes = build_utils.ParseGypList(options.javac_includes) 59 javac_includes = build_utils.ParseGypList(options.javac_includes)
23 filtered_java_files = [] 60 filtered_java_files = []
24 for f in java_files: 61 for f in java_files:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 94
58 javac_cmd = ['javac'] + javac_args + java_files 95 javac_cmd = ['javac'] + javac_args + java_files
59 96
60 def Compile(): 97 def Compile():
61 # Delete the classes directory. This ensures that all .class files in the 98 # Delete the classes directory. This ensures that all .class files in the
62 # output are actually from the input .java files. For example, if a .java 99 # output are actually from the input .java files. For example, if a .java
63 # file is deleted or an inner class is removed, the classes directory should 100 # file is deleted or an inner class is removed, the classes directory should
64 # not contain the corresponding old .class file after running this action. 101 # not contain the corresponding old .class file after running this action.
65 build_utils.DeleteDirectory(output_dir) 102 build_utils.DeleteDirectory(output_dir)
66 build_utils.MakeDirectory(output_dir) 103 build_utils.MakeDirectory(output_dir)
67 build_utils.CheckOutput(javac_cmd, print_stdout=options.chromium_code) 104 build_utils.CheckOutput(
105 javac_cmd,
106 print_stdout=options.chromium_code,
107 stderr_filter=ColorJavacOutput)
108
68 109
69 record_path = '%s/javac.md5.stamp' % options.output_dir 110 record_path = '%s/javac.md5.stamp' % options.output_dir
70 md5_check.CallAndRecordIfStale( 111 md5_check.CallAndRecordIfStale(
71 Compile, 112 Compile,
72 record_path=record_path, 113 record_path=record_path,
73 input_paths=java_files + jar_inputs, 114 input_paths=java_files + jar_inputs,
74 input_strings=javac_cmd) 115 input_strings=javac_cmd)
75 116
76 117
77 def main(): 118 def main():
119 colorama.init()
120
78 parser = optparse.OptionParser() 121 parser = optparse.OptionParser()
79 parser.add_option('--src-gendirs', 122 parser.add_option('--src-gendirs',
80 help='Directories containing generated java files.') 123 help='Directories containing generated java files.')
81 parser.add_option('--javac-includes', 124 parser.add_option('--javac-includes',
82 help='A list of file patterns. If provided, only java files that match' + 125 help='A list of file patterns. If provided, only java files that match' +
83 'one of the patterns will be compiled.') 126 'one of the patterns will be compiled.')
84 parser.add_option('--classpath', help='Classpath for javac.') 127 parser.add_option('--classpath', help='Classpath for javac.')
85 parser.add_option('--output-dir', help='Directory for javac output.') 128 parser.add_option('--output-dir', help='Directory for javac output.')
86 parser.add_option('--stamp', help='Path to touch on success.') 129 parser.add_option('--stamp', help='Path to touch on success.')
87 parser.add_option('--chromium-code', type='int', help='Whether code being ' 130 parser.add_option('--chromium-code', type='int', help='Whether code being '
88 'compiled should be built with stricter warnings for ' 131 'compiled should be built with stricter warnings for '
89 'chromium code.') 132 'chromium code.')
90 133
91 options, args = parser.parse_args() 134 options, args = parser.parse_args()
92 135
93 DoJavac(options, args) 136 DoJavac(options, args)
94 137
95 if options.stamp: 138 if options.stamp:
96 build_utils.Touch(options.stamp) 139 build_utils.Touch(options.stamp)
97 140
98 141
99 if __name__ == '__main__': 142 if __name__ == '__main__':
100 sys.exit(main()) 143 sys.exit(main())
101 144
102 145
OLDNEW
« 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