|
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
5 | 5 | import 'dart:convert'; |
6 | | -import 'dart:io' show File, FileSystemException, InternetAddress, Socket; |
| 6 | +import 'dart:io' show File, FileSystemException; |
7 | 7 |
|
8 | 8 | import 'package:args/args.dart'; |
| 9 | +import 'package:frontend_server/resident_frontend_server_utils.dart' |
| 10 | + show sendAndReceiveResponse; |
9 | 11 | import 'package:path/path.dart' as p; |
10 | 12 |
|
11 | 13 | import 'commands/compilation_server.dart' show CompilationServerCommand; |
@@ -51,51 +53,6 @@ File? getResidentCompilerInfoFileConsideringArgs(final ArgResults args) { |
51 | 53 |
|
52 | 54 | final String packageConfigName = p.join('.dart_tool', 'package_config.json'); |
53 | 55 |
|
54 | | -final class ResidentCompilerInfo { |
55 | | - final String? _sdkHash; |
56 | | - final InternetAddress _address; |
57 | | - final int _port; |
58 | | - |
59 | | - /// The SDK hash that kernel files compiled using the Resident Frontend |
60 | | - /// Compiler associated with this object will be stamped with. |
61 | | - String? get sdkHash => _sdkHash; |
62 | | - |
63 | | - /// The address that the Resident Frontend Compiler associated with this |
64 | | - /// object is listening from. |
65 | | - InternetAddress get address => _address; |
66 | | - |
67 | | - /// The port number that the Resident Frontend Compiler associated with this |
68 | | - /// object is listening on. |
69 | | - int get port => _port; |
70 | | - |
71 | | - /// Extracts the value associated with a key from [entries], where [entries] |
72 | | - /// is a [String] with the format '$key1:$value1 $key2:$value2 $key3:$value3 ...'. |
73 | | - static String _extractValueAssociatedWithKey(String entries, String key) => |
74 | | - RegExp('$key:' r'(\S+)(\s|$)').allMatches(entries).first[1]!; |
75 | | - |
76 | | - static ResidentCompilerInfo fromFile(File file) { |
77 | | - final fileContents = file.readAsStringSync(); |
78 | | - |
79 | | - return ResidentCompilerInfo._( |
80 | | - sdkHash: fileContents.contains('sdkHash:') |
81 | | - ? _extractValueAssociatedWithKey(fileContents, 'sdkHash') |
82 | | - : null, |
83 | | - address: InternetAddress( |
84 | | - _extractValueAssociatedWithKey(fileContents, 'address'), |
85 | | - ), |
86 | | - port: int.parse(_extractValueAssociatedWithKey(fileContents, 'port')), |
87 | | - ); |
88 | | - } |
89 | | - |
90 | | - ResidentCompilerInfo._({ |
91 | | - required String? sdkHash, |
92 | | - required int port, |
93 | | - required InternetAddress address, |
94 | | - }) : _sdkHash = sdkHash, |
95 | | - _port = port, |
96 | | - _address = address; |
97 | | -} |
98 | | - |
99 | 56 | /// Removes the [serverInfoFile]. |
100 | 57 | void cleanupResidentServerInfo(File serverInfoFile) { |
101 | 58 | if (serverInfoFile.existsSync()) { |
@@ -208,38 +165,6 @@ Future<bool> isFileAotSnapshot(final File file) async { |
208 | 165 | return false; |
209 | 166 | } |
210 | 167 |
|
211 | | -// TODO: when frontend_server is migrated to null safe Dart, everything |
212 | | -// below this comment can be removed and imported from resident_frontend_server |
213 | | - |
214 | | -/// Sends a compilation [request] to the Resident Frontend Compiler associated |
215 | | -/// with [serverInfoFile], and returns the compiler's JSON response. |
216 | | -/// |
217 | | -/// Throws a [FileSystemException] if [serverInfoFile] cannot be accessed. |
218 | | -Future<Map<String, dynamic>> sendAndReceiveResponse( |
219 | | - String request, |
220 | | - File serverInfoFile, |
221 | | -) async { |
222 | | - Socket? client; |
223 | | - Map<String, dynamic> jsonResponse; |
224 | | - final residentCompilerInfo = ResidentCompilerInfo.fromFile(serverInfoFile); |
225 | | - try { |
226 | | - client = await Socket.connect( |
227 | | - residentCompilerInfo.address, |
228 | | - residentCompilerInfo.port, |
229 | | - ); |
230 | | - client.write(request); |
231 | | - final data = String.fromCharCodes(await client.first); |
232 | | - jsonResponse = jsonDecode(data); |
233 | | - } catch (e) { |
234 | | - jsonResponse = <String, dynamic>{ |
235 | | - responseSuccessString: false, |
236 | | - responseErrorString: e.toString(), |
237 | | - }; |
238 | | - } |
239 | | - client?.destroy(); |
240 | | - return jsonResponse; |
241 | | -} |
242 | | - |
243 | 168 | /// Used to create compile requests for the run CLI command. |
244 | 169 | /// |
245 | 170 | /// Returns a JSON string that the resident compiler will be able to interpret. |
|
0 commit comments