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, |
| 110 manifest_entries=None): |
110 """Creates a manifest file with the given parameters. | 111 """Creates a manifest file with the given parameters. |
111 | 112 |
112 This generates a manifest file that compiles with the spec found at | 113 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 | 114 http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Manifes
t |
114 | 115 |
115 Args: | 116 Args: |
116 manifest_path: The path to the manifest file that should be created. | 117 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 | 118 classpath: The JAR files that should be listed on the manifest file's |
118 classpath. | 119 classpath. |
119 main_class: If present, the class containing the main() function. | 120 main_class: If present, the class containing the main() function. |
| 121 manifest_entries: If present, a list of (key, value) pairs to add to |
| 122 the manifest. |
120 | 123 |
121 """ | 124 """ |
122 output = ['Manifest-Version: 1.0'] | 125 output = ['Manifest-Version: 1.0'] |
123 if main_class: | 126 if main_class: |
124 output.append('Main-Class: %s' % main_class) | 127 output.append('Main-Class: %s' % main_class) |
| 128 if manifest_entries: |
| 129 for k, v in manifest_entries: |
| 130 output.append('%s: %s' % (k, v)) |
125 if classpath: | 131 if classpath: |
126 sanitized_paths = [] | 132 sanitized_paths = [] |
127 for path in classpath: | 133 for path in classpath: |
128 sanitized_paths.append(os.path.basename(path.strip('"'))) | 134 sanitized_paths.append(os.path.basename(path.strip('"'))) |
129 output.append('Class-Path: %s' % ' '.join(sanitized_paths)) | 135 output.append('Class-Path: %s' % ' '.join(sanitized_paths)) |
130 output.append('Created-By: ') | 136 output.append('Created-By: ') |
131 output.append('') | 137 output.append('') |
132 | 138 |
133 wrapper = textwrap.TextWrapper(break_long_words=True, | 139 wrapper = textwrap.TextWrapper(break_long_words=True, |
134 drop_whitespace=False, | 140 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 ' | 182 help='Whether code being compiled should be built with stricter ' |
177 'warnings for chromium code.') | 183 'warnings for chromium code.') |
178 | 184 |
179 parser.add_option( | 185 parser.add_option( |
180 '--classes-dir', | 186 '--classes-dir', |
181 help='Directory for compiled .class files.') | 187 help='Directory for compiled .class files.') |
182 parser.add_option('--jar-path', help='Jar output path.') | 188 parser.add_option('--jar-path', help='Jar output path.') |
183 parser.add_option( | 189 parser.add_option( |
184 '--main-class', | 190 '--main-class', |
185 help='The class containing the main method.') | 191 help='The class containing the main method.') |
| 192 parser.add_option( |
| 193 '--manifest-entry', |
| 194 action='append', |
| 195 help='Key:value pairs to add to the .jar manifest.') |
186 | 196 |
187 parser.add_option('--stamp', help='Path to touch on success.') | 197 parser.add_option('--stamp', help='Path to touch on success.') |
188 | 198 |
189 options, args = parser.parse_args(argv) | 199 options, args = parser.parse_args(argv) |
190 | 200 |
191 if options.main_class and not options.jar_path: | 201 if options.main_class and not options.jar_path: |
192 parser.error('--main-class requires --jar-path') | 202 parser.error('--main-class requires --jar-path') |
193 | 203 |
194 classpath = [] | 204 classpath = [] |
195 for arg in options.classpath: | 205 for arg in options.classpath: |
(...skipping 29 matching lines...) Expand all Loading... |
225 break | 235 break |
226 java_files = filtered_java_files | 236 java_files = filtered_java_files |
227 | 237 |
228 DoJavac( | 238 DoJavac( |
229 classpath, | 239 classpath, |
230 classes_dir, | 240 classes_dir, |
231 options.chromium_code, | 241 options.chromium_code, |
232 java_files) | 242 java_files) |
233 | 243 |
234 if options.jar_path: | 244 if options.jar_path: |
235 if options.main_class: | 245 if options.main_class or options.manifest_entry: |
| 246 if options.manifest_entry: |
| 247 entries = map(lambda e: e.split(":"), options.manifest_entry) |
| 248 else: |
| 249 entries = [] |
236 manifest_file = os.path.join(temp_dir, 'manifest') | 250 manifest_file = os.path.join(temp_dir, 'manifest') |
237 CreateManifest(manifest_file, classpath, | 251 CreateManifest(manifest_file, classpath, options.main_class, entries) |
238 options.main_class) | |
239 else: | 252 else: |
240 manifest_file = None | 253 manifest_file = None |
241 jar.JarDirectory(classes_dir, | 254 jar.JarDirectory(classes_dir, |
242 build_utils.ParseGypList(options.jar_excluded_classes), | 255 build_utils.ParseGypList(options.jar_excluded_classes), |
243 options.jar_path, | 256 options.jar_path, |
244 manifest_file=manifest_file) | 257 manifest_file=manifest_file) |
245 | 258 |
246 if options.classes_dir: | 259 if options.classes_dir: |
247 # Delete the old classes directory. This ensures that all .class files in | 260 # 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 | 261 # 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 | 262 # .java file is deleted or an inner class is removed, the classes |
250 # directory should not contain the corresponding old .class file after | 263 # directory should not contain the corresponding old .class file after |
251 # running this action. | 264 # running this action. |
252 build_utils.DeleteDirectory(options.classes_dir) | 265 build_utils.DeleteDirectory(options.classes_dir) |
253 shutil.copytree(classes_dir, options.classes_dir) | 266 shutil.copytree(classes_dir, options.classes_dir) |
254 | 267 |
255 if options.depfile: | 268 if options.depfile: |
256 build_utils.WriteDepfile( | 269 build_utils.WriteDepfile( |
257 options.depfile, | 270 options.depfile, |
258 input_files + build_utils.GetPythonDependencies()) | 271 input_files + build_utils.GetPythonDependencies()) |
259 | 272 |
260 if options.stamp: | 273 if options.stamp: |
261 build_utils.Touch(options.stamp) | 274 build_utils.Touch(options.stamp) |
262 | 275 |
263 | 276 |
264 if __name__ == '__main__': | 277 if __name__ == '__main__': |
265 sys.exit(main(sys.argv[1:])) | 278 sys.exit(main(sys.argv[1:])) |
266 | 279 |
267 | 280 |
OLD | NEW |