Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7a6172e

Browse files
authored
Revert "Remove the frontend server wrapper" (#46863)
Reverts #46440 For b/305121780
1 parent ffb3b5b commit 7a6172e

File tree

13 files changed

+538
-201
lines changed

13 files changed

+538
-201
lines changed

build/dart/rules.gni

Lines changed: 67 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -10,115 +10,21 @@ import("//flutter/common/config.gni")
1010
import("//third_party/dart/build/dart/dart_action.gni")
1111
import("//third_party/dart/sdk_args.gni")
1212

13-
# Generates a Dart kernel snapshot using flutter_frontend_server.
14-
#
15-
# Arguments
16-
# main_dart (required):
17-
# The Dart entrypoint file.
18-
#
19-
# kernel_output (required):
20-
# The path to the output kernel snapshot in the out directory.
21-
#
22-
# package_config (optional):
23-
# The path to the package_config.json file.
24-
#
25-
# deps (optional):
26-
# Additional dependencies. Dependencies on the frontend server and
27-
# Flutter's platform.dill are included by default. This rule creates and
28-
# uses a depfile, so listing all Dart sources is not necessary.
29-
#
30-
# extra_args (optional):
31-
# Additional frontend server command line arguments.
32-
template("flutter_frontend_server") {
33-
assert(defined(invoker.main_dart), "The Dart test file must be specified.")
34-
assert(defined(invoker.kernel_output),
35-
"The Dart Kernel file location must be specified.")
36-
37-
kernel_output = invoker.kernel_output
38-
39-
common_deps = [
40-
"//flutter/flutter_frontend_server:frontend_server",
41-
"//flutter/lib/snapshot:strong_platform",
42-
]
43-
if (defined(invoker.deps)) {
44-
common_deps += invoker.deps
45-
}
46-
47-
extra_args = []
48-
if (defined(invoker.extra_args)) {
49-
extra_args += invoker.extra_args
50-
}
51-
52-
packages_args = []
53-
if (defined(invoker.package_config)) {
54-
packages_args += [
55-
"--packages",
56-
rebase_path(invoker.package_config),
57-
]
58-
}
59-
60-
snapshot_depfile = "$kernel_output.d"
61-
62-
common_vm_args = [ "--disable-dart-dev" ]
63-
64-
flutter_patched_sdk = rebase_path("$root_out_dir/flutter_patched_sdk")
65-
66-
common_args = extra_args + packages_args + [
67-
"--sdk-root",
68-
flutter_patched_sdk,
69-
"--target=flutter",
70-
"--depfile",
71-
rebase_path(snapshot_depfile),
72-
"--output-dill",
73-
rebase_path(invoker.kernel_output),
74-
rebase_path(invoker.main_dart),
75-
]
76-
77-
if (flutter_prebuilt_dart_sdk) {
78-
action(target_name) {
79-
forward_variables_from(invoker,
80-
[
81-
"visibility",
82-
"testonly",
83-
],
84-
[ "pool" ])
85-
deps = common_deps
86-
pool = "//flutter/build/dart:dart_pool"
87-
script = "//build/gn_run_binary.py"
88-
inputs = [ invoker.main_dart ]
89-
outputs = [ invoker.kernel_output ]
90-
depfile = snapshot_depfile
91-
92-
ext = ""
93-
if (is_win) {
94-
ext = ".exe"
95-
}
96-
dart = rebase_path("$host_prebuilt_dart_sdk/bin/dart$ext", root_out_dir)
97-
frontend_server =
98-
rebase_path("$root_gen_dir/frontend_server.dart.snapshot")
99-
100-
args = [ dart ] + common_vm_args + [ frontend_server ] + common_args
101-
}
102-
} else {
103-
dart_action(target_name) {
104-
forward_variables_from(invoker,
105-
[
106-
"visibility",
107-
"testonly",
108-
],
109-
[ "pool" ])
110-
deps = common_deps
111-
pool = "//flutter/build/dart:dart_pool"
112-
script = "$root_gen_dir/frontend_server.dart.snapshot"
113-
packages = rebase_path(invoker.package_config)
114-
inputs = [ invoker.main_dart ]
115-
outputs = [ invoker.kernel_output ]
116-
depfile = snapshot_depfile
117-
vm_args = common_vm_args
118-
args = common_args
119-
}
120-
}
121-
}
13+
frontend_server_files =
14+
exec_script("//third_party/dart/tools/list_dart_files.py",
15+
[
16+
"absolute",
17+
rebase_path("//flutter/flutter_frontend_server"),
18+
],
19+
"list lines")
20+
21+
frontend_server_files +=
22+
exec_script("//third_party/dart/tools/list_dart_files.py",
23+
[
24+
"absolute",
25+
rebase_path("//third_party/dart/pkg"),
26+
],
27+
"list lines")
12228

12329
# Creates a dart kernel (dill) file suitable for use with gen_snapshot, as well
12430
# as the app-jit, aot-elf, or aot-assembly snapshot for targeting Flutter on
@@ -142,38 +48,61 @@ template("flutter_snapshot") {
14248

14349
kernel_output = "$target_gen_dir/kernel_blob.bin"
14450

145-
extra_frontend_server_args = []
146-
if (is_aot) {
147-
extra_frontend_server_args += [
148-
"--aot",
149-
"--tfa",
51+
prebuilt_dart_action(kernel_target) {
52+
script = "//flutter/flutter_frontend_server/bin/starter.dart"
53+
54+
main_dart = rebase_path(invoker.main_dart)
55+
package_config = rebase_path(invoker.package_config)
56+
flutter_patched_sdk = rebase_path("$root_out_dir/flutter_patched_sdk")
57+
58+
deps = [ "//flutter/lib/snapshot:strong_platform" ]
59+
60+
inputs = [
61+
main_dart,
62+
package_config,
63+
] + frontend_server_files
64+
65+
outputs = [ kernel_output ]
66+
67+
depfile = "$kernel_output.d"
68+
abs_depfile = rebase_path(depfile)
69+
vm_args = [ "--disable-dart-dev" ]
70+
71+
args = [
72+
"--depfile=$abs_depfile",
73+
"--packages=" + rebase_path(package_config),
74+
"--target=flutter",
75+
"--sdk-root=" + flutter_patched_sdk,
76+
"--output-dill=" + rebase_path(kernel_output, root_build_dir),
15077
]
151-
} else {
152-
# --no-link-platform is only valid when --aot isn't specified
153-
extra_frontend_server_args += [ "--no-link-platform" ]
154-
}
15578

156-
if (defined(invoker.product) && invoker.product) {
157-
# Setting this flag in a non-product release build for AOT (a "profile"
158-
# build) causes the vm service isolate code to be tree-shaken from an app.
159-
# See the pragma on the entrypoint here:
160-
#
161-
# https://github.com/dart-lang/sdk/blob/main/sdk/lib/_internal/vm/bin/vmservice_io.dart#L240
162-
#
163-
# Also, this define excludes debugging and profiling code from Flutter.
164-
extra_frontend_server_args += [ "-Ddart.vm.product=true" ]
165-
} else {
166-
if (flutter_runtime_mode == "profile") {
167-
# The following define excludes debugging code from Flutter.
168-
extra_frontend_server_args += [ "-Ddart.vm.profile=true" ]
79+
if (is_aot) {
80+
args += [
81+
"--aot",
82+
"--tfa",
83+
]
84+
} else {
85+
# --no-link-platform is only valid when --aot isn't specified
86+
args += [ "--no-link-platform" ]
87+
}
88+
89+
if (defined(invoker.product) && invoker.product) {
90+
# Setting this flag in a non-product release build for AOT (a "profile"
91+
# build) causes the vm service isolate code to be tree-shaken from an app.
92+
# See the pragma on the entrypoint here:
93+
#
94+
# https://github.com/dart-lang/sdk/blob/main/sdk/lib/_internal/vm/bin/vmservice_io.dart#L240
95+
#
96+
# Also, this define excludes debugging and profiling code from Flutter.
97+
args += [ "-Ddart.vm.product=true" ]
98+
} else {
99+
if (flutter_runtime_mode == "profile") {
100+
# The following define excludes debugging code from Flutter.
101+
args += [ "-Ddart.vm.profile=true" ]
102+
}
169103
}
170-
}
171104

172-
flutter_frontend_server(kernel_target) {
173-
main_dart = invoker.main_dart
174-
package_config = invoker.package_config
175-
kernel_output = kernel_output
176-
extra_args = extra_frontend_server_args
105+
args += [ rebase_path(main_dart) ]
177106
}
178107

179108
compiled_action(snapshot_target) {
@@ -342,7 +271,7 @@ template("application_snapshot") {
342271
# Ensure the compiled appliation (e.g. frontend-server, ...) will use this
343272
# Dart SDK hash when consuming/producing kernel.
344273
#
345-
# (Instead of ensuring every user of the "application_snapshot" passes its
274+
# (Instead of ensuring every user of the "application_snapshot" passes it's
346275
# own)
347276
snapshot_vm_args += [ "-Dsdk_hash=$sdk_hash" ]
348277

common/config.gni

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,18 @@ if (flutter_prebuilt_dart_sdk) {
113113
_host_os_name = "windows"
114114
}
115115

116-
# When building 32-bit Android development artifacts for Windows host (like
117-
# gen_snapshot), the host_cpu is set to x86. However, the correct prebuilt
118-
# Dart SDK to use during this build is still the 64-bit one.
119-
_host_cpu = host_cpu
120-
if (host_os == "win" && host_cpu == "x86") {
121-
_host_cpu = "x64"
122-
}
123-
124116
_target_prebuilt_dart_sdk_config = "$_target_os_name-$target_cpu"
125-
_host_prebuilt_dart_sdk_config = "$_host_os_name-$_host_cpu"
117+
_host_prebuilt_dart_sdk_config = "$_host_os_name-$host_cpu"
126118

127119
target_prebuilt_dart_sdk =
128120
"//flutter/prebuilts/$_target_prebuilt_dart_sdk_config/dart-sdk"
129121
host_prebuilt_dart_sdk =
130122
"//flutter/prebuilts/$_host_prebuilt_dart_sdk_config/dart-sdk"
131123

132-
# There is no prebuilt Dart SDK targeting Fuchsia, iOS, and Android, but we
133-
# also don't need one, so even when the build is targeting one of these
134-
# platforms, we use the prebuilt Dart SDK for the host.
135-
if (current_toolchain == host_toolchain || target_os == "android" ||
136-
target_os == "fuchsia" || target_os == "ios" || target_os == "wasm") {
124+
# There is no prebuilt Dart SDK targeting Fuchsia, but we also don't need
125+
# one, so even when the build is targeting Fuchsia, use the prebuilt
126+
# Dart SDK for the host.
127+
if (current_toolchain == host_toolchain || is_fuchsia || is_wasm) {
137128
prebuilt_dart_sdk = host_prebuilt_dart_sdk
138129
prebuilt_dart_sdk_config = _host_prebuilt_dart_sdk_config
139130
} else {

flutter_frontend_server/BUILD.gn

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5-
import("//flutter/common/config.gni")
5+
import("//flutter/build/dart/rules.gni")
66

7-
copy("frontend_server") {
8-
if (flutter_prebuilt_dart_sdk) {
9-
snapshot =
10-
"$host_prebuilt_dart_sdk/bin/snapshots/frontend_server.dart.snapshot"
11-
} else {
12-
deps = [ "//flutter/build/dart:dart_sdk" ]
13-
snapshot =
14-
"$root_out_dir/dart-sdk/bin/snapshots/frontend_server.dart.snapshot"
15-
}
7+
application_snapshot("frontend_server") {
8+
main_dart = "bin/starter.dart"
9+
deps = [ "//flutter/lib/snapshot:kernel_platform_files" ]
1610

17-
sources = [ snapshot ]
18-
outputs = [ "$root_gen_dir/frontend_server.dart.snapshot" ]
11+
package_config = rebase_path(".dart_tool/package_config.json")
12+
flutter_patched_sdk = rebase_path("$root_out_dir/flutter_patched_sdk")
13+
training_args = [
14+
"--train",
15+
"--sdk-root=$flutter_patched_sdk",
16+
rebase_path(main_dart),
17+
]
18+
19+
inputs = frontend_server_files
1920
}

flutter_frontend_server/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Frontend Server
2+
3+
Frontend server is simple wrapper around Dart Frontend. It is a Dart application
4+
that compiles Dart source into Dart Kernel binary (.dill-file).
5+
Documentation on Dart Kernel (semantic, binary format, etc) can be found here:
6+
https://github.com/dart-lang/sdk/wiki/Kernel-Documentation.
7+
8+
Frontend server runs in two modes:
9+
- immediate mode, where Dart source file name is provided as command line
10+
argument;
11+
- interactive mode, where communication is happening over stdin/stdout.
12+
13+
## Interactive mode instructions
14+
15+
### Compile/Recompile
16+
```
17+
compile <input.dart>
18+
```
19+
Compiles <input.dart> Dart source file with Dart Frontend. Replies with `result` response.
20+
21+
```
22+
recompile <boundary-key>
23+
<path/to/updated/file1.dart>
24+
<path/to/updated/file2.dart>
25+
...
26+
<boundary-key>
27+
```
28+
Incrementally recompiles Dart program previously compiled in current session, taking into account
29+
changes in the listed files. Replies with `result` response.
30+
31+
Relative paths should be relative to current working directory for the shell that launched
32+
Frontend Server.
33+
34+
### Accept/Reject
35+
```
36+
accept
37+
```
38+
Accepts results of incremental compilation, so that on next recompilation request Dart Frontend
39+
will not include these recompiled files.
40+
```
41+
reject
42+
```
43+
Rejects results of incremental compilation, so that on next recompilation request Dart Frontend
44+
will include compilation results from previously rejected recompilation in addition to what it
45+
will recompile based on newly changed files.
46+
Small technical detail is that Dart Frontend will not recompile files from previously rejected
47+
recompilation attempts (unless they were changed since then), it will just include appropriate
48+
kernel binaries it kept around from those previously rejected compilation requests.
49+
50+
One use of `accept` and `reject` instructions is in the context of Dart VM hot-reload. Dart VM can
51+
reject user-provided incremental change to what is currently running. It could happen for variety
52+
of Dart VM internal reasons. For example, if incremental update changes some `class` to `enum`,
53+
such update can not be hot-reloaded by VM at this point, will be rejected.
54+
55+
### Quit
56+
```
57+
quit
58+
```
59+
Stops the server.
60+
61+
## Response from the server
62+
63+
```
64+
result <boundary-key>
65+
<compiler output>
66+
<boundary-key> [<output.dill>]
67+
```
68+
Response from the Dart Frontend compiler is bracketed by `<boundary-key>` tags. If the compiler
69+
was able to produce a Dart Kernel file, the name of this file `<output.dill>` is provided too.
70+
If the compiler encountered unrecoverable errors, there will be no output file name provided.
71+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
6+
import 'dart:io';
7+
8+
import 'package:flutter_frontend_server/server.dart';
9+
10+
Future<void> main(List<String> args) async {
11+
final int exitCode = await starter(args);
12+
if (exitCode != 0) {
13+
exit(exitCode);
14+
}
15+
}

0 commit comments

Comments
 (0)