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 import 'dart:io'; | 5 import 'dart:io'; |
6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
7 | 7 |
8 final PACKAGE_URI = "package:foo/bar.dart"; | 8 final PACKAGE_URI = "package:foo/bar.dart"; |
9 final PACKAGE_PATH = "file:///no/such/directory/bar.dart"; | 9 final PACKAGE_PATH = "file:///no/such/directory/bar.dart"; |
10 | 10 |
11 main([args, port]) async { | 11 main([args, port]) async { |
12 if (port != null) { | 12 if (port != null) { |
13 testPackageResolution(port); | 13 testPackageResolution(port); |
14 return; | 14 return; |
15 } | 15 } |
16 var p = new RawReceivePort(); | 16 var p = new RawReceivePort(); |
17 Isolate.spawnUri(Platform.script, | 17 Isolate.spawnUri(Platform.script, [], p.sendPort, |
18 [], | 18 automaticPackageResolution: true); |
19 p.sendPort, | |
20 automaticPackageResolution: true); | |
21 p.handler = (msg) { | 19 p.handler = (msg) { |
22 p.close(); | 20 p.close(); |
23 if (msg is! List) { | 21 if (msg is! List) { |
24 print(msg.runtimeType); | 22 print(msg.runtimeType); |
25 throw "Failure return from spawned isolate:\n\n$msg"; | 23 throw "Failure return from spawned isolate:\n\n$msg"; |
26 } | 24 } |
27 var child_pkg_config = Platform.script.resolve(".packages"); | 25 var child_pkg_config = Platform.script.resolve(".packages"); |
28 if (msg[0] != child_pkg_config.toString()) { | 26 if (msg[0] != child_pkg_config.toString()) { |
29 throw "Bad package config in child isolate: ${msg[0]}\n" | 27 throw "Bad package config in child isolate: ${msg[0]}\n" |
30 "Expected: $child_pkg_config"; | 28 "Expected: $child_pkg_config"; |
31 } | 29 } |
32 if (msg[1] != PACKAGE_PATH) { | 30 if (msg[1] != PACKAGE_PATH) { |
33 throw "Package path not matching: ${msg[1]}"; | 31 throw "Package path not matching: ${msg[1]}"; |
34 } | 32 } |
35 print("SUCCESS"); | 33 print("SUCCESS"); |
36 }; | 34 }; |
37 print("Spawning isolate's package root: ${await Isolate.packageRoot}"); | 35 print("Spawning isolate's package root: ${await Isolate.packageRoot}"); |
38 } | 36 } |
39 | 37 |
40 testPackageResolution(port) async { | 38 testPackageResolution(port) async { |
41 try { | 39 try { |
42 var packageRootStr = Platform.packageRoot; | 40 var packageRootStr = Platform.packageRoot; |
43 var packageConfigStr = Platform.packageConfig; | 41 var packageConfigStr = Platform.packageConfig; |
44 var packageConfig = await Isolate.packageConfig; | 42 var packageConfig = await Isolate.packageConfig; |
45 var resolvedPkg = await Isolate.resolvePackageUri(Uri.parse(PACKAGE_URI)); | 43 var resolvedPkg = await Isolate.resolvePackageUri(Uri.parse(PACKAGE_URI)); |
46 print("Spawned isolate's package root flag: $packageRootStr"); | 44 print("Spawned isolate's package root flag: $packageRootStr"); |
47 print("Spawned isolate's package config flag: $packageConfigStr"); | 45 print("Spawned isolate's package config flag: $packageConfigStr"); |
48 print("Spawned isolate's loaded package config: $packageConfig"); | 46 print("Spawned isolate's loaded package config: $packageConfig"); |
49 print("Spawned isolate's resolved package path: $resolvedPkg"); | 47 print("Spawned isolate's resolved package path: $resolvedPkg"); |
50 port.send([packageConfig?.toString(), resolvedPkg?.toString()]); | 48 port.send([packageConfig?.toString(), resolvedPkg?.toString()]); |
51 } catch (e, s) { | 49 } catch (e, s) { |
52 port.send("$e\n$s\n"); | 50 port.send("$e\n$s\n"); |
53 } | 51 } |
54 } | 52 } |
OLD | NEW |