Skip to content

Commit da71c38

Browse files
Create a package-able incremental compiler (flutter#12681)
1 parent daf1eb9 commit da71c38

File tree

5 files changed

+179
-82
lines changed

5 files changed

+179
-82
lines changed

frontend_server/BUILD.gn

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,26 @@ if (is_fuchsia_host || is_fuchsia) {
4040
} else {
4141
import("//third_party/dart/utils/application_snapshot.gni")
4242

43+
frontend_server_files =
44+
exec_script("//third_party/dart/tools/list_dart_files.py",
45+
[
46+
"absolute",
47+
rebase_path("."),
48+
],
49+
"list lines")
50+
51+
frontend_server_files +=
52+
exec_script("//third_party/dart/tools/list_dart_files.py",
53+
[
54+
"absolute",
55+
rebase_path("../../third_party/dart/pkg"),
56+
],
57+
"list lines")
58+
4359
application_snapshot("frontend_server") {
4460
main_dart = "bin/starter.dart"
4561
deps = [
62+
":package_incremental_compiler",
4663
"$flutter_root/lib/snapshot:kernel_platform_files",
4764
]
4865
dot_packages = rebase_path(".packages")
@@ -53,22 +70,28 @@ if (is_fuchsia_host || is_fuchsia) {
5370
rebase_path(main_dart),
5471
]
5572

56-
frontend_server_files =
57-
exec_script("//third_party/dart/tools/list_dart_files.py",
58-
[
59-
"absolute",
60-
rebase_path("."),
61-
],
62-
"list lines")
63-
64-
frontend_server_files +=
65-
exec_script("//third_party/dart/tools/list_dart_files.py",
66-
[
67-
"absolute",
68-
rebase_path("../../third_party/dart/pkg"),
69-
],
70-
"list lines")
73+
inputs = frontend_server_files
74+
}
75+
76+
# For flutter/flutter#36738 we make the source files available so that
77+
# we can generate a local frontend_server snapshot in the tools cache.
78+
action("package_incremental_compiler") {
79+
script = "$flutter_root/frontend_server/package_incremental.py"
7180

7281
inputs = frontend_server_files
82+
83+
outputs = [
84+
"$root_build_dir/dist/packages/frontend_server/pubspec.yaml",
85+
"$root_build_dir/dist/packages/vm/pubspec.yaml",
86+
"$root_build_dir/dist/packages/build_integration/pubspec.yaml",
87+
88+
"$root_build_dir/dist/packages/front_end/pubspec.yaml",
89+
"$root_build_dir/dist/packages/kernel/pubspec.yaml",
90+
]
91+
92+
args = [
93+
"--input-root=" + rebase_path("//third_party/dart/pkg"),
94+
"--output-root=" + rebase_path("$root_gen_dir/dart-pkg"),
95+
]
7396
}
7497
}

frontend_server/lib/server.dart

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,30 @@ import 'package:args/args.dart';
1111
import 'package:path/path.dart' as path;
1212

1313
import 'package:vm/incremental_compiler.dart';
14-
import 'package:vm/frontend_server.dart' as frontend show FrontendCompiler,
15-
CompilerInterface, listenAndCompile, argParser, usage;
14+
import 'package:vm/frontend_server.dart' as frontend
15+
show
16+
FrontendCompiler,
17+
CompilerInterface,
18+
listenAndCompile,
19+
argParser,
20+
usage,
21+
ProgramTransformer;
1622

1723
/// Wrapper around [FrontendCompiler] that adds [widgetCreatorTracker] kernel
1824
/// transformation to the compilation.
19-
class _FlutterFrontendCompiler implements frontend.CompilerInterface{
25+
class _FlutterFrontendCompiler implements frontend.CompilerInterface {
2026
final frontend.CompilerInterface _compiler;
2127

2228
_FlutterFrontendCompiler(StringSink output,
23-
{bool unsafePackageSerialization}) :
24-
_compiler = frontend.FrontendCompiler(output,
25-
unsafePackageSerialization: unsafePackageSerialization);
29+
{bool unsafePackageSerialization,
30+
frontend.ProgramTransformer transformer})
31+
: _compiler = frontend.FrontendCompiler(output,
32+
transformer: transformer,
33+
unsafePackageSerialization: unsafePackageSerialization);
2634

2735
@override
28-
Future<bool> compile(String filename, ArgResults options, {IncrementalCompiler generator}) async {
36+
Future<bool> compile(String filename, ArgResults options,
37+
{IncrementalCompiler generator}) async {
2938
return _compiler.compile(filename, options, generator: generator);
3039
}
3140

@@ -57,8 +66,8 @@ class _FlutterFrontendCompiler implements frontend.CompilerInterface{
5766
String libraryUri,
5867
String klass,
5968
bool isStatic) {
60-
return _compiler.compileExpression(expression, definitions, typeDefinitions,
61-
libraryUri, klass, isStatic);
69+
return _compiler.compileExpression(
70+
expression, definitions, typeDefinitions, libraryUri, klass, isStatic);
6271
}
6372

6473
@override
@@ -77,11 +86,12 @@ class _FlutterFrontendCompiler implements frontend.CompilerInterface{
7786
/// `compiler` is an optional parameter so it can be replaced with mocked
7887
/// version for testing.
7988
Future<int> starter(
80-
List<String> args, {
81-
frontend.CompilerInterface compiler,
82-
Stream<List<int>> input,
83-
StringSink output,
84-
}) async {
89+
List<String> args, {
90+
frontend.CompilerInterface compiler,
91+
Stream<List<int>> input,
92+
StringSink output,
93+
frontend.ProgramTransformer transformer,
94+
}) async {
8595
ArgResults options;
8696
try {
8797
options = frontend.argParser.parse(args);
@@ -98,7 +108,8 @@ Future<int> starter(
98108

99109
final String input = options.rest[0];
100110
final String sdkRoot = options['sdk-root'];
101-
final Directory temp = Directory.systemTemp.createTempSync('train_frontend_server');
111+
final Directory temp =
112+
Directory.systemTemp.createTempSync('train_frontend_server');
102113
try {
103114
final String outputTrainingDill = path.join(temp.path, 'app.dill');
104115
options = frontend.argParser.parse(<String>[
@@ -126,6 +137,7 @@ Future<int> starter(
126137
}
127138

128139
compiler ??= _FlutterFrontendCompiler(output,
140+
transformer: transformer,
129141
unsafePackageSerialization: options['unsafe-package-serialization']);
130142

131143
if (options.rest.isNotEmpty) {
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env python
2+
# Copyright 2013 The Flutter Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
import argparse
7+
import os
8+
import shutil
9+
import sys
10+
11+
# The list of packages copied from the Dart SDK.
12+
PACKAGES = [
13+
"vm", "build_integration", "kernel", "front_end", "frontend_server",
14+
]
15+
16+
VM_PUBSPEC = r'''name: vm
17+
version: 0.0.1
18+
environment:
19+
sdk: ">=2.2.2 <3.0.0"
20+
21+
dependencies:
22+
front_end: any
23+
kernel: any
24+
meta: any
25+
build_integration: any
26+
'''
27+
28+
BUILD_INTEGRATION_PUBSPEC = r'''name: build_integration
29+
version: 0.0.1
30+
environment:
31+
sdk: ">=2.2.2 <3.0.0"
32+
33+
dependencies:
34+
front_end: any
35+
meta: any
36+
'''
37+
38+
FRONTEND_SERVER_PUBSPEC = r'''name: frontend_server
39+
version: 0.0.1
40+
environment:
41+
sdk: ">=2.2.2 <3.0.0"
42+
43+
dependencies:
44+
args: any
45+
path: any
46+
vm: any
47+
'''
48+
49+
KERNEL_PUBSPEC = r'''name: kernel
50+
version: 0.0.1
51+
environment:
52+
sdk: '>=2.2.2 <3.0.0'
53+
54+
dependencies:
55+
args: any
56+
meta: any
57+
'''
58+
59+
FRONT_END_PUBSPEC = r'''name: front_end
60+
version: 0.0.1
61+
environment:
62+
sdk: '>=2.2.2 <3.0.0'
63+
dependencies:
64+
kernel: any
65+
package_config: any
66+
meta: any
67+
'''
68+
69+
PUBSPECS = {
70+
'vm': VM_PUBSPEC,
71+
'build_integration': BUILD_INTEGRATION_PUBSPEC,
72+
'frontend_server': FRONTEND_SERVER_PUBSPEC,
73+
'kernel': KERNEL_PUBSPEC,
74+
'front_end': FRONT_END_PUBSPEC,
75+
}
76+
77+
def main():
78+
parser = argparse.ArgumentParser()
79+
parser.add_argument('--input-root', type=str, dest='input', action='store')
80+
parser.add_argument('--output-root', type=str, dest='output', action='store')
81+
82+
args = parser.parse_args()
83+
for package in PACKAGES:
84+
package_root = os.path.join(args.input, package)
85+
for root, directories, files in os.walk(package_root):
86+
# We only care about actual source files, not generated code or tests.
87+
for skip_dir in ['.git', 'gen', 'test']:
88+
if skip_dir in directories:
89+
directories.remove(skip_dir)
90+
91+
# Ensure we have a dest directory
92+
if not os.path.isdir(os.path.join(args.output, package)):
93+
os.makedirs(os.path.join(args.output, package))
94+
95+
for filename in files:
96+
if filename.endswith('.dart') and not filename.endswith('_test.dart'):
97+
destination_file = os.path.join(args.output, package,
98+
os.path.relpath(os.path.join(root, filename), start=package_root))
99+
parent_path = os.path.abspath(os.path.join(destination_file, os.pardir))
100+
if not os.path.isdir(parent_path):
101+
os.makedirs(parent_path)
102+
shutil.copyfile(os.path.join(root, filename), destination_file)
103+
104+
# Write the overriden pubspec for each package.
105+
pubspec_file = os.path.join(args.output, package, 'pubspec.yaml')
106+
with open(pubspec_file, 'w+') as output_file:
107+
output_file.write(PUBSPECS[package])
108+
109+
if __name__ == '__main__':
110+
sys.exit(main())

frontend_server/pubspec.yaml

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ description: Communication pipe to Dart Frontend
44
homepage: http://flutter.io
55
author: Flutter Authors <[email protected]>
66

7+
environment:
8+
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
9+
sdk: ">=2.2.2 <3.0.0"
10+
711
dependencies:
812
args: any
913
async: any
@@ -22,36 +26,3 @@ dependencies:
2226
typed_data: any
2327
usage: any
2428
vm: any
25-
26-
dev_dependencies:
27-
analyzer: any
28-
boolean_selector: any
29-
cli_util: any
30-
csslib: any
31-
glob: any
32-
html: any
33-
http: any
34-
http_multi_server: any
35-
http_parser: any
36-
matcher: any
37-
mime: any
38-
mockito: any
39-
package_resolver: any
40-
plugin: any
41-
pool: any
42-
pub_semver: any
43-
shelf: any
44-
shelf_packages_handler: any
45-
shelf_static: any
46-
shelf_web_socket: any
47-
source_map_stack_trace: any
48-
source_maps: any
49-
stack_trace: any
50-
stream_channel: any
51-
string_scanner: any
52-
test: any
53-
utf: any
54-
watcher: any
55-
web_socket_channel: any
56-
when: any
57-
yaml: any

frontend_server/test/server_test.dart

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)