Fix building Dart Fuchsia components and packages (flutter/engine#28413)

This commit is contained in:
Rich Kadel
2021-09-09 16:47:02 -05:00
committed by GitHub
parent 8fefd6c656
commit dd51e241e5
39 changed files with 1250 additions and 453 deletions

3
DEPS
View File

@@ -393,6 +393,9 @@ deps = {
'src/third_party/fontconfig/src':
Var('chromium_git') + '/external/fontconfig.git' + '@' + 'c336b8471877371f0190ba06f7547c54e2b890ba',
'src/third_party/pyyaml':
Var('fuchsia_git') + '/third_party/pyyaml.git' + '@' + '25e97546488eee166b1abb229a27856cecd8b7ac',
# Headers for Vulkan 1.1
'src/third_party/vulkan':
Var('github_git') + '/KhronosGroup/Vulkan-Docs.git' + '@' + 'v1.1.91',

View File

@@ -1,2 +1,2 @@
Signature: 556bb3a9c92c7ac1fb27943070183aae
Signature: 0836a8bd0db33f4a7dc3d5cd71458955

View File

@@ -35,3 +35,8 @@ source_set("zircon") {
"//flutter/third_party/tonic",
]
}
source_set("test") {
testonly = true
deps = [ "test" ]
}

View File

@@ -0,0 +1,60 @@
# 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("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/dart/dart_library.gni")
import("//flutter/tools/fuchsia/flutter/flutter_component.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
dart_library("dart_library") {
testonly = true
package_name = "channel_test"
language_version = "2.12"
source_dir = "."
sources = [
"channel_test.dart",
"eventpair_test.dart",
"handle_disposition_test.dart",
"handle_test.dart",
"socket_test.dart",
"vmo_test.dart",
]
deps = [
"//flutter/shell/platform/fuchsia/dart:litetest",
"//flutter/tools/fuchsia/dart:zircon",
]
}
flutter_component("channel_test_flutter_component") {
testonly = true
main_package = "channel_test"
component_name = "channel_test"
main_dart = "channel_test.dart"
manifest = rebase_path("meta/channel_test.cmx")
deps = [ ":dart_library" ]
}
# TODO(richkadel): The target name is set differently compared to fuchsia.git's flutter_app().
# Unlike in fuchsia.git's version of fuchsia_component, the Fuchsia GN SDK
# version passes the component name to fuchsia_component via it's target_name only.
# GN SDK's fuchsia_component doesn't have a `component_name` argument! So I'm forced to set
# the component name via "target_name". This is a problem in fuchsia_package, which uses
# the target_name to name the fuchsia_pm_tool target, creating duplicate target IDs!
# So I have to change the fuchsia_package name to something that is NOT the component name,
# and then set the package_name (which fuchsia_package does support).
fuchsia_package("channel_test_package") {
testonly = true
package_name = "channel_test"
deps = [ ":channel_test_flutter_component" ]
}
group("test") {
testonly = true
deps = [ ":channel_test_package" ]
}

View File

@@ -6,7 +6,8 @@ import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:litetest/litetest.dart';
import 'package:zircon/zircon.dart';
/// Helper method to turn a [String] into a [ByteData] containing the

View File

@@ -0,0 +1,10 @@
{
"program": {
"data": "data/channel_test"
},
"sandbox": {
"services": [
"fuchsia.sys.Environment"
]
}
}

View File

@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//flutter/tools/fuchsia/dart/dart_library.gni")
import("//third_party/dart/build/dart/dart_action.gni")
import("//third_party/dart/utils/application_snapshot.gni")
import("//third_party/dart/utils/compile_platform.gni")
@@ -48,3 +49,68 @@ application_snapshot("list_libraries") {
"/flutter/shell/platform/fuchsia/dart/list_libraries.dart.dill"),
]
}
dart_library("async_helper") {
package_root = "//third_party/dart/pkg/async_helper"
package_name = "async_helper"
language_version = "2.12"
deps = []
sources = [
"async_helper.dart",
"async_minitest.dart",
]
}
dart_library("expect") {
package_root = "//third_party/dart/pkg/expect"
package_name = "expect"
language_version = "2.12"
deps = [ ":meta" ]
sources = [
"expect.dart",
"minitest.dart",
]
}
dart_library("litetest") {
package_root = "//flutter/testing/litetest"
package_name = "litetest"
language_version = "2.12"
source_dir = "lib"
deps = [
":async_helper",
":expect",
":meta",
]
sources = [
"litetest.dart",
"src/matchers.dart",
"src/test.dart",
"src/test_suite.dart",
]
}
dart_library("meta") {
package_root = "//third_party/dart/pkg/meta"
package_name = "meta"
language_version = "2.12"
deps = []
sources = [
"dart2js.dart",
"meta.dart",
"meta_meta.dart",
]
}

View File

@@ -10,7 +10,7 @@ import 'package:expect/expect.dart'; // ignore: unused_import
import 'src/matchers.dart'; // ignore: unused_import
import 'src/test_suite.dart';
export 'package:async_helper/async_minitest.dart' hide group, test;
export 'package:async_helper/async_minitest.dart' hide test;
export 'package:expect/expect.dart';
export 'src/matchers.dart';

View File

@@ -13,39 +13,42 @@ dart_debug_build_cfg = {
enable_asserts = true
}
# Builds the component in a non-product AOT build. This will
# launch the vm service in the runner.
# This configuration is not compatible with a --release build since the
# profile aot runner is built without asserts.
dart_aot_debug_build_cfg = {
runtime_meta = "//flutter/shell/platform/fuchsia/dart_runner/meta/aot_runtime"
runner_dep = "//flutter/shell/platform/fuchsia/dart_runner:dart_aot_runner"
platform_name = "dart_runner"
is_aot = true
is_product = false
enable_asserts = true
}
# TODO(richkadel): Don't confuse these settings with those in dart_build_config.gni,
# in fact, do I really need both? Can I drop flutter_build_config.gni?
# Builds the component in a non-product AOT build. This will
# launch the vm service in the runner.
dart_profile_build_cfg = {
runtime_meta = "//flutter/shell/platform/fuchsia/dart_runner/meta/aot_runtime"
runner_dep = "//flutter/shell/platform/fuchsia/dart_runner:dart_aot_runner"
platform_name = "dart_runner"
is_aot = true
is_product = false
enable_asserts = false
}
# # Builds the component in a non-product AOT build. This will
# # launch the vm service in the runner.
# # This configuration is not compatible with a --release build since the
# # profile aot runner is built without asserts.
# dart_aot_debug_build_cfg = {
# runtime_meta = "//flutter/shell/platform/fuchsia/dart_runner/meta/aot_runtime"
# runner_dep = "//flutter/shell/platform/fuchsia/dart_runner:dart_aot_runner"
# platform_name = "dart_runner"
# is_aot = true
# is_product = false
# enable_asserts = true
# }
# Builds the component in a product AOT build. This will
# not launch the vm service in the runner.
dart_release_build_cfg = {
runtime_meta =
"//flutter/shell/platform/fuchsia/dart_runner/meta/aot_product_runtime"
runner_dep =
"//flutter/shell/platform/fuchsia/dart_runner:dart_aot_product_runner"
platform_name = "dart_runner"
is_aot = true
is_product = true
enable_asserts = false
}
# # Builds the component in a non-product AOT build. This will
# # launch the vm service in the runner.
# dart_profile_build_cfg = {
# runtime_meta = "//flutter/shell/platform/fuchsia/dart_runner/meta/aot_runtime"
# runner_dep = "//flutter/shell/platform/fuchsia/dart_runner:dart_aot_runner"
# platform_name = "dart_runner"
# is_aot = true
# is_product = false
# enable_asserts = false
# }
# # Builds the component in a product AOT build. This will
# # not launch the vm service in the runner.
# dart_release_build_cfg = {
# runtime_meta =
# "//flutter/shell/platform/fuchsia/dart_runner/meta/aot_product_runtime"
# runner_dep =
# "//flutter/shell/platform/fuchsia/dart_runner:dart_aot_product_runner"
# platform_name = "dart_runner"
# is_aot = true
# is_product = true
# enable_asserts = false
# }

View File

@@ -5,7 +5,6 @@
import("//flutter/tools/fuchsia/dart/dart.gni")
import("//flutter/tools/fuchsia/dart/dart_package_config.gni")
import("//flutter/tools/fuchsia/dart/toolchain.gni")
import("//flutter/tools/python/python3_action.gni")
# Defines a Dart library
#
@@ -248,7 +247,7 @@ if (current_toolchain == dart_toolchain) {
# Also warn if nonexistent files are included in sources.
if (!disable_source_verification) {
source_verification_target_name = "${target_name}_source_verification"
python3_action(source_verification_target_name) {
action(source_verification_target_name) {
script = "//flutter/tools/fuchsia/dart/verify_sources.py"
output_file = "$target_gen_dir/$target_name.missing"
@@ -293,7 +292,7 @@ if (current_toolchain == dart_toolchain) {
# analyzer, which recursively reads all sources.
_all_deps_sources_target = "${target_name}.all_deps_sources"
_all_deps_sources_file = "${target_gen_dir}/${target_name}.all_deps_sources"
python3_action(_all_deps_sources_target) {
action(_all_deps_sources_target) {
forward_variables_from(invoker, [ "testonly" ])
script = "//flutter/tools/fuchsia/dart/merge_deps_sources.py"

View File

@@ -77,9 +77,7 @@ template("dart_package_config") {
"visibility",
])
script =
get_label_info("//flutter/tools/fuchsia/dart:gen_dart_package_config",
"target_out_dir") + "/gen_dart_package_config.pyz"
script = "//flutter/tools/fuchsia/dart/gen_dart_package_config.py"
inputs = [ intermediate_file ]
outputs = [ package_config_file ]

View File

@@ -6,8 +6,6 @@ import("//flutter/tools/fuchsia/dart/dart_library.gni")
import("//flutter/tools/fuchsia/dart/dart_package_config.gni")
import("//flutter/tools/fuchsia/dart/toolchain.gni")
import("//flutter/tools/python/python3_action.gni")
# Wraps a dart snapshot in a script to be invoked by dart
#
# Parameters
@@ -35,7 +33,7 @@ template("_dart_snapshot_invocation") {
}
# Builds a convenience script to invoke the app.
python3_action(target_name) {
action(target_name) {
forward_variables_from(invoker,
[
"testonly",

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3.8
#!/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.

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3.8
#!/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.
@@ -12,6 +12,10 @@ import json
import os
import re
import sys
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path += [os.path.join(
THIS_DIR, '..', '..', '..', '..', 'third_party', 'pyyaml', 'lib3')]
import yaml
DEFAULT_LANGUAGE_VERSION = '2.8'

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3.8
#!/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.
@@ -12,23 +12,25 @@ import json
import os
import sys
Entry = collections.namedtuple('Entry', ['source', 'destination'])
Entry = collections.namedtuple('Entry', ['source', 'dest'])
def collect(lines):
def collect(path_prefix, lines):
'''Reads the kernel manifest and creates an array of Entry objects.
- lines: a list of lines from the manifest
'''
entries = []
for line in lines:
values = line.split("=", 1)
entries.append(Entry(source=values[1], destination=values[0]))
entries.append(Entry(source=path_prefix + values[1], dest=values[0]))
return entries
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
'--path_prefix', help='Directory path containing the manifest entry sources', required=True)
parser.add_argument(
'--input', help='Path to original manifest', required=True)
parser.add_argument(
@@ -38,7 +40,7 @@ def main():
with open(args.input, 'r') as input_file:
contents = input_file.read().splitlines()
entries = collect(contents)
entries = collect(args.path_prefix, contents)
if entries is None:
return 1

View File

@@ -26,8 +26,6 @@ import("//flutter/tools/fuchsia/dart/config.gni")
import("//flutter/tools/fuchsia/dart/dart_library.gni")
import("//flutter/tools/fuchsia/dart/toolchain.gni")
import("//flutter/tools/python/python3_action.gni")
_gen_kernel_label =
"//flutter/tools/fuchsia/dart/kernel:gen_kernel($host_toolchain)"
_gen_kernel_path =
@@ -46,7 +44,7 @@ flutter_platform_name = "flutter_runner"
template("_convert_kernel_manifest") {
assert(defined(invoker.manifest), "dart_kernel() requires a manifest")
python3_action(target_name) {
action(target_name) {
forward_variables_from(invoker,
[
"deps",
@@ -58,6 +56,8 @@ template("_convert_kernel_manifest") {
script = "//flutter/tools/fuchsia/dart/kernel/convert_manifest_to_json.py"
args = [
"--path_prefix",
rebase_path(root_out_dir) + "/",
"--input",
rebase_path(invoker.manifest, root_build_dir),
"--output",
@@ -157,12 +157,16 @@ template("dart_kernel") {
_kernel_deps += invoker.deps
}
# TODO(richkadel): The manifest is currently used by flutter_dart_component, to populate the file
# it calls `_convert_kernel_manifest_file`, so I can't make this conditional, right? Or is it
# possible to build Dart AOT Fuchsia packages/components without the data in this file (in which
# case I should make it conditional there as well)?
_generate_manifest = false
if (invoker.is_aot) {
not_needed(invoker, [ "generate_manifest" ])
} else {
if (defined(invoker.generate_manifest) && invoker.generate_manifest) {
_generate_manifest = true
if (defined(invoker.generate_manifest)) {
_generate_manifest = invoker.generate_manifest
}
}
@@ -185,7 +189,7 @@ template("dart_kernel") {
_group_deps += [ ":$_convert_target_name" ]
}
python3_action(_kernel_target_name) {
action(_kernel_target_name) {
forward_variables_from(invoker,
[
"testonly",
@@ -271,6 +275,14 @@ template("dart_kernel") {
rebase_path(_kernel_path, root_build_dir),
]
# TODO(richkadel): It should be possible to remove all of the build rules
# related to `generate_manifest`. Without the following two flags, the
# `gen_kernel` step will produce one large `.dil` file, instead of multiple
# `.dilp` files with a `.dilplist`. But the Fuchsia flutter runner
# _currently_ only looks for a `.dilplist`. If the runner is changed to
# support loading a single `.dil` for the Dart Fuchsia component code, then
# consider removing all code supporting `generate_manifest` (and remove
# `convert_manifest_to_json.py`).
if (_generate_manifest) {
args += [
"--split-output-by-packages",
@@ -279,11 +291,17 @@ template("dart_kernel") {
]
}
if (is_debug) {
args += [ "--embed-sources" ]
} else {
args += [ "--no-embed-sources" ]
}
# TODO(richkadel): NEED TO VALIDATE AND/OR CLEAN UP `is_debug` and `is_aot`.
# `is_debug` is set by the flutter `gn` script to true if --unoptimized,
# but `--unoptimized` is broken for Fuchsia, according to an open bug in
# github flutter/flutter issues. But I have a feeling `is_debug` from
# Fuchsia scripts may have a different meaning for dart/flutter at least.
# if (is_debug) {
args += [ "--embed-sources" ]
# } else {
# args += [ "--no-embed-sources" ]
# }
if (invoker.is_aot) {
args += [
@@ -302,10 +320,12 @@ template("dart_kernel") {
# This define excludes debugging and profiling code from Flutter.
args += [ "-Ddart.vm.product=true" ]
} else {
if (!is_debug) {
# The following define excludes debugging code from Flutter.
args += [ "-Ddart.vm.profile=true" ]
}
# TODO(richkadel): I'm pretty sure we want to assume is_debug even if that's
# not what's set by gn flags (--unoptimized = false because true is currentlyh broken for Fuchsia?)
# if (!is_debug) {
# # The following define excludes debugging code from Flutter.
# args += [ "-Ddart.vm.profile=true" ]
# }
}
if (defined(invoker.main_dart)) {
@@ -324,6 +344,6 @@ template("dart_kernel") {
"testonly",
"visibility",
])
deps = _group_deps
public_deps = _group_deps
}
}

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3.8
#!/usr/bin/env python3
"""Merges sources of a Dart target and its dependencies"""
# Copyright 2013 The Flutter Authors. All rights reserved.

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3.8
#!/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

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3.8
#!/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.

View File

@@ -94,237 +94,3 @@ template("resource") {
}
}
}
# Declare data files to be accessible at runtime on the target device.
#
# Similar to resource() but with a different interface that allows grouping
# multiple files into a single target when their packaged paths don't follow
# a common pattern.
#
# Parameters
#
# data_deps
# Optional: Additional dependencies for the runtime image. These are
# included in the image if this target is, but are not related to the
# $sources list.
# Type: list(label)
#
# deps
# Optional: Targets that produce $sources. Any files listed in
# $sources that are produced by the build should be produced by a
# target listed here. This is the only thing that guarantees those
# files will have been built by the time the image is being packed.
# Targets reached only via this $deps list will *not* contribute their
# own contents to the image directly. For that, list them in $data_deps.
# Targets listed here are used only to produce the $sources files.
# Type: list(label)
#
# files
# Required: List of scopes containing `source` and `dest` paths.
# `source` paths are local file paths.
# `dest` paths are packaged paths.
# For instance:
# files = [
# {
# source = "//path/to/file.txt"
# dest = "data/first.txt"
# },
# {
# source = "//path/to/other_file.txt",
# dest = "data/second.txt"
# },
# ]
# Type: list(scope)
#
# testonly, visibility
template("resource_group") {
if (invoker.files != []) {
_label = get_label_info(":$target_name", "label_with_toolchain")
}
group(target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
"visibility",
])
metadata = {
# Used by the distribution_manifest() template.
distribution_entries_barrier = []
distribution_entries = []
# Used by the zbi() template.
zbi_input_barrier = []
if (defined(invoker.metadata)) {
forward_variables_from(invoker.metadata, "*")
}
# Stop *_manifest() and zbi_test() from picking up files or
# zbi_input() items from the deps, but let them reach the data_deps.
if (defined(data_deps)) {
distribution_entries_barrier += data_deps
zbi_input_barrier += data_deps
}
foreach(file, invoker.files) {
distribution_entries += [
{
source = rebase_path(file.source, root_build_dir)
destination = file.dest
label = _label
},
]
}
}
}
}
# resource_tree() is similar to resource() but makes it easy to replicate
# a tree of sources files, relative to a given sources path prefix, to a
# given destination directory.
#
# For example:
#
# //some/dir/BUILD.gn:
# resource_trees("my-resources") {
# sources_root = "res"
# sources = [
# foo.resource",
# bar/bar-1.resource",
# ]
# dest_dir = "data/resources"
# }
#
# Will declare the following installation requirements:
#
# //some/dir/res/foo.resource --> data/resources/foo.resource
# //some/dir/res/bar/bar.resource --> data/resources/bar/bar.resource
#
# This is difficult to do with resource() because GN source expansion
# cannot preserve the original sources input paths.
#
# This template is useful to avoid calling resource() multiple times
# in a loop when dealing with resource files laid out into different
# sub-directories. Note that the files cannot be renamed though!
#
# Parameters
#
# source_root
# Optional: A path prefix that is prepended to all items in the 'sources'
# list. If not specified, the current target's directory is used.
# Type: string(path)
#
# sources
# Required: List of files in the source tree or build that will be
# installed. Each 'file' item in this list is installed to
# '$dest_dir/$file', and its content taken from '$sources_root/$file'.
# Note that unlike resource(), there is no way to transform or expand
# source paths.
# Type: list(file)
#
# dest_dir
# Required: Destination path where all sources are installed.
# Cannot start with a "/". Use an empty string to install files directory
# to the package's top-level directory.
# Type: string(path)
#
# data_deps
# Optional: Additional dependencies for the runtime image. These are
# included in the image if this target is, but are not related to the
# $sources list.
# Type: list(label)
#
# deps
# Optional: Targets that produce $sources. Any files listed in
# $sources that are produced by the build should be produced by a
# target listed here. This is the only thing that guarantees those
# files will have been built by the time the image is being packed.
# Targets reached only via this $deps list will *not* contribute their
# own contents to the image directly. For that, list them in $data_deps.
# Targets listed here are used only to produce the $sources files.
# Type: list(label)
#
template("resource_tree") {
assert(defined(invoker.sources), "sources is required!")
assert(defined(invoker.dest_dir), "dest_dir is required!")
dest_dir = invoker.dest_dir
if (dest_dir != "") {
# Sanitize dest_dir and append a directory separator.
assert(rebase_path(dest_dir, "foo") != dest_dir,
"dest_dir cannot start with /: $dest_dir")
assert(dest_dir != "." && dest_dir != ".." &&
string_replace(dest_dir, "./", "") == dest_dir,
"dest_dir cannot contain . or .. path elements!: $dest_dir")
dest_dir = string_replace(dest_dir + "/", "//", "/")
}
if (defined(invoker.sources_root)) {
assert(invoker.sources_root != "", "sources_root cannot be empty!")
sources_prefix = invoker.sources_root
# Append trailing separator if needed
if (string_replace(sources_prefix + "###", "/###", "") ==
sources_prefix + "###") {
sources_prefix += "/"
}
} else {
sources_prefix = ""
}
target_label = get_label_info(":$target_name", "label_with_toolchain")
if (invoker.sources == []) {
# Support resource_tree() targets with empty sources list.
not_needed(invoker,
[
"dest_dir",
"sources_root",
])
not_needed([
"sources_prefix",
"dest_dir",
"target_label",
])
}
group(target_name) {
forward_variables_from(invoker,
"*",
[
"dest_dir",
"metadata",
"sources",
"sources_root",
])
metadata = {
# Used by the distribution_manifest() template.
distribution_entries_barrier = []
distribution_entries = []
# Used by the zbi() template.
zbi_input_barrier = []
if (defined(invoker.metadata)) {
forward_variables_from(invoker.metadata, "*")
}
# Stop *_manifest() and zbi_test() from picking up files or
# zbi_input() items from the deps, but let them reach the data_deps.
if (defined(data_deps)) {
distribution_entries_barrier += data_deps
zbi_input_barrier += data_deps
}
foreach(_source, invoker.sources) {
distribution_entries += [
{
source = rebase_path(sources_prefix + _source, root_build_dir)
destination = dest_dir + _source
label = target_label
},
]
}
}
}
}

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3.8
#!/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.

View File

@@ -11,14 +11,21 @@ declare_args() {
}
declare_args() {
if (flutter_force_product) {
# Product AOT
flutter_default_build_cfg = flutter_release_build_cfg
} else if (is_debug) {
# Non-product JIT
flutter_default_build_cfg = flutter_debug_build_cfg
} else {
# Non-product AOT
flutter_default_build_cfg = flutter_profile_build_cfg
}
# TODO(richkadel): Make sure we're using 'debug' (non-aot) consistently,
# across dart and flutter rules.
# Since we're not REALLY building flutter apps, can I just git rid of this
# setting, and the configs in flutter/tools/fuchsia/flutter/flutter_build_config.gni?
# I think it's confusing to have both that one and .../dart/dart_build_config.gni.
# if (flutter_force_product) {
# # Product AOT
# flutter_default_build_cfg = flutter_release_build_cfg
# } else if (is_debug) {
# Non-product JIT
flutter_default_build_cfg = flutter_debug_build_cfg
# } else {
# # Non-product AOT
# flutter_default_build_cfg = flutter_profile_build_cfg
# }
}

View File

@@ -17,40 +17,43 @@ flutter_debug_build_cfg = {
enable_asserts = true
}
# Builds the component in a non-product AOT build. This will
# launch the vm service in the runner.
# This configuration is not compatible with a --release build since the
# profile aot runner is built without asserts.
flutter_aot_debug_build_cfg = {
runtime_meta = "//flutter/shell/platform/fuchsia/flutter/meta/aot_runtime"
runner_dep = "//flutter/shell/platform/fuchsia/flutter:aot"
platform_name = "flutter_runner"
is_aot = true
is_product = false
enable_asserts = true
}
# TODO(richkadel): Don't confuse these settings with those in dart_build_config.gni,
# in fact, do I really need both? Can we just use the settings in dart_build_config.gni?
# Builds the component in a non-product AOT build. This will
# launch the vm service in the runner.
flutter_profile_build_cfg = {
runtime_meta =
"//flutter/shell/platform/fuchsia/flutter/meta/aot_runtime" # profile
# runner
runner_dep = "//flutter/shell/platform/fuchsia/flutter:aot"
platform_name = "flutter_runner"
is_aot = true
is_product = false
enable_asserts = false
}
# # Builds the component in a non-product AOT build. This will
# # launch the vm service in the runner.
# # This configuration is not compatible with a --release build since the
# # profile aot runner is built without asserts.
# flutter_aot_debug_build_cfg = {
# runtime_meta = "//flutter/shell/platform/fuchsia/flutter/meta/aot_runtime"
# runner_dep = "//flutter/shell/platform/fuchsia/flutter:aot"
# platform_name = "flutter_runner"
# is_aot = true
# is_product = false
# enable_asserts = true
# }
# Builds the component in a product AOT build. This will
# not launch the vm service in the runner.
flutter_release_build_cfg = {
runtime_meta =
"//flutter/shell/platform/fuchsia/flutter/meta/aot_product_runtime"
runner_dep = "//flutter/shell/platform/fuchsia/flutter:aot_product"
platform_name = "flutter_runner"
is_aot = true
is_product = true
enable_asserts = false
}
# # Builds the component in a non-product AOT build. This will
# # launch the vm service in the runner.
# flutter_profile_build_cfg = {
# runtime_meta =
# "//flutter/shell/platform/fuchsia/flutter/meta/aot_runtime" # profile
# # runner
# runner_dep = "//flutter/shell/platform/fuchsia/flutter:aot"
# platform_name = "flutter_runner"
# is_aot = true
# is_product = false
# enable_asserts = false
# }
# # Builds the component in a product AOT build. This will
# # not launch the vm service in the runner.
# flutter_release_build_cfg = {
# runtime_meta =
# "//flutter/shell/platform/fuchsia/flutter/meta/aot_product_runtime"
# runner_dep = "//flutter/shell/platform/fuchsia/flutter:aot_product"
# platform_name = "flutter_runner"
# is_aot = true
# is_product = true
# enable_asserts = false
# }

View File

@@ -100,12 +100,16 @@ template("flutter_component") {
_build_cfg = flutter_default_build_cfg
}
if (defined(invoker.component_name)) {
_component_name = invoker.component_name
} else {
_component_name = target_name
}
if (defined(invoker.main_package)) {
_main_package = invoker.main_package
} else if (defined(invoker.component_name)) {
_main_package = string_replace(invoker.component_name, "-", "_")
} else {
_main_package = string_replace(target_name, "-", "_")
_main_package = string_replace(_component_name, "-", "_")
}
if (defined(invoker.main_dart)) {
@@ -126,11 +130,13 @@ template("flutter_component") {
"deps",
"main_dart",
"main_package",
"component_name",
])
deps = _component_deps
main_dart = _main_dart
main_package = _main_package
component_name = _component_name
build_cfg = _build_cfg
}

View File

@@ -8,8 +8,8 @@ import("//flutter/tools/fuchsia/dart/dart.gni")
import("//flutter/tools/fuchsia/dart/dart_package_config.gni")
import("//flutter/tools/fuchsia/dart/kernel/dart_kernel.gni")
import("//flutter/tools/fuchsia/dist/resource.gni")
import("//flutter/tools/fuchsia/sdk/cmc.gni")
import("//flutter/tools/fuchsia/sdk/component.gni")
import("//flutter/tools/fuchsia/gn-sdk/cmc.gni")
import("//flutter/tools/fuchsia/gn-sdk/component.gni")
# Defines a component which will run in a flutter_runner or dart_runner
#
@@ -71,28 +71,42 @@ template("flutter_dart_component") {
_component_name = target_name
}
# merge the runner cmx into this one which allows us to switch runners based
# on compilation modes
_merged_target_name = "${target_name}_merged.cmx"
# Flutter and Dart components need to run inside the runner which matches how
# they were compiled, for example, a JIT component must run in the JIT runner.
# We need to be able to dynamically convert the manifest files to include the
# runner requirements so that we can switch based on build modes.
_manifest_extension = get_path_info(invoker.manifest, "extension")
if (_manifest_extension == "cmx") {
# This is a v1 component, merge with the runtime_meta
_merged_target_name = "${target_name}_merged.cmx"
cmc_merge(_merged_target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
sources = [
invoker.manifest,
rebase_path(build_cfg.runtime_meta, "."),
]
cmc_merge(_merged_target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
output_name = _merged_target_name
sources = [
invoker.manifest,
rebase_path(build_cfg.runtime_meta, "."),
]
}
_merged_outputs = []
_merged_outputs += get_target_outputs(":$_merged_target_name")
_manifest = _merged_outputs[0]
_manifest_output_name = "meta/" + _component_name + ".cmx"
_component_deps += [ ":$_merged_target_name" ]
} else {
# This is a v2 component.
# The v2 runners have not been implemented yet so we just leave the manifest
# as is to avoid breaking the build.
_manifest = invoker.manifest
_manifest_output_name = "meta/" + _component_name + ".cm"
}
_merged_outputs = []
_merged_outputs += get_target_outputs(":$_merged_target_name")
_merged_manifest = _merged_outputs[0]
_component_deps += [ ":$_merged_target_name" ]
_dart_package_config_target_name = "${target_name}_dart_package"
dart_package_config(_dart_package_config_target_name) {
forward_variables_from(invoker,
@@ -140,6 +154,11 @@ template("flutter_dart_component") {
# the kernel will ignore this variable.
generate_manifest = true
# TODO(richkadel): verify the above statement about aot is true (AOT builds,
# using these new scripts derived from Fuchsia, have not been tested yet);
# because as of now, the Fuchsia package/component appears to require data
# from `_convert_kernel_manifest`.
platform_name = build_cfg.platform_name
product = build_cfg.is_product
is_aot = build_cfg.is_aot
@@ -220,6 +239,9 @@ template("flutter_dart_component") {
# copy the snapshot as a resource
_snapshot_resource_target_name = "${target_name}_snapshot_resource"
# TODO(richkadel): It looks like this is the _ONLY_ place resource() is used
# and maybe that logic should simply be embedded here, directly?
resource(_snapshot_resource_target_name) {
sources = [ _snapshot_path ]
outputs = [ "data/${_component_name}/app_aot_snapshot.so" ]
@@ -231,14 +253,35 @@ template("flutter_dart_component") {
]
}
fuchsia_component(target_name) {
fuchsia_component(_component_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
"component_name",
])
deps = _component_deps
manifest = _merged_manifest
manifest = _manifest
manifest_output_name = _manifest_output_name
_convert_kernel_target_name =
"${_kernel_target_name}_convert_kernel_manifest"
_convert_kernel_manifest_file =
# TODO(richkadel): This is prefixed by "dartlang/", which is not found.
# Is the current toolchain set incorrectly somewhere?
string_replace(
"${target_gen_dir}/${_convert_kernel_target_name}_kernel_manifest.json",
"dartlang/",
"")
resources_in_json_files = [ rebase_path(_convert_kernel_manifest_file) ]
}
group(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
deps = [ ":" + _component_name ]
}
}

View File

@@ -0,0 +1,73 @@
# flutter/tools/fuchsia/gn-sdk
This directory contains a few build rules imported from an August 2021 snapshot
of the Fuchsia GN SDK, with small (required) path adjustments.
The Dart Fuchsia tests require the Fuchsia _Core_ SDK, and the build rules in
the GN SDK require slight path modification to support building against the
Fuchsia Core SDK from a different location. Therefore, the Fuchsia Core SDK is
downloaded via `gclient sync` (versioned according to its fingerprint in DEPS),
and the modified build rules from Fuchsia GN SDK are, for now, copied to
and maintained in flutter/engine.
It is not yet clear if Fuchsia will want to provide SDK resources that support
GN build rules with Dart libraries and tests, but if that does happen, these
files should be replaced by the Fuchsia-provided build rules.
<!-- TODO(richkadel): Talk with Fuchsia SDK team about:
1. Splitting the GN rules into a separate CIPD download (so SDK Dart libaries
and reusable GN rules can both be downloaded into flutter)
2. Ensuring the config.gni path to the SDK will work if the GN rules are not
in the same directory as the other SDK artifacts (e.g., FIDL, C++, and
Dart libraries)
3. How to resolve third-party Dart dependencies in Fuchsia Dart meta.json
files (i.e., including something like the `find_dart_libraries.py` script)
4. Address issues found in the Flutter GN SDK build rules, including:
* `cmc_merge` is adding `.cmx` extension redundantly (compared to
fuchsia.git's version, which doesn't).
* `prepare_package_inputs.py` list `unprocessed_binary_paths` can be empty
for non-C++ packages (like Dart) but the code assumes the list is never
empty, and crashes.
* `prepare_package_inputs.py` list seems to require up front knowledge of
all of the resources, at GN time, but for Dart, I seem to need to compile
the libraries, so the compiler ("dart kernel") will generate a manifest
of the compiled libraries that need to be added as resources. I had to
add a separate JSON file of compile-time-generated list of additional
resources to add to the package and its manifest.
* Other `TODO(richkadel)` items in `flutter/tools/fuchsia`, mostly those
in the `gn-sdk` subdirectory, but others (derived from fuchsia.git may
add context.
-->
## Other GN SDK build rules to be considered
<!-- TODO(richkadel): revisit the following build rules and consider replacing
them with existing GN SDK rules.
-->
It may be wise to consider replacing a few other duplicated (but differently
built) build rules in `//flutter/tools/fuchsia` and `//build` with up-to-date
(via `gclient sync`) rules from the GN SDK. Some of the flutter versions of
these rules were originally imported from the fuchsia.git `//build` directory,
and tailored for flutter. The GN SDK build rules offer simplified versions of
these rules, pre-tailored for the Fuchsia SDK layout and out-of-tree use cases.
Known build files in this category, with the same file name and similar GN
templates, in both Flutter and Fuchsia GN SDK, include:
* fidl_library.gni
* gn_run_binary.py
Other Flutter GN SDK build rules that could replace flutter implemented logic
include:
* gn-sdk/build/fuchsia_sdk_pkg.gni could potentially replace some of the build
logic in `//flutter/tools/fuchsia/sdk/sdk_targets.gni` and/or
`//build/fuchsia/sdk.gni`
* gn-sdk/build/pm_tool.gni rules could potentially replace some flutter pm
invocations
SDK build logic that might improve GN target implementations in flutter include:
* gn-sdk/build/test.gni

View File

@@ -223,6 +223,15 @@ template("cmc_merge") {
"visibility",
])
if (!defined(output_name)) {
# TODO(richkadel): THE GN SDK VERSION OF CMC.GNI IS INCONSISTENT WITH fuchsia.git!
# The default name should be `target_name`, which should already include the
# extension... Or change fuchsia.git to add the extension, and fix calls that
# append .cmx to the target name, like flutter_dart_component.gni.
# With the target_name representing the base of the CMC filename results
# in a "Duplicate definition" error in GN, because "flutter_component()"
# typically has the same target name. My current workaround is to
# redundantly assign `output_name` to the same value as the `target_name`,
# which includes the `.cmx` extension.
output_name = "${target_name}.cmx"
}

View File

@@ -183,6 +183,7 @@ template("fuchsia_component") {
"deps",
"data_deps",
"resources",
"resources_in_json_files",
"testonly",
"visibility",
])
@@ -198,6 +199,13 @@ template("fuchsia_component") {
resources = []
}
# TODO(richkadel): Changed from the Fuchsia GN SDK to add
# `resources_in_json_files, so additional resources could be computed at
# compile time (in this case, compiled Dart libraries).
if (!defined(resources_in_json_files)) {
resources_in_json_files = []
}
if (!defined(deps)) {
deps = []
}
@@ -208,7 +216,7 @@ template("fuchsia_component") {
component_contents = [
{
type = "manifest"
source = rebase_path(_manifest_source)
source = rebase_path(get_path_info(_manifest_source, "abspath"))
output_name = manifest_output_name
manifest_version = _manifest_version
},
@@ -223,6 +231,15 @@ template("fuchsia_component") {
},
]
}
foreach(file, resources_in_json_files) {
data += [ file ]
component_contents += [
{
type = "json_of_resources"
source = file
},
]
}
# The contents of the component are enumerated in the
# metadata.

View File

@@ -2,13 +2,22 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# TODO(richkadel): added this import and modified the fuchsia_sdk assignment.
# See below.
import("//build/fuchsia/sdk.gni")
declare_args() {
# Path to the fuchsia SDK. This is intended for use in other templates & rules
# to reference the contents of the fuchsia SDK.
fuchsia_sdk = "$fuchsia_sdk_path"
# TODO(richkadel): Since flutter needs build rules from the GN SDK, but also
# requires the Fuchsia _Core_ SDK (for dart libraries, in the core SDK, but
# excluded from the GN SDK), the Fuchsia SDK assumption that the build files
# are in the same SDK directory path as the APIs does not hold true. (And
# there are are a couple of other minor tweaks that appear to be needed, at
# this time.) This use case will be discussed with the SDK team, to see if we
# can come up with a cleaner solution.
# Build ID uniquely identifying the Fuchsia IDK. This is exposed as a property so
# it can be used to locate images and packages on GCS and as a marker to indicate the
# "version" of the IDK. If it is empty, then it is most likely that something is fatally wrong.
@@ -28,6 +37,13 @@ declare_args() {
if (host_cpu == "x64" || host_cpu == "arm64") {
fuchsia_tool_dir = "${fuchsia_sdk}/tools/${host_cpu}"
}
# fuchsia_auto_index_symbols when true adds the ids.txt file generated from a `fuchsia_package`
# to the Fuchsia symbol index used to symbolize logs and to find source when using zxdb.
# The default value is false, in order to be backwards compatibility with existing builds, and
# only makes sense to set to true when building as a developer that will need to symbolize logs
# or use the debugger with locally build code.
fuchsia_auto_index_symbols = false
}
if (fuchsia_sdk_id == "") {

View File

@@ -0,0 +1,198 @@
# 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("config/config.gni")
import("pm_tool.gni")
import("symbol_index.gni")
# Define a Fuchsia component package target.
#
# Parameters
#
# package_name: [Optional]
# Name of the package. Defaults to target_name.
#
# Type: string
#
# excluded_files: [Optional]
# List of files to exclude from the package.
#
# Type: list of file paths
#
# fidl_ref_out_dir: [Optional]
# Directory for writing out $package_name_all_fidl_refs.txt
# that contains the paths to the internal representation (IR) of every
# FIDL interface referenced in the package. Defaults to $root_build_dir/fidl_refs.
#
# ids_txt_output_path: [Optional]
# Path to write out the ids.txt file for the symbols in the binaries.
# Defaults to `${target_gen_dir}/${package_name}/ids.txt`
#
# Type: file path
#
# deps
# Required: List of fuchsia_component() targets that this
# package contains.
#
template("fuchsia_package") {
if (!defined(invoker.package_name)) {
package_name = target_name
} else {
package_name = invoker.package_name
}
if (!defined(invoker.excluded_files)) {
excluded_files = []
} else {
excluded_files = invoker.excluded_files
}
if (!defined(invoker.fidl_ref_out_dir)) {
fidl_ref_out_dir = "$root_build_dir/fidl_refs"
} else {
fidl_ref_out_dir = invoker.fidl_ref_out_dir
}
_depfile = "${target_gen_dir}/${target_name}_stamp.d"
# target names
_manifest_target = "${target_name}__archive-manifest"
_metadata_target = "${target_name}__archive-metadata"
_packaged_components_metadata_target =
"${target_name}__packaged_components_metadata"
# output values
_pkg_out_dir = "${target_gen_dir}/${package_name}"
_runtime_deps_file = "$_pkg_out_dir/${package_name}.runtime_deps"
_archive_manifest = "$_pkg_out_dir/${package_name}.manifest"
_build_ids_file = "$_pkg_out_dir/ids.txt"
if (defined(invoker.ids_txt_output_path)) {
_build_ids_file = invoker.ids_txt_output_path
}
_package_file = "$_pkg_out_dir/package"
_fidl_json_refs_file = "${fidl_ref_out_dir}/${package_name}_all_fidl_refs.txt"
_packaged_components_metadata_file =
"${target_gen_dir}/${package_name}_packaged_components_metadata.json"
_package_deps = []
if (defined(invoker.deps)) {
_package_deps += invoker.deps
}
if (defined(invoker.data_deps)) {
_package_deps += invoker.data_deps
}
# Generates a JSON file containing the contents of each of the
# components being included in this package.
generated_file(_packaged_components_metadata_target) {
forward_variables_from(invoker, [ "testonly" ])
outputs = [ _packaged_components_metadata_file ]
data_keys = [ "contents" ]
output_conversion = "json"
deps = _package_deps
}
# A generated file that lists all of the .fidl.json files
# used in this package. This is useful for tools that need
# to decode fidl.
generated_file("${package_name}_all_fidl_refs") {
testonly = true
deps = _package_deps
outputs = [ _fidl_json_refs_file ]
data_keys = [ "fidl_json" ]
}
action(_manifest_target) {
forward_variables_from(invoker, [ "testonly" ])
script = "//flutter/tools/fuchsia/gn-sdk/prepare_package_inputs.py"
inputs = [
_runtime_deps_file,
_packaged_components_metadata_file,
]
outputs = [
_archive_manifest,
_build_ids_file,
_package_file,
]
data_deps = _package_deps
deps = _package_deps
deps += [ ":${_packaged_components_metadata_target}" ]
if (defined(invoker.deps)) {
deps += invoker.deps
}
# Use a depfile to trigger package rebuilds if any of the files (static
# assets, shared libraries, etc.) included by the package have changed.
depfile = _depfile
args = [
"--root-dir",
rebase_path("//", root_build_dir),
"--out-dir",
rebase_path(root_out_dir, root_build_dir),
"--app-name",
package_name,
"--runtime-deps-file",
rebase_path(_runtime_deps_file, root_build_dir),
"--depfile-path",
rebase_path(_depfile, root_build_dir),
"--manifest-path",
rebase_path(_archive_manifest, root_build_dir),
"--build-ids-file",
rebase_path(_build_ids_file, root_build_dir),
"--json-file",
rebase_path(_packaged_components_metadata_file),
]
if (defined(excluded_files)) {
foreach(filename, excluded_files) {
args += [
"--exclude-file",
filename,
]
}
}
write_runtime_deps = _runtime_deps_file
# Allows ids.txt paths to be collected by dependent targets.
metadata = {
ids_txt_paths = [ _build_ids_file ]
}
}
# Creates a Fuchsia metadata package.
fuchsia_pm_tool(_metadata_target) {
forward_variables_from(invoker, [ "testonly" ])
package_name = package_name
command = "build"
archive_manifest = _archive_manifest
public_deps = [ ":$_manifest_target" ]
}
fuchsia_pm_tool(target_name) {
forward_variables_from(invoker, [ "testonly" ])
package_name = package_name
command = "archive"
archive_manifest = _archive_manifest
public_deps = [ ":$_metadata_target" ]
if (!defined(deps)) {
deps = []
}
if (defined(fuchsia_auto_index_symbols) && fuchsia_auto_index_symbols) {
deps += [ ":${target_name}_fuchsia_auto_index_symbols" ]
}
}
if (defined(fuchsia_auto_index_symbols) && fuchsia_auto_index_symbols) {
fuchsia_symbol_index_tool("${target_name}_fuchsia_auto_index_symbols") {
forward_variables_from(invoker, [ "testonly" ])
symbols = _build_ids_file
deps = [ ":$_metadata_target" ]
}
}
}

View File

@@ -0,0 +1,110 @@
# 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("config/config.gni")
# Template for running the pm tool for packaging fuchsia packages.
#
# Parameters
# package_name - defaults to target_name
# archive_manifest - required
# version [optional]
# The package version. Defaults to 0.
# command - the packaging step to perform valid steps are build, archive
#
# Forwarded parameters
# testonly
# deps
# public_deps
# visibility
template("fuchsia_pm_tool") {
forward_variables_from(invoker, [ "*" ])
action(target_name) {
forward_variables_from(invoker,
[
"testonly",
"deps",
"public_deps",
"visibility",
])
_valid_commands = [
"build",
"archive",
]
assert(defined(invoker.archive_manifest), "archive_manifest is required.")
archive_manifest = invoker.archive_manifest
assert(defined(invoker.command), "command is required")
assert(invoker.command == "build" || invoker.command == "archive",
"invalid command. valid commands are ${_valid_commands}")
command = invoker.command
package_name = target_name
if (defined(invoker.package_name)) {
package_name = invoker.package_name
}
version = "0"
if (defined(invoker.version)) {
version = invoker.version
}
# tool path
_pm_tool_path = "${fuchsia_tool_dir}/pm"
script = "//build/gn_run_binary.py"
# output files
_pkg_out_dir = "${target_gen_dir}/${package_name}"
_meta_far_file = "${_pkg_out_dir}/meta.far"
inputs = [
# Depend on the SDK hash, to ensure rebuild if the SDK tools change.
fuchsia_sdk_manifest_file,
_pm_tool_path,
archive_manifest,
]
if (command == "build") {
_pkg_output_manifest = "${_pkg_out_dir}/package_manifest.json"
outputs = [
_meta_far_file,
"${_pkg_out_dir}/meta/contents",
"${_meta_far_file}.merkle",
_pkg_output_manifest,
]
depfile = "${_meta_far_file}.d"
} else {
inputs += [ _meta_far_file ]
_final_far_file = "$_pkg_out_dir/${package_name}.far"
outputs = [ _final_far_file ]
}
args = [
rebase_path(_pm_tool_path, root_build_dir),
"-o",
rebase_path(_pkg_out_dir, root_build_dir),
"-m",
rebase_path(archive_manifest, root_build_dir),
"-n",
package_name,
"-version",
version,
]
if (command == "build") {
args += [
command,
"-output-package-manifest",
rebase_path(_pkg_output_manifest, root_build_dir),
"-depfile",
]
} else if (command == "archive") {
args += [
command,
"--output",
rebase_path("${_pkg_out_dir}/${package_name}"),
]
}
}
}

View File

@@ -0,0 +1,385 @@
#!/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.
#
# Derivative work of https://chromium.googlesource.com/chromium/src/+/HEAD/build/config/fuchsia/prepare_package_inputs.py
#
"""Creates a archive manifest used for Fuchsia package generation."""
import argparse
import json
import os
import shutil
import subprocess
import sys
# File extension of a component manifest for each Component Framework version
MANIFEST_VERSION_EXTENSIONS = {"v1": ".cmx", "v2": ".cm"}
def make_package_path(file_path, roots):
"""Computes a path for |file_path| relative to one of the |roots|.
Args:
file_path: The file path to relativize.
roots: A list of directory paths which may serve as a relative root for
|file_path|.
For example:
* make_package_path('/foo/bar.txt', ['/foo/']) 'bar.txt'
* make_package_path('/foo/dir/bar.txt', ['/foo/']) 'dir/bar.txt'
* make_package_path('/foo/out/Debug/bar.exe', ['/foo/', '/foo/out/Debug/']) 'bar.exe'
"""
# Prevents greedily matching against a shallow path when a deeper, better
# matching path exists.
roots.sort(key=len, reverse=True)
for next_root in roots:
if not next_root.endswith(os.sep):
next_root += os.sep
if file_path.startswith(next_root):
relative_path = file_path[len(next_root):]
return relative_path
return file_path
def _get_stripped_path(bin_path):
"""Finds the stripped version of |bin_path| in the build output directory.
returns |bin_path| if no stripped path is found.
"""
stripped_path = bin_path.replace('lib.unstripped/',
'lib/').replace('exe.unstripped/', '')
if os.path.exists(stripped_path):
return stripped_path
else:
return bin_path
def _is_binary(path):
"""Checks if the file at |path| is an ELF executable.
This is done by inspecting its FourCC header.
"""
with open(path, 'rb') as f:
file_tag = f.read(4)
return file_tag == b'\x7fELF'
def _write_build_ids_txt(binary_paths, ids_txt_path):
"""Writes an index text file mapping build IDs to unstripped binaries."""
READELF_FILE_PREFIX = 'File: '
READELF_BUILD_ID_PREFIX = 'Build ID: '
# List of binaries whose build IDs are awaiting processing by readelf.
# Entries are removed as readelf's output is parsed.
unprocessed_binary_paths = set(binary_paths)
build_ids_map = {}
# Sanity check that unstripped binaries do not also have their stripped
# counterpart listed.
for binary_path in binary_paths:
stripped_binary_path = _get_stripped_path(binary_path)
if stripped_binary_path != binary_path:
unprocessed_binary_paths.discard(stripped_binary_path)
with open(ids_txt_path, 'w') as ids_file:
# TODO(richkadel): This script (originally from the Fuchsia GN SDK) was
# changed, adding this `if unprocessed_binary_paths` check, because for
# the Dart packages I tested (child-view and parent-view), this was
# empty. Update the Fuchsia GN SDK? (Or figure out if the Dart packages
# _should_ have at least one unprocessed_binary_path?)
if unprocessed_binary_paths:
# Create a set to dedupe stripped binary paths in case both the stripped and
# unstripped versions of a binary are specified.
readelf_stdout = subprocess.check_output(
['readelf', '-n'] + sorted(unprocessed_binary_paths)).decode('utf8')
if len(binary_paths) == 1:
# Readelf won't report a binary's path if only one was provided to the
# tool.
binary_path = binary_paths[0]
else:
binary_path = None
for line in readelf_stdout.split('\n'):
line = line.strip()
if line.startswith(READELF_FILE_PREFIX):
binary_path = line[len(READELF_FILE_PREFIX):]
assert binary_path in unprocessed_binary_paths
elif line.startswith(READELF_BUILD_ID_PREFIX):
# Paths to the unstripped executables listed in "ids.txt" are specified
# as relative paths to that file.
unstripped_rel_path = os.path.relpath(
os.path.abspath(binary_path),
os.path.dirname(os.path.abspath(ids_txt_path)))
build_id = line[len(READELF_BUILD_ID_PREFIX):]
build_ids_map[build_id] = unstripped_rel_path
unprocessed_binary_paths.remove(binary_path)
for id_and_path in sorted(build_ids_map.items()):
ids_file.write(id_and_path[0] + ' ' + id_and_path[1] + '\n')
# Did readelf forget anything? Make sure that all binaries are accounted for.
assert not unprocessed_binary_paths
def _parse_component(component_info_file):
component_info = json.load(open(component_info_file, 'r'))
return component_info
def _get_component_manifests(component_info):
return [c for c in component_info if c.get('type') == 'manifest']
# TODO(richkadel): Changed, from the Fuchsia GN SDK version to add this function
# and related code, to include support for a file of resources that aren't known
# until compile time.
def _get_resource_items_from_json_items(component_info):
nested_resources = []
files = [c.get('source') for c in component_info if c.get('type') == 'json_of_resources']
for json_file in files:
for resource in _parse_component(json_file):
nested_resources.append(resource)
return nested_resources
def _get_resource_items(component_info):
return (
[c for c in component_info if c.get('type') == 'resource'] +
_get_resource_items_from_json_items(component_info)
)
def _get_expanded_files(runtime_deps_file):
""" Process the runtime deps file for file paths, recursively walking
directories as needed.
Returns a set of expanded files referenced by the runtime deps file.
"""
# runtime_deps may contain duplicate paths, so use a set for
# de-duplication.
expanded_files = set()
for next_path in open(runtime_deps_file, 'r'):
next_path = next_path.strip()
if os.path.isdir(next_path):
for root, _, files in os.walk(next_path):
for current_file in files:
if current_file.startswith('.'):
continue
expanded_files.add(
os.path.normpath(os.path.join(root, current_file)))
else:
expanded_files.add(os.path.normpath(next_path))
return expanded_files
def _write_gn_deps_file(
depfile_path, package_manifest, component_manifests, out_dir,
expanded_files):
with open(depfile_path, 'w') as depfile:
deps_list = [os.path.relpath(f, out_dir) for f in expanded_files]
deps_list.extend(component_manifests)
# The deps file is space-delimited, so filenames containing spaces
# must have them escaped.
deps_list = [f.replace(' ','\\ ') for f in deps_list]
deps_string = ' '.join(sorted(deps_list))
depfile.write('%s: %s' % (package_manifest, deps_string))
def _write_meta_package_manifest(
manifest_entries, manifest_path, app_name, out_dir, package_version):
# Write meta/package manifest file and add to archive manifest.
meta_package = os.path.join(os.path.dirname(manifest_path), 'package')
with open(meta_package, 'w') as package_json:
json_payload = {'version': package_version, 'name': app_name}
json.dump(json_payload, package_json)
package_json_filepath = os.path.relpath(package_json.name, out_dir)
manifest_entries['meta/package'] = package_json_filepath
def _write_component_manifest(
manifest_entries, component_info, archive_manifest_path, out_dir):
"""Copy component manifest files and add to archive manifest.
Raises an exception if a component uses a unknown manifest version.
"""
for component_manifest in _get_component_manifests(component_info):
manifest_version = component_manifest.get('manifest_version')
if manifest_version not in MANIFEST_VERSION_EXTENSIONS:
raise Exception(
'Unknown manifest_version: {}'.format(manifest_version))
# TODO(richkadel): Changed, from the Fuchsia GN SDK version, to assume
# the given `output_name` already includes its extension. This change
# has not been fully validate, in particular, it has not been tested
# with CF v2 `.cm` (from `.cml`) files. Original implementation was:
#
# extension = MANIFEST_VERSION_EXTENSIONS.get(manifest_version)
# manifest_dest_file_path = os.path.join(
# os.path.dirname(archive_manifest_path),
# component_manifest.get('output_name') + extension)
manifest_dest_file_path = os.path.join(
os.path.dirname(archive_manifest_path),
component_manifest.get('output_name'))
# Add the 'meta/' subdir, for example, if `output_name` includes it
os.makedirs(os.path.dirname(manifest_dest_file_path), exist_ok=True)
shutil.copy(component_manifest.get('source'), manifest_dest_file_path)
manifest_entries[
'meta/%s' %
os.path.basename(manifest_dest_file_path)] = os.path.relpath(
manifest_dest_file_path, out_dir)
return manifest_dest_file_path
def _write_package_manifest(
manifest_entries, expanded_files, out_dir, exclude_file, root_dir,
component_info):
"""Writes the package manifest for a Fuchsia package
Returns a list of binaries in the package.
Raises an exception if excluded files are not found."""
gen_dir = os.path.normpath(os.path.join(out_dir, 'gen'))
excluded_files_set = set(exclude_file)
roots = [gen_dir, root_dir, out_dir]
# Filter out component manifests. These are written out elsewhere.
excluded_files_set.update(
[
make_package_path(
os.path.relpath(cf.get('source'), out_dir), roots)
for cf in _get_component_manifests(component_info)
if os.path.relpath(cf.get('source'), out_dir) in expanded_files
])
# Filter out json_of_resources since only their contents are written, and we
# don't know the contained resources until late in the build cycle
excluded_files_set.update(
[
make_package_path(
os.path.relpath(cf.get('source'), out_dir), roots)
for cf in component_info if cf.get('type') == 'json_of_resources' and
os.path.relpath(cf.get('source'), out_dir) in expanded_files
])
# Write out resource files with specific package paths, and exclude them from
# the list of expanded files so they are not listed twice in the manifest.
for resource in _get_resource_items(component_info):
relative_src_file = os.path.relpath(resource.get('source'), out_dir)
resource_path = make_package_path(relative_src_file, roots)
manifest_entries[resource.get('dest')] = relative_src_file
if resource.get('type') == 'resource':
excluded_files_set.add(resource_path)
for current_file in expanded_files:
current_file = _get_stripped_path(current_file)
# make_package_path() may relativize to either the source root or
# output directory.
in_package_path = make_package_path(current_file, roots)
if in_package_path in excluded_files_set:
excluded_files_set.remove(in_package_path)
else:
manifest_entries[in_package_path] = current_file
if excluded_files_set:
raise Exception(
'Some files were excluded with --exclude-file but '
'not found in the deps list, or a resource (data) file '
'was added and not filtered out. Excluded files and resources: '
'%s' % ', '.join(excluded_files_set))
def _build_manifest(args):
# Use a sorted list to make sure the manifest order is deterministic.
expanded_files = sorted(_get_expanded_files(args.runtime_deps_file))
component_info = _parse_component(args.json_file)
component_manifests = []
# Collect the manifest entries in a map since duplication happens
# because of runtime libraries.
manifest_entries = {}
_write_meta_package_manifest(
manifest_entries, args.manifest_path, args.app_name, args.out_dir,
args.package_version)
for component_item in component_info:
_write_package_manifest(
manifest_entries, expanded_files, args.out_dir, args.exclude_file,
args.root_dir, component_item)
component_manifests.append(
_write_component_manifest(
manifest_entries, component_item, args.manifest_path,
args.out_dir))
with open(args.manifest_path, 'w') as manifest:
for key in sorted(manifest_entries.keys()):
manifest.write('%s=%s\n' % (key, manifest_entries[key]))
binaries = [f for f in expanded_files if _is_binary(f)]
_write_build_ids_txt(sorted(binaries), args.build_ids_file)
# Omit any excluded_files from the expanded_files written to the depfile.
gen_dir = os.path.normpath(os.path.join(args.out_dir, 'gen'))
roots = [gen_dir, args.root_dir, args.out_dir]
excluded_files_set = set(args.exclude_file)
expanded_deps_files = [path for path in expanded_files
if make_package_path(path, roots)
not in excluded_files_set]
_write_gn_deps_file(
args.depfile_path, args.manifest_path, component_manifests,
args.out_dir, expanded_deps_files)
return 0
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--root-dir', required=True, help='Build root directory')
parser.add_argument(
'--out-dir', required=True, help='Build output directory')
parser.add_argument('--app-name', required=True, help='Package name')
parser.add_argument(
'--runtime-deps-file',
required=True,
help='File with the list of runtime dependencies.')
parser.add_argument(
'--depfile-path', required=True, help='Path to write GN deps file.')
parser.add_argument(
'--exclude-file',
action='append',
default=[],
help='Package-relative file path to exclude from the package.')
parser.add_argument(
'--manifest-path', required=True, help='Manifest output path.')
parser.add_argument(
'--build-ids-file', required=True, help='Debug symbol index path.')
parser.add_argument('--json-file', required=True)
parser.add_argument(
'--package-version', default='0', help='Version of the package')
args = parser.parse_args()
return _build_manifest(args)
if __name__ == '__main__':
sys.exit(main())

View File

@@ -0,0 +1,58 @@
# 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("config/config.gni")
# Template for running the symbol-index tool for registering symbols with the symbolizer.
#
# Parameters
# symbols - the build_id or ids.txt file to add to the index
# build_dir - optional, the root of the build id used to resolve
# relative source code paths found in the symbols.
#
# Forwarded parameters
# testonly
# deps
# public_deps
# visibility
template("fuchsia_symbol_index_tool") {
forward_variables_from(invoker, [ "*" ])
action(target_name) {
forward_variables_from(invoker,
[
"testonly",
"deps",
"public_deps",
"visibility",
])
assert(defined(invoker.symbols), "symbols is required.")
_symbol_file = invoker.symbols
_build_root_dir = root_build_dir
if (defined(invoker.build_root_dir)) {
_build_root_dir = invoker.build_root_dir
}
_stamp_file = "$target_gen_dir/$target_name.symbol_index.stamp"
outputs = [ _stamp_file ]
# tool path
_tool_path = "${fuchsia_tool_dir}/symbol-index"
script = "//build/gn_run_binary.py"
inputs = [
# Depend on the SDK hash, to ensure rebuild if the SDK tools change.
_symbol_file,
_tool_path,
]
args = [
"--stamp",
rebase_path(_stamp_file, root_build_dir),
rebase_path(_tool_path, root_build_dir),
"add",
rebase_path(_symbol_file, root_build_dir),
rebase_path(_build_root_dir, root_build_dir),
]
}
}

View File

@@ -13,11 +13,15 @@ its provided libraries or its third_party packages.
import argparse
import json
import yaml
import os
import sys
import pkg_resources
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path += [os.path.join(
THIS_DIR, '..', '..', '..', '..', 'third_party', 'pyyaml', 'lib3')]
import yaml
def find_package(root, local_paths, package, version):
"""Return the package target if found with at least this version"""

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3.8
#!/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.

View File

@@ -521,6 +521,8 @@ def main(argv):
# On Windows, generate a Visual Studio project.
command.append('--ide=vs')
command.append('--export-compile-commands=default')
gn_args = to_command_line(to_gn_args(args))
out_dir = get_out_dir(args)
command.append(out_dir)

View File

@@ -1815,6 +1815,7 @@ class _RepositoryRootThirdPartyDirectory extends _RepositoryGenericThirdPartyDir
&& entry.name != 'markupsafe' // build-time only
&& entry.name != 'mockito' // only used by tests
&& entry.name != 'pymock' // presumably only used by tests
&& entry.name != 'pyyaml' // build-time dependency only
&& entry.name != 'android_embedding_dependencies' // testing framework for android
&& entry.name != 'yasm' // build-time dependency only
&& entry.name != 'binutils' // build-time dependency only

View File

@@ -1,60 +0,0 @@
# Copyright 2021 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.
# A ninja action script that calls the given python script with `python3`
# instead of the default `python` (which might be `python2`).
#
# Example
#
# ```
# python3_action("run_this_guy_once") {
# script = "doprocessing.py"
# sources = [ "my_configuration.txt" ]
# outputs = [ "$target_gen_dir/insightful_output.txt" ]
#
# # Our script imports this Python file so we want to rebuild if it
# # changes.
# source_prereqs = [ "helper_library.py" ]
#
# # Note that we have to manually pass the sources to our script if
# # the script needs them as inputs.
# args = [ "--out", to_build_path(target_gen_dir) ] + sources
# }
# ```
#
# Parameters
# args
# data
# datadeps
# depfile
# deps
# inputs
# metadata
# outputs (required)
# script (required)
# source_prereqs
# sources
template("python3_action") {
assert(defined(invoker.outputs), "outputs is required")
assert(defined(invoker.script), "script is required")
action(target_name) {
forward_variables_from(invoker,
[
"data",
"datadeps",
"depfile",
"deps",
"inputs",
"metadata",
"outputs",
"source_prereqs",
"sources",
])
script = "//flutter/tools/python/run_python3_action.py"
args = [ rebase_path(invoker.script) ] + invoker.args
}
}

View File

@@ -1,10 +0,0 @@
#!/usr/bin/env python
#
# Copyright 2021 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 os
import sys
os.execv('/usr/bin/python3', ['python3'] + sys.argv[1:])