mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:37:53 +00:00
Add a host of server debugging options to dartdev migrate.
Use --debug to switch on observatory, assert checking, and stdout/stderr passthrough from the analysis server when running dartdev migrate. Also adds --sdk-path and --server-path options so you have the ability to run without the snapshot or from the non-NNBD SDK. Change-Id: I52aba5268e1f8c2fe1d555b5dfb10e8f9133299d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138610 Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Janice Collins <jcollins@google.com>
This commit is contained in:
parent
7617e327a1
commit
6b71477d6e
|
@ -26,6 +26,10 @@ class Server {
|
|||
/// or if the server has already been stopped.
|
||||
Process _process;
|
||||
|
||||
/// Replicate all stdout/stderr data from the server process to stdout/stderr,
|
||||
/// when true.
|
||||
bool _stdioPassthrough;
|
||||
|
||||
/// Commands that have been sent to the server but not yet acknowledged,
|
||||
/// and the [Completer] objects which should be completed
|
||||
/// when acknowledgement is received.
|
||||
|
@ -43,9 +47,11 @@ class Server {
|
|||
/// [listenToOutput] has not been called or [stop] has been called.
|
||||
StreamSubscription<String> _stdoutSubscription;
|
||||
|
||||
Server({ServerListener listener, Process process})
|
||||
Server(
|
||||
{ServerListener listener, Process process, bool stdioPassthrough = false})
|
||||
: _listener = listener,
|
||||
_process = process;
|
||||
_process = process,
|
||||
_stdioPassthrough = stdioPassthrough;
|
||||
|
||||
/// Force kill the server. Returns exit code future.
|
||||
Future<int> kill({String reason = 'none'}) {
|
||||
|
@ -63,6 +69,7 @@ class Server {
|
|||
.transform(utf8.decoder)
|
||||
.transform(LineSplitter())
|
||||
.listen((String line) {
|
||||
if (_stdioPassthrough) stdout.writeln(line);
|
||||
String trimmedLine = line.trim();
|
||||
|
||||
// Guard against lines like:
|
||||
|
@ -116,6 +123,7 @@ class Server {
|
|||
.transform(utf8.decoder)
|
||||
.transform(LineSplitter())
|
||||
.listen((String line) {
|
||||
if (_stdioPassthrough) stderr.writeln(line);
|
||||
String trimmedLine = line.trim();
|
||||
_listener?.errorMessage(trimmedLine);
|
||||
});
|
||||
|
|
|
@ -61,17 +61,46 @@ class MigrateCommand extends Command {
|
|||
logger.stdout('Migrating ${options.directory}');
|
||||
logger.stdout('');
|
||||
|
||||
Progress progress =
|
||||
logger.progress('${ansi.emphasized('Analyzing project')}');
|
||||
|
||||
Server server =
|
||||
Server(listener: logger.isVerbose ? _ServerListener(logger) : null);
|
||||
Progress getProgress(String message) => options.debug
|
||||
? SimpleProgress(logger, message)
|
||||
: logger.progress(message);
|
||||
|
||||
Map<String, List<AnalysisError>> fileErrors = {};
|
||||
|
||||
bool enableAsserts = false;
|
||||
String instrumentationLogFile;
|
||||
bool profileServer = false;
|
||||
String serverPath = options.serverPath;
|
||||
int servicesPort;
|
||||
String sdkPath = options.sdkPath;
|
||||
bool stdioPassthrough = false;
|
||||
|
||||
if (options.debug) {
|
||||
enableAsserts = true;
|
||||
profileServer = true;
|
||||
servicesPort = 9500;
|
||||
stdioPassthrough = true;
|
||||
instrumentationLogFile = path.join(
|
||||
Directory.systemTemp.createTempSync('migration_debug').path,
|
||||
'instrumentationLog');
|
||||
logger.stdout('Instrumentation log file: ${instrumentationLogFile}');
|
||||
}
|
||||
|
||||
Progress progress = getProgress('${ansi.emphasized('Analyzing project')}');
|
||||
|
||||
Server server = Server(
|
||||
listener: logger.isVerbose ? _ServerListener(logger) : null,
|
||||
stdioPassthrough: stdioPassthrough);
|
||||
try {
|
||||
await server.start(
|
||||
clientId: 'dart $name', clientVersion: _dartSdkVersion);
|
||||
clientId: 'dart $name',
|
||||
clientVersion: _dartSdkVersion,
|
||||
enableAsserts: enableAsserts,
|
||||
instrumentationLogFile: instrumentationLogFile,
|
||||
profileServer: profileServer,
|
||||
serverPath: serverPath,
|
||||
servicesPort: servicesPort,
|
||||
sdkPath: sdkPath);
|
||||
_ServerNotifications serverNotifications = _ServerNotifications(server);
|
||||
await serverNotifications.listenToServer(server);
|
||||
|
||||
|
@ -135,9 +164,8 @@ class MigrateCommand extends Command {
|
|||
|
||||
// Calculate migration suggestions.
|
||||
logger.stdout('');
|
||||
progress = logger
|
||||
.progress('${ansi.emphasized('Generating migration suggestions')}');
|
||||
|
||||
progress =
|
||||
getProgress('${ansi.emphasized('Generating migration suggestions')}');
|
||||
Map<String, dynamic> json;
|
||||
|
||||
try {
|
||||
|
|
|
@ -9,17 +9,27 @@ import 'package:args/src/arg_parser.dart';
|
|||
import 'package:path/path.dart' as path;
|
||||
|
||||
class MigrateOptions {
|
||||
static const ignoreErrorsOption = 'ignore-errors';
|
||||
static const applyChangesOption = 'apply-changes';
|
||||
static const debugOption = 'debug';
|
||||
static const ignoreErrorsOption = 'ignore-errors';
|
||||
static const sdkPathOption = 'sdk-path';
|
||||
static const serverPathOption = 'server-path';
|
||||
static const webPreviewOption = 'web-preview';
|
||||
|
||||
final String directory;
|
||||
final bool applyChanges;
|
||||
final bool debug;
|
||||
final String directory;
|
||||
final bool ignoreErrors;
|
||||
final String serverPath;
|
||||
final String sdkPath;
|
||||
final bool webPreview;
|
||||
|
||||
MigrateOptions(ArgResults argResults, this.directory)
|
||||
: applyChanges = argResults[applyChangesOption] as bool,
|
||||
debug = argResults[debugOption] as bool,
|
||||
ignoreErrors = argResults[ignoreErrorsOption] as bool,
|
||||
sdkPath = argResults[sdkPathOption] as String,
|
||||
serverPath = argResults[serverPathOption] as String,
|
||||
webPreview = argResults['web-preview'] as bool;
|
||||
|
||||
String get directoryAbsolute => Directory(path.canonicalize(directory)).path;
|
||||
|
@ -36,6 +46,14 @@ class MigrateOptions {
|
|||
negatable: false,
|
||||
help: 'Apply the proposed null safety changes to the files on disk.',
|
||||
);
|
||||
argParser.addFlag(
|
||||
debugOption,
|
||||
defaultsTo: false,
|
||||
hide: true,
|
||||
negatable: true,
|
||||
help: 'Show (very verbose) debugging information to stdout during '
|
||||
'migration',
|
||||
);
|
||||
argParser.addFlag(
|
||||
ignoreErrorsOption,
|
||||
defaultsTo: false,
|
||||
|
@ -43,8 +61,18 @@ class MigrateOptions {
|
|||
help: 'Attempt to perform null safety analysis even if there are '
|
||||
'analysis errors in the project.',
|
||||
);
|
||||
argParser.addOption(
|
||||
sdkPathOption,
|
||||
hide: true,
|
||||
help: 'Override the SDK path used for migration.',
|
||||
);
|
||||
argParser.addOption(
|
||||
serverPathOption,
|
||||
hide: true,
|
||||
help: 'Override the analysis server path used for migration.',
|
||||
);
|
||||
argParser.addFlag(
|
||||
'web-preview',
|
||||
webPreviewOption,
|
||||
defaultsTo: true,
|
||||
negatable: true,
|
||||
help: 'Show an interactive preview of the proposed null safety changes '
|
||||
|
|
Loading…
Reference in a new issue