From e19b43e9a605d8622cc5b0bfa22b91000a7549aa Mon Sep 17 00:00:00 2001 From: agrieve Date: Thu, 29 Nov 2018 20:51:26 +0000 Subject: [PATCH] Revert "Cronet: Simplify repackage rules" This reverts commit b74cdf4b03c3748352b6c7641a5701cd1958d511. Reason for revert: Broke compile of remoting_me2me_host_archive (see bug) Original change's description: > 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/1349872 > Reviewed-by: Paul Jensen > Reviewed-by: Eric Stevenson > Commit-Queue: agrieve > Cr-Commit-Position: refs/heads/master@{#612210} TBR=pauljensen@chromium.org,agrieve@chromium.org,estevenson@chromium.org Bug: 910311 Change-Id: I0d06a36a1694e378bdfafda21f63fd2e5f258239 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/c/1355887 Reviewed-by: agrieve Commit-Queue: agrieve Cr-Original-Commit-Position: refs/heads/master@{#612347} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 8adb2d699d485be7080541f9b37fffea60ef1983 --- android/gn/zip.py | 42 +++++++++++ android/gyp/create_dist_jar.py | 32 +++++++++ .../{zip.pydeps => create_dist_jar.pydeps} | 4 +- android/gyp/zip.py | 71 ------------------- config/android/rules.gni | 21 ++---- config/zip.gni | 55 +++++++------- 6 files changed, 113 insertions(+), 112 deletions(-) create mode 100755 android/gn/zip.py create mode 100755 android/gyp/create_dist_jar.py rename android/gyp/{zip.pydeps => create_dist_jar.pydeps} (62%) delete mode 100755 android/gyp/zip.py diff --git a/android/gn/zip.py b/android/gn/zip.py new file mode 100755 index 000000000..3e9668d4a --- /dev/null +++ b/android/gn/zip.py @@ -0,0 +1,42 @@ +#!/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()) diff --git a/android/gyp/create_dist_jar.py b/android/gyp/create_dist_jar.py new file mode 100755 index 000000000..7f78935a4 --- /dev/null +++ b/android/gyp/create_dist_jar.py @@ -0,0 +1,32 @@ +#!/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:]) diff --git a/android/gyp/zip.pydeps b/android/gyp/create_dist_jar.pydeps similarity index 62% rename from android/gyp/zip.pydeps rename to android/gyp/create_dist_jar.pydeps index ce99648ca..f4224d7f9 100644 --- a/android/gyp/zip.pydeps +++ b/android/gyp/create_dist_jar.pydeps @@ -1,7 +1,7 @@ # Generated by running: -# build/print_python_deps.py --root build/android/gyp --output build/android/gyp/zip.pydeps build/android/gyp/zip.py +# build/print_python_deps.py --root build/android/gyp --output build/android/gyp/create_dist_jar.pydeps build/android/gyp/create_dist_jar.py ../../gn_helpers.py +create_dist_jar.py util/__init__.py util/build_utils.py util/md5_check.py -zip.py diff --git a/android/gyp/zip.py b/android/gyp/zip.py deleted file mode 100755 index 854ccd068..000000000 --- a/android/gyp/zip.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/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:]) diff --git a/config/android/rules.gni b/config/android/rules.gni index 008d09ed1..c1c7ae16c 100644 --- a/config/android/rules.gni +++ b/config/android/rules.gni @@ -1447,8 +1447,6 @@ if (enable_java_templates) { # implementation .jars. # use_unprocessed_jars: Use unprocessed / undesugared .jars. # direct_deps_only: Do not recurse on deps. - # jar_excluded_patterns (optional) - # List of globs for paths to exclude. # # Example # dist_jar("lib_fatjar") { @@ -1511,7 +1509,7 @@ if (enable_java_templates) { _rebased_build_config = rebase_path(_build_config, root_build_dir) action_with_pydeps(_jar_target_name) { forward_variables_from(invoker, [ "data" ]) - script = "//build/android/gyp/zip.py" + script = "//build/android/gyp/create_dist_jar.py" depfile = "$target_gen_dir/$target_name.d" deps = _deps @@ -1528,16 +1526,15 @@ if (enable_java_templates) { rebase_path(depfile, root_build_dir), "--output", rebase_path(invoker.output, root_build_dir), - "--no-compress", ] if (_direct_deps_only) { if (_use_interface_jars) { - args += [ "--input-zips=@FileArg($_rebased_build_config:javac:interface_classpath)" ] - } else if (_use_unprocessed_jars) { args += [ - "--input-zips=@FileArg($_rebased_build_config:javac:classpath)", + "--jars=@FileArg($_rebased_build_config:javac:interface_classpath)", ] + } else if (_use_unprocessed_jars) { + args += [ "--jars=@FileArg($_rebased_build_config:javac:classpath)" ] } else { assert( false, @@ -1545,17 +1542,13 @@ if (enable_java_templates) { } } else { if (_use_interface_jars) { - args += [ "--input-zips=@FileArg($_rebased_build_config:dist_jar:all_interface_jars)" ] + args += [ "--jars=@FileArg($_rebased_build_config:dist_jar:all_interface_jars)" ] } else if (_use_unprocessed_jars) { - args += [ "--input-zips=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)" ] + args += [ "--jars=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)" ] } else { - args += [ "--input-zips=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)" ] + args += [ "--jars=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)" ] } } - if (defined(invoker.jar_excluded_patterns)) { - args += - [ "--input-zips-excluded-globs=${invoker.jar_excluded_patterns}" ] - } } } diff --git a/config/zip.gni b/config/zip.gni index 58cb692f7..8265e1dab 100644 --- a/config/zip.gni +++ b/config/zip.gni @@ -2,49 +2,54 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("python.gni") - # Creates a zip archive of the inputs. # -# output (required) -# Path to output zip. # inputs (required) -# List of input files to zip. +# List of input files relative to the current directory. +# +# output (required) +# File name to write. +# # base_dir (optional) # If provided, the archive paths will be relative to this directory. -# Applies only to |inputs|. # -# deps, public_deps, data, data_deps, testonly, visibility +# deps, public_deps, data_deps, testonly, visibility (optional) # Normal meaning. template("zip") { - action_with_pydeps(target_name) { - forward_variables_from(invoker, - [ - "data", - "data_deps", - "deps", - "public_deps", - "testonly", - "visibility", - ]) - script = "//build/android/gyp/zip.py" + action(target_name) { + script = "//build/android/gn/zip.py" + depfile = "$target_gen_dir/$target_name.d" inputs = invoker.inputs outputs = [ invoker.output, ] - args = [ - "--output", - rebase_path(invoker.output, root_build_dir), - ] + assert(defined(invoker.inputs)) + rebase_inputs = rebase_path(invoker.inputs, root_build_dir) - _rebased_inputs = rebase_path(invoker.inputs, root_build_dir) - args += [ "--input-files=$_rebased_inputs" ] + assert(defined(invoker.output)) + rebase_output = rebase_path(invoker.output, root_build_dir) + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--inputs=$rebase_inputs", + "--output=$rebase_output", + ] if (defined(invoker.base_dir)) { args += [ - "--input-files-base-dir", + "--base-dir", rebase_path(invoker.base_dir, root_build_dir), ] } + + forward_variables_from(invoker, + [ + "testonly", + "deps", + "public_deps", + "data_deps", + "visibility", + ]) } }