Commit 81661826 authored by Jinsong Fan's avatar Jinsong Fan Committed by Commit Bot

[Cronet] Exclude unused classes from src jar

List of patterns of .class files to exclude from the cronet_impl_native_java.jar,
while they still exist in the cronet_impl_native_java-src.jar. This CL fixes their
consistency, and reduce the cronet_impl_native_java-src.jar by about 50 KiB.

TBR=xunjieli@chromium.org

Change-Id: Ieefd47e47b406873c941203d509e898371392ee9
Reviewed-on: https://chromium-review.googlesource.com/1102235Reviewed-by: default avatarHelen Li <xunjieli@chromium.org>
Commit-Queue: Helen Li <xunjieli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567667}
parent 1115c1a5
......@@ -946,15 +946,8 @@ action("extract_cronet_native_jars") {
]
}
action("repackage_extracted_native_jars") {
_output_jar = "$_package_dir/cronet_impl_native_java.jar"
script = "//build/android/gyp/jar.py"
outputs = [
_output_jar,
]
jar_excluded_patterns = [
# List of patterns of .class files to exclude from the jar.
jar_excluded_patterns = [
# Excludes Android support libraries crbug.com/832770.
"android/*",
"*/library_loader/*.class",
......@@ -963,6 +956,14 @@ action("repackage_extracted_native_jars") {
"*/SysUtils.class",
"*/CachedMetrics*.class",
"org/chromium/base/memory/MemoryPressureMonitor*.class",
]
action("repackage_extracted_native_jars") {
_output_jar = "$_package_dir/cronet_impl_native_java.jar"
script = "//build/android/gyp/jar.py"
outputs = [
_output_jar,
]
args = [
......@@ -1120,6 +1121,10 @@ template("jar_src") {
deps += invoker.deps
}
_excluded_patterns = []
if (defined(invoker.excluded_patterns)) {
_excluded_patterns = invoker.excluded_patterns
}
_src_jars = []
# Add src-jar files that are listed in "src_jars".
......@@ -1157,6 +1162,7 @@ template("jar_src") {
args += [ "--src-jar=${_src_jars}" ]
args += [ "--src-files=${_src_files}" ]
args += [ "--src-list-files=${_src_list_files}" ]
args += [ "--excluded-classes=$_excluded_patterns" ]
inputs = _src_jars
inputs += _src_files
......@@ -1220,6 +1226,7 @@ jar_src("jar_cronet_impl_native_java_source") {
"//net/android:net_android_java_enums_srcjar",
"//net/android:net_errors_java",
]
excluded_patterns = jar_excluded_patterns
jar_path = "$_package_dir/cronet_impl_native_java-src.jar"
}
......
......@@ -43,6 +43,8 @@ def UnzipSourceJar(jar, unzipped_jar_path):
def main():
parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser)
parser.add_option('--excluded-classes',
help='A list of .class file patterns to exclude from the jar.')
parser.add_option('--src-search-dirs', action="append",
help='A list of directories that should be searched'
' for the source files.')
......@@ -94,6 +96,15 @@ def main():
if prefix_position != -1:
src_files[i] = s[prefix_position:]
excluded_classes = []
if options.excluded_classes:
classes = build_utils.ParseGnList(options.excluded_classes)
excluded_classes.extend(f.replace('.class', '.java') for f in classes)
predicate = None
if excluded_classes:
predicate = lambda f: not build_utils.MatchesGlob(f, excluded_classes)
# Create a dictionary that maps every source directory
# to source files that it contains.
dir_to_files_map = {}
......@@ -106,6 +117,7 @@ def main():
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
if not predicate or predicate(src_file):
dir_to_files_map[src_search_dir].append(src_file)
if (number_of_file_instances > 1):
raise Exception(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment