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

Side by Side Diff: lib/src/command_runner.dart

Issue 1227913009: Warn if pub isn't up-to-date in the SDK repo. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 5 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
« no previous file with comments | « no previous file | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library pub.command_runner; 5 library pub.command_runner;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:args/args.dart'; 10 import 'package:args/args.dart';
11 import 'package:args/command_runner.dart'; 11 import 'package:args/command_runner.dart';
12 import 'package:http/http.dart' as http; 12 import 'package:http/http.dart' as http;
13 import 'package:path/path.dart' as p;
13 14
14 import 'command/build.dart'; 15 import 'command/build.dart';
15 import 'command/cache.dart'; 16 import 'command/cache.dart';
16 import 'command/deps.dart'; 17 import 'command/deps.dart';
17 import 'command/downgrade.dart'; 18 import 'command/downgrade.dart';
18 import 'command/get.dart'; 19 import 'command/get.dart';
19 import 'command/global.dart'; 20 import 'command/global.dart';
20 import 'command/lish.dart'; 21 import 'command/lish.dart';
21 import 'command/list_package_dirs.dart'; 22 import 'command/list_package_dirs.dart';
22 import 'command/run.dart'; 23 import 'command/run.dart';
23 import 'command/serve.dart'; 24 import 'command/serve.dart';
24 import 'command/upgrade.dart'; 25 import 'command/upgrade.dart';
25 import 'command/uploader.dart'; 26 import 'command/uploader.dart';
26 import 'command/version.dart'; 27 import 'command/version.dart';
27 import 'exceptions.dart'; 28 import 'exceptions.dart';
28 import 'exit_codes.dart' as exit_codes; 29 import 'exit_codes.dart' as exit_codes;
30 import 'git.dart' as git;
29 import 'http.dart'; 31 import 'http.dart';
30 import 'io.dart'; 32 import 'io.dart';
31 import 'log.dart' as log; 33 import 'log.dart' as log;
32 import 'sdk.dart' as sdk; 34 import 'sdk.dart' as sdk;
33 import 'solver/version_solver.dart'; 35 import 'solver/version_solver.dart';
34 import 'utils.dart'; 36 import 'utils.dart';
35 37
36 class PubCommandRunner extends CommandRunner { 38 class PubCommandRunner extends CommandRunner {
37 String get usageFooter => "See http://dartlang.org/tools/pub for detailed " 39 String get usageFooter => "See http://dartlang.org/tools/pub for detailed "
38 "documentation."; 40 "documentation.";
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } on UsageException catch (error) { 84 } on UsageException catch (error) {
83 log.error(error.message); 85 log.error(error.message);
84 await flushThenExit(exit_codes.USAGE); 86 await flushThenExit(exit_codes.USAGE);
85 } 87 }
86 await runCommand(options); 88 await runCommand(options);
87 } 89 }
88 90
89 Future runCommand(ArgResults options) async { 91 Future runCommand(ArgResults options) async {
90 log.withPrejudice = options['with-prejudice']; 92 log.withPrejudice = options['with-prejudice'];
91 93
94 _checkDepsSynced();
95
92 if (options['version']) { 96 if (options['version']) {
93 log.message('Pub ${sdk.version}'); 97 log.message('Pub ${sdk.version}');
94 return; 98 return;
95 } 99 }
96 100
97 if (options['trace']) { 101 if (options['trace']) {
98 log.recordTranscript(); 102 log.recordTranscript();
99 } 103 }
100 104
101 switch (options['verbosity']) { 105 switch (options['verbosity']) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 147 }
144 148
145 await flushThenExit(_chooseExitCode(error)); 149 await flushThenExit(_chooseExitCode(error));
146 } 150 }
147 } 151 }
148 152
149 void printUsage() { 153 void printUsage() {
150 log.message(usage); 154 log.message(usage);
151 } 155 }
152 156
157 /// Print a warning if we're running from the Dart SDK repo and pub isn't
158 /// up-to-date.
159 ///
160 /// This is otherwise hard to tell, and can produce confusing behavior issues.
161 void _checkDepsSynced() {
162 if (!runningFromDartRepo) return;
163
164 var deps = readTextFile(p.join(dartRepoRoot, 'DEPS'));
165 var pubRevRegExp = new RegExp(
166 r'^ +"pub_rev": +"@([^"]+)"', multiLine: true);
167 var match = pubRevRegExp.firstMatch(deps);
168 if (match == null) return;
169 var depsRev = match[1];
170
171 var actualRev = git.runSync(["rev-parse", "HEAD"], workingDir: pubRoot)
172 .single;
173
174 if (depsRev == actualRev) return;
175 log.warning(
176 "${log.yellow('Warning:')} the revision of pub in DEPS is "
177 "${log.bold(depsRev)},\n"
178 "but ${log.bold(actualRev)} is checked out in "
179 "${p.relative(pubRoot)}.\n\n");
180 }
181
153 /// Returns the appropriate exit code for [exception], falling back on 1 if no 182 /// Returns the appropriate exit code for [exception], falling back on 1 if no
154 /// appropriate exit code could be found. 183 /// appropriate exit code could be found.
155 int _chooseExitCode(exception) { 184 int _chooseExitCode(exception) {
156 while (exception is WrappedException) exception = exception.innerError; 185 while (exception is WrappedException) exception = exception.innerError;
157 186
158 if (exception is HttpException || exception is http.ClientException || 187 if (exception is HttpException || exception is http.ClientException ||
159 exception is SocketException || exception is PubHttpException || 188 exception is SocketException || exception is PubHttpException ||
160 exception is DependencyNotFoundException) { 189 exception is DependencyNotFoundException) {
161 return exit_codes.UNAVAILABLE; 190 return exit_codes.UNAVAILABLE;
162 } else if (exception is FormatException || exception is DataException) { 191 } else if (exception is FormatException || exception is DataException) {
(...skipping 12 matching lines...) Expand all
175 Future _validatePlatform() async { 204 Future _validatePlatform() async {
176 if (Platform.operatingSystem != 'windows') return; 205 if (Platform.operatingSystem != 'windows') return;
177 206
178 var result = await runProcess('ver', []); 207 var result = await runProcess('ver', []);
179 if (result.stdout.join('\n').contains('XP')) { 208 if (result.stdout.join('\n').contains('XP')) {
180 log.error('Sorry, but pub is not supported on Windows XP.'); 209 log.error('Sorry, but pub is not supported on Windows XP.');
181 await flushThenExit(exit_codes.USAGE); 210 await flushThenExit(exit_codes.USAGE);
182 } 211 }
183 } 212 }
184 } 213 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698