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