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