| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// This is an interface to the Dart Kernel parser and Kernel binary generator. | 5 /// This is an interface to the Dart Kernel parser and Kernel binary generator. |
| 6 /// | 6 /// |
| 7 /// It is used by the kernel-isolate to load Dart source code and generate | 7 /// It is used by the kernel-isolate to load Dart source code and generate |
| 8 /// Kernel binary format. | 8 /// Kernel binary format. |
| 9 /// | 9 /// |
| 10 /// This is either invoked as the root script of the Kernel isolate when used | 10 /// This is either invoked as the root script of the Kernel isolate when used |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 import 'dart:async'; | 23 import 'dart:async'; |
| 24 import 'dart:io' hide FileSystemEntity; | 24 import 'dart:io' hide FileSystemEntity; |
| 25 import 'dart:isolate'; | 25 import 'dart:isolate'; |
| 26 | 26 |
| 27 import 'package:front_end/file_system.dart'; | 27 import 'package:front_end/file_system.dart'; |
| 28 import 'package:front_end/memory_file_system.dart'; | 28 import 'package:front_end/memory_file_system.dart'; |
| 29 import 'package:front_end/physical_file_system.dart'; | 29 import 'package:front_end/physical_file_system.dart'; |
| 30 import 'package:front_end/src/fasta/vm.dart' | 30 import 'package:front_end/src/fasta/vm.dart' |
| 31 show CompilationResult, Status, parseScriptInFileSystem; | 31 show CompilationResult, Status, parseScriptInFileSystem; |
| 32 import 'package:front_end/src/testing/hybrid_file_system.dart'; |
| 32 | 33 |
| 33 const bool verbose = const bool.fromEnvironment('DFE_VERBOSE'); | 34 const bool verbose = const bool.fromEnvironment('DFE_VERBOSE'); |
| 34 | 35 |
| 35 const bool strongMode = const bool.fromEnvironment('DFE_STRONG_MODE'); | 36 const bool strongMode = const bool.fromEnvironment('DFE_STRONG_MODE'); |
| 36 | 37 |
| 37 Future<CompilationResult> _processLoadRequestImpl( | 38 Future<CompilationResult> _processLoadRequestImpl( |
| 38 String inputFilePathOrUri, FileSystem fileSystem) { | 39 String inputFilePathOrUri, FileSystem fileSystem) { |
| 39 Uri scriptUri = Uri.parse(inputFilePathOrUri); | 40 Uri scriptUri = Uri.parse(inputFilePathOrUri); |
| 40 | 41 |
| 41 // Because we serve both Loader and bootstrapping requests we need to | 42 // Because we serve both Loader and bootstrapping requests we need to |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 FileSystem _buildFileSystem(List namedSources) { | 108 FileSystem _buildFileSystem(List namedSources) { |
| 108 MemoryFileSystem fileSystem = new MemoryFileSystem(Uri.parse('file:///')); | 109 MemoryFileSystem fileSystem = new MemoryFileSystem(Uri.parse('file:///')); |
| 109 for (int i = 0; i < namedSources.length ~/ 2; i++) { | 110 for (int i = 0; i < namedSources.length ~/ 2; i++) { |
| 110 fileSystem | 111 fileSystem |
| 111 .entityForUri(Uri.parse(namedSources[i * 2])) | 112 .entityForUri(Uri.parse(namedSources[i * 2])) |
| 112 .writeAsBytesSync(namedSources[i * 2 + 1]); | 113 .writeAsBytesSync(namedSources[i * 2 + 1]); |
| 113 } | 114 } |
| 114 return new HybridFileSystem(fileSystem); | 115 return new HybridFileSystem(fileSystem); |
| 115 } | 116 } |
| 116 | 117 |
| 117 /// A file system that mixes files from memory and a physical file system. All | |
| 118 /// memory entities take priotity over file system entities. | |
| 119 class HybridFileSystem implements FileSystem { | |
| 120 final MemoryFileSystem memory; | |
| 121 final PhysicalFileSystem physical = PhysicalFileSystem.instance; | |
| 122 | |
| 123 HybridFileSystem(this.memory); | |
| 124 | |
| 125 @override | |
| 126 FileSystemEntity entityForUri(Uri uri) => new HybridFileSystemEntity( | |
| 127 memory.entityForUri(uri), physical.entityForUri(uri)); | |
| 128 } | |
| 129 | |
| 130 /// Entity that delegates to an underlying memory or phisical file system | |
| 131 /// entity. | |
| 132 class HybridFileSystemEntity implements FileSystemEntity { | |
| 133 final FileSystemEntity memory; | |
| 134 final FileSystemEntity physical; | |
| 135 | |
| 136 HybridFileSystemEntity(this.memory, this.physical); | |
| 137 | |
| 138 FileSystemEntity _delegate; | |
| 139 Future<FileSystemEntity> get delegate async { | |
| 140 return _delegate ??= (await memory.exists()) ? memory : physical; | |
| 141 } | |
| 142 | |
| 143 @override | |
| 144 Uri get uri => memory.uri; | |
| 145 | |
| 146 @override | |
| 147 Future<bool> exists() async => (await delegate).exists(); | |
| 148 | |
| 149 @override | |
| 150 Future<DateTime> lastModified() async => (await delegate).lastModified(); | |
| 151 | |
| 152 @override | |
| 153 Future<List<int>> readAsBytes() async => (await delegate).readAsBytes(); | |
| 154 | |
| 155 @override | |
| 156 Future<String> readAsString() async => (await delegate).readAsString(); | |
| 157 } | |
| 158 | |
| 159 train(String scriptUri) { | 118 train(String scriptUri) { |
| 160 // TODO(28532): Enable on Windows. | 119 // TODO(28532): Enable on Windows. |
| 161 if (Platform.isWindows) return; | 120 if (Platform.isWindows) return; |
| 162 | 121 |
| 163 var tag = 1; | 122 var tag = 1; |
| 164 var responsePort = new RawReceivePort(); | 123 var responsePort = new RawReceivePort(); |
| 165 responsePort.handler = (response) { | 124 responsePort.handler = (response) { |
| 166 if (response[0] == tag) { | 125 if (response[0] == tag) { |
| 167 // Success. | 126 // Success. |
| 168 responsePort.close(); | 127 responsePort.close(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 180 main([args]) { | 139 main([args]) { |
| 181 if (args?.length == 2 && args[0] == '--train') { | 140 if (args?.length == 2 && args[0] == '--train') { |
| 182 // This entry point is used when creating an app snapshot. The argument | 141 // This entry point is used when creating an app snapshot. The argument |
| 183 // provides a script to compile to warm-up generated code. | 142 // provides a script to compile to warm-up generated code. |
| 184 train(args[1]); | 143 train(args[1]); |
| 185 } else { | 144 } else { |
| 186 // Entry point for the Kernel isolate. | 145 // Entry point for the Kernel isolate. |
| 187 return new RawReceivePort()..handler = _processLoadRequest; | 146 return new RawReceivePort()..handler = _processLoadRequest; |
| 188 } | 147 } |
| 189 } | 148 } |
| OLD | NEW |