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..f54231bfd923c8b415cb51b15afcf36cc277d3b4 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,19 @@ Future _processLoadRequest(request) async { |
| } |
| } |
| +// Given namedSources list of interleaved source file name, source content |
| +// strings this function builds up and returns MemoryFileSystem instance that |
| +// can be used instead of PhysicalFileSystem.instance by the frontend. |
|
Paul Berry
2017/05/11 21:11:53
Would it be better for the VM to pass this in as a
aam
2017/05/11 23:02:59
Okay, done.
I don't have strong opinion on this.
|
| +FileSystem _buildMemoryFileSystem(List<String> namedSources) { |
| + FileSystem fileSystem = new MemoryFileSystem(Uri.parse('file:///')); |
| + for (int i = 0; i < namedSources.length / 2; i++) { |
| + fileSystem |
| + .entityForUri(Uri.parse(namedSources[i * 2])) |
| + .writeAsStringSync(namedSources[i * 2 + 1]); |
| + } |
| + return fileSystem; |
| +} |
| + |
| train(String scriptUri) { |
| // TODO(28532): Enable on Windows. |
| if (Platform.isWindows) return; |