Chromium Code Reviews| Index: components/cronet/tools/jar_src.py |
| diff --git a/components/cronet/tools/jar_src.py b/components/cronet/tools/jar_src.py |
| index b2d39d648f9b2ec27db16b6bbf9c8a841bd6eb69..41541d0ee8eae428e0eba6911833db7782c6a007 100755 |
| --- a/components/cronet/tools/jar_src.py |
| +++ b/components/cronet/tools/jar_src.py |
| @@ -16,17 +16,18 @@ sys.path.append(os.path.join(REPOSITORY_ROOT, 'build/android/gyp/util')) |
| import build_utils |
| -def JarSources(src_dir, jar_path): |
| +def JarSources(src_dir, src_files, jar_path): |
| # The paths of the files in the jar will be the same as they are passed in to |
| # the command. Because of this, the command should be run in |
| # options.src_dir so the .java file paths in the jar are correct. |
| jar_cwd = src_dir |
| jar_path = os.path.abspath(jar_path) |
| if os.path.exists(jar_path): |
| - jar_cmd = ['jar', 'uf', jar_path, '.'] |
| + jar_cmd = ['jar', 'uf', jar_path] |
| else: |
| - jar_cmd = ['jar', 'cf', jar_path, '.'] |
| + jar_cmd = ['jar', 'cf', jar_path] |
| + jar_cmd.extend(src_files) |
| build_utils.CheckOutput(jar_cmd, cwd=jar_cwd) |
| # Uncompress source jars so that they can be combined with other sources |
| @@ -41,8 +42,11 @@ def UnzipSourceJar(jar, unzipped_jar_path): |
| def main(): |
| parser = optparse.OptionParser() |
| build_utils.AddDepfileOption(parser) |
| - parser.add_option('--src-dir', action="append", |
| - help='Directory containing .java files.') |
| + parser.add_option('--src-search-dirs', action="append", |
| + help='A list of directories that should be searched ' |
| + 'for the source files.') |
| + parser.add_option('--src-files', action="append", |
| + help='A list of source files to jar.') |
| parser.add_option('--src-jars', action="append", |
| help='A list of source jars to include in addition to source files.') |
| parser.add_option('--jar-path', help='Jar output path.') |
| @@ -52,10 +56,8 @@ def main(): |
| # A temporary directory to put the output of jar files. |
| unzipped_jar_path = None |
| - generated_src_dirs = [] |
| if options.src_jars: |
| unzipped_jar_path = tempfile.mkdtemp(dir=os.path.dirname(options.jar_path)) |
| - generated_src_dirs.append(unzipped_jar_path) |
| jar_list = [] |
| for gn_list in options.src_jars: |
| jar_list.extend(build_utils.ParseGnList(gn_list)) |
| @@ -63,16 +65,52 @@ def main(): |
| for jar in jar_list: |
| UnzipSourceJar(jar, unzipped_jar_path) |
| - src_dirs = [] |
| - for src_dir in options.src_dir: |
| - src_dirs.extend(build_utils.ParseGnList(src_dir)) |
| - |
| - for src_dir in src_dirs + generated_src_dirs: |
| - JarSources(src_dir, options.jar_path) |
| + src_search_dirs = [] |
| + for gn_src_search_dirs in options.src_search_dirs: |
| + src_search_dirs.extend(build_utils.ParseGnList(gn_src_search_dirs)) |
| + |
| + src_files = [] |
| + for gn_src_files in options.src_files: |
| + src_files.extend(build_utils.ParseGnList(gn_src_files)) |
| + |
| + # Create a dictionary that maps every source directory |
| + # to source files that it contains. |
| + dir_to_files_map = {} |
| + #Initialize the map |
|
pauljensen
2016/09/16 18:38:39
space between "#" and "I"
xunjieli
2016/09/16 18:39:49
nit: leave a space after #.
kapishnikov
2016/09/16 20:28:27
Done.
kapishnikov
2016/09/16 20:28:27
Done.
|
| + for src_search_dir in src_search_dirs: |
| + dir_to_files_map[src_search_dir] = [] |
| + # Fill the map |
| + for src_file in src_files: |
| + number_of_file_instances = 0 |
| + for src_search_dir in src_search_dirs: |
| + if os.path.isfile(os.path.join(src_search_dir, src_file)): |
| + number_of_file_instances += 1 |
| + dir_to_files_map[src_search_dir].append(src_file) |
| + if (number_of_file_instances > 1): |
| + raise Exception( |
| + 'There are more that one instance of file %s in %s' |
| + % (src_file, src_search_dirs)) |
| + if (number_of_file_instances < 1): |
| + raise Exception( |
| + 'Unable to find file %s in %s' % (src_file, src_search_dirs)) |
| + |
| + # Jar the sources from every source search directory |
| + for src_search_dir in src_search_dirs: |
| + if len(dir_to_files_map[src_search_dir]) > 0: |
| + JarSources(src_search_dir, dir_to_files_map[src_search_dir], |
| + options.jar_path) |
| + else: |
| + raise Exception( |
| + 'Directory %s does not contain any files and can be' |
| + 'removes from the search path' % src_search_dir) |
|
pauljensen
2016/09/16 18:38:39
removes->removed
search path->list of directories
kapishnikov
2016/09/16 20:28:27
Done.
|
| + |
| + # Jar additional src jars |
| + if unzipped_jar_path: |
| + JarSources(unzipped_jar_path, ['.'], options.jar_path) |
| if options.depfile: |
| deps = [] |
| - for src_dir in src_dirs: |
| + for src_dir in src_search_dirs: |
| for root, _, filenames in os.walk(src_dir): |
| deps.extend(os.path.join(root, f) for f in filenames) |
| # Srcjar deps already captured in GN rules (no need to list them here). |