Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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(r'^ +"pub_rev": +"@([^"]+)"', multiLine: true) ; | |
|
Bob Nystrom
2015/07/13 17:15:35
Long line.
nweiz
2015/07/13 20:13:34
Done.
| |
| 166 var match = pubRevRegExp.firstMatch(deps); | |
| 167 if (match == null) return; | |
|
Bob Nystrom
2015/07/13 17:15:35
Do we want to silently fail?
nweiz
2015/07/13 20:13:33
I don't really want to make this a place where we
| |
| 168 var depsRev = match[1]; | |
| 169 | |
| 170 var actualRev = git.runSync(["rev-parse", "HEAD"], workingDir: pubRoot) | |
|
Bob Nystrom
2015/07/13 17:15:35
What does this do to the test cycle time?
nweiz
2015/07/13 20:13:34
I'll run a test. I suspect it won't be that bad; g
| |
| 171 .single; | |
| 172 | |
| 173 if (depsRev == actualRev) return; | |
| 174 log.warning( | |
| 175 "${log.yellow('Warning:')} the revision of pub in DEPS is " | |
| 176 "${log.bold(depsRev)},\n" | |
| 177 "but ${log.bold(actualRev)} is checked out in " | |
| 178 "${p.relative(pubRoot)}.\n\n"); | |
| 179 } | |
| 180 | |
| 153 /// Returns the appropriate exit code for [exception], falling back on 1 if no | 181 /// Returns the appropriate exit code for [exception], falling back on 1 if no |
| 154 /// appropriate exit code could be found. | 182 /// appropriate exit code could be found. |
| 155 int _chooseExitCode(exception) { | 183 int _chooseExitCode(exception) { |
| 156 while (exception is WrappedException) exception = exception.innerError; | 184 while (exception is WrappedException) exception = exception.innerError; |
| 157 | 185 |
| 158 if (exception is HttpException || exception is http.ClientException || | 186 if (exception is HttpException || exception is http.ClientException || |
| 159 exception is SocketException || exception is PubHttpException || | 187 exception is SocketException || exception is PubHttpException || |
| 160 exception is DependencyNotFoundException) { | 188 exception is DependencyNotFoundException) { |
| 161 return exit_codes.UNAVAILABLE; | 189 return exit_codes.UNAVAILABLE; |
| 162 } else if (exception is FormatException || exception is DataException) { | 190 } else if (exception is FormatException || exception is DataException) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 175 Future _validatePlatform() async { | 203 Future _validatePlatform() async { |
| 176 if (Platform.operatingSystem != 'windows') return; | 204 if (Platform.operatingSystem != 'windows') return; |
| 177 | 205 |
| 178 var result = await runProcess('ver', []); | 206 var result = await runProcess('ver', []); |
| 179 if (result.stdout.join('\n').contains('XP')) { | 207 if (result.stdout.join('\n').contains('XP')) { |
| 180 log.error('Sorry, but pub is not supported on Windows XP.'); | 208 log.error('Sorry, but pub is not supported on Windows XP.'); |
| 181 await flushThenExit(exit_codes.USAGE); | 209 await flushThenExit(exit_codes.USAGE); |
| 182 } | 210 } |
| 183 } | 211 } |
| 184 } | 212 } |
| OLD | NEW |