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 |
11 /// as a part of | 11 /// as a part of |
12 /// | 12 /// |
13 /// dart --dfe=utils/kernel-service/kernel-service.dart ... | 13 /// dart --dfe=utils/kernel-service/kernel-service.dart ... |
14 /// | 14 /// |
15 /// invocation or it is invoked as a standalone script to perform training for | 15 /// invocation or it is invoked as a standalone script to perform training for |
16 /// the app-jit snapshot | 16 /// the app-jit snapshot |
17 /// | 17 /// |
18 /// dart utils/kernel-service/kernel-service.dart --train <source-file> | 18 /// dart utils/kernel-service/kernel-service.dart --train <source-file> |
19 /// | 19 /// |
20 /// | 20 /// |
21 library runtime.tools.kernel_service; | 21 library runtime.tools.kernel_service; |
22 | 22 |
23 import 'dart:async' show Future; | 23 import 'dart:async' show Future; |
24 import 'dart:io' show File, Platform hide FileSystemEntity; | 24 import 'dart:io' show Platform hide FileSystemEntity; |
25 import 'dart:isolate'; | 25 import 'dart:isolate'; |
26 import 'dart:typed_data' show Uint8List; | 26 import 'dart:typed_data' show Uint8List; |
27 | 27 |
28 import 'package:front_end/file_system.dart'; | 28 import 'package:front_end/file_system.dart'; |
29 import 'package:front_end/front_end.dart'; | 29 import 'package:front_end/front_end.dart'; |
30 import 'package:front_end/memory_file_system.dart'; | 30 import 'package:front_end/memory_file_system.dart'; |
31 import 'package:front_end/physical_file_system.dart'; | 31 import 'package:front_end/physical_file_system.dart'; |
32 import 'package:front_end/src/fasta/kernel/utils.dart'; | 32 import 'package:front_end/src/fasta/kernel/utils.dart'; |
33 import 'package:front_end/src/testing/hybrid_file_system.dart'; | 33 import 'package:front_end/src/testing/hybrid_file_system.dart'; |
34 import 'package:kernel/kernel.dart' show Program; | 34 import 'package:kernel/kernel.dart' show Program; |
35 import 'package:kernel/target/targets.dart' show TargetFlags; | 35 import 'package:kernel/target/targets.dart' show TargetFlags; |
36 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; | 36 import 'package:kernel/target/vm_fasta.dart' show VmFastaTarget; |
37 | 37 |
38 const bool verbose = const bool.fromEnvironment('DFE_VERBOSE'); | 38 const bool verbose = const bool.fromEnvironment('DFE_VERBOSE'); |
39 | 39 |
40 const bool strongMode = const bool.fromEnvironment('DFE_STRONG_MODE'); | 40 const bool strongMode = const bool.fromEnvironment('DFE_STRONG_MODE'); |
41 | 41 |
42 Future<CompilationResult> _parseScriptInFileSystem( | 42 Future<CompilationResult> _parseScriptInFileSystem( |
43 Uri script, FileSystem fileSystem, | 43 Uri script, FileSystem fileSystem, |
44 {bool verbose: false, bool strongMode: false}) async { | 44 {bool verbose: false, bool strongMode: false}) async { |
45 final Uri packagesUri = (Platform.packageConfig != null) | 45 final Uri packagesUri = (Platform.packageConfig != null) |
46 ? Uri.parse(Platform.packageConfig) | 46 ? Uri.parse(Platform.packageConfig) |
47 : await _findPackagesFile(fileSystem, script); | 47 : null; |
48 if (packagesUri == null) { | |
49 throw "Could not find .packages"; | |
50 } | |
51 | 48 |
52 final Uri patchedSdk = Uri.base | 49 final Uri patchedSdk = Uri.base |
53 .resolveUri(new Uri.file(Platform.resolvedExecutable)) | 50 .resolveUri(new Uri.file(Platform.resolvedExecutable)) |
54 .resolveUri(new Uri.directory("patched_sdk")); | 51 .resolveUri(new Uri.directory("patched_sdk")); |
55 | 52 |
56 if (verbose) { | 53 if (verbose) { |
57 print("""DFE: Requesting compilation { | 54 print("""DFE: Requesting compilation { |
58 scriptUri: ${script} | 55 scriptUri: ${script} |
59 packagesUri: ${packagesUri} | 56 packagesUri: ${packagesUri} |
60 patchedSdk: ${patchedSdk} | 57 patchedSdk: ${patchedSdk} |
(...skipping 20 matching lines...) Expand all Loading... |
81 // marked `external`, so we can use that bit to decide what to excluce. | 78 // marked `external`, so we can use that bit to decide what to excluce. |
82 // TODO(sigmund): remove the following line (Issue #30111) | 79 // TODO(sigmund): remove the following line (Issue #30111) |
83 program.libraries.forEach((e) => e.isExternal = false); | 80 program.libraries.forEach((e) => e.isExternal = false); |
84 return new CompilationResult.ok( | 81 return new CompilationResult.ok( |
85 serializeProgram(program, filter: (lib) => !lib.isExternal)); | 82 serializeProgram(program, filter: (lib) => !lib.isExternal)); |
86 } catch (err, stack) { | 83 } catch (err, stack) { |
87 return new CompilationResult.crash(err, stack); | 84 return new CompilationResult.crash(err, stack); |
88 } | 85 } |
89 } | 86 } |
90 | 87 |
91 /// This duplicates functionality from the Loader which we can't easily | |
92 /// access from here. | |
93 // TODO(sigmund): delete, this should be supported by the default options in | |
94 // package:front_end. | |
95 Future<Uri> _findPackagesFile(FileSystem fileSystem, Uri base) async { | |
96 var dir = new File.fromUri(base).parent; | |
97 while (true) { | |
98 final packagesFile = dir.uri.resolve(".packages"); | |
99 if (await fileSystem.entityForUri(packagesFile).exists()) { | |
100 return packagesFile; | |
101 } | |
102 if (dir.parent.path == dir.path) { | |
103 break; | |
104 } | |
105 dir = dir.parent; | |
106 } | |
107 return null; | |
108 } | |
109 | |
110 Future<CompilationResult> _processLoadRequestImpl( | 88 Future<CompilationResult> _processLoadRequestImpl( |
111 String inputFilePathOrUri, FileSystem fileSystem) { | 89 String inputFilePathOrUri, FileSystem fileSystem) { |
112 Uri scriptUri = Uri.parse(inputFilePathOrUri); | 90 Uri scriptUri = Uri.parse(inputFilePathOrUri); |
113 | 91 |
114 // Because we serve both Loader and bootstrapping requests we need to | 92 // Because we serve both Loader and bootstrapping requests we need to |
115 // duplicate the logic from _resolveScriptUri(...) here and attempt to | 93 // duplicate the logic from _resolveScriptUri(...) here and attempt to |
116 // resolve schemaless uris using current working directory. | 94 // resolve schemaless uris using current working directory. |
117 if (!scriptUri.hasScheme) { | 95 if (!scriptUri.hasScheme) { |
118 // Script does not have a scheme, assume that it is a path, | 96 // Script does not have a scheme, assume that it is a path, |
119 // resolve it against the working directory. | 97 // resolve it against the working directory. |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 _CompilationCrash(this.exception, this.stack); | 274 _CompilationCrash(this.exception, this.stack); |
297 | 275 |
298 @override | 276 @override |
299 Status get status => Status.crash; | 277 Status get status => Status.crash; |
300 | 278 |
301 @override | 279 @override |
302 String get errorString => "${exception}\n${stack}"; | 280 String get errorString => "${exception}\n${stack}"; |
303 | 281 |
304 String toString() => "_CompilationCrash(${errorString})"; | 282 String toString() => "_CompilationCrash(${errorString})"; |
305 } | 283 } |
OLD | NEW |