From a314735828a59fbd35c0b2b75b52fe4547f28116 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Wed, 4 May 2022 15:54:02 -0700 Subject: [PATCH 1/2] Move embedder jar file processing to GN. Recipes currently contain a lot of logic to manipulate jar file names and creating the expected folder structures. This PR moves the logic to process embedder android artifacts to GN. Bug: https://github.com/flutter/flutter/issues/81855 --- build/android_artifacts.py | 36 ++++++++++++++++++++++++++ shell/platform/android/BUILD.gn | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 build/android_artifacts.py diff --git a/build/android_artifacts.py b/build/android_artifacts.py new file mode 100644 index 0000000000000..379ca639e3565 --- /dev/null +++ b/build/android_artifacts.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +"""Copies and renames android artifacts.""" + + + +import sys +import shutil +import os +import argparse + + +def cp_files(args): + """Copies files from source to destination. + + It creates the destination folder if it does not exists yet. + """ + for src, dst in args.input_pairs: + os.makedirs(os.path.dirname(dst), exist_ok=True) + shutil.copyfile(src, dst) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('-i', dest='input_pairs', nargs=2, action='append', + help='The input file and its destination.') + cp_files(parser.parse_args()) + + return 0 + +if __name__ == '__main__': + sys.exit(main()) diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 100323a8dc3a0..3387d83f33e19 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -607,3 +607,48 @@ group("android") { deps += [ ":gen_snapshot" ] } } + +# Renames embedding android artifacts and places them in the final +# expected folder structure. +action("embedding_jars") { + script = "//flutter/build/android_artifacts.py" + + deps = [ + ":flutter_shell_java", + ":pom_embedding", + ] + sources = [ + "$root_out_dir/flutter_embedding_$flutter_runtime_mode.jar", + "$root_out_dir/flutter_embedding_$flutter_runtime_mode.pom", + ] + outputs = [] + args = [] + base_name = "$root_out_dir/zip_archives/flutter_download_io/" + + "flutter_embedding_$flutter_runtime_mode/1.0.0-$engine_version/" + + "flutter_embedding_$flutter_runtime_mode-1.0.0-${engine_version}" + foreach(source, sources) { + extension = get_path_info(source, "extension") + name = get_path_info(source, "name") + if (extension == "jar") { + outputs += [ + "${base_name}.jar", + "${base_name}-sources.jar", + ] + args += [ + "-i", + "${name}.jar", + rebase_path("${base_name}.jar"), + "-i", + "${name}-sources.jar", + rebase_path("${base_name}-sources.jar"), + ] + } else { + outputs += [ "${base_name}.${extension}" ] + args += [ + "-i", + rebase_path(source), + rebase_path("${base_name}.${extension}"), + ] + } + } +} From b41b85f90b494103beec322eacba56dd8d5f0580 Mon Sep 17 00:00:00 2001 From: Godofredo Contreras Date: Wed, 4 May 2022 16:33:10 -0700 Subject: [PATCH 2/2] Address code-review comments. --- build/android_artifacts.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/build/android_artifacts.py b/build/android_artifacts.py index 379ca639e3565..3f5de89b5a357 100644 --- a/build/android_artifacts.py +++ b/build/android_artifacts.py @@ -6,12 +6,10 @@ """Copies and renames android artifacts.""" - - -import sys -import shutil -import os import argparse +import os +import shutil +import sys def cp_files(args): @@ -29,8 +27,8 @@ def main(): parser.add_argument('-i', dest='input_pairs', nargs=2, action='append', help='The input file and its destination.') cp_files(parser.parse_args()) - return 0 + if __name__ == '__main__': sys.exit(main())