OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
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 | |
5 # found in the LICENSE file. | |
6 | |
7 import fnmatch | |
8 import optparse | |
9 import os | |
10 import subprocess | |
11 import sys | |
12 | |
13 from pylib import build_utils | |
14 | |
15 | |
16 def DoJar(options): | |
17 class_files = build_utils.FindInDirectory(options.classes_dir, '*.class') | |
18 for exclude in build_utils.ParseGypList(options.jar_excludes): | |
19 class_files = filter( | |
20 lambda f: not fnmatch.fnmatch(f, exclude), class_files) | |
21 | |
22 jar_path = os.path.abspath(options.jar_path) | |
23 | |
24 # 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 | |
26 # options.classes_dir so the .class file paths in the jar are correct. | |
27 jar_cwd = options.classes_dir | |
28 class_files = map(lambda f: os.path.relpath(f, jar_cwd), class_files) | |
newt (away)
2013/03/15 03:25:04
I think a list comprehension is preferred:
class_
cjhopman
2013/03/15 22:44:39
Done. Not preferred by me, though :).
| |
29 jar_cmd = ['jar', 'cf0', jar_path] + class_files | |
30 subprocess.check_call(jar_cmd, cwd=jar_cwd) | |
31 | |
32 | |
33 def main(argv): | |
34 parser = optparse.OptionParser() | |
35 parser.add_option('--classes-dir') | |
36 parser.add_option('--jar-path') | |
37 parser.add_option('--jar-excludes') | |
38 parser.add_option('--stamp') | |
39 | |
40 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja. | |
41 parser.add_option('--ignore') | |
42 | |
43 options, _ = parser.parse_args() | |
44 | |
45 DoJar(options) | |
46 | |
47 if options.stamp: | |
48 build_utils.Touch(options.stamp) | |
49 | |
50 | |
51 if __name__ == '__main__': | |
52 sys.exit(main(sys.argv)) | |
53 | |
Yaron
2013/03/14 23:03:51
double trailing ws?
cjhopman
2013/03/15 22:44:39
Done.
| |
54 | |
OLD | NEW |