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