Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: components/cronet/tools/jar_src.py

Issue 2347233002: Add src_files to src_jar GN template (Closed)
Patch Set: Comment fixes + rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/android/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..758333b949957971edf7008189a7005e89f5d1c8 100755
--- a/components/cronet/tools/jar_src.py
+++ b/components/cronet/tools/jar_src.py
@@ -15,18 +15,20 @@ REPOSITORY_ROOT = os.path.abspath(os.path.join(
sys.path.append(os.path.join(REPOSITORY_ROOT, 'build/android/gyp/util'))
import build_utils
+JAVA_PACKAGE_PREFIX = 'org/chromium/'
-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,10 +43,16 @@ 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('--src-list-files', action="append",
+ help='A list of files that contain a list of sources,'
+ ' e.g. a list of \'.sources\' files generated by GN.')
parser.add_option('--jar-path', help='Jar output path.')
parser.add_option('--stamp', help='Path to touch on success.')
@@ -52,10 +60,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 +69,69 @@ 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_list_files = []
+ if options.src_list_files:
+ for gn_src_list_file in options.src_list_files:
+ src_list_files.extend(build_utils.ParseGnList(gn_src_list_file))
+
+ src_files = []
+ for gn_src_files in options.src_files:
+ src_files.extend(build_utils.ParseGnList(gn_src_files))
+
+ # Add files from --source_list_files
+ for src_list_file in src_list_files:
+ with open(src_list_file, 'r') as f:
+ src_files.extend(f.read().splitlines())
+
+ # Preprocess source files by removing any prefix that comes before
+ # the Java package name.
+ for i, s in enumerate(src_files):
+ prefix_position = s.find(JAVA_PACKAGE_PREFIX)
+ if prefix_position != -1:
+ src_files[i] = s[prefix_position:]
+
+ # Create a dictionary that maps every source directory
+ # to source files that it contains.
+ dir_to_files_map = {}
+ # Initialize the map.
+ 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 is more than 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'
+ ' removed from the list of directories to search' % src_search_dir)
+
+ # 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).
« no previous file with comments | « components/cronet/android/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698