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

Side by Side Diff: runtime/bin/process_patch.dart

Issue 233093004: - Apply review comments from https://codereview.chromium.org/232223004/ (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/io/file_system_entity.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 patch class _WindowsCodePageDecoder { 5 patch class _WindowsCodePageDecoder {
6 /* patch */ static String _decodeBytes(List<int> bytes) 6 /* patch */ static String _decodeBytes(List<int> bytes)
7 native "SystemEncodingToString"; 7 native "SystemEncodingToString";
8 } 8 }
9 9
10 10
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 throw new ArgumentError("Arguments is not a List: $arguments"); 174 throw new ArgumentError("Arguments is not a List: $arguments");
175 } 175 }
176 int len = arguments.length; 176 int len = arguments.length;
177 _arguments = new List<String>(len); 177 _arguments = new List<String>(len);
178 for (int i = 0; i < len; i++) { 178 for (int i = 0; i < len; i++) {
179 var arg = arguments[i]; 179 var arg = arguments[i];
180 if (arg is !String) { 180 if (arg is !String) {
181 throw new ArgumentError("Non-string argument: $arg"); 181 throw new ArgumentError("Non-string argument: $arg");
182 } 182 }
183 _arguments[i] = arguments[i]; 183 _arguments[i] = arguments[i];
184 if (Platform.operatingSystem == 'windows') { 184 if (Platform.isWindows) {
185 _arguments[i] = _windowsArgumentEscape(_arguments[i]); 185 _arguments[i] = _windowsArgumentEscape(_arguments[i]);
186 } 186 }
187 } 187 }
188 188
189 if (_workingDirectory != null && _workingDirectory is !String) { 189 if (_workingDirectory != null && _workingDirectory is !String) {
190 throw new ArgumentError( 190 throw new ArgumentError(
191 "WorkingDirectory is not a String: $_workingDirectory"); 191 "WorkingDirectory is not a String: $_workingDirectory");
192 } 192 }
193 193
194 _environment = []; 194 _environment = [];
195 var environmentEntryHandler = (key, value) { 195 // Ensure that we have a non-null environment.
196 environment = (environment == null) ? (const {}) : environment;
Anders Johnsen 2014/04/10 16:41:20 if (environment == null) environment = const {};
197 if (environment is !Map) {
198 throw new ArgumentError("Environment is not a map: $environment");
199 }
200 environment.forEach((key, value) {
196 if (key is !String || value is !String) { 201 if (key is !String || value is !String) {
197 throw new ArgumentError( 202 throw new ArgumentError(
198 "Environment key or value is not a string: ($key, $value)"); 203 "Environment key or value is not a string: ($key, $value)");
199 } 204 }
200 _environment.add('$key=$value'); 205 _environment.add('$key=$value');
201 }; 206 });
202 if (environment != null) {
203 if (environment is !Map) {
204 throw new ArgumentError("Environment is not a map: $environment");
205 }
206 environment.forEach(environmentEntryHandler);
207 }
208 if (includeParentEnvironment) { 207 if (includeParentEnvironment) {
209 Platform.environment.forEach(environmentEntryHandler); 208 Platform.environment.forEach((key, value) {
209 assert(key is String);
210 assert(value is String);
211 // Do not override keys already set as part of environment.
212 if (!environment.containsKey(key)) {
213 _environment.add('$key=$value');
214 }
215 });
210 } 216 }
211 217
212 // stdin going to process. 218 // stdin going to process.
213 _stdin = new _StdSink(new _Socket._writePipe()); 219 _stdin = new _StdSink(new _Socket._writePipe());
214 // stdout coming from process. 220 // stdout coming from process.
215 _stdout = new _StdStream(new _Socket._readPipe()); 221 _stdout = new _StdStream(new _Socket._readPipe());
216 // stderr coming from process. 222 // stderr coming from process.
217 _stderr = new _StdStream(new _Socket._readPipe()); 223 _stderr = new _StdStream(new _Socket._readPipe());
218 _exitHandler = new _Socket._readPipe(); 224 _exitHandler = new _Socket._readPipe();
219 _ended = false; 225 _ended = false;
220 _started = false; 226 _started = false;
221 } 227 }
222 228
223 static String _getShellCommand() { 229 static String _getShellCommand() {
224 if (Platform.operatingSystem == 'windows') { 230 if (Platform.isWindows) {
225 return 'cmd.exe'; 231 return 'cmd.exe';
226 } 232 }
227 return '/bin/sh'; 233 return '/bin/sh';
228 } 234 }
229 235
230 static List<String> _getShellArguments(String executable, 236 static List<String> _getShellArguments(String executable,
231 List<String> arguments) { 237 List<String> arguments) {
232 List<String> shellArguments = []; 238 List<String> shellArguments = [];
233 if (Platform.operatingSystem == 'windows') { 239 if (Platform.isWindows) {
234 shellArguments.add('/c'); 240 shellArguments.add('/c');
235 shellArguments.add(executable); 241 shellArguments.add(executable);
236 for (var arg in arguments) { 242 for (var arg in arguments) {
237 shellArguments.add(arg); 243 shellArguments.add(arg);
238 } 244 }
239 } else { 245 } else {
240 var commandLine = new StringBuffer(); 246 var commandLine = new StringBuffer();
241 executable = executable.replaceAll("'", "'\"'\"'"); 247 executable = executable.replaceAll("'", "'\"'\"'");
242 commandLine.write("'$executable'"); 248 commandLine.write("'$executable'");
243 shellArguments.add("-c"); 249 shellArguments.add("-c");
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 var status = new _ProcessStartStatus(); 319 var status = new _ProcessStartStatus();
314 bool success = _startNative(_path, 320 bool success = _startNative(_path,
315 _arguments, 321 _arguments,
316 _workingDirectory, 322 _workingDirectory,
317 _environment, 323 _environment,
318 _stdin._sink._nativeSocket, 324 _stdin._sink._nativeSocket,
319 _stdout._stream._nativeSocket, 325 _stdout._stream._nativeSocket,
320 _stderr._stream._nativeSocket, 326 _stderr._stream._nativeSocket,
321 _exitHandler._nativeSocket, 327 _exitHandler._nativeSocket,
322 status); 328 status);
323 _environment = null; // The environment will not be needed going forward.
324 if (!success) { 329 if (!success) {
325 completer.completeError( 330 completer.completeError(
326 new ProcessException(_path, 331 new ProcessException(_path,
327 _arguments, 332 _arguments,
328 status._errorMessage, 333 status._errorMessage,
329 status._errorCode)); 334 status._errorCode));
330 return; 335 return;
331 } 336 }
337 // Reset values which are no longer needed.
338 _path = null;
339 _aguments = null;
340 _workingDirectory = null;
341 _environment = null;
342
332 _started = true; 343 _started = true;
333 344
334 // Setup an exit handler to handle internal cleanup and possible 345 // Setup an exit handler to handle internal cleanup and possible
335 // callback when a process terminates. 346 // callback when a process terminates.
336 int exitDataRead = 0; 347 int exitDataRead = 0;
337 final int EXIT_DATA_SIZE = 8; 348 final int EXIT_DATA_SIZE = 8;
338 List<int> exitDataBuffer = new List<int>(EXIT_DATA_SIZE); 349 List<int> exitDataBuffer = new List<int>(EXIT_DATA_SIZE);
339 _exitHandler.listen((data) { 350 _exitHandler.listen((data) {
340 351
341 int exitCode(List<int> ints) { 352 int exitCode(List<int> ints) {
(...skipping 27 matching lines...) Expand all
369 var status = new _ProcessStartStatus(); 380 var status = new _ProcessStartStatus();
370 bool success = _startNative(_path, 381 bool success = _startNative(_path,
371 _arguments, 382 _arguments,
372 _workingDirectory, 383 _workingDirectory,
373 _environment, 384 _environment,
374 _stdin._sink._nativeSocket, 385 _stdin._sink._nativeSocket,
375 _stdout._stream._nativeSocket, 386 _stdout._stream._nativeSocket,
376 _stderr._stream._nativeSocket, 387 _stderr._stream._nativeSocket,
377 _exitHandler._nativeSocket, 388 _exitHandler._nativeSocket,
378 status); 389 status);
379 _environment = null; // The environment will not be needed going forward.
380 if (!success) { 390 if (!success) {
381 throw new ProcessException(_path, 391 throw new ProcessException(_path,
382 _arguments, 392 _arguments,
383 status._errorMessage, 393 status._errorMessage,
384 status._errorCode); 394 status._errorCode);
385 } 395 }
396 // Reset values which are no longer needed.
397 _path = null;
398 _aguments = null;
399 _workingDirectory = null;
400 _environment = null;
386 401
387 var result = _wait( 402 var result = _wait(
388 _stdin._sink._nativeSocket, 403 _stdin._sink._nativeSocket,
389 _stdout._stream._nativeSocket, 404 _stdout._stream._nativeSocket,
390 _stderr._stream._nativeSocket, 405 _stderr._stream._nativeSocket,
391 _exitHandler._nativeSocket); 406 _exitHandler._nativeSocket);
392 407
393 getOutput(output, encoding) { 408 getOutput(output, encoding) {
394 if (encoding == null) return output; 409 if (encoding == null) return output;
395 return encoding.decode(output); 410 return encoding.decode(output);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 const _ProcessResult(int this.pid, 550 const _ProcessResult(int this.pid,
536 int this.exitCode, 551 int this.exitCode,
537 this.stdout, 552 this.stdout,
538 this.stderr); 553 this.stderr);
539 554
540 final int pid; 555 final int pid;
541 final int exitCode; 556 final int exitCode;
542 final stdout; 557 final stdout;
543 final stderr; 558 final stderr;
544 } 559 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/io/file_system_entity.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698