OLD | NEW |
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 | |
14 | 13 |
15 from util import build_utils | 14 from util import build_utils |
16 from util import md5_check | 15 from util import md5_check |
17 | 16 |
18 import jar | 17 import jar |
19 | 18 |
20 sys.path.append(build_utils.COLORAMA_ROOT) | 19 sys.path.append(build_utils.COLORAMA_ROOT) |
21 import colorama | 20 import colorama |
22 | 21 |
23 | 22 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 _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 | |
147 def main(argv): | 109 def main(argv): |
148 colorama.init() | 110 colorama.init() |
149 | 111 |
150 argv = build_utils.ExpandFileArgs(argv) | 112 argv = build_utils.ExpandFileArgs(argv) |
151 | 113 |
152 parser = optparse.OptionParser() | 114 parser = optparse.OptionParser() |
153 build_utils.AddDepfileOption(parser) | 115 build_utils.AddDepfileOption(parser) |
154 | 116 |
155 parser.add_option( | 117 parser.add_option( |
156 '--src-gendirs', | 118 '--src-gendirs', |
(...skipping 20 matching lines...) Expand all Loading... |
177 parser.add_option( | 139 parser.add_option( |
178 '--chromium-code', | 140 '--chromium-code', |
179 type='int', | 141 type='int', |
180 help='Whether code being compiled should be built with stricter ' | 142 help='Whether code being compiled should be built with stricter ' |
181 'warnings for chromium code.') | 143 'warnings for chromium code.') |
182 | 144 |
183 parser.add_option( | 145 parser.add_option( |
184 '--classes-dir', | 146 '--classes-dir', |
185 help='Directory for compiled .class files.') | 147 help='Directory for compiled .class files.') |
186 parser.add_option('--jar-path', help='Jar output path.') | 148 parser.add_option('--jar-path', help='Jar output path.') |
187 parser.add_option( | |
188 '--main-class', | |
189 help='The class containing the main method.') | |
190 | 149 |
191 parser.add_option('--stamp', help='Path to touch on success.') | 150 parser.add_option('--stamp', help='Path to touch on success.') |
192 | 151 |
193 options, args = parser.parse_args(argv) | 152 options, args = parser.parse_args(argv) |
194 | 153 |
195 if options.main_class and not options.jar_path: | |
196 parser.error('--main-class requires --jar-path') | |
197 | |
198 classpath = [] | 154 classpath = [] |
199 for arg in options.classpath: | 155 for arg in options.classpath: |
200 classpath += build_utils.ParseGypList(arg) | 156 classpath += build_utils.ParseGypList(arg) |
201 | 157 |
202 java_srcjars = [] | 158 java_srcjars = [] |
203 for arg in options.java_srcjars: | 159 for arg in options.java_srcjars: |
204 java_srcjars += build_utils.ParseGypList(arg) | 160 java_srcjars += build_utils.ParseGypList(arg) |
205 | 161 |
206 java_files = args | 162 java_files = args |
207 if options.src_gendirs: | 163 if options.src_gendirs: |
(...skipping 21 matching lines...) Expand all Loading... |
229 break | 185 break |
230 java_files = filtered_java_files | 186 java_files = filtered_java_files |
231 | 187 |
232 DoJavac( | 188 DoJavac( |
233 classpath, | 189 classpath, |
234 classes_dir, | 190 classes_dir, |
235 options.chromium_code, | 191 options.chromium_code, |
236 java_files) | 192 java_files) |
237 | 193 |
238 if options.jar_path: | 194 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 | |
245 jar.JarDirectory(classes_dir, | 195 jar.JarDirectory(classes_dir, |
246 build_utils.ParseGypList(options.jar_excluded_classes), | 196 build_utils.ParseGypList(options.jar_excluded_classes), |
247 options.jar_path, | 197 options.jar_path) |
248 manifest_file=manifest_file) | |
249 | 198 |
250 if options.classes_dir: | 199 if options.classes_dir: |
251 # Delete the old classes directory. This ensures that all .class files in | 200 # Delete the old classes directory. This ensures that all .class files in |
252 # the output are actually from the input .java files. For example, if a | 201 # the output are actually from the input .java files. For example, if a |
253 # .java file is deleted or an inner class is removed, the classes | 202 # .java file is deleted or an inner class is removed, the classes |
254 # directory should not contain the corresponding old .class file after | 203 # directory should not contain the corresponding old .class file after |
255 # running this action. | 204 # running this action. |
256 build_utils.DeleteDirectory(options.classes_dir) | 205 build_utils.DeleteDirectory(options.classes_dir) |
257 shutil.copytree(classes_dir, options.classes_dir) | 206 shutil.copytree(classes_dir, options.classes_dir) |
258 | 207 |
259 if options.depfile: | 208 if options.depfile: |
260 build_utils.WriteDepfile( | 209 build_utils.WriteDepfile( |
261 options.depfile, | 210 options.depfile, |
262 input_files + build_utils.GetPythonDependencies()) | 211 input_files + build_utils.GetPythonDependencies()) |
263 | 212 |
264 if options.stamp: | 213 if options.stamp: |
265 build_utils.Touch(options.stamp) | 214 build_utils.Touch(options.stamp) |
266 | 215 |
267 | 216 |
268 if __name__ == '__main__': | 217 if __name__ == '__main__': |
269 sys.exit(main(sys.argv[1:])) | 218 sys.exit(main(sys.argv[1:])) |
270 | 219 |
271 | 220 |
OLD | NEW |