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

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

Issue 10689169: Use environment variables to find the Dart SDK and the Pub cache directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 8 years, 5 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 | « utils/pub/io.dart ('k') | utils/pub/sdk_source.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) 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 * The main entrypoint for the pub command line application. 6 * The main entrypoint for the pub command line application.
7 */ 7 */
8 #library('pub'); 8 #library('pub');
9 9
10 #import('../../lib/args/args.dart'); 10 #import('../../lib/args/args.dart');
11 #import('dart:io');
11 #import('io.dart'); 12 #import('io.dart');
12 #import('command_install.dart'); 13 #import('command_install.dart');
13 #import('command_list.dart'); 14 #import('command_list.dart');
14 #import('command_update.dart'); 15 #import('command_update.dart');
15 #import('command_version.dart'); 16 #import('command_version.dart');
16 #import('entrypoint.dart'); 17 #import('entrypoint.dart');
17 #import('git_source.dart'); 18 #import('git_source.dart');
18 #import('package.dart'); 19 #import('package.dart');
19 #import('pubspec.dart'); 20 #import('pubspec.dart');
20 #import('repo_source.dart'); 21 #import('repo_source.dart');
(...skipping 15 matching lines...) Expand all
36 'install': new InstallCommand(), 37 'install': new InstallCommand(),
37 'update': new UpdateCommand(), 38 'update': new UpdateCommand(),
38 'version': new VersionCommand() 39 'version': new VersionCommand()
39 }; 40 };
40 41
41 var parser = new ArgParser(); 42 var parser = new ArgParser();
42 parser.addFlag('help', abbr: 'h', negatable: false, 43 parser.addFlag('help', abbr: 'h', negatable: false,
43 help: 'Prints this usage information'); 44 help: 'Prints this usage information');
44 parser.addFlag('version', negatable: false, 45 parser.addFlag('version', negatable: false,
45 help: 'Prints the version of Pub'); 46 help: 'Prints the version of Pub');
46 // TODO(rnystrom): Hack. These are temporary options to allow the pub tests to
47 // pass in relevant paths. Eventually these should be environment variables.
48 parser.addOption('cachedir', help: 'The directory containing the system-wide '
49 'Pub cache');
50 parser.addOption('sdkdir', help: 'The directory containing the Dart SDK');
51 parser.addFlag('trace', help: 'Prints a stack trace when an error occurs'); 47 parser.addFlag('trace', help: 'Prints a stack trace when an error occurs');
52 48
53 var globalOptions; 49 var globalOptions;
54 try { 50 try {
55 globalOptions = parser.parse(new Options().arguments); 51 globalOptions = parser.parse(new Options().arguments);
56 } catch (ArgFormatException e) { 52 } catch (ArgFormatException e) {
57 printUsage(parser, commands, description: e.message); 53 printUsage(parser, commands, description: e.message);
58 return; 54 return;
59 } 55 }
60 56
61 if (globalOptions['version']) { 57 if (globalOptions['version']) {
62 printVersion(); 58 printVersion();
63 return; 59 return;
64 } 60 }
65 61
66 if (globalOptions['help'] || globalOptions.rest.isEmpty()) { 62 if (globalOptions['help'] || globalOptions.rest.isEmpty()) {
67 printUsage(parser, commands); 63 printUsage(parser, commands);
68 return; 64 return;
69 } 65 }
70 66
71 var cache = new SystemCache(globalOptions['cachedir']); 67 // TODO(nweiz): Have a fallback for this this out automatically once 1145 is
72 cache.register(new SdkSource(globalOptions['sdkdir'])); 68 // fixed.
69 var sdkDir = Platform.environment['DART_SDK'];
70 var cacheDir;
71 if (Platform.environment.containsKey('PUB_CACHE')) {
72 cacheDir = Platform.environment['PUB_CACHE'];
73 } else {
74 // TODO(nweiz): Choose a better default for Windows.
75 cacheDir = '${Platform.environment['HOME']}/.pub-cache';
76 }
77
78 var cache = new SystemCache(cacheDir);
79 cache.register(new SdkSource(sdkDir));
73 cache.register(new GitSource()); 80 cache.register(new GitSource());
74 cache.register(new RepoSource()); 81 cache.register(new RepoSource());
75 // TODO(nweiz): Make 'repo' the default once pub.dartlang.org exists 82 // TODO(nweiz): Make 'repo' the default once pub.dartlang.org exists
76 cache.sources.setDefault('sdk'); 83 cache.sources.setDefault('sdk');
77 84
78 // Select the command. 85 // Select the command.
79 var command = commands[globalOptions.rest[0]]; 86 var command = commands[globalOptions.rest[0]];
80 if (command == null) { 87 if (command == null) {
81 printError('Unknown command "${globalOptions.rest[0]}".'); 88 printError('Unknown command "${globalOptions.rest[0]}".');
82 printError('Run "pub help" to see available commands.'); 89 printError('Run "pub help" to see available commands.');
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 future.handleException((e) => handleError(e, future.stackTrace)); 184 future.handleException((e) => handleError(e, future.stackTrace));
178 } 185 }
179 186
180 /** 187 /**
181 * Override this to perform the specific command. Return a future that 188 * Override this to perform the specific command. Return a future that
182 * completes when the command is done or fails if the command fails. If the 189 * completes when the command is done or fails if the command fails. If the
183 * command is synchronous, it may return `null`. 190 * command is synchronous, it may return `null`.
184 */ 191 */
185 abstract Future onRun(); 192 abstract Future onRun();
186 } 193 }
OLDNEW
« no previous file with comments | « utils/pub/io.dart ('k') | utils/pub/sdk_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698