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

Side by Side Diff: sdk/lib/_internal/pub/lib/src/io.dart

Issue 141113011: Support directories other than "web" in pub build. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 6 years, 10 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
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 /// Helper functionality to make working with IO easier. 5 /// Helper functionality to make working with IO easier.
6 library pub.io; 6 library pub.io;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:collection'; 9 import 'dart:collection';
10 import 'dart:convert'; 10 import 'dart:convert';
11 import 'dart:io'; 11 import 'dart:io';
12 12
13 import 'package:path/path.dart' as path; 13 import 'package:path/path.dart' as path;
14 import 'package:http/http.dart' show ByteStream; 14 import 'package:http/http.dart' show ByteStream;
15 import 'package:stack_trace/stack_trace.dart'; 15 import 'package:stack_trace/stack_trace.dart';
16 16
17 import 'exit_codes.dart' as exit_codes;
17 import 'error_group.dart'; 18 import 'error_group.dart';
18 import 'log.dart' as log; 19 import 'log.dart' as log;
19 import 'pool.dart'; 20 import 'pool.dart';
20 import 'sdk.dart' as sdk; 21 import 'sdk.dart' as sdk;
21 import 'utils.dart'; 22 import 'utils.dart';
22 23
23 export 'package:http/http.dart' show ByteStream; 24 export 'package:http/http.dart' show ByteStream;
24 25
25 /// The pool used for restricting access to asynchronous operations that consume 26 /// The pool used for restricting access to asynchronous operations that consume
26 /// file descriptors. 27 /// file descriptors.
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 // process.exitCode, and we don't want them being top-levelled by 721 // process.exitCode, and we don't want them being top-levelled by
721 // std{out,err}Sink. 722 // std{out,err}Sink.
722 store(process.stdout.handleError((_) {}), stdout, closeSink: false); 723 store(process.stdout.handleError((_) {}), stdout, closeSink: false);
723 store(process.stderr.handleError((_) {}), stderr, closeSink: false); 724 store(process.stderr.handleError((_) {}), stderr, closeSink: false);
724 return Future.wait([ 725 return Future.wait([
725 store(stream, process.stdin), 726 store(stream, process.stdin),
726 process.exitCode 727 process.exitCode
727 ]); 728 ]);
728 }).then((results) { 729 }).then((results) {
729 var exitCode = results[1]; 730 var exitCode = results[1];
730 if (exitCode != 0) { 731 if (exitCode != exit_codes.SUCCESS) {
731 throw new Exception("Failed to extract .tar.gz stream to $destination " 732 throw new Exception("Failed to extract .tar.gz stream to $destination "
732 "(exit code $exitCode)."); 733 "(exit code $exitCode).");
733 } 734 }
734 log.fine("Extracted .tar.gz stream to $destination. Exit code $exitCode."); 735 log.fine("Extracted .tar.gz stream to $destination. Exit code $exitCode.");
735 }); 736 });
736 } 737 }
737 738
738 String get pathTo7zip { 739 String get pathTo7zip {
739 if (runningFromSdk) return resourcePath(path.join('7zip', '7za.exe')); 740 if (runningFromSdk) return resourcePath(path.join('7zip', '7za.exe'));
740 return path.join(repoRoot, 'third_party', '7zip', '7za.exe'); 741 return path.join(repoRoot, 'third_party', '7zip', '7za.exe');
(...skipping 11 matching lines...) Expand all
752 return withTempDir((tempDir) { 753 return withTempDir((tempDir) {
753 // Write the archive to a temp file. 754 // Write the archive to a temp file.
754 var dataFile = path.join(tempDir, 'data.tar.gz'); 755 var dataFile = path.join(tempDir, 'data.tar.gz');
755 return createFileFromStream(stream, dataFile).then((_) { 756 return createFileFromStream(stream, dataFile).then((_) {
756 // 7zip can't unarchive from gzip -> tar -> destination all in one step 757 // 7zip can't unarchive from gzip -> tar -> destination all in one step
757 // first we un-gzip it to a tar file. 758 // first we un-gzip it to a tar file.
758 // Note: Setting the working directory instead of passing in a full file 759 // Note: Setting the working directory instead of passing in a full file
759 // path because 7zip says "A full path is not allowed here." 760 // path because 7zip says "A full path is not allowed here."
760 return runProcess(pathTo7zip, ['e', 'data.tar.gz'], workingDir: tempDir); 761 return runProcess(pathTo7zip, ['e', 'data.tar.gz'], workingDir: tempDir);
761 }).then((result) { 762 }).then((result) {
762 if (result.exitCode != 0) { 763 if (result.exitCode != exit_codes.SUCCESS) {
763 throw new Exception('Could not un-gzip (exit code ${result.exitCode}). ' 764 throw new Exception('Could not un-gzip (exit code ${result.exitCode}). '
764 'Error:\n' 765 'Error:\n'
765 '${result.stdout.join("\n")}\n' 766 '${result.stdout.join("\n")}\n'
766 '${result.stderr.join("\n")}'); 767 '${result.stderr.join("\n")}');
767 } 768 }
768 769
769 // Find the tar file we just created since we don't know its name. 770 // Find the tar file we just created since we don't know its name.
770 var tarFile = listDir(tempDir).firstWhere( 771 var tarFile = listDir(tempDir).firstWhere(
771 (file) => path.extension(file) == '.tar', 772 (file) => path.extension(file) == '.tar',
772 orElse: () { 773 orElse: () {
773 throw new FormatException('The gzip file did not contain a tar file.'); 774 throw new FormatException('The gzip file did not contain a tar file.');
774 }); 775 });
775 776
776 // Untar the archive into the destination directory. 777 // Untar the archive into the destination directory.
777 return runProcess(pathTo7zip, ['x', tarFile], workingDir: destination); 778 return runProcess(pathTo7zip, ['x', tarFile], workingDir: destination);
778 }).then((result) { 779 }).then((result) {
779 if (result.exitCode != 0) { 780 if (result.exitCode != exit_codes.SUCCESS) {
780 throw new Exception('Could not un-tar (exit code ${result.exitCode}). ' 781 throw new Exception('Could not un-tar (exit code ${result.exitCode}). '
781 'Error:\n' 782 'Error:\n'
782 '${result.stdout.join("\n")}\n' 783 '${result.stdout.join("\n")}\n'
783 '${result.stderr.join("\n")}'); 784 '${result.stderr.join("\n")}');
784 } 785 }
785 return true; 786 return true;
786 }); 787 });
787 }); 788 });
788 } 789 }
789 790
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 } 849 }
849 850
850 /// Contains the results of invoking a [Process] and waiting for it to complete. 851 /// Contains the results of invoking a [Process] and waiting for it to complete.
851 class PubProcessResult { 852 class PubProcessResult {
852 final List<String> stdout; 853 final List<String> stdout;
853 final List<String> stderr; 854 final List<String> stderr;
854 final int exitCode; 855 final int exitCode;
855 856
856 const PubProcessResult(this.stdout, this.stderr, this.exitCode); 857 const PubProcessResult(this.stdout, this.stderr, this.exitCode);
857 858
858 bool get success => exitCode == 0; 859 bool get success => exitCode == exit_codes.SUCCESS;
859 } 860 }
860 861
861 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. 862 /// Gets a [Uri] for [uri], which can either already be one, or be a [String].
862 Uri _getUri(uri) { 863 Uri _getUri(uri) {
863 if (uri is Uri) return uri; 864 if (uri is Uri) return uri;
864 return Uri.parse(uri); 865 return Uri.parse(uri);
865 } 866 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698