@@ -9,10 +9,13 @@ import 'package:usage/uuid/uuid.dart';
9
9
10
10
import 'artifacts.dart' ;
11
11
import 'base/common.dart' ;
12
+ import 'base/context.dart' ;
12
13
import 'base/io.dart' ;
13
14
import 'base/process_manager.dart' ;
14
15
import 'globals.dart' ;
15
16
17
+ KernelCompiler get kernelCompiler => context[KernelCompiler ];
18
+
16
19
typedef void CompilerMessageConsumer (String message);
17
20
18
21
class CompilerOutput {
@@ -59,7 +62,10 @@ class _StdoutHandler {
59
62
}
60
63
}
61
64
62
- Future <CompilerOutput > compile (
65
+ class KernelCompiler {
66
+ const KernelCompiler ();
67
+
68
+ Future <CompilerOutput > compile (
63
69
{String sdkRoot,
64
70
String mainPath,
65
71
String outputFilePath,
@@ -73,80 +79,81 @@ Future<CompilerOutput> compile(
73
79
String packagesPath,
74
80
List <String > fileSystemRoots,
75
81
String fileSystemScheme}) async {
76
- final String frontendServer = artifacts.getArtifactPath (
77
- Artifact .frontendServerSnapshotForEngineDartSdk
78
- );
79
-
80
- // This is a URI, not a file path, so the forward slash is correct even on Windows.
81
- if (! sdkRoot.endsWith ('/' ))
82
- sdkRoot = '$sdkRoot /' ;
83
- final String engineDartPath = artifacts.getArtifactPath (Artifact .engineDartBinary);
84
- if (! processManager.canRun (engineDartPath)) {
85
- throwToolExit ('Unable to find Dart binary at $engineDartPath ' );
86
- }
87
- final List <String > command = < String > [
88
- engineDartPath,
89
- frontendServer,
90
- '--sdk-root' ,
91
- sdkRoot,
92
- '--strong' ,
93
- '--target=flutter' ,
94
- ];
95
- if (trackWidgetCreation)
96
- command.add ('--track-widget-creation' );
97
- if (! linkPlatformKernelIn)
98
- command.add ('--no-link-platform' );
99
- if (aot) {
100
- command.add ('--aot' );
101
- command.add ('--tfa' );
102
- }
103
- if (entryPointsJsonFiles != null ) {
104
- for (String entryPointsJson in entryPointsJsonFiles) {
105
- command.addAll (< String > ['--entry-points' , entryPointsJson]);
82
+ final String frontendServer = artifacts.getArtifactPath (
83
+ Artifact .frontendServerSnapshotForEngineDartSdk
84
+ );
85
+
86
+ // This is a URI, not a file path, so the forward slash is correct even on Windows.
87
+ if (! sdkRoot.endsWith ('/' ))
88
+ sdkRoot = '$sdkRoot /' ;
89
+ final String engineDartPath = artifacts.getArtifactPath (Artifact .engineDartBinary);
90
+ if (! processManager.canRun (engineDartPath)) {
91
+ throwToolExit ('Unable to find Dart binary at $engineDartPath ' );
106
92
}
107
- }
108
- if (incrementalCompilerByteStorePath != null ) {
109
- command.add ('--incremental' );
110
- }
111
- if (packagesPath != null ) {
112
- command.addAll (< String > ['--packages' , packagesPath]);
113
- }
114
- if (outputFilePath != null ) {
115
- command.addAll (< String > ['--output-dill' , outputFilePath]);
116
- }
117
- if (depFilePath != null && (fileSystemRoots == null || fileSystemRoots.isEmpty)) {
118
- command.addAll (< String > ['--depfile' , depFilePath]);
119
- }
120
- if (fileSystemRoots != null ) {
121
- for (String root in fileSystemRoots) {
122
- command.addAll (< String > ['--filesystem-root' , root]);
93
+ final List <String > command = < String > [
94
+ engineDartPath,
95
+ frontendServer,
96
+ '--sdk-root' ,
97
+ sdkRoot,
98
+ '--strong' ,
99
+ '--target=flutter' ,
100
+ ];
101
+ if (trackWidgetCreation)
102
+ command.add ('--track-widget-creation' );
103
+ if (! linkPlatformKernelIn)
104
+ command.add ('--no-link-platform' );
105
+ if (aot) {
106
+ command.add ('--aot' );
107
+ command.add ('--tfa' );
123
108
}
124
- }
125
- if (fileSystemScheme != null ) {
126
- command.addAll (< String > ['--filesystem-scheme' , fileSystemScheme]);
127
- }
109
+ if (entryPointsJsonFiles != null ) {
110
+ for (String entryPointsJson in entryPointsJsonFiles) {
111
+ command.addAll (< String > ['--entry-points' , entryPointsJson]);
112
+ }
113
+ }
114
+ if (incrementalCompilerByteStorePath != null ) {
115
+ command.add ('--incremental' );
116
+ }
117
+ if (packagesPath != null ) {
118
+ command.addAll (< String > ['--packages' , packagesPath]);
119
+ }
120
+ if (outputFilePath != null ) {
121
+ command.addAll (< String > ['--output-dill' , outputFilePath]);
122
+ }
123
+ if (depFilePath != null && (fileSystemRoots == null || fileSystemRoots.isEmpty)) {
124
+ command.addAll (< String > ['--depfile' , depFilePath]);
125
+ }
126
+ if (fileSystemRoots != null ) {
127
+ for (String root in fileSystemRoots) {
128
+ command.addAll (< String > ['--filesystem-root' , root]);
129
+ }
130
+ }
131
+ if (fileSystemScheme != null ) {
132
+ command.addAll (< String > ['--filesystem-scheme' , fileSystemScheme]);
133
+ }
134
+
135
+ if (extraFrontEndOptions != null )
136
+ command.addAll (extraFrontEndOptions);
137
+ command.add (mainPath);
138
+ printTrace (command.join (' ' ));
139
+ final Process server = await processManager
140
+ .start (command)
141
+ .catchError ((dynamic error, StackTrace stack) {
142
+ printError ('Failed to start frontend server $error , $stack ' );
143
+ });
128
144
129
- if (extraFrontEndOptions != null )
130
- command.addAll (extraFrontEndOptions);
131
- command.add (mainPath);
132
- printTrace (command.join (' ' ));
133
- final Process server = await processManager
134
- .start (command)
135
- .catchError ((dynamic error, StackTrace stack) {
136
- printError ('Failed to start frontend server $error , $stack ' );
137
- });
138
-
139
- final _StdoutHandler stdoutHandler = new _StdoutHandler ();
140
-
141
- server.stderr
142
- .transform (utf8.decoder)
143
- .listen ((String s) { printError ('compiler message: $s ' ); });
144
- server.stdout
145
- .transform (utf8.decoder)
146
- .transform (const LineSplitter ())
147
- .listen (stdoutHandler.handler);
148
- final int exitCode = await server.exitCode;
149
- return exitCode == 0 ? stdoutHandler.compilerOutput.future : null ;
145
+ final _StdoutHandler stdoutHandler = new _StdoutHandler ();
146
+
147
+ server.stderr
148
+ .transform (utf8.decoder)
149
+ .listen ((String s) { printError ('compiler message: $s ' ); });
150
+ server.stdout
151
+ .transform (utf8.decoder)
152
+ .transform (const LineSplitter ())
153
+ .listen (stdoutHandler.handler);
154
+ final int exitCode = await server.exitCode;
155
+ return exitCode == 0 ? stdoutHandler.compilerOutput.future : null ;
156
+ }
150
157
}
151
158
152
159
/// Wrapper around incremental frontend server compiler, that communicates with
0 commit comments