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