Commit b74cdf4b authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Cronet: Simplify repackage rules

* Use dist_jar() rather than a custom script
  * Avoids needing to extract .jars.
  * Avoids needing to reference ".javac.jar" files, which
    are somewhat of an implementation detail.

* Added jar_excluded_patterns support to dist_jar()

* Merges zip.py and dist_jar.py, since they were doing the
  same thing.

Spot checked that these two jars are the same before/after:
* cronet/cronet_impl_common_java.jar
* cronet/cronet_impl_native_java.jar

Change-Id: I4d5a5f495ce0376ef2e53b6d4e3c9ebbc3d75ae1
Reviewed-on: https://chromium-review.googlesource.com/c/1349872Reviewed-by: default avatarPaul Jensen <pauljensen@chromium.org>
Reviewed-by: default avatarEric Stevenson <estevenson@chromium.org>
Commit-Queue: agrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612210}
parent ed43eedc
...@@ -661,7 +661,6 @@ _ANDROID_SPECIFIC_PYDEPS_FILES = [ ...@@ -661,7 +661,6 @@ _ANDROID_SPECIFIC_PYDEPS_FILES = [
'build/android/gyp/copy_ex.pydeps', 'build/android/gyp/copy_ex.pydeps',
'build/android/gyp/create_app_bundle.pydeps', 'build/android/gyp/create_app_bundle.pydeps',
'build/android/gyp/create_apk_operations_script.pydeps', 'build/android/gyp/create_apk_operations_script.pydeps',
'build/android/gyp/create_dist_jar.pydeps',
'build/android/gyp/create_java_binary_script.pydeps', 'build/android/gyp/create_java_binary_script.pydeps',
'build/android/gyp/create_stack_script.pydeps', 'build/android/gyp/create_stack_script.pydeps',
'build/android/gyp/create_test_runner_script.pydeps', 'build/android/gyp/create_test_runner_script.pydeps',
...@@ -686,6 +685,7 @@ _ANDROID_SPECIFIC_PYDEPS_FILES = [ ...@@ -686,6 +685,7 @@ _ANDROID_SPECIFIC_PYDEPS_FILES = [
'build/android/gyp/proguard.pydeps', 'build/android/gyp/proguard.pydeps',
'build/android/gyp/write_build_config.pydeps', 'build/android/gyp/write_build_config.pydeps',
'build/android/gyp/write_ordered_libraries.pydeps', 'build/android/gyp/write_ordered_libraries.pydeps',
'build/android/gyp/zip.pydeps',
'build/android/incremental_install/generate_android_manifest.pydeps', 'build/android/incremental_install/generate_android_manifest.pydeps',
'build/android/incremental_install/write_installer_json.pydeps', 'build/android/incremental_install/write_installer_json.pydeps',
'build/android/resource_sizes.pydeps', 'build/android/resource_sizes.pydeps',
......
#!/usr/bin/env python
#
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Archives a set of files.
"""
import ast
import optparse
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'gyp'))
from util import build_utils
def main():
parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser)
parser.add_option('--inputs', help='List of files to archive.')
parser.add_option('--output', help='Path to output archive.')
parser.add_option('--base-dir',
help='If provided, the paths in the archive will be '
'relative to this directory', default='.')
options, _ = parser.parse_args()
inputs = ast.literal_eval(options.inputs)
output = options.output
base_dir = options.base_dir
with build_utils.AtomicOutput(output) as f:
build_utils.DoZip(inputs, f, base_dir)
if options.depfile:
build_utils.WriteDepfile(options.depfile, output)
if __name__ == '__main__':
sys.exit(main())
#!/usr/bin/env python
#
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Merges a list of jars into a single jar."""
import argparse
import sys
from util import build_utils
def main(args):
args = build_utils.ExpandFileArgs(args)
parser = argparse.ArgumentParser()
build_utils.AddDepfileOption(parser)
parser.add_argument('--output', required=True, help='Path to output jar.')
parser.add_argument('--jars', required=True, help='GN list of jar inputs.')
options = parser.parse_args(args)
input_jars = build_utils.ParseGnList(options.jars)
build_utils.MergeZips(options.output, input_jars)
if options.depfile:
build_utils.WriteDepfile(options.depfile, options.output, input_jars,
add_pydeps=False)
if __name__ == '__main__':
main(sys.argv[1:])
#!/usr/bin/env python
#
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Archives a set of files."""
import argparse
import os
import sys
import zipfile
from util import build_utils
def main(args):
args = build_utils.ExpandFileArgs(args)
parser = argparse.ArgumentParser(args)
parser.add_argument('--input-files', help='GN-list of files to zip.')
parser.add_argument(
'--input-files-base-dir',
help='Paths in the archive will be relative to this directory')
parser.add_argument('--input-zips', help='GN-list of zips to merge.')
parser.add_argument(
'--input-zips-excluded-globs',
help='GN-list of globs for paths to exclude.')
parser.add_argument('--output', required=True, help='Path to output archive.')
compress_group = parser.add_mutually_exclusive_group()
compress_group.add_argument(
'--compress', action='store_true', help='Compress entries')
compress_group.add_argument(
'--no-compress',
action='store_false',
dest='compress',
help='Do not compress entries')
build_utils.AddDepfileOption(parser)
options = parser.parse_args(args)
with build_utils.AtomicOutput(options.output) as f:
with zipfile.ZipFile(f.name, 'w') as out_zip:
depfile_deps = None
if options.input_files:
files = build_utils.ParseGnList(options.input_files)
build_utils.DoZip(
files,
out_zip,
options.input_files_base_dir,
compress_fn=lambda _: options.compress)
if options.input_zips:
files = build_utils.ParseGnList(options.input_zips)
depfile_deps = files
path_transform = None
if options.input_zips_excluded_globs:
globs = build_utils.ParseGnList(options.input_zips_excluded_globs)
path_transform = (
lambda p: None if build_utils.MatchesGlob(p, globs) else p)
build_utils.MergeZips(
out_zip,
files,
path_transform=path_transform,
compress=options.compress)
# Depfile used only by dist_jar().
if options.depfile:
build_utils.WriteDepfile(
options.depfile, options.output, inputs=depfile_deps, add_pydeps=False)
if __name__ == '__main__':
main(sys.argv[1:])
# Generated by running: # Generated by running:
# build/print_python_deps.py --root build/android/gyp --output build/android/gyp/create_dist_jar.pydeps build/android/gyp/create_dist_jar.py # build/print_python_deps.py --root build/android/gyp --output build/android/gyp/zip.pydeps build/android/gyp/zip.py
../../gn_helpers.py ../../gn_helpers.py
create_dist_jar.py
util/__init__.py util/__init__.py
util/build_utils.py util/build_utils.py
util/md5_check.py util/md5_check.py
zip.py
...@@ -1447,6 +1447,8 @@ if (enable_java_templates) { ...@@ -1447,6 +1447,8 @@ if (enable_java_templates) {
# implementation .jars. # implementation .jars.
# use_unprocessed_jars: Use unprocessed / undesugared .jars. # use_unprocessed_jars: Use unprocessed / undesugared .jars.
# direct_deps_only: Do not recurse on deps. # direct_deps_only: Do not recurse on deps.
# jar_excluded_patterns (optional)
# List of globs for paths to exclude.
# #
# Example # Example
# dist_jar("lib_fatjar") { # dist_jar("lib_fatjar") {
...@@ -1509,7 +1511,7 @@ if (enable_java_templates) { ...@@ -1509,7 +1511,7 @@ if (enable_java_templates) {
_rebased_build_config = rebase_path(_build_config, root_build_dir) _rebased_build_config = rebase_path(_build_config, root_build_dir)
action_with_pydeps(_jar_target_name) { action_with_pydeps(_jar_target_name) {
forward_variables_from(invoker, [ "data" ]) forward_variables_from(invoker, [ "data" ])
script = "//build/android/gyp/create_dist_jar.py" script = "//build/android/gyp/zip.py"
depfile = "$target_gen_dir/$target_name.d" depfile = "$target_gen_dir/$target_name.d"
deps = _deps deps = _deps
...@@ -1526,15 +1528,16 @@ if (enable_java_templates) { ...@@ -1526,15 +1528,16 @@ if (enable_java_templates) {
rebase_path(depfile, root_build_dir), rebase_path(depfile, root_build_dir),
"--output", "--output",
rebase_path(invoker.output, root_build_dir), rebase_path(invoker.output, root_build_dir),
"--no-compress",
] ]
if (_direct_deps_only) { if (_direct_deps_only) {
if (_use_interface_jars) { if (_use_interface_jars) {
args += [ "--input-zips=@FileArg($_rebased_build_config:javac:interface_classpath)" ]
} else if (_use_unprocessed_jars) {
args += [ args += [
"--jars=@FileArg($_rebased_build_config:javac:interface_classpath)", "--input-zips=@FileArg($_rebased_build_config:javac:classpath)",
] ]
} else if (_use_unprocessed_jars) {
args += [ "--jars=@FileArg($_rebased_build_config:javac:classpath)" ]
} else { } else {
assert( assert(
false, false,
...@@ -1542,12 +1545,16 @@ if (enable_java_templates) { ...@@ -1542,12 +1545,16 @@ if (enable_java_templates) {
} }
} else { } else {
if (_use_interface_jars) { if (_use_interface_jars) {
args += [ "--jars=@FileArg($_rebased_build_config:dist_jar:all_interface_jars)" ] args += [ "--input-zips=@FileArg($_rebased_build_config:dist_jar:all_interface_jars)" ]
} else if (_use_unprocessed_jars) { } else if (_use_unprocessed_jars) {
args += [ "--jars=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)" ] args += [ "--input-zips=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)" ]
} else { } else {
args += [ "--jars=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)" ] args += [ "--input-zips=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)" ]
}
} }
if (defined(invoker.jar_excluded_patterns)) {
args +=
[ "--input-zips-excluded-globs=${invoker.jar_excluded_patterns}" ]
} }
} }
} }
......
...@@ -2,54 +2,49 @@ ...@@ -2,54 +2,49 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("python.gni")
# Creates a zip archive of the inputs. # Creates a zip archive of the inputs.
# #
# inputs (required)
# List of input files relative to the current directory.
#
# output (required) # output (required)
# File name to write. # Path to output zip.
# # inputs (required)
# List of input files to zip.
# base_dir (optional) # base_dir (optional)
# If provided, the archive paths will be relative to this directory. # If provided, the archive paths will be relative to this directory.
# Applies only to |inputs|.
# #
# deps, public_deps, data_deps, testonly, visibility (optional) # deps, public_deps, data, data_deps, testonly, visibility
# Normal meaning. # Normal meaning.
template("zip") { template("zip") {
action(target_name) { action_with_pydeps(target_name) {
script = "//build/android/gn/zip.py" forward_variables_from(invoker,
depfile = "$target_gen_dir/$target_name.d" [
"data",
"data_deps",
"deps",
"public_deps",
"testonly",
"visibility",
])
script = "//build/android/gyp/zip.py"
inputs = invoker.inputs inputs = invoker.inputs
outputs = [ outputs = [
invoker.output, invoker.output,
] ]
assert(defined(invoker.inputs))
rebase_inputs = rebase_path(invoker.inputs, root_build_dir)
assert(defined(invoker.output))
rebase_output = rebase_path(invoker.output, root_build_dir)
args = [ args = [
"--depfile", "--output",
rebase_path(depfile, root_build_dir), rebase_path(invoker.output, root_build_dir),
"--inputs=$rebase_inputs",
"--output=$rebase_output",
] ]
_rebased_inputs = rebase_path(invoker.inputs, root_build_dir)
args += [ "--input-files=$_rebased_inputs" ]
if (defined(invoker.base_dir)) { if (defined(invoker.base_dir)) {
args += [ args += [
"--base-dir", "--input-files-base-dir",
rebase_path(invoker.base_dir, root_build_dir), rebase_path(invoker.base_dir, root_build_dir),
] ]
} }
forward_variables_from(invoker,
[
"testonly",
"deps",
"public_deps",
"data_deps",
"visibility",
])
} }
} }
This diff is collapsed.
#!/usr/bin/env python
#
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import optparse
import os
import sys
REPOSITORY_ROOT = os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', '..', '..'))
sys.path.append(os.path.join(REPOSITORY_ROOT, 'build/android/gyp/util'))
import build_utils
def ExtractJars(options):
# 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.classes_dir so the .class file paths in the jar are correct.
jar_cwd = options.classes_dir
build_utils.DeleteDirectory(jar_cwd)
build_utils.MakeDirectory(jar_cwd)
for jar in build_utils.ParseGnList(options.jars):
jar_path = os.path.abspath(jar)
jar_cmd = ['jar', 'xf', jar_path]
build_utils.CheckOutput(jar_cmd, cwd=jar_cwd)
def main():
parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser)
parser.add_option('--classes-dir', help='Directory to extract .class files.')
parser.add_option('--jars', help='Paths to jars to extract.')
parser.add_option('--stamp', help='Path to touch on success.')
options, _ = parser.parse_args()
ExtractJars(options)
if options.depfile:
assert options.stamp
build_utils.WriteDepfile(options.depfile, options.stamp)
if options.stamp:
build_utils.Touch(options.stamp)
if __name__ == '__main__':
sys.exit(main())
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