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

Side by Side Diff: build/android/gyp/javac.py

Issue 291783002: Add colorama to third_party/colorama (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: http://i1.kym-cdn.com/photos/images/original/000/234/739/fa5.jpg Created 6 years, 7 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
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)
17 import colorama
18
19
20 def ColorJavacOutput(output):
21 # Disable line-too-long.
22 # pylint: disable=C0301
23 fileline_prefix = '(?P<fileline>(?P<file>[-.\w/\\]+.java):(?P<line>[0-9]+):)'
24 # ../base/android/java/src/org/chromium/base/library_loader/ProcessInitExcepti on.java:10: warning: [serial] serializable class org.chromium.base.library_loade r.ProcessInitException has no definition of serialVersionUID
25 warning_re = re.compile(
26 fileline_prefix + '(?P<full_message> warning: (?P<message>.*))$')
27 # ../base/android/java/src/org/chromium/base/ActivityState.java:44: non-static method foo() cannot be referenced from a static context
28 error_re = re.compile(
29 fileline_prefix + '(?P<full_message> (?P<message>.*))$')
30 # public class ProcessInitException extends Exception {
31 # ^
32 marker_re = re.compile(r'\s*(?P<marker>\^)\s*$')
33 # pylint: enable=C0301
34
35 warning_color = ['full_message', colorama.Fore.YELLOW + colorama.Style.DIM]
36 error_color = ['full_message', colorama.Fore.MAGENTA + colorama.Style.BRIGHT]
37 marker_color = ['marker', colorama.Fore.BLUE + colorama.Style.BRIGHT]
38
39 def Colorize(line, regex, color):
40 match = regex.match(line)
41 start = match.start(color[0])
42 end = match.end(color[0])
43 return (line[:start]
44 + color[1] + line[start:end]
45 + colorama.Fore.RESET + colorama.Style.RESET_ALL
46 + line[end:])
47
48 def ApplyColor(line):
49 if warning_re.match(line):
50 line = Colorize(line, warning_re, warning_color)
51 elif error_re.match(line):
52 line = Colorize(line, error_re, error_color)
53 elif marker_re.match(line):
54 line = Colorize(line, marker_re, marker_color)
55 return line
56
57 return '\n'.join(map(ApplyColor, output.split('\n')))
58
15 59
16 def DoJavac(options, args): 60 def DoJavac(options, args):
17 output_dir = options.output_dir 61 output_dir = options.output_dir
18 62
19 src_gendirs = build_utils.ParseGypList(options.src_gendirs) 63 src_gendirs = build_utils.ParseGypList(options.src_gendirs)
20 java_files = args + build_utils.FindInDirectories(src_gendirs, '*.java') 64 java_files = args + build_utils.FindInDirectories(src_gendirs, '*.java')
21 if options.javac_includes: 65 if options.javac_includes:
22 javac_includes = build_utils.ParseGypList(options.javac_includes) 66 javac_includes = build_utils.ParseGypList(options.javac_includes)
23 filtered_java_files = [] 67 filtered_java_files = []
24 for f in java_files: 68 for f in java_files:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 101
58 javac_cmd = ['javac'] + javac_args + java_files 102 javac_cmd = ['javac'] + javac_args + java_files
59 103
60 def Compile(): 104 def Compile():
61 # Delete the classes directory. This ensures that all .class files in the 105 # 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 106 # 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 107 # 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. 108 # not contain the corresponding old .class file after running this action.
65 build_utils.DeleteDirectory(output_dir) 109 build_utils.DeleteDirectory(output_dir)
66 build_utils.MakeDirectory(output_dir) 110 build_utils.MakeDirectory(output_dir)
67 build_utils.CheckOutput(javac_cmd, print_stdout=options.chromium_code) 111 build_utils.CheckOutput(
112 javac_cmd,
113 print_stdout=options.chromium_code,
114 stderr_filter=ColorJavacOutput)
115
68 116
69 record_path = '%s/javac.md5.stamp' % options.output_dir 117 record_path = '%s/javac.md5.stamp' % options.output_dir
70 md5_check.CallAndRecordIfStale( 118 md5_check.CallAndRecordIfStale(
71 Compile, 119 Compile,
72 record_path=record_path, 120 record_path=record_path,
73 input_paths=java_files + jar_inputs, 121 input_paths=java_files + jar_inputs,
74 input_strings=javac_cmd) 122 input_strings=javac_cmd)
75 123
76 124
77 def main(): 125 def main():
126 colorama.init()
127
78 parser = optparse.OptionParser() 128 parser = optparse.OptionParser()
79 parser.add_option('--src-gendirs', 129 parser.add_option('--src-gendirs',
80 help='Directories containing generated java files.') 130 help='Directories containing generated java files.')
81 parser.add_option('--javac-includes', 131 parser.add_option('--javac-includes',
82 help='A list of file patterns. If provided, only java files that match' + 132 help='A list of file patterns. If provided, only java files that match' +
83 'one of the patterns will be compiled.') 133 'one of the patterns will be compiled.')
84 parser.add_option('--classpath', help='Classpath for javac.') 134 parser.add_option('--classpath', help='Classpath for javac.')
85 parser.add_option('--output-dir', help='Directory for javac output.') 135 parser.add_option('--output-dir', help='Directory for javac output.')
86 parser.add_option('--stamp', help='Path to touch on success.') 136 parser.add_option('--stamp', help='Path to touch on success.')
87 parser.add_option('--chromium-code', type='int', help='Whether code being ' 137 parser.add_option('--chromium-code', type='int', help='Whether code being '
88 'compiled should be built with stricter warnings for ' 138 'compiled should be built with stricter warnings for '
89 'chromium code.') 139 'chromium code.')
90 140
91 options, args = parser.parse_args() 141 options, args = parser.parse_args()
92 142
93 DoJavac(options, args) 143 DoJavac(options, args)
94 144
95 if options.stamp: 145 if options.stamp:
96 build_utils.Touch(options.stamp) 146 build_utils.Touch(options.stamp)
97 147
98 148
99 if __name__ == '__main__': 149 if __name__ == '__main__':
100 sys.exit(main()) 150 sys.exit(main())
101 151
102 152
OLDNEW
« DEPS ('K') | « DEPS ('k') | build/android/gyp/util/build_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698