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 optparse | 8 import optparse |
8 import os | 9 import os |
9 import sys | 10 import sys |
10 | 11 |
11 from util import build_utils | 12 from util import build_utils |
12 from util import md5_check | 13 from util import md5_check |
13 | 14 |
14 | 15 |
15 def Jar(class_files, classes_dir, jar_path, manifest_file=None): | 16 def Jar(class_files, classes_dir, jar_path, manifest_file=None): |
16 jar_path = os.path.abspath(jar_path) | 17 jar_path = os.path.abspath(jar_path) |
(...skipping 20 matching lines...) Expand all Loading... |
37 input_paths=class_files, | 38 input_paths=class_files, |
38 input_strings=jar_cmd, | 39 input_strings=jar_cmd, |
39 force=not os.path.exists(jar_path), | 40 force=not os.path.exists(jar_path), |
40 ) | 41 ) |
41 | 42 |
42 build_utils.Touch(jar_path, fail_if_missing=True) | 43 build_utils.Touch(jar_path, fail_if_missing=True) |
43 | 44 |
44 | 45 |
45 def JarDirectory(classes_dir, excluded_classes, jar_path, manifest_file=None): | 46 def JarDirectory(classes_dir, excluded_classes, jar_path, manifest_file=None): |
46 class_files = build_utils.FindInDirectory(classes_dir, '*.class') | 47 class_files = build_utils.FindInDirectory(classes_dir, '*.class') |
47 class_files = [f for f in class_files | 48 for exclude in excluded_classes: |
48 if not build_utils.MatchesGlob(f, excluded_classes)] | 49 class_files = filter( |
| 50 lambda f: not fnmatch.fnmatch(f, exclude), class_files) |
49 | 51 |
50 Jar(class_files, classes_dir, jar_path, manifest_file=manifest_file) | 52 Jar(class_files, classes_dir, jar_path, manifest_file=manifest_file) |
51 | 53 |
52 | 54 |
53 def main(): | 55 def main(): |
54 parser = optparse.OptionParser() | 56 parser = optparse.OptionParser() |
55 parser.add_option('--classes-dir', help='Directory containing .class files.') | 57 parser.add_option('--classes-dir', help='Directory containing .class files.') |
56 parser.add_option('--jar-path', help='Jar output path.') | 58 parser.add_option('--jar-path', help='Jar output path.') |
57 parser.add_option('--excluded-classes', | 59 parser.add_option('--excluded-classes', |
58 help='List of .class file patterns to exclude from the jar.') | 60 help='List of .class file patterns to exclude from the jar.') |
59 parser.add_option('--stamp', help='Path to touch on success.') | 61 parser.add_option('--stamp', help='Path to touch on success.') |
60 | 62 |
61 options, _ = parser.parse_args() | 63 options, _ = parser.parse_args() |
62 | 64 |
63 if options.excluded_classes: | 65 if options.excluded_classes: |
64 excluded_classes = build_utils.ParseGypList(options.excluded_classes) | 66 excluded_classes = build_utils.ParseGypList(options.excluded_classes) |
65 else: | 67 else: |
66 excluded_classes = [] | 68 excluded_classes = [] |
67 JarDirectory(options.classes_dir, | 69 JarDirectory(options.classes_dir, |
68 excluded_classes, | 70 excluded_classes, |
69 options.jar_path) | 71 options.jar_path) |
70 | 72 |
71 if options.stamp: | 73 if options.stamp: |
72 build_utils.Touch(options.stamp) | 74 build_utils.Touch(options.stamp) |
73 | 75 |
74 | 76 |
75 if __name__ == '__main__': | 77 if __name__ == '__main__': |
76 sys.exit(main()) | 78 sys.exit(main()) |
77 | 79 |
OLD | NEW |