Chromium Code Reviews| 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 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 # 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. |
| 22 jar_cwd = src_dir | 22 jar_cwd = src_dir |
| 23 jar_path = os.path.abspath(jar_path) | 23 jar_path = os.path.abspath(jar_path) |
| 24 if os.path.exists(jar_path): | 24 if os.path.exists(jar_path): |
| 25 jar_cmd = ['jar', 'uf', jar_path, '.'] | 25 jar_cmd = ['jar', 'uf', jar_path, '.'] |
| 26 else: | 26 else: |
| 27 jar_cmd = ['jar', 'cf', jar_path, '.'] | 27 jar_cmd = ['jar', 'cf', jar_path, '.'] |
| 28 | 28 |
| 29 build_utils.CheckOutput(jar_cmd, cwd=jar_cwd) | 29 build_utils.CheckOutput(jar_cmd, cwd=jar_cwd) |
| 30 | 30 |
| 31 # Uncompress source jars so that they can be combined with other sources | |
| 32 def UnzipSourceJar(jar, unzipped_jar_path): | |
| 33 if os.path.exists(jar): | |
| 34 # Need to execute the jar command inside the temporary directory, and that | |
| 35 # is why the ../../ is needed. | |
| 36 jar_cmd = ['jar', 'xf', '../../' + jar] | |
|
kapishnikov
2016/08/12 15:33:39
Can we use os.path.abspath here instead of "../../
xunjieli
2016/08/12 17:52:58
We need to execute the jar command inside the temp
kapishnikov
2016/08/12 19:18:51
I was thinking of something like:
jar_cmd = ['jar'
xunjieli
2016/08/12 19:30:44
Ah, that's very smart. Why I didn't think of that.
| |
| 37 build_utils.CheckOutput(jar_cmd, cwd=unzipped_jar_path) | |
| 38 else: | |
| 39 raise Exception('Jar file does not exist %s' % jar) | |
| 40 | |
| 31 | 41 |
| 32 def main(): | 42 def main(): |
| 33 parser = optparse.OptionParser() | 43 parser = optparse.OptionParser() |
| 34 build_utils.AddDepfileOption(parser) | 44 build_utils.AddDepfileOption(parser) |
| 35 parser.add_option('--src-dir', action="append", | 45 parser.add_option('--src-dir', action="append", |
| 36 help='Directory containing .java files.') | 46 help='Directory containing .java files.') |
| 47 parser.add_option('--src-jars', action="append", | |
| 48 help='A list of source jars to include in addition to source files.') | |
| 37 parser.add_option('--jar-path', help='Jar output path.') | 49 parser.add_option('--jar-path', help='Jar output path.') |
| 38 parser.add_option('--stamp', help='Path to touch on success.') | 50 parser.add_option('--stamp', help='Path to touch on success.') |
| 39 | 51 |
| 40 options, _ = parser.parse_args() | 52 options, _ = parser.parse_args() |
| 41 | 53 |
| 54 # A temporary directory to put the output of jar files. | |
| 55 unzipped_jar_path = None | |
| 56 if options.src_jars: | |
| 57 unzipped_jar_path = os.path.join(os.path.dirname(options.jar_path), 'tmp') | |
| 58 build_utils.MakeDirectory(unzipped_jar_path) | |
|
kapishnikov
2016/08/12 15:33:39
Similar to the previous comment, make sure that th
xunjieli
2016/08/12 17:52:58
Done.
| |
| 59 jar_list = [] | |
| 60 for gyp_list in options.src_jars: | |
|
kapishnikov
2016/08/12 15:33:39
Rename "gyp_list" to "gn_list"?
xunjieli
2016/08/12 17:52:58
Done.
| |
| 61 jar_list.extend(build_utils.ParseGypList(gyp_list)) | |
|
kapishnikov
2016/08/12 15:33:39
ParseGypList => ParseGnList?
xunjieli
2016/08/12 17:52:58
Done.
| |
| 62 | |
| 63 for jar in jar_list: | |
| 64 UnzipSourceJar(jar, unzipped_jar_path) | |
| 65 | |
| 42 src_dirs = [] | 66 src_dirs = [] |
| 43 for src_dir in options.src_dir: | 67 for src_dir in options.src_dir: |
| 44 src_dirs.extend(build_utils.ParseGypList(src_dir)) | 68 src_dirs.extend(build_utils.ParseGypList(src_dir)) |
| 69 if unzipped_jar_path: | |
| 70 src_dirs += [unzipped_jar_path] | |
| 45 | 71 |
| 46 for src_dir in src_dirs: | 72 for src_dir in src_dirs: |
| 47 JarSources(src_dir, options.jar_path) | 73 JarSources(src_dir, options.jar_path) |
| 48 | 74 |
| 49 if options.depfile: | 75 if options.depfile: |
| 50 input_paths = [] | 76 input_paths = [] |
| 51 for src_dir in src_dirs: | 77 for src_dir in src_dirs: |
| 52 for root, _, filenames in os.walk(src_dir): | 78 for root, _, filenames in os.walk(src_dir): |
| 53 input_paths.extend(os.path.join(root, f) for f in filenames) | 79 input_paths.extend(os.path.join(root, f) for f in filenames) |
| 54 build_utils.WriteDepfile(options.depfile, | 80 build_utils.WriteDepfile(options.depfile, |
| 55 input_paths + build_utils.GetPythonDependencies()) | 81 input_paths + build_utils.GetPythonDependencies()) |
| 82 # Clean up temporary output directory. | |
| 83 if unzipped_jar_path: | |
| 84 build_utils.DeleteDirectory(unzipped_jar_path) | |
| 56 | 85 |
| 57 if options.stamp: | 86 if options.stamp: |
| 58 build_utils.Touch(options.stamp) | 87 build_utils.Touch(options.stamp) |
| 59 | 88 |
| 60 if __name__ == '__main__': | 89 if __name__ == '__main__': |
| 61 sys.exit(main()) | 90 sys.exit(main()) |
| 62 | 91 |
| OLD | NEW |