| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 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 import tempfile | |
| 11 | 10 |
| 12 REPOSITORY_ROOT = os.path.abspath(os.path.join( | 11 REPOSITORY_ROOT = os.path.abspath(os.path.join( |
| 13 os.path.dirname(__file__), '..', '..', '..')) | 12 os.path.dirname(__file__), '..', '..', '..')) |
| 14 | 13 |
| 15 sys.path.append(os.path.join(REPOSITORY_ROOT, 'build/android/gyp/util')) | 14 sys.path.append(os.path.join(REPOSITORY_ROOT, 'build/android/gyp/util')) |
| 16 import build_utils | 15 import build_utils |
| 17 | 16 |
| 18 | 17 |
| 19 def JarSources(src_dir, jar_path): | 18 def JarSources(src_dir, jar_path): |
| 20 # The paths of the files in the jar will be the same as they are passed in to | 19 # The paths of the files in the jar will be the same as they are passed in to |
| 21 # the command. Because of this, the command should be run in | 20 # the command. Because of this, the command should be run in |
| 22 # options.src_dir so the .java file paths in the jar are correct. | 21 # options.src_dir so the .java file paths in the jar are correct. |
| 23 jar_cwd = src_dir | 22 jar_cwd = src_dir |
| 24 jar_path = os.path.abspath(jar_path) | 23 jar_path = os.path.abspath(jar_path) |
| 25 if os.path.exists(jar_path): | 24 if os.path.exists(jar_path): |
| 26 jar_cmd = ['jar', 'uf', jar_path, '.'] | 25 jar_cmd = ['jar', 'uf', jar_path, '.'] |
| 27 else: | 26 else: |
| 28 jar_cmd = ['jar', 'cf', jar_path, '.'] | 27 jar_cmd = ['jar', 'cf', jar_path, '.'] |
| 29 | 28 |
| 30 build_utils.CheckOutput(jar_cmd, cwd=jar_cwd) | 29 build_utils.CheckOutput(jar_cmd, cwd=jar_cwd) |
| 31 | 30 |
| 32 # Uncompress source jars so that they can be combined with other sources | |
| 33 def UnzipSourceJar(jar, unzipped_jar_path): | |
| 34 if os.path.exists(jar): | |
| 35 jar_cmd = ['jar', 'xf', os.path.abspath(jar)] | |
| 36 build_utils.CheckOutput(jar_cmd, cwd=unzipped_jar_path) | |
| 37 else: | |
| 38 raise Exception('Jar file does not exist %s' % jar) | |
| 39 | |
| 40 | 31 |
| 41 def main(): | 32 def main(): |
| 42 parser = optparse.OptionParser() | 33 parser = optparse.OptionParser() |
| 43 build_utils.AddDepfileOption(parser) | 34 build_utils.AddDepfileOption(parser) |
| 44 parser.add_option('--src-dir', action="append", | 35 parser.add_option('--src-dir', action="append", |
| 45 help='Directory containing .java files.') | 36 help='Directory containing .java files.') |
| 46 parser.add_option('--src-jars', action="append", | |
| 47 help='A list of source jars to include in addition to source files.') | |
| 48 parser.add_option('--jar-path', help='Jar output path.') | 37 parser.add_option('--jar-path', help='Jar output path.') |
| 49 parser.add_option('--stamp', help='Path to touch on success.') | 38 parser.add_option('--stamp', help='Path to touch on success.') |
| 50 | 39 |
| 51 options, _ = parser.parse_args() | 40 options, _ = parser.parse_args() |
| 52 | 41 |
| 53 # A temporary directory to put the output of jar files. | |
| 54 unzipped_jar_path = None | |
| 55 if options.src_jars: | |
| 56 unzipped_jar_path = tempfile.mkdtemp(dir=os.path.dirname(options.jar_path)) | |
| 57 jar_list = [] | |
| 58 for gn_list in options.src_jars: | |
| 59 jar_list.extend(build_utils.ParseGnList(gn_list)) | |
| 60 | |
| 61 for jar in jar_list: | |
| 62 UnzipSourceJar(jar, unzipped_jar_path) | |
| 63 | |
| 64 src_dirs = [] | 42 src_dirs = [] |
| 65 for src_dir in options.src_dir: | 43 for src_dir in options.src_dir: |
| 66 src_dirs.extend(build_utils.ParseGypList(src_dir)) | 44 src_dirs.extend(build_utils.ParseGypList(src_dir)) |
| 67 if unzipped_jar_path: | |
| 68 src_dirs += [unzipped_jar_path] | |
| 69 | 45 |
| 70 for src_dir in src_dirs: | 46 for src_dir in src_dirs: |
| 71 JarSources(src_dir, options.jar_path) | 47 JarSources(src_dir, options.jar_path) |
| 72 | 48 |
| 73 if options.depfile: | 49 if options.depfile: |
| 74 input_paths = [] | 50 input_paths = [] |
| 75 for src_dir in src_dirs: | 51 for src_dir in src_dirs: |
| 76 for root, _, filenames in os.walk(src_dir): | 52 for root, _, filenames in os.walk(src_dir): |
| 77 input_paths.extend(os.path.join(root, f) for f in filenames) | 53 input_paths.extend(os.path.join(root, f) for f in filenames) |
| 78 build_utils.WriteDepfile(options.depfile, | 54 build_utils.WriteDepfile(options.depfile, |
| 79 input_paths + build_utils.GetPythonDependencies()) | 55 input_paths + build_utils.GetPythonDependencies()) |
| 80 # Clean up temporary output directory. | |
| 81 if unzipped_jar_path: | |
| 82 build_utils.DeleteDirectory(unzipped_jar_path) | |
| 83 | 56 |
| 84 if options.stamp: | 57 if options.stamp: |
| 85 build_utils.Touch(options.stamp) | 58 build_utils.Touch(options.stamp) |
| 86 | 59 |
| 87 if __name__ == '__main__': | 60 if __name__ == '__main__': |
| 88 sys.exit(main()) | 61 sys.exit(main()) |
| 89 | 62 |
| OLD | NEW |