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 optparse | 7 import optparse |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 | 10 |
| 11 from util import build_utils | 11 from util import build_utils |
| 12 | 12 |
| 13 | 13 |
| 14 _RESOURCE_CLASSES = [ | |
| 15 "R.class", | |
| 16 "R##*.class", | |
| 17 "Manifest.class", | |
| 18 "Manifest##*.class", | |
| 19 ] | |
| 20 | |
| 21 | |
| 14 def Jar(class_files, classes_dir, jar_path, manifest_file=None): | 22 def Jar(class_files, classes_dir, jar_path, manifest_file=None): |
| 15 jar_path = os.path.abspath(jar_path) | 23 jar_path = os.path.abspath(jar_path) |
| 16 | 24 |
| 17 # The paths of the files in the jar will be the same as they are passed in to | 25 # The paths of the files in the jar will be the same as they are passed in to |
| 18 # the command. Because of this, the command should be run in | 26 # the command. Because of this, the command should be run in |
| 19 # options.classes_dir so the .class file paths in the jar are correct. | 27 # options.classes_dir so the .class file paths in the jar are correct. |
| 20 jar_cwd = classes_dir | 28 jar_cwd = classes_dir |
| 21 class_files_rel = [os.path.relpath(f, jar_cwd) for f in class_files] | 29 class_files_rel = [os.path.relpath(f, jar_cwd) for f in class_files] |
| 22 jar_cmd = ['jar', 'cf0', jar_path] | 30 jar_cmd = ['jar', 'cf0', jar_path] |
| 23 if manifest_file: | 31 if manifest_file: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 37 class_files = build_utils.FindInDirectory(classes_dir, '*.class') | 45 class_files = build_utils.FindInDirectory(classes_dir, '*.class') |
| 38 if predicate: | 46 if predicate: |
| 39 class_files = [f for f in class_files if predicate(f)] | 47 class_files = [f for f in class_files if predicate(f)] |
| 40 | 48 |
| 41 Jar(class_files, classes_dir, jar_path, manifest_file=manifest_file) | 49 Jar(class_files, classes_dir, jar_path, manifest_file=manifest_file) |
| 42 | 50 |
| 43 | 51 |
| 44 def main(): | 52 def main(): |
| 45 parser = optparse.OptionParser() | 53 parser = optparse.OptionParser() |
| 46 parser.add_option('--classes-dir', help='Directory containing .class files.') | 54 parser.add_option('--classes-dir', help='Directory containing .class files.') |
| 55 parser.add_option('--input-jar', help='Jar to include .class files from') | |
| 47 parser.add_option('--jar-path', help='Jar output path.') | 56 parser.add_option('--jar-path', help='Jar output path.') |
| 48 parser.add_option('--excluded-classes', | 57 parser.add_option('--excluded-classes', |
| 49 help='List of .class file patterns to exclude from the jar.') | 58 help='GYP list of .class file patterns to exclude from the jar.') |
| 59 parser.add_option('--strip-resource-classes-for', | |
| 60 help='GYP list of java package names exclude R.class files in.') | |
| 50 parser.add_option('--stamp', help='Path to touch on success.') | 61 parser.add_option('--stamp', help='Path to touch on success.') |
| 51 | 62 |
| 52 options, _ = parser.parse_args() | 63 args = build_utils.ExpandFileArgs(sys.argv[1:]) |
| 64 options, _ = parser.parse_args(args) | |
| 65 # Current implementation supports just one or the other of these: | |
| 66 assert not options.classes_dir or not options.input_jar | |
| 67 | |
| 68 excluded_classes = [] | |
| 69 if options.excluded_classes: | |
| 70 excluded_classes = build_utils.ParseGypList(options.excluded_classes) | |
| 71 | |
| 72 if options.strip_resource_classes_for: | |
| 73 packages = build_utils.ParseGypList(options.strip_resource_classes_for) | |
| 74 excluded_classes.extend(p.replace('.', '/') + '/' + f | |
| 75 for p in packages for f in _RESOURCE_CLASSES) | |
| 53 | 76 |
| 54 predicate = None | 77 predicate = None |
| 55 if options.excluded_classes: | 78 if excluded_classes: |
| 56 excluded_classes = build_utils.ParseGypList(options.excluded_classes) | 79 print excluded_classes |
|
jbudorick
2016/05/10 23:24:43
you got your print messages in the build output :(
| |
| 57 predicate = lambda f: not build_utils.MatchesGlob(f, excluded_classes) | 80 predicate = lambda f: not build_utils.MatchesGlob(f, excluded_classes) |
| 58 | 81 |
| 59 JarDirectory(options.classes_dir, options.jar_path, predicate=predicate) | 82 with build_utils.TempDir() as temp_dir: |
| 83 classes_dir = options.classes_dir | |
| 84 if options.input_jar: | |
| 85 build_utils.ExtractAll(options.input_jar, temp_dir) | |
| 86 classes_dir = temp_dir | |
| 87 JarDirectory(classes_dir, options.jar_path, predicate=predicate) | |
| 60 | 88 |
| 61 if options.stamp: | 89 if options.stamp: |
| 62 build_utils.Touch(options.stamp) | 90 build_utils.Touch(options.stamp) |
| 63 | 91 |
| 64 | 92 |
| 65 if __name__ == '__main__': | 93 if __name__ == '__main__': |
| 66 sys.exit(main()) | 94 sys.exit(main()) |
| 67 | 95 |
| OLD | NEW |