Chromium Code Reviews| 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. |
|
qsr
2015/02/06 17:16:13
Add the comment for manifest_entries
etiennej
2015/02/09 14:09:51
Done.
| |
| 120 | 121 |
| 121 """ | 122 """ |
| 122 output = ['Manifest-Version: 1.0'] | 123 output = ['Manifest-Version: 1.0'] |
| 123 if main_class: | 124 if main_class: |
| 124 output.append('Main-Class: %s' % main_class) | 125 output.append('Main-Class: %s' % main_class) |
| 126 if manifest_entries: | |
| 127 for k, v in manifest_entries: | |
| 128 output.append('%s: %s' % (k, v)) | |
| 125 if classpath: | 129 if classpath: |
| 126 sanitized_paths = [] | 130 sanitized_paths = [] |
| 127 for path in classpath: | 131 for path in classpath: |
| 128 sanitized_paths.append(os.path.basename(path.strip('"'))) | 132 sanitized_paths.append(os.path.basename(path.strip('"'))) |
| 129 output.append('Class-Path: %s' % ' '.join(sanitized_paths)) | 133 output.append('Class-Path: %s' % ' '.join(sanitized_paths)) |
| 130 output.append('Created-By: ') | 134 output.append('Created-By: ') |
| 131 output.append('') | 135 output.append('') |
| 132 | 136 |
| 133 wrapper = textwrap.TextWrapper(break_long_words=True, | 137 wrapper = textwrap.TextWrapper(break_long_words=True, |
| 134 drop_whitespace=False, | 138 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 ' | 180 help='Whether code being compiled should be built with stricter ' |
| 177 'warnings for chromium code.') | 181 'warnings for chromium code.') |
| 178 | 182 |
| 179 parser.add_option( | 183 parser.add_option( |
| 180 '--classes-dir', | 184 '--classes-dir', |
| 181 help='Directory for compiled .class files.') | 185 help='Directory for compiled .class files.') |
| 182 parser.add_option('--jar-path', help='Jar output path.') | 186 parser.add_option('--jar-path', help='Jar output path.') |
| 183 parser.add_option( | 187 parser.add_option( |
| 184 '--main-class', | 188 '--main-class', |
| 185 help='The class containing the main method.') | 189 help='The class containing the main method.') |
| 190 parser.add_option( | |
| 191 '--manifest-entry', | |
| 192 action='append', | |
| 193 help='Key:value pairs to add to the .jar manifest.') | |
| 186 | 194 |
| 187 parser.add_option('--stamp', help='Path to touch on success.') | 195 parser.add_option('--stamp', help='Path to touch on success.') |
| 188 | 196 |
| 189 options, args = parser.parse_args(argv) | 197 options, args = parser.parse_args(argv) |
| 190 | 198 |
| 191 if options.main_class and not options.jar_path: | 199 if options.main_class and not options.jar_path: |
| 192 parser.error('--main-class requires --jar-path') | 200 parser.error('--main-class requires --jar-path') |
| 193 | 201 |
| 194 classpath = [] | 202 classpath = [] |
| 195 for arg in options.classpath: | 203 for arg in options.classpath: |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 225 break | 233 break |
| 226 java_files = filtered_java_files | 234 java_files = filtered_java_files |
| 227 | 235 |
| 228 DoJavac( | 236 DoJavac( |
| 229 classpath, | 237 classpath, |
| 230 classes_dir, | 238 classes_dir, |
| 231 options.chromium_code, | 239 options.chromium_code, |
| 232 java_files) | 240 java_files) |
| 233 | 241 |
| 234 if options.jar_path: | 242 if options.jar_path: |
| 235 if options.main_class: | 243 if options.main_class or options.manifest_entry: |
| 244 entries = map(lambda e: e.split(":"), options.manifest_entry) | |
| 236 manifest_file = os.path.join(temp_dir, 'manifest') | 245 manifest_file = os.path.join(temp_dir, 'manifest') |
| 237 CreateManifest(manifest_file, classpath, | 246 CreateManifest(manifest_file, classpath, options.main_class, entries) |
| 238 options.main_class) | |
| 239 else: | 247 else: |
| 240 manifest_file = None | 248 manifest_file = None |
| 241 jar.JarDirectory(classes_dir, | 249 jar.JarDirectory(classes_dir, |
| 242 build_utils.ParseGypList(options.jar_excluded_classes), | 250 build_utils.ParseGypList(options.jar_excluded_classes), |
| 243 options.jar_path, | 251 options.jar_path, |
| 244 manifest_file=manifest_file) | 252 manifest_file=manifest_file) |
| 245 | 253 |
| 246 if options.classes_dir: | 254 if options.classes_dir: |
| 247 # Delete the old classes directory. This ensures that all .class files in | 255 # 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 | 256 # 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 | 257 # .java file is deleted or an inner class is removed, the classes |
| 250 # directory should not contain the corresponding old .class file after | 258 # directory should not contain the corresponding old .class file after |
| 251 # running this action. | 259 # running this action. |
| 252 build_utils.DeleteDirectory(options.classes_dir) | 260 build_utils.DeleteDirectory(options.classes_dir) |
| 253 shutil.copytree(classes_dir, options.classes_dir) | 261 shutil.copytree(classes_dir, options.classes_dir) |
| 254 | 262 |
| 255 if options.depfile: | 263 if options.depfile: |
| 256 build_utils.WriteDepfile( | 264 build_utils.WriteDepfile( |
| 257 options.depfile, | 265 options.depfile, |
| 258 input_files + build_utils.GetPythonDependencies()) | 266 input_files + build_utils.GetPythonDependencies()) |
| 259 | 267 |
| 260 if options.stamp: | 268 if options.stamp: |
| 261 build_utils.Touch(options.stamp) | 269 build_utils.Touch(options.stamp) |
| 262 | 270 |
| 263 | 271 |
| 264 if __name__ == '__main__': | 272 if __name__ == '__main__': |
| 265 sys.exit(main(sys.argv[1:])) | 273 sys.exit(main(sys.argv[1:])) |
| 266 | 274 |
| 267 | 275 |
| OLD | NEW |