Skip to content

Commit 39592d1

Browse files
author
Rich Kadel
committed
Fix building Dart Fuchsia components and packages
The previous PR did not build the Fuchsia packages correctly: > GN build rules for tests using Fuchsia SDK Dart libraries and bindings flutter-team-archive#27996 The new changes bring in more of the Fuchsia GN-SDK build rules. Some changes to these rules were required because the fuchsia.git-derived flutter/dart build rules depend on a different implementation of similar-sounding rules (fuchsia.git <> Fuchsia GN SDK, regarding build rule implementations). I renamed flutter/tools/fuchsia/sdk to flutter/tools/fuchsia/gn-sdk to be more clear that GN SDK was the original source. Also, I realized there were still some references to python3.8 and python3_action. Now that flutter is building with python3 by default, that action is no longer needed, so I've removed it. Fixes: flutter/flutter#87999 (because the original fix had deficiencies) Tested in Fuchsia and confirmed the dart package/component launches and runs.
1 parent 344c728 commit 39592d1

32 files changed

Lines changed: 384 additions & 980 deletions

‎tools/fuchsia/dart/dart_build_config.gni‎

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,42 @@ dart_debug_build_cfg = {
1313
enable_asserts = true
1414
}
1515

16-
# Builds the component in a non-product AOT build. This will
17-
# launch the vm service in the runner.
18-
# This configuration is not compatible with a --release build since the
19-
# profile aot runner is built without asserts.
20-
dart_aot_debug_build_cfg = {
21-
runtime_meta = "//flutter/shell/platform/fuchsia/dart_runner/meta/aot_runtime"
22-
runner_dep = "//flutter/shell/platform/fuchsia/dart_runner:dart_aot_runner"
23-
platform_name = "dart_runner"
24-
is_aot = true
25-
is_product = false
26-
enable_asserts = true
27-
}
16+
# TODO(richkadel): Don't confuse these settings with those in dart_build_config.gni,
17+
# in fact, do I really need both? Can I drop flutter_build_config.gni?
2818

29-
# Builds the component in a non-product AOT build. This will
30-
# launch the vm service in the runner.
31-
dart_profile_build_cfg = {
32-
runtime_meta = "//flutter/shell/platform/fuchsia/dart_runner/meta/aot_runtime"
33-
runner_dep = "//flutter/shell/platform/fuchsia/dart_runner:dart_aot_runner"
34-
platform_name = "dart_runner"
35-
is_aot = true
36-
is_product = false
37-
enable_asserts = false
38-
}
19+
# # Builds the component in a non-product AOT build. This will
20+
# # launch the vm service in the runner.
21+
# # This configuration is not compatible with a --release build since the
22+
# # profile aot runner is built without asserts.
23+
# dart_aot_debug_build_cfg = {
24+
# runtime_meta = "//flutter/shell/platform/fuchsia/dart_runner/meta/aot_runtime"
25+
# runner_dep = "//flutter/shell/platform/fuchsia/dart_runner:dart_aot_runner"
26+
# platform_name = "dart_runner"
27+
# is_aot = true
28+
# is_product = false
29+
# enable_asserts = true
30+
# }
3931

40-
# Builds the component in a product AOT build. This will
41-
# not launch the vm service in the runner.
42-
dart_release_build_cfg = {
43-
runtime_meta =
44-
"//flutter/shell/platform/fuchsia/dart_runner/meta/aot_product_runtime"
45-
runner_dep =
46-
"//flutter/shell/platform/fuchsia/dart_runner:dart_aot_product_runner"
47-
platform_name = "dart_runner"
48-
is_aot = true
49-
is_product = true
50-
enable_asserts = false
51-
}
32+
# # Builds the component in a non-product AOT build. This will
33+
# # launch the vm service in the runner.
34+
# dart_profile_build_cfg = {
35+
# runtime_meta = "//flutter/shell/platform/fuchsia/dart_runner/meta/aot_runtime"
36+
# runner_dep = "//flutter/shell/platform/fuchsia/dart_runner:dart_aot_runner"
37+
# platform_name = "dart_runner"
38+
# is_aot = true
39+
# is_product = false
40+
# enable_asserts = false
41+
# }
42+
43+
# # Builds the component in a product AOT build. This will
44+
# # not launch the vm service in the runner.
45+
# dart_release_build_cfg = {
46+
# runtime_meta =
47+
# "//flutter/shell/platform/fuchsia/dart_runner/meta/aot_product_runtime"
48+
# runner_dep =
49+
# "//flutter/shell/platform/fuchsia/dart_runner:dart_aot_product_runner"
50+
# platform_name = "dart_runner"
51+
# is_aot = true
52+
# is_product = true
53+
# enable_asserts = false
54+
# }

‎tools/fuchsia/dart/dart_library.gni‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import("//flutter/tools/fuchsia/dart/dart.gni")
66
import("//flutter/tools/fuchsia/dart/dart_package_config.gni")
77
import("//flutter/tools/fuchsia/dart/toolchain.gni")
8-
import("//flutter/tools/python/python3_action.gni")
98

109
# Defines a Dart library
1110
#
@@ -248,7 +247,7 @@ if (current_toolchain == dart_toolchain) {
248247
# Also warn if nonexistent files are included in sources.
249248
if (!disable_source_verification) {
250249
source_verification_target_name = "${target_name}_source_verification"
251-
python3_action(source_verification_target_name) {
250+
action(source_verification_target_name) {
252251
script = "//flutter/tools/fuchsia/dart/verify_sources.py"
253252
output_file = "$target_gen_dir/$target_name.missing"
254253

@@ -293,7 +292,7 @@ if (current_toolchain == dart_toolchain) {
293292
# analyzer, which recursively reads all sources.
294293
_all_deps_sources_target = "${target_name}.all_deps_sources"
295294
_all_deps_sources_file = "${target_gen_dir}/${target_name}.all_deps_sources"
296-
python3_action(_all_deps_sources_target) {
295+
action(_all_deps_sources_target) {
297296
forward_variables_from(invoker, [ "testonly" ])
298297

299298
script = "//flutter/tools/fuchsia/dart/merge_deps_sources.py"

‎tools/fuchsia/dart/dart_package_config.gni‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ template("dart_package_config") {
7777
"visibility",
7878
])
7979

80-
script =
81-
get_label_info("//flutter/tools/fuchsia/dart:gen_dart_package_config",
82-
"target_out_dir") + "/gen_dart_package_config.pyz"
80+
script = "//flutter/tools/fuchsia/dart/gen_dart_package_config.py"
8381

8482
inputs = [ intermediate_file ]
8583
outputs = [ package_config_file ]

‎tools/fuchsia/dart/dart_tool.gni‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import("//flutter/tools/fuchsia/dart/dart_library.gni")
66
import("//flutter/tools/fuchsia/dart/dart_package_config.gni")
77
import("//flutter/tools/fuchsia/dart/toolchain.gni")
88

9-
import("//flutter/tools/python/python3_action.gni")
10-
119
# Wraps a dart snapshot in a script to be invoked by dart
1210
#
1311
# Parameters
@@ -35,7 +33,7 @@ template("_dart_snapshot_invocation") {
3533
}
3634

3735
# Builds a convenience script to invoke the app.
38-
python3_action(target_name) {
36+
action(target_name) {
3937
forward_variables_from(invoker,
4038
[
4139
"testonly",

‎tools/fuchsia/dart/gen_app_invocation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3.8
1+
#!/usr/bin/env vpython3
22
# Copyright 2013 The Flutter Authors. All rights reserved.
33
# Use of this source code is governed by a BSD-style license that can be
44
# found in the LICENSE file.

‎tools/fuchsia/dart/gen_dart_package_config.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3.8
1+
#!/usr/bin/env vpython3
22
# Copyright 2013 The Flutter Authors. All rights reserved.
33
# Use of this source code is governed by a BSD-style license that can be
44
# found in the LICENSE file.

‎tools/fuchsia/dart/kernel/convert_manifest_to_json.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3.8
1+
#!/usr/bin/env vpython3
22
# Copyright 2013 The Flutter Authors. All rights reserved.
33
# Use of this source code is governed by a BSD-style license that can be
44
# found in the LICENSE file.
@@ -12,23 +12,25 @@
1212
import os
1313
import sys
1414

15-
Entry = collections.namedtuple('Entry', ['source', 'destination'])
15+
Entry = collections.namedtuple('Entry', ['source', 'dest'])
1616

1717

18-
def collect(lines):
18+
def collect(path_prefix, lines):
1919
'''Reads the kernel manifest and creates an array of Entry objects.
2020
- lines: a list of lines from the manifest
2121
'''
2222
entries = []
2323
for line in lines:
2424
values = line.split("=", 1)
25-
entries.append(Entry(source=values[1], destination=values[0]))
25+
entries.append(Entry(source=path_prefix + values[1], dest=values[0]))
2626

2727
return entries
2828

2929

3030
def main():
3131
parser = argparse.ArgumentParser(description=__doc__)
32+
parser.add_argument(
33+
'--path_prefix', help='Directory path containing the manifest entry sources', required=True)
3234
parser.add_argument(
3335
'--input', help='Path to original manifest', required=True)
3436
parser.add_argument(
@@ -38,7 +40,7 @@ def main():
3840
with open(args.input, 'r') as input_file:
3941
contents = input_file.read().splitlines()
4042

41-
entries = collect(contents)
43+
entries = collect(args.path_prefix, contents)
4244

4345
if entries is None:
4446
return 1

‎tools/fuchsia/dart/kernel/dart_kernel.gni‎

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import("//flutter/tools/fuchsia/dart/config.gni")
2626
import("//flutter/tools/fuchsia/dart/dart_library.gni")
2727
import("//flutter/tools/fuchsia/dart/toolchain.gni")
2828

29-
import("//flutter/tools/python/python3_action.gni")
30-
3129
_gen_kernel_label =
3230
"//flutter/tools/fuchsia/dart/kernel:gen_kernel($host_toolchain)"
3331
_gen_kernel_path =
@@ -46,7 +44,7 @@ flutter_platform_name = "flutter_runner"
4644
template("_convert_kernel_manifest") {
4745
assert(defined(invoker.manifest), "dart_kernel() requires a manifest")
4846

49-
python3_action(target_name) {
47+
action(target_name) {
5048
forward_variables_from(invoker,
5149
[
5250
"deps",
@@ -58,6 +56,8 @@ template("_convert_kernel_manifest") {
5856

5957
script = "//flutter/tools/fuchsia/dart/kernel/convert_manifest_to_json.py"
6058
args = [
59+
"--path_prefix",
60+
rebase_path(root_out_dir) + "/",
6161
"--input",
6262
rebase_path(invoker.manifest, root_build_dir),
6363
"--output",
@@ -157,12 +157,16 @@ template("dart_kernel") {
157157
_kernel_deps += invoker.deps
158158
}
159159

160+
# TODO(richkadel): The manifest is currently used by flutter_dart_component, to populate the file
161+
# it calls `_convert_kernel_manifest_file`, so I can't make this conditional, right? Or is it
162+
# possible to build Dart AOT Fuchsia packages/components without the data in this file (in which
163+
# case I should make it conditional there as well)?
160164
_generate_manifest = false
161165
if (invoker.is_aot) {
162166
not_needed(invoker, [ "generate_manifest" ])
163167
} else {
164-
if (defined(invoker.generate_manifest) && invoker.generate_manifest) {
165-
_generate_manifest = true
168+
if (defined(invoker.generate_manifest)) {
169+
_generate_manifest = invoker.generate_manifest
166170
}
167171
}
168172

@@ -185,7 +189,7 @@ template("dart_kernel") {
185189
_group_deps += [ ":$_convert_target_name" ]
186190
}
187191

188-
python3_action(_kernel_target_name) {
192+
action(_kernel_target_name) {
189193
forward_variables_from(invoker,
190194
[
191195
"testonly",
@@ -271,6 +275,11 @@ template("dart_kernel") {
271275
rebase_path(_kernel_path, root_build_dir),
272276
]
273277

278+
# TODO(richkadel): Chase said these are not needed in flutter/engine tests,
279+
# but I believe they are needed (at least for non-AOT builds; I haven't
280+
# tested AOT yet) because the generated manifest is used to produce the
281+
# Fuchsia package manifest... the list of Dart libraries, etc. to be added
282+
# to the Fuchsia package.
274283
if (_generate_manifest) {
275284
args += [
276285
"--split-output-by-packages",
@@ -279,11 +288,17 @@ template("dart_kernel") {
279288
]
280289
}
281290

282-
if (is_debug) {
283-
args += [ "--embed-sources" ]
284-
} else {
285-
args += [ "--no-embed-sources" ]
286-
}
291+
# TODO(richkadel): NEED TO VALIDATE AND/OR CLEAN UP `is_debug` and `is_aot`.
292+
# `is_debug` is set by the flutter `gn` script to true if --unoptimized,
293+
# but `--unoptimized` is broken for Fuchsia, according to an open bug in
294+
# github flutter/flutter issues. But I have a feeling `is_debug` from
295+
# Fuchsia scripts may have a different meaning for dart/flutter at least.
296+
# if (is_debug) {
297+
args += [ "--embed-sources" ]
298+
299+
# } else {
300+
# args += [ "--no-embed-sources" ]
301+
# }
287302

288303
if (invoker.is_aot) {
289304
args += [
@@ -302,10 +317,12 @@ template("dart_kernel") {
302317
# This define excludes debugging and profiling code from Flutter.
303318
args += [ "-Ddart.vm.product=true" ]
304319
} else {
305-
if (!is_debug) {
306-
# The following define excludes debugging code from Flutter.
307-
args += [ "-Ddart.vm.profile=true" ]
308-
}
320+
# TODO(richkadel): I'm pretty sure we want to assume is_debug even if that's
321+
# not what's set by gn flags (--unoptimized = false because true is currentlyh broken for Fuchsia?)
322+
# if (!is_debug) {
323+
# # The following define excludes debugging code from Flutter.
324+
# args += [ "-Ddart.vm.profile=true" ]
325+
# }
309326
}
310327

311328
if (defined(invoker.main_dart)) {
@@ -324,6 +341,6 @@ template("dart_kernel") {
324341
"testonly",
325342
"visibility",
326343
])
327-
deps = _group_deps
344+
public_deps = _group_deps
328345
}
329346
}

‎tools/fuchsia/dart/merge_deps_sources.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3.8
1+
#!/usr/bin/env vpython3
22
"""Merges sources of a Dart target and its dependencies"""
33

44
# Copyright 2013 The Flutter Authors. All rights reserved.

‎tools/fuchsia/dart/verify_sources.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3.8
1+
#!/usr/bin/env vpython3
22

33
# Copyright 2013 The Flutter Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be

0 commit comments

Comments
 (0)