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 26 matching lines...) Expand all Loading... | |
37 | 37 |
38 /// Runs [executable] from [package] reachable from [entrypoint]. | 38 /// Runs [executable] from [package] reachable from [entrypoint]. |
39 /// | 39 /// |
40 /// The executable string is a relative Dart file path using native path | 40 /// The executable string is a relative Dart file path using native path |
41 /// separators with or without a trailing ".dart" extension. It is contained | 41 /// separators with or without a trailing ".dart" extension. It is contained |
42 /// within [package], which should either be the entrypoint package or an | 42 /// within [package], which should either be the entrypoint package or an |
43 /// immediate dependency of it. | 43 /// immediate dependency of it. |
44 /// | 44 /// |
45 /// Arguments from [args] will be passed to the spawned Dart application. | 45 /// Arguments from [args] will be passed to the spawned Dart application. |
46 /// | 46 /// |
47 /// If [mode] is passed, it's used as the barback mode; it defaults to | 47 /// If [checked] is true, the program is run in checked mode. If [mode] is |
48 /// [BarbackMode.RELEASE]. | 48 /// passed, it's used as the barback mode; it defaults to [BarbackMode.RELEASE]. |
49 /// | 49 /// |
50 /// Returns the exit code of the spawned app. | 50 /// Returns the exit code of the spawned app. |
51 Future<int> runExecutable(Entrypoint entrypoint, String package, | 51 Future<int> runExecutable(Entrypoint entrypoint, String package, |
52 String executable, Iterable<String> args, {bool isGlobal: false, | 52 String executable, Iterable<String> args, {bool isGlobal: false, |
53 BarbackMode mode}) async { | 53 bool checked: false, BarbackMode mode}) async { |
54 if (mode == null) mode = BarbackMode.RELEASE; | 54 if (mode == null) mode = BarbackMode.RELEASE; |
55 | 55 |
56 // Make sure the package is an immediate dependency of the entrypoint or the | 56 // Make sure the package is an immediate dependency of the entrypoint or the |
57 // entrypoint itself. | 57 // entrypoint itself. |
58 if (entrypoint.root.name != package && | 58 if (entrypoint.root.name != package && |
59 !entrypoint.root.immediateDependencies | 59 !entrypoint.root.immediateDependencies |
60 .any((dep) => dep.name == package)) { | 60 .any((dep) => dep.name == package)) { |
61 var graph = await entrypoint.loadPackageGraph(); | 61 var graph = await entrypoint.loadPackageGraph(); |
62 if (graph.packages.containsKey(package)) { | 62 if (graph.packages.containsKey(package)) { |
63 dataError('Package "$package" is not an immediate dependency.\n' | 63 dataError('Package "$package" is not an immediate dependency.\n' |
(...skipping 13 matching lines...) Expand all Loading... | |
77 // Ensure that there's a trailing extension. | 77 // Ensure that there's a trailing extension. |
78 if (p.extension(executable) != ".dart") executable += ".dart"; | 78 if (p.extension(executable) != ".dart") executable += ".dart"; |
79 | 79 |
80 var localSnapshotPath = p.join(".pub", "bin", package, | 80 var localSnapshotPath = p.join(".pub", "bin", package, |
81 "$executable.snapshot"); | 81 "$executable.snapshot"); |
82 if (!isGlobal && fileExists(localSnapshotPath) && | 82 if (!isGlobal && fileExists(localSnapshotPath) && |
83 // Dependencies are only snapshotted in release mode, since that's the | 83 // Dependencies are only snapshotted in release mode, since that's the |
84 // default mode for them to run. We can't run them in a different mode | 84 // default mode for them to run. We can't run them in a different mode |
85 // using the snapshot. | 85 // using the snapshot. |
86 mode == BarbackMode.RELEASE) { | 86 mode == BarbackMode.RELEASE) { |
87 return _runCachedExecutable(entrypoint, localSnapshotPath, args); | 87 return _runCachedExecutable(entrypoint, localSnapshotPath, args, |
88 checked: checked); | |
88 } | 89 } |
89 | 90 |
90 // If the command has a path separator, then it's a path relative to the | 91 // If the command has a path separator, then it's a path relative to the |
91 // root of the package. Otherwise, it's implicitly understood to be in | 92 // root of the package. Otherwise, it's implicitly understood to be in |
92 // "bin". | 93 // "bin". |
93 if (p.split(executable).length == 1) executable = p.join("bin", executable); | 94 if (p.split(executable).length == 1) executable = p.join("bin", executable); |
94 | 95 |
95 var vmArgs = []; | 96 var vmArgs = []; |
96 | 97 |
97 // Run in checked mode. | 98 // Run in checked mode. |
98 // TODO(rnystrom): Make this configurable. | 99 if (checked) vmArgs.add("--checked"); |
99 vmArgs.add("--checked"); | |
100 | 100 |
101 var executableUrl = await _executableUrl( | 101 var executableUrl = await _executableUrl( |
102 entrypoint, package, executable, isGlobal: isGlobal, mode: mode); | 102 entrypoint, package, executable, isGlobal: isGlobal, mode: mode); |
103 | 103 |
104 if (executableUrl == null) { | 104 if (executableUrl == null) { |
105 var message = "Could not find ${log.bold(executable)}"; | 105 var message = "Could not find ${log.bold(executable)}"; |
106 if (package != entrypoint.root.name) { | 106 if (package != entrypoint.root.name) { |
107 message += " in package ${log.bold(package)}"; | 107 message += " in package ${log.bold(package)}"; |
108 } | 108 } |
109 log.error("$message."); | 109 log.error("$message."); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 for (var signal in _catchableSignals) { | 261 for (var signal in _catchableSignals) { |
262 signal.watch().listen((_) { | 262 signal.watch().listen((_) { |
263 log.fine("Forwarding $signal to running process."); | 263 log.fine("Forwarding $signal to running process."); |
264 process.kill(signal); | 264 process.kill(signal); |
265 }); | 265 }); |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
269 /// Runs the executable snapshot at [snapshotPath]. | 269 /// Runs the executable snapshot at [snapshotPath]. |
270 Future<int> _runCachedExecutable(Entrypoint entrypoint, String snapshotPath, | 270 Future<int> _runCachedExecutable(Entrypoint entrypoint, String snapshotPath, |
271 List<String> args) { | 271 List<String> args, {bool checked}) { |
nweiz
2015/08/06 00:08:28
": false"
Bob Nystrom
2015/08/06 16:54:42
Done.
| |
272 return runSnapshot(snapshotPath, args, checked: true, recompile: () { | 272 return runSnapshot(snapshotPath, args, checked: checked, recompile: () { |
273 log.fine("Precompiled executable is out of date."); | 273 log.fine("Precompiled executable is out of date."); |
274 return entrypoint.precompileExecutables(); | 274 return entrypoint.precompileExecutables(); |
275 }); | 275 }); |
276 } | 276 } |
OLD | NEW |