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