Skip to content

Commit

Permalink
Android targets create final zip artifacts (flutter#13059)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored Oct 10, 2019
1 parent d908002 commit a05803a
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 135 deletions.
37 changes: 37 additions & 0 deletions build/zip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
# 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.

import argparse
import zipfile
import os
import sys


def _zip_dir(path, zip_file, prefix):
path = path.rstrip('/\\')
for root, dirs, files in os.walk(path):
for file in files:
zip_file.write(os.path.join(root, file), os.path.join(
root.replace(path, prefix), file))


def main(args):
zip_file = zipfile.ZipFile(args.output, 'w', zipfile.ZIP_DEFLATED)
for path, archive_name in args.input_pairs:
if os.path.isdir(path):
_zip_dir(path, zip_file, archive_name)
else:
zip_file.write(path, archive_name)
zip_file.close()


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='This script creates zip files.')
parser.add_argument('-o', dest='output', action='store',
help='The name of the output zip file.')
parser.add_argument('-i', dest='input_pairs', nargs=2, action='append',
help='The input file and its destination location in the zip archive.')
sys.exit(main(parser.parse_args()))
54 changes: 54 additions & 0 deletions build/zip_bundle.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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.

import("//flutter/common/config.gni")

if (flutter_runtime_mode == "jit_release") {
android_zip_archive_dir = "android-$target_cpu-jit-release"
} else {
android_zip_archive_dir = "android-$target_cpu"
}

# Creates a zip file in the $root_build_dir/zip_archives folder.
#
# The output variable specifies the name of the zip file to create.
# The files variable is an array of scopes that specify a source file or
# directory and a destination path in the archive to create.
#
# For example, to create a zip file named archive.zip with all files in the
# root directory of the archive:
#
# zip_bundle("sample") {
# output = "archive.zip"
# files = [
# {
# source = "$root_build_dir/some/path/to/lib.so"
# destination = "lib.so"
# },
# {
# source = "$root_build_dir/some/other/path/with/files"
# destination = "other_files"
# },
# ]
# }
template("zip_bundle") {
assert(defined(invoker.output), "output must be defined")
assert(defined(invoker.files), "files must be defined as a list of scopes")
action(target_name) {
script = "//flutter/build/zip.py"
outputs = [ "$root_build_dir/zip_archives/${invoker.output}" ]
inputs = []
deps = invoker.deps

args = [ "-o", rebase_path(outputs[0]) ]
foreach(input, invoker.files) {
args += [
"-i",
rebase_path(input.source),
rebase_path(input.destination),
]
inputs += [ input.source ]
}
}
}
Loading

0 comments on commit a05803a

Please sign in to comment.