Remove unused python_binary build artifacts (flutter/engine#28111)

This commit is contained in:
Rich Kadel 2021-08-16 14:52:02 -05:00 committed by GitHub
parent 4f335b7991
commit f88ab69db4
4 changed files with 1 additions and 277 deletions

View File

@ -3,14 +3,9 @@
# found in the LICENSE file.
import("//flutter/tools/fuchsia/dart/toolchain.gni")
import("//flutter/tools/fuchsia/python/python_binary.gni")
import("//flutter/tools/fuchsia/sdk/sdk_targets.gni")
import("//flutter/tools/fuchsia/toolchain/basic_toolchain.gni")
python_binary("gen_dart_package_config") {
main_source = "gen_dart_package_config.py"
}
if (current_toolchain == default_toolchain) {
# A toolchain dedicated to processing and analyzing Dart packages.
# The only targets in this toolchain are action() targets, so it

View File

@ -97,10 +97,7 @@ template("dart_package_config") {
if (!defined(deps)) {
deps = []
}
deps += [
":$generate_target",
"//flutter/tools/fuchsia/dart:gen_dart_package_config",
]
deps += [ ":$generate_target" ]
metadata = {
# Add a barrier here to avoid double of inclusion of elements listed in

View File

@ -1,145 +0,0 @@
#!/usr/bin/env python3.8
"""Creats a Python zip archive for the input main source."""
# 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 json
import os
import shutil
import sys
import zipapp
def main():
parser = argparse.ArgumentParser(
'Creates a Python zip archive for the input main source')
parser.add_argument(
'--target_name',
help='Name of the build target',
required=True,
)
parser.add_argument(
'--main_source',
help='Path to the source containing the main function',
required=True,
)
parser.add_argument(
'--main_callable',
help=
'Name of the the main callable, that is the entry point of the generated archive',
required=True,
)
parser.add_argument(
'--gen_dir',
help='Path to gen directory, used to stage temporary directories',
required=True,
)
parser.add_argument('--output', help='Path to output', required=True)
parser.add_argument(
'--sources',
help='Sources of this target, including main source',
nargs='*',
)
parser.add_argument(
'--library_infos',
help='Path to the library infos JSON file',
type=argparse.FileType('r'),
required=True,
)
parser.add_argument(
'--depfile',
help='Path to the depfile to generate',
type=argparse.FileType('w'),
required=True,
)
args = parser.parse_args()
infos = json.load(args.library_infos)
# Temporary directory to stage the source tree for this python binary,
# including sources of itself and all the libraries it imports.
#
# It is possible to have multiple python_binaries in the same directory, so
# using target name, which should be unique in the same directory, to
# distinguish between them.
app_dir = os.path.join(args.gen_dir, args.target_name)
os.makedirs(app_dir, exist_ok=True)
# Copy over the sources of this binary.
for source in args.sources:
basename = os.path.basename(source)
if basename == '__main__.py':
print(
'__main__.py in sources of python_binary is not supported, see https://fxbug.dev/73576',
file=sys.stderr,
)
return 1
dest = os.path.join(app_dir, basename)
shutil.copy2(source, dest)
# For writing a depfile.
files_to_copy = []
# Make sub directories for all libraries and copy over their sources.
for info in infos:
dest_lib_root = os.path.join(app_dir, info['library_name'])
os.makedirs(dest_lib_root, exist_ok=True)
src_lib_root = info['source_root']
# Sources are relative to library root.
for source in info['sources']:
src = os.path.join(src_lib_root, source)
dest = os.path.join(dest_lib_root, source)
# Make sub directories if necessary.
os.makedirs(os.path.dirname(dest), exist_ok=True)
files_to_copy.append(src)
shutil.copy2(src, dest)
args.depfile.write('{}: {}\n'.format(args.output, ' '.join(files_to_copy)))
# Main module is the main source without its extension.
main_module = os.path.splitext(os.path.basename(args.main_source))[0]
# Manually create a __main__.py file for the archive, instead of using the
# `main` parameter from `create_archive`. This way we can import everything
# from the main module (create_archive only `import pkg`), which is
# necessary for including all test cases for unit tests.
#
# TODO(https://fxbug.dev/73576): figure out another way to support unit
# tests when users need to provide their own custom __main__.py.
main_file = os.path.join(app_dir, "__main__.py")
with open(main_file, 'w') as f:
f.write(
f'''
import sys
from {main_module} import *
sys.exit({args.main_callable}())
''')
zipapp.create_archive(
app_dir,
target=args.output,
interpreter='/usr/bin/env python3.8',
compressed=True,
)
# Manually remove the temporary app directory and all the files, instead of
# using shutil.rmtree. rmtree records reads on directories which throws off
# the action tracer.
for root, dirs, files in os.walk(app_dir, topdown=False):
for file in files:
os.remove(os.path.join(root, file))
for dir in dirs:
os.rmdir(os.path.join(root, dir))
os.rmdir(app_dir)
if __name__ == '__main__':
sys.exit(main())

View File

@ -1,123 +0,0 @@
# 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/tools/python/python3_action.gni")
# Defines a Python binary.
#
# Example
#
# ```
# python_binary("main") {
# main_source = "main.py"
# main_callable = "main"
# sources = [
# "foo.py",
# "bar.py",
# ]
# output_name = "main.pyz"
# deps = [ "//path/to/lib" ]
# }
# ```
#
# Parameters
#
# main_source (required)
# Source file including the entry callable for this binary.
# This file will typically contain
# ```
# if __name__ == "__main__":
# main()
# ```
# Type: path
#
# main_callable (optional)
# Main callable, which serves as the entry point of the output zip archive.
# In the example above, this is "main".
# Type: string
# Default: main
#
# output_name (optional)
# Name of the output Python zip archive, must have .pyz as extension.
# Type: string
# Default: ${target_name}.pyz
#
# sources
# deps
# visibility
# testonly
template("python_binary") {
assert(defined(invoker.main_source), "main_source is required")
_library_infos_target = "${target_name}_library_infos"
_library_infos_json = "${target_gen_dir}/${target_name}_library_infos.json"
generated_file(_library_infos_target) {
forward_variables_from(invoker,
[
"testonly",
"deps",
])
visibility = [ ":*" ]
outputs = [ _library_infos_json ]
output_conversion = "json"
data_keys = [ "library_info" ]
walk_keys = [ "library_info_barrier" ]
}
# action(target_name) {
python3_action(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
sources = [ invoker.main_source ]
if (defined(invoker.sources)) {
sources += invoker.sources
}
inputs = [ _library_infos_json ]
deps = [ ":${_library_infos_target}" ]
# Output must be a .pyz, so our build knows to use a vendored Python
# interpreter to run them.
#
# Output a single .pyz file makes the output deterministic, otherwise we'd
# have to list out all the library sources that will be copied to output
# directory, which is not possible because they are not known until the
# generated JSON file is parsed at build time.
_output = "${target_out_dir}/${target_name}.pyz"
if (defined(invoker.output_name)) {
assert(get_path_info(invoker.output_name, "extension") == "pyz",
"output_name must have .pyz as extension")
_output = "${target_out_dir}/${invoker.output_name}"
}
outputs = [ _output ]
_main_callable = "main"
if (defined(invoker.main_callable)) {
_main_callable = invoker.main_callable
}
script = "//flutter/tools/fuchsia/python/package_python_binary.py"
depfile = "${target_out_dir}/${target_name}.d"
args = [ "--sources" ] + rebase_path(sources, root_build_dir) + [
"--target_name",
target_name,
"--main_source",
rebase_path(invoker.main_source, root_build_dir),
"--main_callable",
_main_callable,
"--library_infos",
rebase_path(_library_infos_json, root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
"--gen_dir",
rebase_path(target_gen_dir, root_build_dir),
"--output",
rebase_path(_output, root_build_dir),
]
}
}