Decouple the migration tool from package:dartdev so it can be migrated.

In order to migrate the migration tool to null safety, it can't have a
dependency on `package:dartdev`, because `package:dartdev` isn't
migrated yet.  (This is a problem because once the migration tool's
tests have been migrated to null safety, they will require the
transitive closure of all the packages they depend on to also be
migrated).

Fortunately, it's quite easy to change the migration tool so that it
doesn't depend on `package:dartdev`; we only need to move the class
`MigrateCommand` from `package:nnbd_migration` to `package:dartdev`.

To make this work, we have to move the constant `migrationGuideLink`
from `MigrateCommand` to `MigrationCli`, and make the method
`MigrationCli._defineOptions` public.

Change-Id: Ie1ce8db0e8245e98bbb72facddd723300816340e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/204540
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry 2021-06-23 22:57:21 +00:00 committed by commit-bot@chromium.org
parent 5377034390
commit c041afad9f
4 changed files with 55 additions and 49 deletions

View file

@ -10,8 +10,8 @@ import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:cli_util/cli_logging.dart';
import 'package:dart_style/src/cli/format_command.dart';
import 'package:dartdev/src/commands/migrate.dart';
import 'package:meta/meta.dart';
import 'package:nnbd_migration/migration_cli.dart';
import 'package:pedantic/pedantic.dart';
import 'package:pub/pub.dart';
import 'package:usage/usage.dart';

View file

@ -0,0 +1,43 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:dartdev/src/core.dart';
import 'package:nnbd_migration/migration_cli.dart';
class MigrateCommand extends DartdevCommand {
static const String cmdName = 'migrate';
static const String cmdDescription =
'Perform null safety migration on a project.';
/// Return whether the SDK has null safety on by default.
static bool get nullSafetyOnByDefault => IsEnabledByDefault.non_nullable;
final bool verbose;
MigrateCommand({this.verbose = false})
: super(cmdName, '$cmdDescription\n\n${MigrationCli.migrationGuideLink}',
verbose) {
MigrationCli.defineOptions(argParser, !verbose);
}
@override
String get invocation {
return '${super.invocation} [project or directory]';
}
@override
FutureOr<int> run() async {
var cli = MigrationCli(binaryName: 'dart $name');
try {
await cli.decodeCommandLineArgs(argResults, isVerbose: verbose)?.run();
} on MigrationExit catch (migrationExit) {
return migrationExit.exitCode;
}
return 0;
}
}

View file

@ -14,7 +14,6 @@ import 'package:analyzer/file_system/file_system.dart'
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/util/sdk.dart';
@ -22,7 +21,6 @@ import 'package:analyzer_plugin/protocol/protocol_common.dart'
hide AnalysisError;
import 'package:args/args.dart';
import 'package:cli_util/cli_logging.dart';
import 'package:dartdev/src/core.dart';
import 'package:meta/meta.dart';
import 'package:nnbd_migration/src/edit_plan.dart';
import 'package:nnbd_migration/src/exceptions.dart';
@ -137,42 +135,6 @@ class CommandLineOptions {
@required this.webPreview});
}
class MigrateCommand extends DartdevCommand {
static const String cmdName = 'migrate';
static const String cmdDescription =
'Perform null safety migration on a project.';
static const String migrationGuideLink =
'See https://dart.dev/go/null-safety-migration for a migration guide.';
/// Return whether the SDK has null safety on by default.
static bool get nullSafetyOnByDefault => IsEnabledByDefault.non_nullable;
final bool verbose;
MigrateCommand({this.verbose = false})
: super(cmdName, '$cmdDescription\n\n$migrationGuideLink', verbose) {
MigrationCli._defineOptions(argParser, !verbose);
}
@override
String get invocation {
return '${super.invocation} [project or directory]';
}
@override
FutureOr<int> run() async {
var cli = MigrationCli(binaryName: 'dart $name');
try {
await cli.decodeCommandLineArgs(argResults, isVerbose: verbose)?.run();
} on MigrationExit catch (migrationExit) {
return migrationExit.exitCode;
}
return 0;
}
}
/// Command-line API for the migration tool, with additional parameters exposed
/// for testing.
///
@ -281,6 +243,9 @@ class MigrationCli {
)),
];
static const String migrationGuideLink =
'See https://dart.dev/go/null-safety-migration for a migration guide.';
/// The name of the executable, for reporting in help messages.
final String binaryName;
@ -432,10 +397,16 @@ class MigrationCli {
'Display this help message. Add --verbose to show hidden options.',
defaultsTo: false,
negatable: false);
_defineOptions(parser, hide);
defineOptions(parser, hide);
return parser;
}
static void defineOptions(ArgParser parser, bool hide) {
for (var option in options) {
option.addToParser(parser, hide);
}
}
static Logger _defaultLoggerFactory(bool isVerbose) {
var ansi = Ansi(Ansi.terminalSupportsAnsi);
if (isVerbose) {
@ -444,12 +415,6 @@ class MigrationCli {
return Logger.standard(ansi: ansi);
}
}
static void _defineOptions(ArgParser parser, bool hide) {
for (var option in options) {
option.addToParser(parser, hide);
}
}
}
/// Data structure representing a single command-line option to the migration
@ -679,7 +644,7 @@ Exception details:
logger.stdout('Migrating ${options.directory}');
logger.stdout('');
logger.stdout(MigrateCommand.migrationGuideLink);
logger.stdout(MigrationCli.migrationGuideLink);
logger.stdout('');
if (hasMultipleAnalysisContext) {

View file

@ -18,8 +18,6 @@ dependencies:
cli_util: ^0.2.0
collection: ^1.14.11
crypto: ^2.0.6
dartdev:
path: ../dartdev
meta:
path: ../meta
path: ^1.6.2