Skip to content

Commit 6118481

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Migrator: use dart pub to check outdated
Fixes #42343 This also prevents a crash if the binary-to-execute could not be found. Change-Id: I19dd9f6dcbb41a5c8b4ef2a04a87c1fc83429120 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151327 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 1a2cbd5 commit 6118481

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pkg/nnbd_migration/lib/migration_cli.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ class CommandLineOptions {
8989

9090
@visibleForTesting
9191
class DependencyChecker {
92-
static final _pubName = Platform.isWindows ? 'pub.bat' : 'pub';
93-
9492
/// The directory which contains the package being migrated.
9593
final String _directory;
9694
final Context _pathContext;
@@ -101,16 +99,15 @@ class DependencyChecker {
10199
this._directory, this._pathContext, this._logger, this._processManager);
102100

103101
bool check() {
104-
var pubPath = _pathContext.join(getSdkPath(), 'bin', _pubName);
105-
var result = _processManager.runSync(
106-
pubPath, ['outdated', '--mode=null-safety', '--json'],
107-
workingDirectory: _directory);
108-
102+
var pubPath = _pathContext.join(getSdkPath(), 'bin', 'dart');
103+
var pubArguments = ['pub', 'outdated', '--mode=null-safety', '--json'];
109104
var preNullSafetyPackages = <String, String>{};
110105
try {
106+
var result = _processManager.runSync(pubPath, pubArguments,
107+
workingDirectory: _directory);
111108
if ((result.stderr as String).isNotEmpty) {
112109
throw FormatException(
113-
'`pub outdated --mode=null-safety` exited with exit code '
110+
'`dart pub outdated --mode=null-safety` exited with exit code '
114111
'${result.exitCode} and stderr:\n\n${result.stderr}');
115112
}
116113
var outdatedOutput = jsonDecode(result.stdout as String);
@@ -139,6 +136,12 @@ class DependencyChecker {
139136
var version = json.expectType<String>(current['version'], 'version');
140137
preNullSafetyPackages[name] = version;
141138
}
139+
} on ProcessException catch (e) {
140+
_logger.stderr(
141+
'Warning: Could not execute `$pubPath ${pubArguments.join(' ')}`: '
142+
'"${e.message}"');
143+
// Allow the program to continue; users should be allowed to attempt to
144+
// migrate when `pub outdated` is misbehaving, or if there is a bug above.
142145
} on FormatException catch (e) {
143146
_logger.stderr('Warning: ${e.message}');
144147
// Allow the program to continue; users should be allowed to attempt to
@@ -156,7 +159,7 @@ class DependencyChecker {
156159
}
157160
_logger.stderr('');
158161
_logger.stderr('It is highly recommended to upgrade all dependencies to '
159-
'versions which have migrated. Use `$_pubName outdated '
162+
'versions which have migrated. Use `dart pub outdated '
160163
'--mode=null-safety` to check the status of dependencies.');
161164
_logger.stderr('');
162165
_logger.stderr('Visit https://dart.dev/tools/pub/cmd/pub-outdated for '

0 commit comments

Comments
 (0)