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

Side by Side Diff: utils/pub/io.dart

Issue 11170003: Pub fix for Windows (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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
« utils/pub/hosted_source.dart ('K') | « utils/pub/hosted_source.dart ('k') | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * Helper functionality to make working with IO easier. 6 * Helper functionality to make working with IO easier.
7 */ 7 */
8 library io; 8 library io;
9 9
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 args = flatten(["/c", executable, args]); 492 args = flatten(["/c", executable, args]);
493 executable = "cmd"; 493 executable = "cmd";
494 } 494 }
495 495
496 final options = new ProcessOptions(); 496 final options = new ProcessOptions();
497 if (workingDir != null) { 497 if (workingDir != null) {
498 options.workingDirectory = _getDirectory(workingDir).path; 498 options.workingDirectory = _getDirectory(workingDir).path;
499 } 499 }
500 options.environment = environment; 500 options.environment = environment;
501 501
502 final process = Process.start(executable, args, options); 502 var future = Process.run(executable, args, options);
503 503 return future.transform((result) {
504 final outStream = new StringInputStream(process.stdout); 504 return new PubProcessResult(result.stdout, result.stderr, result.exitCode);
505 final processStdout = <String>[]; 505 });
506
507 final errStream = new StringInputStream(process.stderr);
508 final processStderr = <String>[];
509
510 final completer = new Completer<PubProcessResult>();
511
512 checkComplete() {
513 // Wait until the process is done and its output streams are closed.
514 if (!pipeStdout && !outStream.closed) return;
515 if (!pipeStderr && !errStream.closed) return;
516 if (exitCode == null) return;
517
518 completer.complete(new PubProcessResult(
519 processStdout, processStderr, exitCode));
520 }
521
522 if (pipeStdout) {
523 process.stdout.pipe(stdout, close: false);
524 } else {
525 outStream.onLine = () => processStdout.add(outStream.readLine());
526 outStream.onClosed = checkComplete;
527 outStream.onError = (error) => completer.completeException(error);
528 }
529
530 if (pipeStderr) {
531 process.stderr.pipe(stderr, close: false);
532 } else {
533 errStream.onLine = () => processStderr.add(errStream.readLine());
534 errStream.onClosed = checkComplete;
535 errStream.onError = (error) => completer.completeException(error);
536 }
537
538 process.onExit = (actualExitCode) {
539 exitCode = actualExitCode;
540 checkComplete();
541 };
542
543 process.onError = (error) => completer.completeException(error);
544
545 return completer.future;
546 } 506 }
547 507
548 /** 508 /**
549 * Wraps [input] to provide a timeout. If [input] completes before 509 * Wraps [input] to provide a timeout. If [input] completes before
550 * [milliseconds] have passed, then the return value completes in the same way. 510 * [milliseconds] have passed, then the return value completes in the same way.
551 * However, if [milliseconds] pass before [input] has completed, it completes 511 * However, if [milliseconds] pass before [input] has completed, it completes
552 * with a [TimeoutException] with [message]. 512 * with a [TimeoutException] with [message].
553 * 513 *
554 * Note that timing out will not cancel the asynchronous operation behind 514 * Note that timing out will not cancel the asynchronous operation behind
555 * [input]. 515 * [input].
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 // 7zip seems to periodically fail when we invoke it from Dart and tell it to 629 // 7zip seems to periodically fail when we invoke it from Dart and tell it to
670 // read from stdin instead of a file. Consider resurrecting that version if 630 // read from stdin instead of a file. Consider resurrecting that version if
671 // we can figure out why it fails. 631 // we can figure out why it fails.
672 632
673 // Find 7zip. 633 // Find 7zip.
674 var scriptPath = new File(new Options().script).fullPathSync(); 634 var scriptPath = new File(new Options().script).fullPathSync();
675 var scriptDir = new Path.fromNative(scriptPath).directoryPath; 635 var scriptDir = new Path.fromNative(scriptPath).directoryPath;
676 636
677 // Note: This line of code gets munged by create_sdk.py to be the correct 637 // Note: This line of code gets munged by create_sdk.py to be the correct
678 // relative path to 7zip in the SDK. 638 // relative path to 7zip in the SDK.
679 var pathTo7zip = '../../third_party/7zip/7za.exe'; 639 var pathTo7zip = '7zip/7za.exe';
kasperl 2012/10/16 08:01:27 Have you double checked that this works with creat
Anders Johnsen 2012/10/16 08:03:19 I didn't see this change. Is this intentional?
Johnni Winther 2012/10/16 08:08:01 Removed.
680 var command = scriptDir.append(pathTo7zip).canonicalize().toNativePath(); 640 var command = scriptDir.append(pathTo7zip).canonicalize().toNativePath();
681 641
682 var tempDir; 642 var tempDir;
683 643
684 return createTempDir().chain((temp) { 644 return createTempDir().chain((temp) {
685 // Write the archive to a temp file. 645 // Write the archive to a temp file.
686 tempDir = temp; 646 tempDir = temp;
687 return createFileFromStream(stream, join(tempDir, 'data.tar.gz')); 647 return createFileFromStream(stream, join(tempDir, 'data.tar.gz'));
688 }).chain((_) { 648 }).chain((_) {
689 // TODO(rnystrom): Hack. We get intermittent "file already in use" errors. 649 // TODO(rnystrom): Hack. We get intermittent "file already in use" errors.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 return new Directory(entry); 745 return new Directory(entry);
786 } 746 }
787 747
788 /** 748 /**
789 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. 749 * Gets a [Uri] for [uri], which can either already be one, or be a [String].
790 */ 750 */
791 Uri _getUri(uri) { 751 Uri _getUri(uri) {
792 if (uri is Uri) return uri; 752 if (uri is Uri) return uri;
793 return new Uri.fromString(uri); 753 return new Uri.fromString(uri);
794 } 754 }
OLDNEW
« utils/pub/hosted_source.dart ('K') | « utils/pub/hosted_source.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698