Chromium Code Reviews| Index: utils/kernel-service/kernel-service.dart |
| diff --git a/utils/kernel-service/kernel-service.dart b/utils/kernel-service/kernel-service.dart |
| index 072697b961e0216f5ab3563863070a7d2f173847..ffd5c513081d82fc69ebf8520c0e2557ff4e09d1 100644 |
| --- a/utils/kernel-service/kernel-service.dart |
| +++ b/utils/kernel-service/kernel-service.dart |
| @@ -24,14 +24,17 @@ import 'dart:async'; |
| import 'dart:io'; |
| import 'dart:isolate'; |
| +import 'package:front_end/memory_file_system.dart'; |
| +import 'package:front_end/physical_file_system.dart'; |
| import 'package:front_end/src/fasta/vm.dart' |
| - show CompilationResult, Status, parseScript; |
| + show CompilationResult, Status, parseScriptInFileSystem; |
| const bool verbose = const bool.fromEnvironment('DFE_VERBOSE'); |
| const bool strongMode = const bool.fromEnvironment('DFE_STRONG_MODE'); |
| -Future<CompilationResult> _processLoadRequestImpl(String inputFilePathOrUri) { |
| +Future<CompilationResult> _processLoadRequestImpl( |
| + String inputFilePathOrUri, FileSystem fileSystem) { |
| Uri scriptUri = Uri.parse(inputFilePathOrUri); |
| // Because we serve both Loader and bootstrapping requests we need to |
| @@ -48,8 +51,8 @@ Future<CompilationResult> _processLoadRequestImpl(String inputFilePathOrUri) { |
| return new Future<CompilationResult>.value(new CompilationResult.error( |
| "Expected 'file' scheme for a script uri: got ${scriptUri.scheme}")); |
| } |
| - |
| - return parseScript(scriptUri, verbose: verbose, strongMode: strongMode); |
| + return parseScriptInFileSystem(scriptUri, fileSystem, |
| + verbose: verbose, strongMode: strongMode); |
| } |
| // Process a request from the runtime. See KernelIsolate::CompileToKernel in |
| @@ -64,10 +67,13 @@ Future _processLoadRequest(request) async { |
| int tag = request[0]; |
| final SendPort port = request[1]; |
| final String inputFileUrl = request[2]; |
| + FileSystem fileSystem = request.length > 3 |
| + ? _buildMemoryFileSystem(request[3]) |
| + : PhysicalFileSystem.instance; |
| CompilationResult result; |
| try { |
| - result = await _processLoadRequestImpl(inputFileUrl); |
| + result = await _processLoadRequestImpl(inputFileUrl, fileSystem); |
| } catch (error, stack) { |
| result = new CompilationResult.crash(error, stack); |
| } |
| @@ -90,6 +96,20 @@ Future _processLoadRequest(request) async { |
| } |
| } |
| +// Given namedSources list of interleaved file name string and |
| +// raw file content Uint8List this function builds up and returns |
| +// MemoryFileSystem instance that can be used instead of |
| +// PhysicalFileSystem.instance by the frontend. |
| +FileSystem _buildMemoryFileSystem(List namedSources) { |
| + FileSystem fileSystem = new MemoryFileSystem(Uri.parse('file:///')); |
| + for (int i = 0; i < namedSources.length / 2; i++) { |
|
scheglov
2017/05/12 00:48:59
namedSources.length ~/ 2
aam
2017/05/12 22:11:19
Done.
|
| + fileSystem |
| + .entityForUri(Uri.parse(namedSources[i * 2])) |
| + .writeAsBytesSync(namedSources[i * 2 + 1]); |
| + } |
| + return fileSystem; |
| +} |
| + |
| train(String scriptUri) { |
| // TODO(28532): Enable on Windows. |
| if (Platform.isWindows) return; |