@@ -301,6 +301,53 @@ class ResidentFrontendServer {
301301 return residentCompiler;
302302 }
303303
304+ static Future <String > _handleCompileRequest (
305+ Map <String , dynamic > request,
306+ ) async {
307+ if (request[_executableString] == null || request[_outputString] == null ) {
308+ return _encodeErrorMessage (
309+ "'$_compileString ' requests must include an '$_executableString ' "
310+ "property and an '$_outputString ' property." ,
311+ );
312+ }
313+
314+ final String canonicalizedExecutablePath =
315+ path.canonicalize (request[_executableString]);
316+
317+ late final String cachedDillPath;
318+ try {
319+ cachedDillPath = computeCachedDillPath (canonicalizedExecutablePath);
320+ } on Exception catch (e) {
321+ return _encodeErrorMessage (e.toString ());
322+ }
323+
324+ final ArgResults options = _generateCompilerOptions (
325+ request: request,
326+ outputDillOverride: cachedDillPath,
327+ );
328+ final ResidentCompiler residentCompiler = _getResidentCompilerForEntrypoint (
329+ canonicalizedExecutablePath,
330+ options,
331+ );
332+ final Map <String , dynamic > response = await residentCompiler.compile ();
333+
334+ if (response['success' ] != true ) {
335+ return jsonEncode (response);
336+ }
337+
338+ final String outputDillPath = request[_outputString];
339+ if (cachedDillPath != outputDillPath) {
340+ try {
341+ new File (cachedDillPath).copySync (outputDillPath);
342+ } catch (e) {
343+ return _encodeErrorMessage (
344+ 'Could not write output dill to ${request [_outputString ]}.' ,
345+ );
346+ }
347+ }
348+ return jsonEncode ({...response, _outputString: outputDillPath});
349+ }
350+
304351 /// Takes in JSON [input] from the socket and compiles the request,
305352 /// using incremental compilation if possible. Returns a JSON string to be
306353 /// sent back to the client socket containing either an error message or the
@@ -319,50 +366,7 @@ class ResidentFrontendServer {
319366
320367 switch (request[_commandString]) {
321368 case _compileString:
322- if (request[_executableString] == null ||
323- request[_outputString] == null ) {
324- return _encodeErrorMessage (
325- "'$_compileString ' requests must include an '$_executableString ' "
326- "property and an '$_outputString ' property." ,
327- );
328- }
329-
330- final String canonicalizedExecutablePath =
331- path.canonicalize (request[_executableString]);
332-
333- late final String cachedDillPath;
334- try {
335- cachedDillPath = computeCachedDillPath (canonicalizedExecutablePath);
336- } on Exception catch (e) {
337- return _encodeErrorMessage (e.toString ());
338- }
339-
340- final ArgResults options = _generateCompilerOptions (
341- request: request,
342- outputDillOverride: cachedDillPath,
343- );
344- final ResidentCompiler residentCompiler =
345- _getResidentCompilerForEntrypoint (
346- canonicalizedExecutablePath,
347- options,
348- );
349- final Map <String , dynamic > response = await residentCompiler.compile ();
350-
351- if (response['success' ] != true ) {
352- return jsonEncode (response);
353- }
354-
355- final String outputDillPath = request[_outputString];
356- if (cachedDillPath != outputDillPath) {
357- try {
358- new File (cachedDillPath).copySync (outputDillPath);
359- } catch (e) {
360- return _encodeErrorMessage (
361- 'Could not write output dill to ${request [_outputString ]}.' ,
362- );
363- }
364- }
365- return jsonEncode ({...response, _outputString: outputDillPath});
369+ return _handleCompileRequest (request);
366370 case _shutdownString:
367371 return _shutdownJsonResponse;
368372 default :
0 commit comments