@@ -7,7 +7,6 @@ import 'dart:typed_data';
7
7
8
8
import 'package:meta/meta.dart' ;
9
9
import 'package:package_config/package_config.dart' ;
10
- import 'package:pool/pool.dart' ;
11
10
import 'package:process/process.dart' ;
12
11
import 'package:usage/uuid/uuid.dart' ;
13
12
@@ -17,7 +16,6 @@ import 'base/file_system.dart';
17
16
import 'base/io.dart' ;
18
17
import 'base/logger.dart' ;
19
18
import 'base/platform.dart' ;
20
- import 'base/process.dart' ;
21
19
import 'build_info.dart' ;
22
20
import 'convert.dart' ;
23
21
@@ -591,7 +589,7 @@ abstract class ResidentCompiler {
591
589
/// Should be invoked when results of compilation are accepted by the client.
592
590
///
593
591
/// Either [accept] or [reject] should be called after every [recompile] call.
594
- Future < void > accept ();
592
+ void accept ();
595
593
596
594
/// Should be invoked when results of compilation are rejected by the client.
597
595
///
@@ -601,7 +599,7 @@ abstract class ResidentCompiler {
601
599
/// Should be invoked when frontend server compiler should forget what was
602
600
/// accepted previously so that next call to [recompile] produces complete
603
601
/// kernel file.
604
- Future < void > reset ();
602
+ void reset ();
605
603
606
604
Future <Object > shutdown ();
607
605
}
@@ -744,9 +742,11 @@ class DefaultResidentCompiler implements ResidentCompiler {
744
742
final String inputKey = Uuid ().generateV4 ();
745
743
746
744
if (nativeAssets != null && nativeAssets.isNotEmpty) {
747
- await _writelnToServerStdin ('native-assets $nativeAssets ' , printTrace: true );
745
+ server.stdin.writeln ('native-assets $nativeAssets ' );
746
+ _logger.printTrace ('<- native-assets $nativeAssets ' );
748
747
}
749
- await _writelnToServerStdin ('recompile $mainUri $inputKey ' , printTrace: true );
748
+ server.stdin.writeln ('recompile $mainUri $inputKey ' );
749
+ _logger.printTrace ('<- recompile $mainUri $inputKey ' );
750
750
final List <Uri >? invalidatedFiles = request.invalidatedFiles;
751
751
if (invalidatedFiles != null ) {
752
752
for (final Uri fileUri in invalidatedFiles) {
@@ -761,7 +761,8 @@ class DefaultResidentCompiler implements ResidentCompiler {
761
761
_logger.printTrace (message);
762
762
}
763
763
}
764
- await _writelnToServerStdin (inputKey, printTrace: true );
764
+ server.stdin.writeln (inputKey);
765
+ _logger.printTrace ('<- $inputKey ' );
765
766
766
767
return _stdoutHandler.compilerOutput? .future;
767
768
}
@@ -898,10 +899,12 @@ class DefaultResidentCompiler implements ResidentCompiler {
898
899
}));
899
900
900
901
if (nativeAssetsUri != null && nativeAssetsUri.isNotEmpty) {
901
- await _writelnToServerStdin ('native assets $nativeAssetsUri ' , printTrace: true );
902
+ _server? .stdin.writeln ('native-assets $nativeAssetsUri ' );
903
+ _logger.printTrace ('<- native-assets $nativeAssetsUri ' );
902
904
}
903
905
904
- await _writelnToServerStdin ('compile $scriptUri ' , printTrace: true );
906
+ _server? .stdin.writeln ('compile $scriptUri ' );
907
+ _logger.printTrace ('<- compile $scriptUri ' );
905
908
906
909
return _stdoutHandler.compilerOutput? .future;
907
910
}
@@ -942,24 +945,24 @@ class DefaultResidentCompiler implements ResidentCompiler {
942
945
}
943
946
944
947
final String inputKey = Uuid ().generateV4 ();
945
- await _writelnToServerStdinAll ( < String > [
946
- 'compile-expression $inputKey ' ,
947
- request.expression,
948
- ... ? request.definitions,
949
- inputKey,
950
- ... ? request.definitionTypes,
951
- inputKey,
952
- ... ? request.typeDefinitions,
953
- inputKey,
954
- ... ? request.typeBounds,
955
- inputKey,
956
- ... ? request.typeDefaults,
957
- inputKey,
958
- request.libraryUri ?? '' ,
959
- request.klass ?? '' ,
960
- request.method ?? '' ,
961
- request.isStatic. toString (),
962
- ] );
948
+ server.stdin
949
+ .. writeln ( 'compile-expression $inputKey ' )
950
+ .. writeln ( request.expression);
951
+ request.definitions ? . forEach (server.stdin.writeln);
952
+ server.stdin. writeln ( inputKey);
953
+ request.definitionTypes ? . forEach (server.stdin.writeln);
954
+ server.stdin. writeln ( inputKey);
955
+ request.typeDefinitions ? . forEach (server.stdin.writeln);
956
+ server.stdin. writeln ( inputKey);
957
+ request.typeBounds ? . forEach (server.stdin.writeln);
958
+ server.stdin. writeln ( inputKey);
959
+ request.typeDefaults ? . forEach (server.stdin.writeln);
960
+ server.stdin
961
+ .. writeln (inputKey)
962
+ .. writeln ( request.libraryUri ?? '' )
963
+ .. writeln ( request.klass ?? '' )
964
+ .. writeln (request.method ?? '' )
965
+ .. writeln (request.isStatic );
963
966
964
967
return _stdoutHandler.compilerOutput? .future;
965
968
}
@@ -997,28 +1000,27 @@ class DefaultResidentCompiler implements ResidentCompiler {
997
1000
}
998
1001
999
1002
final String inputKey = Uuid ().generateV4 ();
1000
- await _writelnToServerStdinAll (< String > [
1001
- 'compile-expression-to-js $inputKey ' ,
1002
- request.libraryUri ?? '' ,
1003
- request.line.toString (),
1004
- request.column.toString (),
1005
- for (final MapEntry <String , String > entry in request.jsModules? .entries ?? < MapEntry <String , String >> [])
1006
- '${entry .key }:${entry .value }' ,
1007
- inputKey,
1008
- for (final MapEntry <String , String > entry in request.jsFrameValues? .entries ?? < MapEntry <String , String >> [])
1009
- '${entry .key }:${entry .value }' ,
1010
- inputKey,
1011
- request.moduleName ?? '' ,
1012
- request.expression ?? ''
1013
- ]);
1003
+ server.stdin
1004
+ ..writeln ('compile-expression-to-js $inputKey ' )
1005
+ ..writeln (request.libraryUri ?? '' )
1006
+ ..writeln (request.line)
1007
+ ..writeln (request.column);
1008
+ request.jsModules? .forEach ((String k, String v) { server.stdin.writeln ('$k :$v ' ); });
1009
+ server.stdin.writeln (inputKey);
1010
+ request.jsFrameValues? .forEach ((String k, String v) { server.stdin.writeln ('$k :$v ' ); });
1011
+ server.stdin
1012
+ ..writeln (inputKey)
1013
+ ..writeln (request.moduleName ?? '' )
1014
+ ..writeln (request.expression ?? '' );
1014
1015
1015
1016
return _stdoutHandler.compilerOutput? .future;
1016
1017
}
1017
1018
1018
1019
@override
1019
- Future < void > accept () async {
1020
+ void accept () {
1020
1021
if (_compileRequestNeedsConfirmation) {
1021
- await _writelnToServerStdin ('accept' , printTrace: true );
1022
+ _server? .stdin.writeln ('accept' );
1023
+ _logger.printTrace ('<- accept' );
1022
1024
}
1023
1025
_compileRequestNeedsConfirmation = false ;
1024
1026
}
@@ -1039,14 +1041,16 @@ class DefaultResidentCompiler implements ResidentCompiler {
1039
1041
return Future <CompilerOutput ?>.value ();
1040
1042
}
1041
1043
_stdoutHandler.reset (expectSources: false );
1042
- await _writelnToServerStdin ('reject' , printTrace: true );
1044
+ _server? .stdin.writeln ('reject' );
1045
+ _logger.printTrace ('<- reject' );
1043
1046
_compileRequestNeedsConfirmation = false ;
1044
1047
return _stdoutHandler.compilerOutput? .future;
1045
1048
}
1046
1049
1047
1050
@override
1048
- Future <void > reset () async {
1049
- await _writelnToServerStdin ('reset' , printTrace: true );
1051
+ void reset () {
1052
+ _server? .stdin.writeln ('reset' );
1053
+ _logger.printTrace ('<- reset' );
1050
1054
}
1051
1055
1052
1056
@override
@@ -1060,43 +1064,6 @@ class DefaultResidentCompiler implements ResidentCompiler {
1060
1064
server.kill ();
1061
1065
return server.exitCode;
1062
1066
}
1063
-
1064
- Future <void > _writelnToServerStdin (String line, {
1065
- bool printTrace = false ,
1066
- }) async {
1067
- await _writelnToServerStdinAll (< String > [line], printTrace: printTrace);
1068
- }
1069
-
1070
- // TODO(andrewkolos): Concurrent calls to ProcessUtils.writelnToStdinUnsafe
1071
- // against the same stdin will result in an exception. To guard against this,
1072
- // we need to force calls to run serially. Ideally, this wouldn't be
1073
- // necessary since we shouldn't have multiple concurrent writes to the
1074
- // compiler process.
1075
- // However, we do. See https://github.com/flutter/flutter/issues/152577.
1076
- final Pool _serverStdinWritePool = Pool (1 );
1077
- Future <void > _writelnToServerStdinAll (List <String > lines, {
1078
- bool printTrace = false ,
1079
- }) async {
1080
- final Process ? server = _server;
1081
- if (server == null ) {
1082
- return ;
1083
- }
1084
- final PoolResource request = await _serverStdinWritePool.request ();
1085
- try {
1086
- await ProcessUtils .writelnToStdinUnsafe (
1087
- stdin: server.stdin,
1088
- line: lines.join ('\n ' ),
1089
- );
1090
-
1091
- for (final String line in lines) {
1092
- if (printTrace) {
1093
- _logger.printTrace ('<- $line ' );
1094
- }
1095
- }
1096
- } finally {
1097
- request.release ();
1098
- }
1099
- }
1100
1067
}
1101
1068
1102
1069
/// Convert a file URI into a multi-root scheme URI if provided, otherwise
0 commit comments