Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 patch class _WindowsCodePageEncoder { | 11 patch class _WindowsCodePageEncoder { |
| 12 /* patch */ static List<int> _encodeString(String string) | 12 /* patch */ static List<int> _encodeString(String string) |
| 13 native "StringToSystemEncoding"; | 13 native "StringToSystemEncoding"; |
| 14 } | 14 } |
| 15 | 15 |
| 16 | 16 |
| 17 patch class Process { | 17 patch class Process { |
| 18 /* patch */ static Future<Process> start( | 18 /* patch */ static Future<Process> start( |
| 19 String executable, | 19 String executable, |
| 20 List<String> arguments, | 20 List<String> arguments, |
| 21 {String workingDirectory, | 21 {String workingDirectory, |
| 22 Map<String, String> environment, | 22 Map<String, String> environment, |
| 23 bool runInShell}) { | 23 bool includeParentEnvironment: true, |
| 24 bool runInShell: false}) { | |
| 24 _ProcessImpl process = new _ProcessImpl(executable, | 25 _ProcessImpl process = new _ProcessImpl(executable, |
| 25 arguments, | 26 arguments, |
| 26 workingDirectory, | 27 workingDirectory, |
| 27 environment, | 28 environment, |
| 29 includeParentEnvironment, | |
| 28 runInShell); | 30 runInShell); |
| 29 return process._start(); | 31 return process._start(); |
| 30 } | 32 } |
| 31 | 33 |
| 32 /* patch */ static Future<ProcessResult> run( | 34 /* patch */ static Future<ProcessResult> run( |
| 33 String executable, | 35 String executable, |
| 34 List<String> arguments, | 36 List<String> arguments, |
| 35 {String workingDirectory, | 37 {String workingDirectory, |
| 36 Map<String, String> environment, | 38 Map<String, String> environment, |
| 37 bool runInShell, | 39 bool includeParentEnvironment: true, |
| 40 bool runInShell: false, | |
| 38 Encoding stdoutEncoding: Encoding.SYSTEM, | 41 Encoding stdoutEncoding: Encoding.SYSTEM, |
| 39 Encoding stderrEncoding: Encoding.SYSTEM}) { | 42 Encoding stderrEncoding: Encoding.SYSTEM}) { |
| 40 return _runNonInteractiveProcess(executable, | 43 return _runNonInteractiveProcess(executable, |
| 41 arguments, | 44 arguments, |
| 42 workingDirectory, | 45 workingDirectory, |
| 43 environment, | 46 environment, |
| 47 includeParentEnvironment, | |
| 44 runInShell, | 48 runInShell, |
| 45 stdoutEncoding, | 49 stdoutEncoding, |
| 46 stderrEncoding); | 50 stderrEncoding); |
| 47 } | 51 } |
| 48 } | 52 } |
| 49 | 53 |
| 50 | 54 |
| 51 patch class _ProcessUtils { | 55 patch class _ProcessUtils { |
| 52 /* patch */ static void _exit(int status) native "Process_Exit"; | 56 /* patch */ static void _exit(int status) native "Process_Exit"; |
| 53 /* patch */ static void _setExitCode(int status) | 57 /* patch */ static void _setExitCode(int status) |
| 54 native "Process_SetExitCode"; | 58 native "Process_SetExitCode"; |
| 55 /* patch */ static void _sleep(int millis) native "Process_Sleep"; | 59 /* patch */ static void _sleep(int millis) native "Process_Sleep"; |
| 56 /* patch */ static int _pid(Process process) native "Process_Pid"; | 60 /* patch */ static int _pid(Process process) native "Process_Pid"; |
| 57 } | 61 } |
| 58 | 62 |
| 59 | 63 |
| 60 class _ProcessStartStatus { | 64 class _ProcessStartStatus { |
| 61 int _errorCode; // Set to OS error code if process start failed. | 65 int _errorCode; // Set to OS error code if process start failed. |
| 62 String _errorMessage; // Set to OS error message if process start failed. | 66 String _errorMessage; // Set to OS error message if process start failed. |
| 63 } | 67 } |
| 64 | 68 |
| 65 | 69 |
| 66 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { | 70 class _ProcessImpl extends NativeFieldWrapperClass1 implements Process { |
| 67 _ProcessImpl(String path, | 71 _ProcessImpl(String path, |
| 68 List<String> arguments, | 72 List<String> arguments, |
| 69 String this._workingDirectory, | 73 String this._workingDirectory, |
| 70 Map<String, String> environment, | 74 Map<String, String> environment, |
| 75 bool includeParentEnvironment, | |
| 71 bool runInShell) { | 76 bool runInShell) { |
| 72 runInShell = identical(runInShell, true); | 77 runInShell = identical(runInShell, true); |
| 73 if (runInShell) { | 78 if (runInShell) { |
| 74 arguments = _getShellArguments(path, arguments); | 79 arguments = _getShellArguments(path, arguments); |
| 75 path = _getShellCommand(); | 80 path = _getShellCommand(); |
| 76 } | 81 } |
| 77 | 82 |
| 78 if (path is !String) { | 83 if (path is !String) { |
| 79 throw new ArgumentError("Path is not a String: $path"); | 84 throw new ArgumentError("Path is not a String: $path"); |
| 80 } | 85 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 95 _arguments[i] = _windowsArgumentEscape(_arguments[i], | 100 _arguments[i] = _windowsArgumentEscape(_arguments[i], |
| 96 shellEscape: runInShell); | 101 shellEscape: runInShell); |
| 97 } | 102 } |
| 98 } | 103 } |
| 99 | 104 |
| 100 if (_workingDirectory != null && _workingDirectory is !String) { | 105 if (_workingDirectory != null && _workingDirectory is !String) { |
| 101 throw new ArgumentError( | 106 throw new ArgumentError( |
| 102 "WorkingDirectory is not a String: $_workingDirectory"); | 107 "WorkingDirectory is not a String: $_workingDirectory"); |
| 103 } | 108 } |
| 104 | 109 |
| 105 if (environment != null) { | 110 _environment = []; |
| 106 var env = environment; | 111 if (environment == null) { |
| 107 if (env is !Map) { | 112 environment = {}; |
| 108 throw new ArgumentError("Environment is not a map: $env"); | 113 } |
| 114 if (identical(true, includeParentEnvironment)) { | |
| 115 environment = Platform.environment..addAll(environment); | |
| 116 } | |
|
Søren Gjesse
2013/06/20 20:15:50
I think this type check needs to be before the if
Anders Johnsen
2013/06/21 06:44:09
Done.
| |
| 117 if (environment is !Map) { | |
| 118 throw new ArgumentError("Environment is not a map: $environment"); | |
| 119 } | |
| 120 environment.forEach((key, value) { | |
| 121 if (key is !String || value is !String) { | |
| 122 throw new ArgumentError( | |
| 123 "Environment key or value is not a string: ($key, $value)"); | |
| 109 } | 124 } |
| 110 _environment = []; | 125 _environment.add('$key=$value'); |
| 111 env.forEach((key, value) { | 126 }); |
| 112 if (key is !String || value is !String) { | |
| 113 throw new ArgumentError( | |
| 114 "Environment key or value is not a string: ($key, $value)"); | |
| 115 } | |
| 116 _environment.add('$key=$value'); | |
| 117 }); | |
| 118 } | |
| 119 | 127 |
| 120 // stdin going to process. | 128 // stdin going to process. |
| 121 _stdin = new _StdSink(new _Socket._writePipe()); | 129 _stdin = new _StdSink(new _Socket._writePipe()); |
| 122 // stdout coming from process. | 130 // stdout coming from process. |
| 123 _stdout = new _StdStream(new _Socket._readPipe()); | 131 _stdout = new _StdStream(new _Socket._readPipe()); |
| 124 // stderr coming from process. | 132 // stderr coming from process. |
| 125 _stderr = new _StdStream(new _Socket._readPipe()); | 133 _stderr = new _StdStream(new _Socket._readPipe()); |
| 126 _exitHandler = new _Socket._readPipe(); | 134 _exitHandler = new _Socket._readPipe(); |
| 127 _ended = false; | 135 _ended = false; |
| 128 _started = false; | 136 _started = false; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 | 334 |
| 327 | 335 |
| 328 // _NonInteractiveProcess is a wrapper around an interactive process | 336 // _NonInteractiveProcess is a wrapper around an interactive process |
| 329 // that buffers output so it can be delivered when the process exits. | 337 // that buffers output so it can be delivered when the process exits. |
| 330 // _NonInteractiveProcess is used to implement the Process.run | 338 // _NonInteractiveProcess is used to implement the Process.run |
| 331 // method. | 339 // method. |
| 332 Future<ProcessResult> _runNonInteractiveProcess(String path, | 340 Future<ProcessResult> _runNonInteractiveProcess(String path, |
| 333 List<String> arguments, | 341 List<String> arguments, |
| 334 String workingDirectory, | 342 String workingDirectory, |
| 335 Map<String, String> environment, | 343 Map<String, String> environment, |
| 344 bool includeParentEnvironment, | |
| 336 bool runInShell, | 345 bool runInShell, |
| 337 Encoding stdoutEncoding, | 346 Encoding stdoutEncoding, |
| 338 Encoding stderrEncoding) { | 347 Encoding stderrEncoding) { |
| 339 // Start the underlying process. | 348 // Start the underlying process. |
| 340 return Process.start(path, | 349 return Process.start(path, |
| 341 arguments, | 350 arguments, |
| 342 workingDirectory: workingDirectory, | 351 workingDirectory: workingDirectory, |
| 343 environment: environment, | 352 environment: environment, |
| 353 includeParentEnvironment: includeParentEnvironment, | |
| 344 runInShell: runInShell).then((Process p) { | 354 runInShell: runInShell).then((Process p) { |
| 345 int pid = p.pid; | 355 int pid = p.pid; |
| 346 | 356 |
| 347 // Make sure the process stdin is closed. | 357 // Make sure the process stdin is closed. |
| 348 p.stdin.close(); | 358 p.stdin.close(); |
| 349 | 359 |
| 350 // Setup stdout and stderr handling. | 360 // Setup stdout and stderr handling. |
| 351 Future foldStream(Stream<List<int>> stream, Encoding encoding) { | 361 Future foldStream(Stream<List<int>> stream, Encoding encoding) { |
| 352 if (encoding == null) { | 362 if (encoding == null) { |
| 353 return stream | 363 return stream |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 const _ProcessResult(int this.pid, | 395 const _ProcessResult(int this.pid, |
| 386 int this.exitCode, | 396 int this.exitCode, |
| 387 this.stdout, | 397 this.stdout, |
| 388 this.stderr); | 398 this.stderr); |
| 389 | 399 |
| 390 final int pid; | 400 final int pid; |
| 391 final int exitCode; | 401 final int exitCode; |
| 392 final stdout; | 402 final stdout; |
| 393 final stderr; | 403 final stderr; |
| 394 } | 404 } |
| OLD | NEW |