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

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

Issue 269943005: Add android_library template (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | « build/android/gyp/jar_toc.py ('k') | 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 shutil 10 import shutil
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 if warning_re.match(line): 45 if warning_re.match(line):
46 line = Colorize(line, warning_re, warning_color) 46 line = Colorize(line, warning_re, warning_color)
47 elif error_re.match(line): 47 elif error_re.match(line):
48 line = Colorize(line, error_re, error_color) 48 line = Colorize(line, error_re, error_color)
49 elif marker_re.match(line): 49 elif marker_re.match(line):
50 line = Colorize(line, marker_re, marker_color) 50 line = Colorize(line, marker_re, marker_color)
51 return line 51 return line
52 52
53 return '\n'.join(map(ApplyColor, output.split('\n'))) 53 return '\n'.join(map(ApplyColor, output.split('\n')))
54 54
55
55 def DoJavac( 56 def DoJavac(
56 classpath, javac_includes, classes_dir, chromium_code, java_files): 57 classpath, classes_dir, chromium_code, java_files):
57 if javac_includes: 58 """Runs javac.
58 javac_includes = build_utils.ParseGypList(javac_includes) 59
59 filtered_java_files = [] 60 Builds |java_files| with the provided |classpath| and puts the generated
60 for f in java_files: 61 .class files into |classes_dir|. If |chromium_code| is true, extra lint
61 for include in javac_includes: 62 checking will be enabled.
62 if fnmatch.fnmatch(f, include): 63 """
63 filtered_java_files.append(f)
64 break
65 java_files = filtered_java_files
66 64
67 # Compiling guava with certain orderings of input files causes a compiler 65 # Compiling guava with certain orderings of input files causes a compiler
68 # crash... Sorted order works, so use that. 66 # crash... Sorted order works, so use that.
69 # See https://code.google.com/p/guava-libraries/issues/detail?id=950 67 # See https://code.google.com/p/guava-libraries/issues/detail?id=950
68 # TODO(cjhopman): Remove this when we have update guava or the compiler to a
69 # version without this problem.
70 java_files.sort() 70 java_files.sort()
71 classpath = build_utils.ParseGypList(classpath)
72 71
73 jar_inputs = [] 72 jar_inputs = []
74 for path in classpath: 73 for path in classpath:
75 if os.path.exists(path + '.TOC'): 74 if os.path.exists(path + '.TOC'):
76 jar_inputs.append(path + '.TOC') 75 jar_inputs.append(path + '.TOC')
77 else: 76 else:
78 jar_inputs.append(path) 77 jar_inputs.append(path)
79 78
80 javac_args = [ 79 javac_args = [
81 '-g', 80 '-g',
(...skipping 18 matching lines...) Expand all
100 stderr_filter=ColorJavacOutput) 99 stderr_filter=ColorJavacOutput)
101 100
102 record_path = os.path.join(classes_dir, 'javac.md5.stamp') 101 record_path = os.path.join(classes_dir, 'javac.md5.stamp')
103 md5_check.CallAndRecordIfStale( 102 md5_check.CallAndRecordIfStale(
104 Compile, 103 Compile,
105 record_path=record_path, 104 record_path=record_path,
106 input_paths=java_files + jar_inputs, 105 input_paths=java_files + jar_inputs,
107 input_strings=javac_cmd) 106 input_strings=javac_cmd)
108 107
109 108
110 def main(): 109 def main(argv):
111 colorama.init() 110 colorama.init()
112 111
112 argv = build_utils.ExpandFileArgs(argv)
113
113 parser = optparse.OptionParser() 114 parser = optparse.OptionParser()
114 build_utils.AddDepfileOption(parser) 115 build_utils.AddDepfileOption(parser)
115 116
116 parser.add_option( 117 parser.add_option(
117 '--src-gendirs', 118 '--src-gendirs',
118 help='Directories containing generated java files.') 119 help='Directories containing generated java files.')
119 parser.add_option('--classpath', help='Classpath for javac.') 120 parser.add_option(
121 '--java-srcjars',
122 help='List of srcjars to include in compilation.')
123 parser.add_option(
124 '--classpath',
125 action='append',
126 help='Classpath for javac. If this is specified multiple times, they '
127 'will all be appended to construct the classpath.')
120 parser.add_option( 128 parser.add_option(
121 '--javac-includes', 129 '--javac-includes',
122 help='A list of file patterns. If provided, only java files that match' + 130 help='A list of file patterns. If provided, only java files that match'
123 'one of the patterns will be compiled.') 131 'one of the patterns will be compiled.')
124 parser.add_option( 132 parser.add_option(
125 '--jar-excluded-classes', 133 '--jar-excluded-classes',
134 default='',
126 help='List of .class file patterns to exclude from the jar.') 135 help='List of .class file patterns to exclude from the jar.')
127 136
128 parser.add_option( 137 parser.add_option(
129 '--chromium-code', 138 '--chromium-code',
130 type='int', 139 type='int',
131 help='Whether code being compiled should be built with stricter ' 140 help='Whether code being compiled should be built with stricter '
132 'warnings for chromium code.') 141 'warnings for chromium code.')
133 142
134 parser.add_option( 143 parser.add_option(
135 '--classes-dir', 144 '--classes-dir',
136 help='Directory for compiled .class files.') 145 help='Directory for compiled .class files.')
137 parser.add_option('--jar-path', help='Jar output path.') 146 parser.add_option('--jar-path', help='Jar output path.')
138 147
139 parser.add_option('--stamp', help='Path to touch on success.') 148 parser.add_option('--stamp', help='Path to touch on success.')
140 149
141 options, args = parser.parse_args() 150 options, args = parser.parse_args(argv)
151
152 classpath = []
153 for arg in options.classpath:
154 classpath += build_utils.ParseGypList(arg)
142 155
143 java_files = args 156 java_files = args
144 if options.src_gendirs: 157 if options.src_gendirs:
145 src_gendirs = build_utils.ParseGypList(options.src_gendirs) 158 src_gendirs = build_utils.ParseGypList(options.src_gendirs)
146 java_files += build_utils.FindInDirectories(src_gendirs, '*.java') 159 java_files += build_utils.FindInDirectories(src_gendirs, '*.java')
147 160
148 with build_utils.TempDir() as classes_dir: 161 with build_utils.TempDir() as temp_dir:
162 classes_dir = os.path.join(temp_dir, 'classes')
163 os.makedirs(classes_dir)
164 if options.java_srcjars:
165 java_dir = os.path.join(temp_dir, 'java')
166 os.makedirs(java_dir)
167 for srcjar in build_utils.ParseGypList(options.java_srcjars):
168 build_utils.ExtractAll(srcjar, path=java_dir)
169 java_files += build_utils.FindInDirectory(java_dir, '*.java')
170
171 if options.javac_includes:
172 javac_includes = build_utils.ParseGypList(options.javac_includes)
173 filtered_java_files = []
174 for f in java_files:
175 for include in javac_includes:
176 if fnmatch.fnmatch(f, include):
177 filtered_java_files.append(f)
178 break
179 java_files = filtered_java_files
180
149 DoJavac( 181 DoJavac(
150 options.classpath, 182 classpath,
151 options.javac_includes,
152 classes_dir, 183 classes_dir,
153 options.chromium_code, 184 options.chromium_code,
154 java_files) 185 java_files)
155 186
156 if options.jar_path: 187 if options.jar_path:
157 jar.JarDirectory(classes_dir, 188 jar.JarDirectory(classes_dir,
158 build_utils.ParseGypList(options.jar_excluded_classes), 189 build_utils.ParseGypList(options.jar_excluded_classes),
159 options.jar_path) 190 options.jar_path)
160 191
161 if options.classes_dir: 192 if options.classes_dir:
162 # Delete the old classes directory. This ensures that all .class files in 193 # Delete the old classes directory. This ensures that all .class files in
163 # the output are actually from the input .java files. For example, if a 194 # the output are actually from the input .java files. For example, if a
164 # .java file is deleted or an inner class is removed, the classes 195 # .java file is deleted or an inner class is removed, the classes
165 # directory should not contain the corresponding old .class file after 196 # directory should not contain the corresponding old .class file after
166 # running this action. 197 # running this action.
167 build_utils.DeleteDirectory(options.classes_dir) 198 build_utils.DeleteDirectory(options.classes_dir)
168 shutil.copytree(classes_dir, options.classes_dir) 199 shutil.copytree(classes_dir, options.classes_dir)
169 200
170 if options.depfile: 201 if options.depfile:
171 build_utils.WriteDepfile( 202 build_utils.WriteDepfile(
172 options.depfile, 203 options.depfile,
173 build_utils.GetPythonDependencies()) 204 classpath + build_utils.GetPythonDependencies())
174 205
175 if options.stamp: 206 if options.stamp:
176 build_utils.Touch(options.stamp) 207 build_utils.Touch(options.stamp)
177 208
178 209
179 if __name__ == '__main__': 210 if __name__ == '__main__':
180 sys.exit(main()) 211 sys.exit(main(sys.argv[1:]))
181 212
182 213
OLDNEW
« no previous file with comments | « build/android/gyp/jar_toc.py ('k') | build/android/gyp/util/build_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698