Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: lib/src/executable.dart

Issue 1277773002: Support resources in "pub run" and "pub global run". (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/command.dart ('k') | lib/src/global_packages.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
11 import 'package:path/path.dart' as p; 11 import 'package:path/path.dart' as p;
12 import 'package:stack_trace/stack_trace.dart';
13 12
14 import 'barback/asset_environment.dart'; 13 import 'barback/asset_environment.dart';
15 import 'entrypoint.dart'; 14 import 'entrypoint.dart';
16 import 'exit_codes.dart' as exit_codes; 15 import 'exit_codes.dart' as exit_codes;
17 import 'io.dart'; 16 import 'io.dart';
18 import 'log.dart' as log; 17 import 'log.dart' as log;
19 import 'utils.dart'; 18 import 'utils.dart';
20 19
21 /// All signals that can be caught by a Dart process. 20 /// All signals that can be caught by a Dart process.
22 /// 21 ///
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 message += " in package ${log.bold(package)}"; 106 message += " in package ${log.bold(package)}";
108 } 107 }
109 log.error("$message."); 108 log.error("$message.");
110 return exit_codes.NO_INPUT; 109 return exit_codes.NO_INPUT;
111 } 110 }
112 111
113 // If we're running an executable directly from the filesystem, make sure that 112 // If we're running an executable directly from the filesystem, make sure that
114 // it knows where to load the packages. If it's a dependency's executable, for 113 // it knows where to load the packages. If it's a dependency's executable, for
115 // example, it may not have the right packages directory itself. 114 // example, it may not have the right packages directory itself.
116 if (executableUrl.scheme == 'file' || executableUrl.scheme == '') { 115 if (executableUrl.scheme == 'file' || executableUrl.scheme == '') {
117 // TODO(nweiz): use a .packages file once sdk#23369 is fixed.
118
119 // We use an absolute path here not because the VM insists but because it's 116 // We use an absolute path here not because the VM insists but because it's
120 // helpful for the subprocess to be able to spawn Dart with 117 // helpful for the subprocess to be able to spawn Dart with
121 // Platform.executableArguments and have that work regardless of the working 118 // Platform.executableArguments and have that work regardless of the working
122 // directory. 119 // directory.
123 vmArgs.add('--packages=${p.toUri(p.absolute(entrypoint.packagesFile))}'); 120 vmArgs.add('--packages=${p.toUri(p.absolute(entrypoint.packagesFile))}');
124 } 121 }
125 122
126 vmArgs.add(executableUrl.toString()); 123 vmArgs.add(executableUrl.toString());
127 vmArgs.addAll(args); 124 vmArgs.addAll(args);
128 125
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 /// If [recompile] is passed, it's called if the snapshot is out-of-date. It's 200 /// If [recompile] is passed, it's called if the snapshot is out-of-date. It's
204 /// expected to regenerate a snapshot at [path], after which the snapshot will 201 /// expected to regenerate a snapshot at [path], after which the snapshot will
205 /// be re-run. It may return a Future. 202 /// be re-run. It may return a Future.
206 /// 203 ///
207 /// If [checked] is set, runs the snapshot in checked mode. 204 /// If [checked] is set, runs the snapshot in checked mode.
208 /// 205 ///
209 /// Returns the snapshot's exit code. 206 /// Returns the snapshot's exit code.
210 /// 207 ///
211 /// This doesn't do any validation of the snapshot's SDK version. 208 /// This doesn't do any validation of the snapshot's SDK version.
212 Future<int> runSnapshot(String path, Iterable<String> args, {recompile(), 209 Future<int> runSnapshot(String path, Iterable<String> args, {recompile(),
213 bool checked: false}) async { 210 String packagesFile, bool checked: false}) async {
214 var vmArgs = [path]..addAll(args);
215
216 // TODO(nweiz): pass a flag to silence the "Wrong full snapshot version" 211 // TODO(nweiz): pass a flag to silence the "Wrong full snapshot version"
217 // message when issue 20784 is fixed. 212 // message when issue 20784 is fixed.
218 if (checked) vmArgs.insert(0, "--checked"); 213 var vmArgs = [];
214 if (checked) vmArgs.add("--checked");
215
216 if (packagesFile != null) {
217 // We use an absolute path here not because the VM insists but because it's
218 // helpful for the subprocess to be able to spawn Dart with
219 // Platform.executableArguments and have that work regardless of the working
220 // directory.
221 vmArgs.add("--packages=${p.toUri(p.absolute(packagesFile))}");
222 }
223
224 vmArgs.add(path);
225 vmArgs.addAll(args);
219 226
220 // We need to split stdin so that we can send the same input both to the 227 // We need to split stdin so that we can send the same input both to the
221 // first and second process, if we start more than one. 228 // first and second process, if we start more than one.
222 var stdin1; 229 var stdin1;
223 var stdin2; 230 var stdin2;
224 if (recompile == null) { 231 if (recompile == null) {
225 stdin1 = stdin; 232 stdin1 = stdin;
226 } else { 233 } else {
227 var pair = tee(stdin); 234 var pair = tee(stdin);
228 stdin1 = pair.first; 235 stdin1 = pair.first;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 signal.watch().listen((_) { 269 signal.watch().listen((_) {
263 log.fine("Forwarding $signal to running process."); 270 log.fine("Forwarding $signal to running process.");
264 process.kill(signal); 271 process.kill(signal);
265 }); 272 });
266 } 273 }
267 } 274 }
268 275
269 /// Runs the executable snapshot at [snapshotPath]. 276 /// Runs the executable snapshot at [snapshotPath].
270 Future<int> _runCachedExecutable(Entrypoint entrypoint, String snapshotPath, 277 Future<int> _runCachedExecutable(Entrypoint entrypoint, String snapshotPath,
271 List<String> args, {bool checked: false}) { 278 List<String> args, {bool checked: false}) {
272 return runSnapshot(snapshotPath, args, checked: checked, recompile: () { 279 return runSnapshot(snapshotPath, args,
280 packagesFile: entrypoint.packagesFile,
281 checked: checked,
282 recompile: () {
273 log.fine("Precompiled executable is out of date."); 283 log.fine("Precompiled executable is out of date.");
274 return entrypoint.precompileExecutables(); 284 return entrypoint.precompileExecutables();
275 }); 285 });
276 } 286 }
OLDNEW
« no previous file with comments | « lib/src/command.dart ('k') | lib/src/global_packages.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698