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 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 md5_check.CallAndRecordIfStale( | 99 md5_check.CallAndRecordIfStale( |
100 Compile, | 100 Compile, |
101 record_path=record_path, | 101 record_path=record_path, |
102 input_paths=java_files + jar_inputs, | 102 input_paths=java_files + jar_inputs, |
103 input_strings=javac_cmd) | 103 input_strings=javac_cmd) |
104 | 104 |
105 | 105 |
106 _MAX_MANIFEST_LINE_LEN = 72 | 106 _MAX_MANIFEST_LINE_LEN = 72 |
107 | 107 |
108 | 108 |
109 def CreateManifest(manifest_path, classpath, main_class=None): | 109 def CreateManifest(manifest_path, classpath, main_class=None, is_mojo=False): |
qsr
2015/02/05 16:50:06
What about adding a dict instead of this mojo spec
etiennej
2015/02/06 16:22:29
Done.
| |
110 """Creates a manifest file with the given parameters. | 110 """Creates a manifest file with the given parameters. |
111 | 111 |
112 This generates a manifest file that compiles with the spec found at | 112 This generates a manifest file that compiles with the spec found at |
113 http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Manifes t | 113 http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Manifes t |
114 | 114 |
115 Args: | 115 Args: |
116 manifest_path: The path to the manifest file that should be created. | 116 manifest_path: The path to the manifest file that should be created. |
117 classpath: The JAR files that should be listed on the manifest file's | 117 classpath: The JAR files that should be listed on the manifest file's |
118 classpath. | 118 classpath. |
119 main_class: If present, the class containing the main() function. | 119 main_class: If present, the class containing the main() function. |
120 | 120 |
121 """ | 121 """ |
122 output = ['Manifest-Version: 1.0'] | 122 output = ['Manifest-Version: 1.0'] |
123 if main_class: | 123 if main_class: |
124 output.append('Main-Class: %s' % main_class) | 124 if not is_mojo: |
125 output.append('Main-Class: %s' % main_class) | |
126 else: | |
127 output.append('Mojo-Class: %s' % main_class) | |
125 if classpath: | 128 if classpath: |
126 sanitized_paths = [] | 129 sanitized_paths = [] |
127 for path in classpath: | 130 for path in classpath: |
128 sanitized_paths.append(os.path.basename(path.strip('"'))) | 131 sanitized_paths.append(os.path.basename(path.strip('"'))) |
129 output.append('Class-Path: %s' % ' '.join(sanitized_paths)) | 132 output.append('Class-Path: %s' % ' '.join(sanitized_paths)) |
130 output.append('Created-By: ') | 133 output.append('Created-By: ') |
131 output.append('') | 134 output.append('') |
132 | 135 |
133 wrapper = textwrap.TextWrapper(break_long_words=True, | 136 wrapper = textwrap.TextWrapper(break_long_words=True, |
134 drop_whitespace=False, | 137 drop_whitespace=False, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 help='Whether code being compiled should be built with stricter ' | 179 help='Whether code being compiled should be built with stricter ' |
177 'warnings for chromium code.') | 180 'warnings for chromium code.') |
178 | 181 |
179 parser.add_option( | 182 parser.add_option( |
180 '--classes-dir', | 183 '--classes-dir', |
181 help='Directory for compiled .class files.') | 184 help='Directory for compiled .class files.') |
182 parser.add_option('--jar-path', help='Jar output path.') | 185 parser.add_option('--jar-path', help='Jar output path.') |
183 parser.add_option( | 186 parser.add_option( |
184 '--main-class', | 187 '--main-class', |
185 help='The class containing the main method.') | 188 help='The class containing the main method.') |
189 parser.add_option( | |
190 '--mojo-jar', | |
191 type=int, | |
192 help='The output JAR is a mojo application.') | |
qsr
2015/02/05 16:50:07
And here you can have a repeated option that would
etiennej
2015/02/06 16:22:29
Done.
| |
186 | 193 |
187 parser.add_option('--stamp', help='Path to touch on success.') | 194 parser.add_option('--stamp', help='Path to touch on success.') |
188 | 195 |
189 options, args = parser.parse_args(argv) | 196 options, args = parser.parse_args(argv) |
190 | 197 |
191 if options.main_class and not options.jar_path: | 198 if options.main_class and not options.jar_path: |
192 parser.error('--main-class requires --jar-path') | 199 parser.error('--main-class requires --jar-path') |
193 | 200 |
194 classpath = [] | 201 classpath = [] |
195 for arg in options.classpath: | 202 for arg in options.classpath: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 DoJavac( | 235 DoJavac( |
229 classpath, | 236 classpath, |
230 classes_dir, | 237 classes_dir, |
231 options.chromium_code, | 238 options.chromium_code, |
232 java_files) | 239 java_files) |
233 | 240 |
234 if options.jar_path: | 241 if options.jar_path: |
235 if options.main_class: | 242 if options.main_class: |
236 manifest_file = os.path.join(temp_dir, 'manifest') | 243 manifest_file = os.path.join(temp_dir, 'manifest') |
237 CreateManifest(manifest_file, classpath, | 244 CreateManifest(manifest_file, classpath, |
238 options.main_class) | 245 options.main_class, options.mojo_jar) |
239 else: | 246 else: |
240 manifest_file = None | 247 manifest_file = None |
241 jar.JarDirectory(classes_dir, | 248 jar.JarDirectory(classes_dir, |
242 build_utils.ParseGypList(options.jar_excluded_classes), | 249 build_utils.ParseGypList(options.jar_excluded_classes), |
243 options.jar_path, | 250 options.jar_path, |
244 manifest_file=manifest_file) | 251 manifest_file=manifest_file) |
245 | 252 |
246 if options.classes_dir: | 253 if options.classes_dir: |
247 # Delete the old classes directory. This ensures that all .class files in | 254 # Delete the old classes directory. This ensures that all .class files in |
248 # the output are actually from the input .java files. For example, if a | 255 # the output are actually from the input .java files. For example, if a |
249 # .java file is deleted or an inner class is removed, the classes | 256 # .java file is deleted or an inner class is removed, the classes |
250 # directory should not contain the corresponding old .class file after | 257 # directory should not contain the corresponding old .class file after |
251 # running this action. | 258 # running this action. |
252 build_utils.DeleteDirectory(options.classes_dir) | 259 build_utils.DeleteDirectory(options.classes_dir) |
253 shutil.copytree(classes_dir, options.classes_dir) | 260 shutil.copytree(classes_dir, options.classes_dir) |
254 | 261 |
255 if options.depfile: | 262 if options.depfile: |
256 build_utils.WriteDepfile( | 263 build_utils.WriteDepfile( |
257 options.depfile, | 264 options.depfile, |
258 input_files + build_utils.GetPythonDependencies()) | 265 input_files + build_utils.GetPythonDependencies()) |
259 | 266 |
260 if options.stamp: | 267 if options.stamp: |
261 build_utils.Touch(options.stamp) | 268 build_utils.Touch(options.stamp) |
262 | 269 |
263 | 270 |
264 if __name__ == '__main__': | 271 if __name__ == '__main__': |
265 sys.exit(main(sys.argv[1:])) | 272 sys.exit(main(sys.argv[1:])) |
266 | 273 |
267 | 274 |
OLD | NEW |