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 subprocess | |
11 import sys | 10 import sys |
12 | 11 |
13 from pylib import build_utils | 12 from pylib import build_utils |
14 | 13 |
15 | 14 |
16 def DoJar(options): | 15 def DoJar(options): |
17 class_files = build_utils.FindInDirectory(options.classes_dir, '*.class') | 16 class_files = build_utils.FindInDirectory(options.classes_dir, '*.class') |
18 for exclude in build_utils.ParseGypList(options.excluded_classes): | 17 for exclude in build_utils.ParseGypList(options.excluded_classes): |
19 class_files = filter( | 18 class_files = filter( |
20 lambda f: not fnmatch.fnmatch(f, exclude), class_files) | 19 lambda f: not fnmatch.fnmatch(f, exclude), class_files) |
21 | 20 |
22 jar_path = os.path.abspath(options.jar_path) | 21 jar_path = os.path.abspath(options.jar_path) |
23 | 22 |
24 # The paths of the files in the jar will be the same as they are passed in to | 23 # The paths of the files in the jar will be the same as they are passed in to |
25 # the command. Because of this, the command should be run in | 24 # the command. Because of this, the command should be run in |
26 # options.classes_dir so the .class file paths in the jar are correct. | 25 # options.classes_dir so the .class file paths in the jar are correct. |
27 jar_cwd = options.classes_dir | 26 jar_cwd = options.classes_dir |
28 class_files = [os.path.relpath(f, jar_cwd) for f in class_files] | 27 class_files = [os.path.relpath(f, jar_cwd) for f in class_files] |
29 jar_cmd = ['jar', 'cf0', jar_path] + class_files | 28 jar_cmd = ['jar', 'cf0', jar_path] + class_files |
30 subprocess.check_call(jar_cmd, cwd=jar_cwd) | 29 build_utils.CheckCallDie(jar_cmd, cwd=jar_cwd) |
31 | 30 |
32 | 31 |
33 def main(argv): | 32 def main(argv): |
34 parser = optparse.OptionParser() | 33 parser = optparse.OptionParser() |
35 parser.add_option('--classes-dir', help='Directory containing .class files.') | 34 parser.add_option('--classes-dir', help='Directory containing .class files.') |
36 parser.add_option('--jar-path', help='Jar output path.') | 35 parser.add_option('--jar-path', help='Jar output path.') |
37 parser.add_option('--excluded-classes', | 36 parser.add_option('--excluded-classes', |
38 help='List of .class file patterns to exclude from the jar.') | 37 help='List of .class file patterns to exclude from the jar.') |
39 parser.add_option('--stamp', help='Path to touch on success.') | 38 parser.add_option('--stamp', help='Path to touch on success.') |
40 | 39 |
41 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja. | 40 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja. |
42 parser.add_option('--ignore', help='Ignored.') | 41 parser.add_option('--ignore', help='Ignored.') |
43 | 42 |
44 options, _ = parser.parse_args() | 43 options, _ = parser.parse_args() |
45 | 44 |
46 DoJar(options) | 45 DoJar(options) |
47 | 46 |
48 if options.stamp: | 47 if options.stamp: |
49 build_utils.Touch(options.stamp) | 48 build_utils.Touch(options.stamp) |
50 | 49 |
51 | 50 |
52 if __name__ == '__main__': | 51 if __name__ == '__main__': |
53 sys.exit(main(sys.argv)) | 52 sys.exit(main(sys.argv)) |
54 | 53 |
OLD | NEW |