| Index: sdk/lib/_internal/pub/lib/src/executable.dart
|
| diff --git a/sdk/lib/_internal/pub/lib/src/executable.dart b/sdk/lib/_internal/pub/lib/src/executable.dart
|
| index 2becb86920e12dc18f4914507da7c87b77d5cbef..38105925f88befd4f655776caada5d51c17d5710 100644
|
| --- a/sdk/lib/_internal/pub/lib/src/executable.dart
|
| +++ b/sdk/lib/_internal/pub/lib/src/executable.dart
|
| @@ -36,6 +36,21 @@ Future<int> runExecutable(Entrypoint entrypoint, String package,
|
| BarbackMode mode}) async {
|
| if (mode == null) mode = BarbackMode.RELEASE;
|
|
|
| + // Make sure the package is an immediate dependency of the entrypoint or the
|
| + // entrypoint itself.
|
| + if (entrypoint.root.name != package &&
|
| + !entrypoint.root.immediateDependencies
|
| + .any((dep) => dep.name == package)) {
|
| + var graph = await entrypoint.loadPackageGraph();
|
| + if (graph.packages.containsKey(package)) {
|
| + dataError('Package "$package" is not an immediate dependency.\n'
|
| + 'Cannot run executables in transitive dependencies.');
|
| + } else {
|
| + dataError('Could not find package "$package". Did you forget to add a '
|
| + 'dependency?');
|
| + }
|
| + }
|
| +
|
| // Unless the user overrides the verbosity, we want to filter out the
|
| // normal pub output shown while loading the environment.
|
| if (log.verbosity == log.Verbosity.NORMAL) {
|
| @@ -69,10 +84,13 @@ Future<int> runExecutable(Entrypoint entrypoint, String package,
|
| executable = p.join("bin", executable);
|
| }
|
|
|
| + var assetPath = "${p.url.joinAll(p.split(executable))}.dart";
|
| + var id = new AssetId(package, assetPath);
|
| +
|
| // TODO(nweiz): Use [packages] to only load assets from packages that the
|
| // executable might load.
|
| var environment = await AssetEnvironment.create(entrypoint, mode,
|
| - useDart2JS: false);
|
| + useDart2JS: false, entrypoints: [id]);
|
| environment.barback.errors.listen((error) {
|
| log.error(log.red("Build error:\n$error"));
|
| });
|
| @@ -84,27 +102,10 @@ Future<int> runExecutable(Entrypoint entrypoint, String package,
|
| // will work from within some deeply nested script.
|
| server = await environment.serveDirectory(rootDir);
|
| } else {
|
| - // Make sure the dependency exists.
|
| - var dep = entrypoint.root.immediateDependencies.firstWhere(
|
| - (dep) => dep.name == package, orElse: () => null);
|
| - if (dep == null) {
|
| - if (environment.graph.packages.containsKey(package)) {
|
| - dataError('Package "$package" is not an immediate dependency.\n'
|
| - 'Cannot run executables in transitive dependencies.');
|
| - } else {
|
| - dataError('Could not find package "$package". Did you forget to '
|
| - 'add a dependency?');
|
| - }
|
| - }
|
| -
|
| // For other packages, always use the "bin" directory.
|
| server = await environment.servePackageBinDirectory(package);
|
| }
|
|
|
| - // Try to make sure the entrypoint script exists (or is generated) before
|
| - // we spawn the process to run it.
|
| - var assetPath = "${p.url.joinAll(p.split(executable))}.dart";
|
| - var id = new AssetId(server.package, assetPath);
|
| // TODO(rnystrom): Use try/catch here when
|
| // https://github.com/dart-lang/async_await/issues/4 is fixed.
|
| return environment.barback.getAssetById(id).then((_) async {
|
|
|