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

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

Issue 574433003: [Android] JUnit runner + gyp changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@deps-changes
Patch Set: fix findbugs issues Created 6 years, 2 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
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
11 import re 11 import re
12 import sys 12 import sys
13 import textwrap
13 14
14 from util import build_utils 15 from util import build_utils
15 from util import md5_check 16 from util import md5_check
16 17
17 import jar 18 import jar
18 19
19 sys.path.append(build_utils.COLORAMA_ROOT) 20 sys.path.append(build_utils.COLORAMA_ROOT)
20 import colorama 21 import colorama
21 22
22 23
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 stderr_filter=ColorJavacOutput) 100 stderr_filter=ColorJavacOutput)
100 101
101 record_path = os.path.join(classes_dir, 'javac.md5.stamp') 102 record_path = os.path.join(classes_dir, 'javac.md5.stamp')
102 md5_check.CallAndRecordIfStale( 103 md5_check.CallAndRecordIfStale(
103 Compile, 104 Compile,
104 record_path=record_path, 105 record_path=record_path,
105 input_paths=java_files + jar_inputs, 106 input_paths=java_files + jar_inputs,
106 input_strings=javac_cmd) 107 input_strings=javac_cmd)
107 108
108 109
110 _MAX_MANIFEST_LINE_LEN = 72
111
112
113 def CreateManifest(manifest_path, classpath, main_class=None):
114 """Creates a manifest file with the given parameters.
115
116 This generates a manifest file that compiles with the spec found at
117 http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Manifes t
118
119 Args:
120 manifest_path: The path to the manifest file that should be created.
121 classpath: The JAR files that should be listed on the manifest file's
122 classpath.
123 main_class: If present, the class containing the main() function.
124
125 """
126 output = ['Manifest-Version: 1.0']
127 if main_class:
128 output.append('Main-Class: %s' % main_class)
129 if classpath:
130 sanitized_paths = []
131 for path in classpath:
132 sanitized_paths.append(os.path.basename(path.strip('"')))
133 output.append('Class-Path: %s' % ' '.join(sanitized_paths))
134 output.append('Created-By: ')
135 output.append('')
136
137 wrapper = textwrap.TextWrapper(break_long_words=True,
138 drop_whitespace=False,
139 subsequent_indent=' ',
140 width=_MAX_MANIFEST_LINE_LEN - 2)
141 output = '\r\n'.join(w for l in output for w in wrapper.wrap(l))
142
143 with open(manifest_path, 'w') as f:
144 f.write(output)
145
146
109 def main(argv): 147 def main(argv):
110 colorama.init() 148 colorama.init()
111 149
112 argv = build_utils.ExpandFileArgs(argv) 150 argv = build_utils.ExpandFileArgs(argv)
113 151
114 parser = optparse.OptionParser() 152 parser = optparse.OptionParser()
115 build_utils.AddDepfileOption(parser) 153 build_utils.AddDepfileOption(parser)
116 154
117 parser.add_option( 155 parser.add_option(
118 '--src-gendirs', 156 '--src-gendirs',
(...skipping 20 matching lines...) Expand all
139 parser.add_option( 177 parser.add_option(
140 '--chromium-code', 178 '--chromium-code',
141 type='int', 179 type='int',
142 help='Whether code being compiled should be built with stricter ' 180 help='Whether code being compiled should be built with stricter '
143 'warnings for chromium code.') 181 'warnings for chromium code.')
144 182
145 parser.add_option( 183 parser.add_option(
146 '--classes-dir', 184 '--classes-dir',
147 help='Directory for compiled .class files.') 185 help='Directory for compiled .class files.')
148 parser.add_option('--jar-path', help='Jar output path.') 186 parser.add_option('--jar-path', help='Jar output path.')
187 parser.add_option(
188 '--main-class',
189 help='The class containing the main method.')
149 190
150 parser.add_option('--stamp', help='Path to touch on success.') 191 parser.add_option('--stamp', help='Path to touch on success.')
151 192
152 options, args = parser.parse_args(argv) 193 options, args = parser.parse_args(argv)
153 194
195 if options.main_class and not options.jar_path:
196 parser.error('--main-class requires --jar-path')
197
154 classpath = [] 198 classpath = []
155 for arg in options.classpath: 199 for arg in options.classpath:
156 classpath += build_utils.ParseGypList(arg) 200 classpath += build_utils.ParseGypList(arg)
157 201
158 java_srcjars = [] 202 java_srcjars = []
159 for arg in options.java_srcjars: 203 for arg in options.java_srcjars:
160 java_srcjars += build_utils.ParseGypList(arg) 204 java_srcjars += build_utils.ParseGypList(arg)
161 205
162 java_files = args 206 java_files = args
163 if options.src_gendirs: 207 if options.src_gendirs:
(...skipping 21 matching lines...) Expand all
185 break 229 break
186 java_files = filtered_java_files 230 java_files = filtered_java_files
187 231
188 DoJavac( 232 DoJavac(
189 classpath, 233 classpath,
190 classes_dir, 234 classes_dir,
191 options.chromium_code, 235 options.chromium_code,
192 java_files) 236 java_files)
193 237
194 if options.jar_path: 238 if options.jar_path:
239 if options.main_class:
240 manifest_file = os.path.join(temp_dir, 'manifest')
241 CreateManifest(manifest_file, classpath,
242 options.main_class)
243 else:
244 manifest_file = None
195 jar.JarDirectory(classes_dir, 245 jar.JarDirectory(classes_dir,
196 build_utils.ParseGypList(options.jar_excluded_classes), 246 build_utils.ParseGypList(options.jar_excluded_classes),
197 options.jar_path) 247 options.jar_path,
248 manifest_file=manifest_file)
198 249
199 if options.classes_dir: 250 if options.classes_dir:
200 # Delete the old classes directory. This ensures that all .class files in 251 # Delete the old classes directory. This ensures that all .class files in
201 # the output are actually from the input .java files. For example, if a 252 # the output are actually from the input .java files. For example, if a
202 # .java file is deleted or an inner class is removed, the classes 253 # .java file is deleted or an inner class is removed, the classes
203 # directory should not contain the corresponding old .class file after 254 # directory should not contain the corresponding old .class file after
204 # running this action. 255 # running this action.
205 build_utils.DeleteDirectory(options.classes_dir) 256 build_utils.DeleteDirectory(options.classes_dir)
206 shutil.copytree(classes_dir, options.classes_dir) 257 shutil.copytree(classes_dir, options.classes_dir)
207 258
208 if options.depfile: 259 if options.depfile:
209 build_utils.WriteDepfile( 260 build_utils.WriteDepfile(
210 options.depfile, 261 options.depfile,
211 input_files + build_utils.GetPythonDependencies()) 262 input_files + build_utils.GetPythonDependencies())
212 263
213 if options.stamp: 264 if options.stamp:
214 build_utils.Touch(options.stamp) 265 build_utils.Touch(options.stamp)
215 266
216 267
217 if __name__ == '__main__': 268 if __name__ == '__main__':
218 sys.exit(main(sys.argv[1:])) 269 sys.exit(main(sys.argv[1:]))
219 270
220 271
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698