Skip to content

Commit da029c6

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: try to help users who update their pubspec before migrating.
Fixes #44144. Bug: #44144 Change-Id: I5db52426ba4e6a4cde803ae38fbc479cb8bbb862 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171624 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent da92120 commit da029c6

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

pkg/nnbd_migration/lib/migration_cli.dart

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:async';
66
import 'dart:io' hide File;
77

88
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
9+
import 'package:analyzer/dart/analysis/features.dart';
910
import 'package:analyzer/dart/analysis/results.dart';
1011
import 'package:analyzer/diagnostic/diagnostic.dart';
1112
import 'package:analyzer/error/error.dart';
@@ -50,9 +51,10 @@ class AnalysisResult {
5051
final Map<String, LineInfo> lineInfo;
5152
final Context pathContext;
5253
final String rootDirectory;
54+
final bool allSourcesAlreadyMigrated;
5355

54-
AnalysisResult(
55-
this.errors, this.lineInfo, this.pathContext, this.rootDirectory) {
56+
AnalysisResult(this.errors, this.lineInfo, this.pathContext,
57+
this.rootDirectory, this.allSourcesAlreadyMigrated) {
5658
errors.sort((AnalysisError one, AnalysisError two) {
5759
if (one.source != two.source) {
5860
return one.source.fullName.compareTo(two.source.fullName);
@@ -876,6 +878,14 @@ Exception details:
876878
.stdout('Unresolved URIs found. Did you forget to run "pub get"?');
877879
logger.stdout('');
878880
}
881+
if (analysisResult.allSourcesAlreadyMigrated) {
882+
logger.stdout('''
883+
All files appear to have null safety already enabled. Did you update the
884+
language version prior to running "dart migrate"? If so, you need to un-do this
885+
(and re-run "pub get") prior to performing the migration.
886+
''');
887+
logger.stdout('');
888+
}
879889
logger.stdout(
880890
'Please fix the analysis issues (or, force generation of migration '
881891
'suggestions by re-running with '
@@ -1037,7 +1047,11 @@ class _FixCodeProcessor extends Object {
10371047
_progressBar = ProgressBar(_migrationCli.logger, pathsToProcess.length);
10381048

10391049
// Process each source file.
1050+
bool allSourcesAlreadyMigrated = true;
10401051
await processResources((ResolvedUnitResult result) async {
1052+
if (!result.unit.featureSet.isEnabled(Feature.non_nullable)) {
1053+
allSourcesAlreadyMigrated = false;
1054+
}
10411055
_progressBar.tick();
10421056
List<AnalysisError> errors = result.errors
10431057
.where((error) => error.severity == Severity.error)
@@ -1061,8 +1075,12 @@ class _FixCodeProcessor extends Object {
10611075
}
10621076
}
10631077

1064-
return AnalysisResult(analysisErrors, _migrationCli.lineInfo,
1065-
_migrationCli.pathContext, _migrationCli.options.directory);
1078+
return AnalysisResult(
1079+
analysisErrors,
1080+
_migrationCli.lineInfo,
1081+
_migrationCli.pathContext,
1082+
_migrationCli.options.directory,
1083+
allSourcesAlreadyMigrated);
10661084
}
10671085

10681086
Future<MigrationState> runLaterPhases() async {

pkg/nnbd_migration/test/migration_cli_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ int f() => null
750750
contains(
751751
'analysis errors will result in erroneous migration suggestions'));
752752
expect(output, contains('Please fix the analysis issues'));
753+
expect(
754+
output,
755+
isNot(
756+
contains('All files appear to have null safety already enabled')));
753757
}
754758

755759
test_lifecycle_ignore_errors_enable() async {
@@ -1491,6 +1495,10 @@ int f() => null;
14911495
expect(output,
14921496
contains('Unresolved URIs found. Did you forget to run "pub get"?'));
14931497
expect(output, contains('Please fix the analysis issues'));
1498+
expect(
1499+
output,
1500+
isNot(
1501+
contains('All files appear to have null safety already enabled')));
14941502
}
14951503

14961504
test_migrate_path_absolute() {
@@ -1904,6 +1912,9 @@ environment:
19041912
errorOutput,
19051913
contains("A value of type 'Null' can't be returned from function 'f' "
19061914
"because it has a return type of 'int'"));
1915+
expect(errorOutput, contains('''
1916+
All files appear to have null safety already enabled. Did you update the
1917+
language version prior to running "dart migrate"?'''));
19071918
}
19081919

19091920
String _getHelpText({@required bool verbose}) {

0 commit comments

Comments
 (0)