mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 15:17:07 +00:00
- Allow specifying of package: URIs for packageConfig and packageRoot when
spawning a new isolate. BUG= R=rmacnak@google.com Review URL: https://codereview.chromium.org/1586653003 .
This commit is contained in:
parent
2d44ed69e9
commit
7b75f2dbb7
15 changed files with 162 additions and 3 deletions
|
@ -378,6 +378,12 @@ patch class Isolate {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure to resolve package: URIs being handed in as parameters.
|
||||
packageRoot = (packageRoot == null) ? null :
|
||||
await Isolate.resolvePackageUri(packageRoot);
|
||||
packageConfig = (packageConfig == null) ? null :
|
||||
await Isolate.resolvePackageUri(packageConfig);
|
||||
|
||||
// The VM will invoke [_startIsolate] and not `main`.
|
||||
readyPort = new RawReceivePort();
|
||||
var packageRootString = packageRoot?.toString();
|
||||
|
|
|
@ -126,7 +126,7 @@ package_root_test: SkipByDesign # Uses Isolate.packageRoot
|
|||
package_config_test: SkipByDesign # Uses Isolate.packageConfig
|
||||
package_resolve_test: SkipByDesign # Uses Isolate.resolvePackageUri
|
||||
spawn_uri_fail_test: SkipByDesign # Uses dart:io.
|
||||
scenarios/*: SkipByDesign # Use automatic package resolution and .dart URIs.
|
||||
scenarios/*: SkipByDesign # Use automatic package resolution, spawnFunction and .dart URIs.
|
||||
|
||||
[ ($noopt || $compiler == precompiler) ]
|
||||
# Imports dart:mirrors
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
||||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
||||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// PackageRoot=none
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import "package:foo/foo.dart";
|
||||
import "package:bar/bar.dart";
|
||||
|
||||
var CONFIG_URI = "package:bar/spawned_packages/";
|
||||
|
||||
main([args, port]) async {
|
||||
if (port != null) {
|
||||
testCorrectBarPackage(port);
|
||||
return;
|
||||
}
|
||||
var p = new RawReceivePort();
|
||||
Isolate.spawnUri(Platform.script,
|
||||
[],
|
||||
p.sendPort,
|
||||
packageRoot: Uri.parse(CONFIG_URI));
|
||||
p.handler = (msg) {
|
||||
p.close();
|
||||
if (msg is! List) {
|
||||
print(msg.runtimeType);
|
||||
throw "Failure return from spawned isolate:\n\n$msg";
|
||||
}
|
||||
if (msg[0] != "Foo") {
|
||||
throw "Bad package config in child isolate: ${msg[0]}\n"
|
||||
"Expected: 'Foo'";
|
||||
}
|
||||
if (msg[1] != "Bar2") {
|
||||
throw "Package path not matching: ${msg[1]}\n"
|
||||
"Expected: 'Bar2'";
|
||||
}
|
||||
print("SUCCESS");
|
||||
};
|
||||
if (Bar.value != "Bar1") {
|
||||
throw "Spawning isolate package:bar invalid.";
|
||||
}
|
||||
print("Spawned isolate resolved $CONFIG_URI to: "
|
||||
"${await Isolate.resolvePackageUri(Uri.parse(CONFIG_URI))}");
|
||||
}
|
||||
|
||||
testCorrectBarPackage(port) async {
|
||||
try {
|
||||
var packageRootStr = Platform.packageRoot;
|
||||
var packageConfigStr = Platform.packageConfig;
|
||||
var packageConfig = await Isolate.packageConfig;
|
||||
var resolvedPkg = await Isolate.resolvePackageUri(Uri.parse(CONFIG_URI));
|
||||
print("Spawned isolate's package root flag: $packageRootStr");
|
||||
print("Spawned isolate's package config flag: $packageConfigStr");
|
||||
print("Spawned isolate's loaded package config: $packageConfig");
|
||||
print("Spawned isolate's resolved package path: $resolvedPkg");
|
||||
port.send([Foo.value, Bar.value]);
|
||||
} catch (e, s) {
|
||||
port.send("$e\n$s\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Bar {
|
||||
static var value = "Bar1";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Bar {
|
||||
static var value = "Bar2";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Foo {
|
||||
static var value = "Foo";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Foo {
|
||||
static var value = "Foo";
|
||||
}
|
4
tests/isolate/scenarios/package_relative_spec/.packages
Normal file
4
tests/isolate/scenarios/package_relative_spec/.packages
Normal file
|
@ -0,0 +1,4 @@
|
|||
# This is the package spec for the spawning isolate.
|
||||
|
||||
foo:foo_package/
|
||||
bar:bar1_package/
|
|
@ -0,0 +1,3 @@
|
|||
class Bar {
|
||||
static var value = "Bar1";
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
# This is the package spec for the spawned isolate.
|
||||
|
||||
foo:../foo_package/
|
||||
bar:../bar2_package/
|
|
@ -0,0 +1,3 @@
|
|||
class Bar {
|
||||
static var value = "Bar2";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
class Foo {
|
||||
static var value = "Foo";
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// PackageRoot=none
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import "package:foo/foo.dart";
|
||||
import "package:bar/bar.dart";
|
||||
|
||||
var CONFIG_URI = "package:bar/package.config";
|
||||
|
||||
main([args, port]) async {
|
||||
if (port != null) {
|
||||
testCorrectBarPackage(port);
|
||||
return;
|
||||
}
|
||||
var p = new RawReceivePort();
|
||||
Isolate.spawnUri(Platform.script,
|
||||
[],
|
||||
p.sendPort,
|
||||
packageConfig: Uri.parse(CONFIG_URI));
|
||||
p.handler = (msg) {
|
||||
p.close();
|
||||
if (msg is! List) {
|
||||
print(msg.runtimeType);
|
||||
throw "Failure return from spawned isolate:\n\n$msg";
|
||||
}
|
||||
if (msg[0] != "Foo") {
|
||||
throw "Bad package config in child isolate: ${msg[0]}\n"
|
||||
"Expected: 'Foo'";
|
||||
}
|
||||
if (msg[1] != "Bar2") {
|
||||
throw "Package path not matching: ${msg[1]}\n"
|
||||
"Expected: 'Bar2'";
|
||||
}
|
||||
print("SUCCESS");
|
||||
};
|
||||
if (Bar.value != "Bar1") {
|
||||
throw "Spawning isolate package:bar invalid.";
|
||||
}
|
||||
print("Spawned isolate resolved $CONFIG_URI to: "
|
||||
"${await Isolate.resolvePackageUri(Uri.parse(CONFIG_URI))}");
|
||||
}
|
||||
|
||||
testCorrectBarPackage(port) async {
|
||||
try {
|
||||
var packageRootStr = Platform.packageRoot;
|
||||
var packageConfigStr = Platform.packageConfig;
|
||||
var packageConfig = await Isolate.packageConfig;
|
||||
var resolvedPkg = await Isolate.resolvePackageUri(Uri.parse(CONFIG_URI));
|
||||
print("Spawned isolate's package root flag: $packageRootStr");
|
||||
print("Spawned isolate's package config flag: $packageConfigStr");
|
||||
print("Spawned isolate's loaded package config: $packageConfig");
|
||||
print("Spawned isolate's resolved package path: $resolvedPkg");
|
||||
port.send([Foo.value, Bar.value]);
|
||||
} catch (e, s) {
|
||||
port.send("$e\n$s\n");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue