OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library pub.executable; | 5 library pub.executable; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 Future<int> runExecutable(Entrypoint entrypoint, String package, | 50 Future<int> runExecutable(Entrypoint entrypoint, String package, |
51 String executable, Iterable<String> args, {bool isGlobal: false, | 51 String executable, Iterable<String> args, {bool isGlobal: false, |
52 bool checked: false, BarbackMode mode}) async { | 52 bool checked: false, BarbackMode mode}) async { |
53 if (mode == null) mode = BarbackMode.RELEASE; | 53 if (mode == null) mode = BarbackMode.RELEASE; |
54 | 54 |
55 // Make sure the package is an immediate dependency of the entrypoint or the | 55 // Make sure the package is an immediate dependency of the entrypoint or the |
56 // entrypoint itself. | 56 // entrypoint itself. |
57 if (entrypoint.root.name != package && | 57 if (entrypoint.root.name != package && |
58 !entrypoint.root.immediateDependencies | 58 !entrypoint.root.immediateDependencies |
59 .any((dep) => dep.name == package)) { | 59 .any((dep) => dep.name == package)) { |
60 var graph = await entrypoint.loadPackageGraph(); | 60 if (entrypoint.packageGraph.packages.containsKey(package)) { |
61 if (graph.packages.containsKey(package)) { | |
62 dataError('Package "$package" is not an immediate dependency.\n' | 61 dataError('Package "$package" is not an immediate dependency.\n' |
63 'Cannot run executables in transitive dependencies.'); | 62 'Cannot run executables in transitive dependencies.'); |
64 } else { | 63 } else { |
65 dataError('Could not find package "$package". Did you forget to add a ' | 64 dataError('Could not find package "$package". Did you forget to add a ' |
66 'dependency?'); | 65 'dependency?'); |
67 } | 66 } |
68 } | 67 } |
69 | 68 |
70 // Unless the user overrides the verbosity, we want to filter out the | 69 // Unless the user overrides the verbosity, we want to filter out the |
71 // normal pub output shown while loading the environment. | 70 // normal pub output shown while loading the environment. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 {bool isGlobal: false, BarbackMode mode}) async { | 143 {bool isGlobal: false, BarbackMode mode}) async { |
145 assert(p.isRelative(path)); | 144 assert(p.isRelative(path)); |
146 | 145 |
147 // If neither the executable nor any of its dependencies are transformed, | 146 // If neither the executable nor any of its dependencies are transformed, |
148 // there's no need to spin up a barback server. Just run the VM directly | 147 // there's no need to spin up a barback server. Just run the VM directly |
149 // against the filesystem. | 148 // against the filesystem. |
150 // | 149 // |
151 // TODO(nweiz): Once sdk#23369 is fixed, allow global executables to be run | 150 // TODO(nweiz): Once sdk#23369 is fixed, allow global executables to be run |
152 // (and snapshotted) from the filesystem using package specs. A spec can by | 151 // (and snapshotted) from the filesystem using package specs. A spec can by |
153 // saved when activating the package. | 152 // saved when activating the package. |
154 var packageGraph = await entrypoint.loadPackageGraph(); | 153 if (!isGlobal && !entrypoint.packageGraph.isPackageTransformed(package)) { |
155 if (!isGlobal && !packageGraph.isPackageTransformed(package)) { | 154 var fullPath = entrypoint.packageGraph.packages[package].path(path); |
156 var fullPath = packageGraph.packages[package].path(path); | |
157 if (!fileExists(fullPath)) return null; | 155 if (!fileExists(fullPath)) return null; |
158 return p.toUri(fullPath); | 156 return p.toUri(fullPath); |
159 } | 157 } |
160 | 158 |
161 var assetPath = p.url.joinAll(p.split(path)); | 159 var assetPath = p.url.joinAll(p.split(path)); |
162 var id = new AssetId(package, assetPath); | 160 var id = new AssetId(package, assetPath); |
163 | 161 |
164 // TODO(nweiz): Use [packages] to only load assets from packages that the | 162 // TODO(nweiz): Use [packages] to only load assets from packages that the |
165 // executable might load. | 163 // executable might load. |
166 var environment = await AssetEnvironment.create(entrypoint, mode, | 164 var environment = await AssetEnvironment.create(entrypoint, mode, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 Future<int> _runCachedExecutable(Entrypoint entrypoint, String snapshotPath, | 275 Future<int> _runCachedExecutable(Entrypoint entrypoint, String snapshotPath, |
278 List<String> args, {bool checked: false}) { | 276 List<String> args, {bool checked: false}) { |
279 return runSnapshot(snapshotPath, args, | 277 return runSnapshot(snapshotPath, args, |
280 packagesFile: entrypoint.packagesFile, | 278 packagesFile: entrypoint.packagesFile, |
281 checked: checked, | 279 checked: checked, |
282 recompile: () { | 280 recompile: () { |
283 log.fine("Precompiled executable is out of date."); | 281 log.fine("Precompiled executable is out of date."); |
284 return entrypoint.precompileExecutables(); | 282 return entrypoint.precompileExecutables(); |
285 }); | 283 }); |
286 } | 284 } |
OLD | NEW |