[Fuchsia] Use shared gn-sdk from chromium (flutter/engine#50855)

Fuchsia team is working on getting rid of non-versioned libraries and sysroot (see b/40935282), but flutter is using a fairly old version of in-house gn-sdk. It's hard to maintain it anymore.
So this change removes the in-house gn-sdk and replaces it with the gn-sdk from chromium.
This is a prerequisite to select the idk / sdk lib version according to the api-level.

This change contains three parts:
1) Replacing gn-sdk/ with gn-sdk/src/ since the chromium needs a README.chromium in gn-sdk/ folder.
2) Making the existing build rules work with the newer gn-sdk.
3) Drive-by replacing "gtest_runner.shard.cml" with "sys/testing/gtest_runner.shard.cml", it's in fuchsia sdk already.

Bug: [b/40935282](https://issues.chromium.org/issues/40935282?pli=1&authuser=0)

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
zijiehe@
2024-02-27 09:30:05 -08:00
committed by GitHub
parent fce1fe5b2c
commit c274921fa6
38 changed files with 69 additions and 1518 deletions

14
DEPS
View File

@@ -254,6 +254,10 @@ vars = {
# will be used altogether with fuchsia-sdk to setup the build / test
# environment.
'fuchsia_test_scripts_version': 'vf8imeAzGv_gjYQDoqub2laI-6nkB3gQNiGuVaFForMC',
# The version / instance id of the cipd:chromium/fuchsia/gn-sdk which will be
# used altogether with fuchsia-sdk to generate gn based build rules.
'fuchsia_gn_sdk_version': 'l8zShEOXGGjtLYRulEX5CjT2RemKvUPOT6L-uXy41tMC',
}
gclient_gn_args_file = 'src/third_party/dart/build/config/gclient_args.gni'
@@ -1020,6 +1024,16 @@ deps = {
'dep_type': 'cipd',
},
'src/flutter/tools/fuchsia/gn-sdk': {
'packages': [
{
'package': 'chromium/fuchsia/gn-sdk',
'version': Var('fuchsia_gn_sdk_version'),
}
],
'dep_type': 'cipd',
},
'src/third_party/impeller-cmake-example': {
'url': Var('flutter_git') + '/third_party/impeller-cmake-example.git' + '@' + 'c44e8093972c969acf171be72591e408a85fdc53',
'condition': 'download_impeller_cmake_example',

View File

@@ -139,3 +139,6 @@ app.*.symbols
# The test-scripts from Chromium and managed by DEPS and gclient.
/tools/fuchsia/test_scripts
# The gn-sdk from Chromium and managed by DEPS and gclient.
/tools/fuchsia/gn-sdk

View File

@@ -53,3 +53,14 @@ if (fuchsia_sdk_id == "") {
_meta = read_file(fuchsia_sdk_manifest_file, "json")
fuchsia_sdk_id = _meta.id
}
declare_args() {
# Specify a readelf_exec path to use. If not specified, the host's system
# executable will be used. Passed to populate_build_id_dir.py and
# prepare_package_inputs.py via the --readelf-exec flag.
# Must be a GN path (not an absolute path) since it is adjusted with
# rebase_path().
if (!defined(fuchsia_sdk_readelf_exec)) {
fuchsia_sdk_readelf_exec = ""
}
}

View File

@@ -6,7 +6,7 @@ import("//build/fuchsia/sdk.gni")
import("//flutter/testing/testing.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")
import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
config("zircon_config") {
include_dirs = [ "." ]

View File

@@ -4,7 +4,7 @@
{
include: [
"gtest_runner.shard.cml",
"sys/testing/gtest_runner.shard.cml",
"sys/component/realm_builder_absolute.shard.cml",
// This test needs both the vulkan facet and the hermetic-tier-2 facet,

View File

@@ -1,18 +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.
{
program: {
runner: "gtest_runner",
},
capabilities: [
{ protocol: "fuchsia.test.Suite" },
],
expose: [
{
protocol: "fuchsia.test.Suite",
from: "self",
},
],
}

View File

@@ -6,7 +6,7 @@ import("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/dart/dart_component.gni")
import("//flutter/tools/fuchsia/dart/dart_library.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
dart_library("lib") {
testonly = true

View File

@@ -4,7 +4,7 @@
{
include: [
"gtest_runner.shard.cml",
"sys/testing/gtest_runner.shard.cml",
"sys/component/realm_builder_absolute.shard.cml",
// This test needs both the vulkan facet and the hermetic-tier-2 facet,

View File

@@ -1,18 +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.
{
program: {
runner: "gtest_runner",
},
capabilities: [
{ protocol: "fuchsia.test.Suite" },
],
expose: [
{
protocol: "fuchsia.test.Suite",
from: "self",
},
],
}

View File

@@ -5,7 +5,7 @@
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")
import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
dart_library("lib") {
package_name = "child-view"

View File

@@ -3,7 +3,7 @@
// found in the LICENSE file.
{
include: [
"gtest_runner.shard.cml",
"sys/testing/gtest_runner.shard.cml",
"sys/component/realm_builder_absolute.shard.cml",
// This test needs both the vulkan facet and the hermetic-tier-2 facet,

View File

@@ -1,17 +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.
{
program: {
runner: "gtest_runner",
},
capabilities: [
{ protocol: "fuchsia.test.Suite" },
],
expose: [
{
protocol: "fuchsia.test.Suite",
from: "self",
},
],
}

View File

@@ -5,7 +5,7 @@
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")
import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
dart_library("lib") {
package_name = "parent-view"

View File

@@ -6,7 +6,7 @@ assert(is_fuchsia)
import("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/fuchsia_archive.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
group("tests") {
testonly = true

View File

@@ -1,17 +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.
{
program: {
runner: "gtest_runner",
},
capabilities: [
{ protocol: "fuchsia.test.Suite" },
],
expose: [
{
protocol: "fuchsia.test.Suite",
from: "self",
},
],
}

View File

@@ -3,7 +3,7 @@
// found in the LICENSE file.
{
include: [
"gtest_runner.shard.cml",
"sys/testing/gtest_runner.shard.cml",
"sys/component/realm_builder_absolute.shard.cml",
// This test needs both the vulkan facet and the hermetic-tier-2 facet,

View File

@@ -5,8 +5,8 @@
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/component.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/component.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
dart_library("lib") {
package_name = "mouse-input-view"

View File

@@ -6,7 +6,7 @@ assert(is_fuchsia)
import("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/fuchsia_archive.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
group("tests") {
testonly = true

View File

@@ -1,17 +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.
{
program: {
runner: "gtest_runner",
},
capabilities: [
{ protocol: "fuchsia.test.Suite" },
],
expose: [
{
protocol: "fuchsia.test.Suite",
from: "self",
},
],
}

View File

@@ -3,7 +3,7 @@
// found in the LICENSE file.
{
include: [
"gtest_runner.shard.cml",
"sys/testing/gtest_runner.shard.cml",
"sys/component/realm_builder_absolute.shard.cml",
// This test needs both the vulkan facet and the hermetic-tier-2 facet,

View File

@@ -5,8 +5,8 @@
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/component.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/component.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
dart_library("lib") {
testonly = true

View File

@@ -6,7 +6,7 @@ assert(is_fuchsia)
import("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/fuchsia_archive.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
group("tests") {
testonly = true

View File

@@ -5,8 +5,8 @@
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/component.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/component.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
dart_library("lib") {
package_name = "embedding-flutter-view"

View File

@@ -1,17 +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.
{
program: {
runner: "gtest_runner",
},
capabilities: [
{ protocol: "fuchsia.test.Suite" },
],
expose: [
{
protocol: "fuchsia.test.Suite",
from: "self",
},
],
}

View File

@@ -3,7 +3,7 @@
// found in the LICENSE file.
{
include: [
"gtest_runner.shard.cml",
"sys/testing/gtest_runner.shard.cml",
"sys/component/realm_builder_absolute.shard.cml",
// This test needs both the vulkan facet and the hermetic-tier-2 facet,

View File

@@ -5,8 +5,8 @@
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/component.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/component.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
dart_library("lib") {
package_name = "touch-input-view"

View File

@@ -1,46 +0,0 @@
#!/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.
""" Compiles a cml manifest file.
"""
import argparse
import os
import subprocess
import sys
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--cmc-bin', dest='cmc_bin', action='store', required=True)
parser.add_argument('--output', dest='output', action='store', required=True)
parser.add_argument('--manifest-file', dest='manifest_file', action='store', required=True)
parser.add_argument(
'--includepath',
dest='includepath',
action='append',
required=True,
)
args = parser.parse_args()
assert os.path.exists(args.cmc_bin)
assert os.path.exists(args.manifest_file)
subprocess.check_output([
args.cmc_bin,
'compile',
'--output',
args.output,
args.manifest_file,
] + (args.includepath and ['--includepath'] + args.includepath))
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@@ -5,7 +5,9 @@
import("//flutter/tools/executable_action.gni")
import("//flutter/tools/fuchsia/fidl/fidl.gni")
import("//flutter/tools/fuchsia/fidl/toolchain.gni")
import("//flutter/tools/fuchsia/gn-sdk/config/config.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/config/config.gni")
# TODO(zijiehe): May use fidl_library in gn-sdk if possible. - http://crbug.com/40935282
# Generates some representation of a FIDL library that's consumable by Language
# bindings generators.

View File

@@ -7,8 +7,8 @@ import("//flutter/tools/fuchsia/dart/config.gni")
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/gn-sdk/cmc.gni")
import("//flutter/tools/fuchsia/gn-sdk/component.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/cmc.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/component.gni")
# Defines a component which will run in a flutter_runner or dart_runner
#

View File

@@ -5,47 +5,31 @@
import("//build/fuchsia/config.gni")
import("//flutter/tools/fuchsia/fuchsia_debug_symbols.gni")
import("//flutter/tools/fuchsia/fuchsia_libs.gni")
import("//flutter/tools/fuchsia/gn-sdk/config/config.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/cmc.gni")
import("//flutter/tools/fuchsia/gn-sdk/src/gn_configs.gni")
# Compiles a CML file for a V2 component.
#
# manifest (required):
# The path to the .cml file for the component. Should include the file extension.
# output (optional):
# The path for the output .cm file. Should include the file extension.
# Alias of cmc_compile in gn-sdk/src/cmc.gni
template("_compile_cml") {
assert(defined(invoker.manifest), "_compile_cml must define manifest")
action(target_name) {
# Create an empty depfile, it's not used in flutter.
write_file("${target_gen_dir}/${target_name}/${target_name}.d",
[],
"list lines")
cmc_compile(target_name) {
forward_variables_from(invoker,
[
"deps",
"manifest",
"testonly",
"visibility",
])
script = "//flutter/tools/fuchsia/compile_cml.py"
inputs = [ "$fuchsia_tool_dir/cmc" ]
sources = [ invoker.manifest ]
args = [
"--cmc-bin",
rebase_path("$fuchsia_tool_dir/cmc"),
"--manifest-file",
rebase_path(invoker.manifest),
"--output",
rebase_path(invoker.output, root_build_dir),
"--includepath",
rebase_path("$fuchsia_sdk/pkg/", root_build_dir),
"--includepath",
get_path_info(invoker.manifest, "dir"),
"--includepath",
rebase_path("//"),
]
outputs = [ invoker.output ]
output_file = invoker.output
}
}
# TODO(zijiehe): May use fuchsia_package in gn-sdk if possible. - http://crbug.com/40935282
# Creates a Fuchsia archive (.far) file using PM from the Fuchsia SDK.
#
# binary (required):

View File

@@ -1,73 +0,0 @@
# 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

@@ -1,252 +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("config/config.gni")
# Internal template for the cmc tool.
#
# Invokes cmc
#
# Example:
#
# ```
# _cmc_tool("validate_cmx") {
# inputs = [ manifest ]
# outputs = [ stamp_file ]
#
# args = [
# "--stamp",
# rebase_path(stamp_file, root_build_dir),
# "validate",
# rebase_path(invoker.manifest),
# ]
# }
# ```
#
# Parameters:
#
# inputs (required)
# List of files that are input for cmc.
# Type: list(path)
#
# outputs (required)
# List paths that are output for the run of cmc.
# Type: list(path)
#
# args (required)
# List command line args for cmc.
# Type: list(path)
#
# deps
# public_deps
# testonly
# visibility
#
template("_cmc_tool") {
action(target_name) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
"testonly",
"visibility",
])
script = "//build/gn_run_binary.py"
_cmc_tool_path = "${fuchsia_tool_dir}/cmc"
assert(defined(invoker.inputs), "inputs is a required parameter.")
assert(defined(invoker.outputs), "outputs is a required parameter.")
assert(defined(invoker.args), "args is a required parameter.")
inputs =
[
_cmc_tool_path,
# Depend on the SDK hash, to ensure rebuild if the SDK tools change.
fuchsia_sdk_manifest_file,
] + invoker.inputs
outputs = invoker.outputs
args = [ rebase_path(_cmc_tool_path, root_build_dir) ] + invoker.args
}
}
# Compiles a Components Framework v2 manifest (.cml) file to .cm
#
# Example:
#
# ```
# cmc_compile(_compiled_manifest_target) {
# forward_variables_from(invoker, [ "deps" ])
# manifest = rebase_path(manifest)
# }
# ```
#
# Parameters:
#
# manifest (required)
# The input Component Framework v2 manifest source (.cml) file.
# The file must have the extension ".cml".
#
# output_name (optional)
# Name of the output file to generate. Defaults to $target_name.
# This should not include a file extension (.cm)
#
# deps
# public_deps
# testonly
# visibility
#
template("cmc_compile") {
output_name = target_name
if (defined(invoker.output_name)) {
output_name = invoker.output_name
}
_cmc_tool(target_name) {
forward_variables_from(invoker,
[
"deps",
"manifest",
"public_deps",
"testonly",
"visibility",
])
assert(defined(manifest), "manifest file required")
inputs = [ manifest ]
output_file = "$target_out_dir/$output_name.cm"
outputs = [ output_file ]
depfile = "$target_out_dir/$target_name.d"
args = [
"compile",
rebase_path(manifest, root_build_dir),
"--output",
rebase_path(output_file, root_build_dir),
"--includeroot",
rebase_path("//", root_build_dir),
"--includepath",
rebase_path("$fuchsia_sdk/pkg/", root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
]
}
}
# Validates a component manifest file
#
# The cmc_validate template will ensure that a given cmx file is conformant to
# the cmx schema, as defined by //tools/cmc/schema.json. A stamp file is
# generated to mark that a given cmx file has passed.
#
# Parameters:
#
# manifest (required)
# [file] The path to the cmx file that is to be validated
#
# deps
# testonly
# visibility
#
template("cmc_validate") {
_cmc_tool(target_name) {
forward_variables_from(invoker,
[
"manifest",
"deps",
"testonly",
"visibility",
])
stamp_file = "$target_gen_dir/$target_name.verified"
assert(defined(manifest), "manifest file required")
inputs = [ manifest ]
outputs = [ stamp_file ]
args = [
"--stamp",
rebase_path(stamp_file, root_build_dir),
"validate",
rebase_path(invoker.manifest),
]
}
}
# Merges multiple component manifest files into one.
#
# Combines mutliple component manifests into a single manifest.
# This is useful for merging fragments of sandbox configurations into
# a single component manifest.
#
# Example
#
# ```
# cmc_merge("combined_cmx") {
# sources = ["sandbox.cmx", "services.cmx", "program.cmx"]
# output_name = "my-component.cmx"
# }
# ```
#
# Parameters
#
# sources
# The list of cmx files to merge together.
#
# Type: list of strings (filepath)
#
# output_name [optional]
# The name of the merged cmx file. This file is created in $target_out_dir.
# If not specified, $target_name.cmx is used.
#
# Type: string
#
# Standard parameters:
# deps
# testonly
# visibility
#
template("cmc_merge") {
_cmc_tool(target_name) {
forward_variables_from(invoker,
[
"deps",
"output_name",
"sources",
"testonly",
"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"
}
merged_output = "${target_out_dir}/${output_name}"
inputs = invoker.sources
outputs = [ merged_output ]
args = [
"merge",
"--output",
rebase_path(merged_output, root_build_dir),
]
foreach(source, sources) {
args += [ rebase_path(source, root_build_dir) ]
}
}
}

View File

@@ -1,252 +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("cmc.gni")
declare_args() {
# Enable code coverage for Fuchsia components. Only applies to v1 components.
fuchsia_code_coverage = false
}
# Defines a Fuchsia component.
# See: https://fuchsia.dev/fuchsia-src/glossary#component
#
# A component is defined by a component manifest.
# A component is a unit of executable software on Fuchsia. When the componet is executed, there are usually many files
# needed at runtime, such as the executable itself, shared libraries, and possibly other data resources. These files are
# specified by using the GN concept of "data_deps".
#
# Components are distributed using a fuchsia package which can contain multiple components. The component manifest and
# the runtime dependencies of the component are packaged using the fuchsia_package rule.
#
# By default, the runtime depenencies of the component are included in the package using relative paths calcualted from
# the "closest" root of: $root_gen_dir, $root_dir, $out_dir. If a specific path is desired in the package, the "resources" parameter can
# be used to explicitly specify the path of a specific file.
#
# A component is launched by a URL which identifies the package and the component manifest.
# See: https://fuchsia.dev/fuchsia-src/glossary#component_url
#
# Example
#
# ```
# fuchsia_component("my_component") {
# manifest = "meta/component-manifest.cmx"
# resources = [
# {
# path = "testdata/use_case1.json"
# dest = "data/testdata/use_case1.json"
# },
# ]
# data_deps = [ ":hello_world_executable"]
# }
# ```
#
# Parameters
#
# manifest
# The source manifest file for this component. This can be either v1 (.cmx)
# or v2 (.cml) manifest.
#
# Type: string (filepath)
#
# data_deps
# The labels of targets that generate the files needed at runtime by the component.
# At minimum, this should include the label of the binary to include in the component.
#
# Type: list of labels
#
# manifest_output_name [optional]
# The name of the manifest file contained in the distribution that this
# component is included in. The output name should have no extension or
# prefixes. The resulting filename will have the extension correct for the
# manifest version. For example, if `manifest` is "foo.cmx"
# and `manifest_output_name` is "bar", the filename will be "bar.cmx". If
# `manifest` is "foo.cml" (a v2 manifest), the filename will be "bar.cm".
#
# Type: string
# Default: The base file name of `manifest` without an extension.
#
# resources [optional]
# Lists additional files to include for runtime access by the component.
# Defines the resources in a package containing this component. A resource
# is a data file that may be produced by the build system, checked in to a
# source repository, or produced by another system that runs before the
# build. Resources are placed in the `data/` directory of the assembled
# package.
#
# Type: list of scopes. Entries in a scope in the resources list:
# path (required)
# Location of resource in source or build directory. If the
# resource is checked in, this will typically be specified
# as a path relative to the BUILD.gn file containing the
# `package()` target. If the resource is generated, this will
# typically be specified relative to `$target_gen_dir`.
#
# dest (required) string (path) Location the resource will be placed within `data/`.
#
# Standard parameters:
# deps
# testonly
# visibility
#
# Metadata
# contents - list of scopes describing files for this component. This metadata is consumed by
# The fuchsia_package rule, which describes the entries used.
# Entries in scope:
# type: the usage type of the element, manifest or resource.
# Each type can have specific properties included in the scope.
# source [type == manifest || resource] The source file to include in
# the package for this component. In the case of v2 components,
# this is the compiled manifest.
# output_name [type == manifest] The basename of the manifest as it should appear in the package.
# manifest_version [type == manifest]
# dest: [type == resource] The package relative path of the resource.
template("fuchsia_component") {
forward_variables_from(invoker,
[
"manifest",
"manifest_output_name",
])
assert(defined(manifest), "manifest file required for this component")
if (!defined(manifest_output_name)) {
manifest_output_name = get_path_info(manifest, "name")
}
# Determine manifest_version from the `manifest` file extension.
_manifest_extension = get_path_info(manifest, "extension")
assert(_manifest_extension == "cmx" || _manifest_extension == "cml",
"Manifest file extension must be .cmx or .cml")
if (_manifest_extension == "cmx") {
_manifest_version = "v1"
} else if (_manifest_extension == "cml") {
_manifest_version = "v2"
}
if (fuchsia_code_coverage) {
if (_manifest_version == "v1") {
merged_manifest = "${target_name}-coverage.cmx"
cmc_merge(merged_manifest) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
sources = [
"${fuchsia_sdk}/build/enable_coverage_data.cmx",
manifest,
]
output_name = merged_manifest
}
manifest = "${target_out_dir}/${merged_manifest}"
}
}
# The component manifest validated using cmx_validation for v1,
# or cmc_compile for v2.
_cm_validation_target =
"${target_name}_validate_" + get_path_info(manifest, "file")
if (_manifest_version == "v1") {
cmc_validate(_cm_validation_target) {
forward_variables_from(invoker, [ "testonly" ])
manifest = manifest
deps = []
if (defined(invoker.deps)) {
deps += invoker.deps
}
if (fuchsia_code_coverage) {
deps += [ ":${merged_manifest}" ]
}
}
_manifest_source = manifest
} else if (_manifest_version == "v2") {
cmc_compile(_cm_validation_target) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
manifest = rebase_path(manifest)
}
_compiled_manifest_outputs = get_target_outputs(":$_cm_validation_target")
_manifest_source = _compiled_manifest_outputs[0]
}
group(target_name) {
forward_variables_from(invoker,
[
"data",
"deps",
"data_deps",
"resources",
"resources_in_json_files",
"testonly",
"visibility",
])
# Data is used for adding files as runtime dependencies. Files used as
# sources in the resources parameter are added as data to make sure
# non-generated files listed are captured as dependencies.
if (!defined(data)) {
data = []
}
if (!defined(resources)) {
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 = []
}
deps += [ ":$_cm_validation_target" ]
# Create the component metadata entries. These capture the manifest information and
# the resources parameter contents. The metadata is intended for the fuchsia_package rule.
component_contents = [
{
type = "manifest"
source = rebase_path(get_path_info(_manifest_source, "abspath"))
output_name = manifest_output_name
manifest_version = _manifest_version
},
]
foreach(resource, resources) {
data += [ resource.path ]
component_contents += [
{
type = "resource"
source = rebase_path(resource.path)
dest = resource.dest
},
]
}
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.
metadata = {
contents = [ component_contents ]
}
}
}

View File

@@ -1,198 +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("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

@@ -1,104 +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("config/config.gni")
# Template for running the pm tool for packaging fuchsia packages.
#
# Parameters
# package_name - defaults to target_name
# archive_manifest - required
# 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
}
# 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,
]
if (command == "build") {
assert(fuchsia_target_api_level != -1,
"Must set a target api level when creating an archive")
args += [
"--api-level=${fuchsia_target_api_level}",
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

@@ -1,373 +0,0 @@
#!/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

@@ -1,63 +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("config/config.gni")
# TODO(akbiggs): Delete this, symbol-index no longer exists, it has been
# replaced with ffx debug symbol-index. I don't think this build rule is being
# used because it would be failing if it was, so it can probably be removed
# safely.
#
# 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

@@ -618,6 +618,8 @@ def to_gn_args(args):
if args.target_os in ['android'] and gn_args['target_cpu'] in ['x64', 'arm64']:
gn_args['dart_use_compressed_pointers'] = True
if args.target_os == 'fuchsia':
gn_args['gn_configs_path'] = '//flutter/build/config/fuchsia/gn_configs.gni'
if args.fuchsia_target_api_level is not None:
gn_args['fuchsia_target_api_level'] = args.fuchsia_target_api_level
elif args.target_os == 'fuchsia':