Skip to content

Commit 6b71477

Browse files
jcollins-gcommit-bot@chromium.org
authored andcommitted
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 <[email protected]> Commit-Queue: Janice Collins <[email protected]>
1 parent 7617e32 commit 6b71477

File tree

3 files changed

+78
-14
lines changed

3 files changed

+78
-14
lines changed

pkg/analysis_server_client/lib/server.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class Server {
2626
/// or if the server has already been stopped.
2727
Process _process;
2828

29+
/// Replicate all stdout/stderr data from the server process to stdout/stderr,
30+
/// when true.
31+
bool _stdioPassthrough;
32+
2933
/// Commands that have been sent to the server but not yet acknowledged,
3034
/// and the [Completer] objects which should be completed
3135
/// when acknowledgement is received.
@@ -43,9 +47,11 @@ class Server {
4347
/// [listenToOutput] has not been called or [stop] has been called.
4448
StreamSubscription<String> _stdoutSubscription;
4549

46-
Server({ServerListener listener, Process process})
50+
Server(
51+
{ServerListener listener, Process process, bool stdioPassthrough = false})
4752
: _listener = listener,
48-
_process = process;
53+
_process = process,
54+
_stdioPassthrough = stdioPassthrough;
4955

5056
/// Force kill the server. Returns exit code future.
5157
Future<int> kill({String reason = 'none'}) {
@@ -63,6 +69,7 @@ class Server {
6369
.transform(utf8.decoder)
6470
.transform(LineSplitter())
6571
.listen((String line) {
72+
if (_stdioPassthrough) stdout.writeln(line);
6673
String trimmedLine = line.trim();
6774

6875
// Guard against lines like:
@@ -116,6 +123,7 @@ class Server {
116123
.transform(utf8.decoder)
117124
.transform(LineSplitter())
118125
.listen((String line) {
126+
if (_stdioPassthrough) stderr.writeln(line);
119127
String trimmedLine = line.trim();
120128
_listener?.errorMessage(trimmedLine);
121129
});

pkg/dartfix/lib/src/migrate/migrate.dart

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,46 @@ class MigrateCommand extends Command {
6161
logger.stdout('Migrating ${options.directory}');
6262
logger.stdout('');
6363

64-
Progress progress =
65-
logger.progress('${ansi.emphasized('Analyzing project')}');
66-
67-
Server server =
68-
Server(listener: logger.isVerbose ? _ServerListener(logger) : null);
64+
Progress getProgress(String message) => options.debug
65+
? SimpleProgress(logger, message)
66+
: logger.progress(message);
6967

7068
Map<String, List<AnalysisError>> fileErrors = {};
7169

70+
bool enableAsserts = false;
71+
String instrumentationLogFile;
72+
bool profileServer = false;
73+
String serverPath = options.serverPath;
74+
int servicesPort;
75+
String sdkPath = options.sdkPath;
76+
bool stdioPassthrough = false;
77+
78+
if (options.debug) {
79+
enableAsserts = true;
80+
profileServer = true;
81+
servicesPort = 9500;
82+
stdioPassthrough = true;
83+
instrumentationLogFile = path.join(
84+
Directory.systemTemp.createTempSync('migration_debug').path,
85+
'instrumentationLog');
86+
logger.stdout('Instrumentation log file: ${instrumentationLogFile}');
87+
}
88+
89+
Progress progress = getProgress('${ansi.emphasized('Analyzing project')}');
90+
91+
Server server = Server(
92+
listener: logger.isVerbose ? _ServerListener(logger) : null,
93+
stdioPassthrough: stdioPassthrough);
7294
try {
7395
await server.start(
74-
clientId: 'dart $name', clientVersion: _dartSdkVersion);
96+
clientId: 'dart $name',
97+
clientVersion: _dartSdkVersion,
98+
enableAsserts: enableAsserts,
99+
instrumentationLogFile: instrumentationLogFile,
100+
profileServer: profileServer,
101+
serverPath: serverPath,
102+
servicesPort: servicesPort,
103+
sdkPath: sdkPath);
75104
_ServerNotifications serverNotifications = _ServerNotifications(server);
76105
await serverNotifications.listenToServer(server);
77106

@@ -135,9 +164,8 @@ class MigrateCommand extends Command {
135164

136165
// Calculate migration suggestions.
137166
logger.stdout('');
138-
progress = logger
139-
.progress('${ansi.emphasized('Generating migration suggestions')}');
140-
167+
progress =
168+
getProgress('${ansi.emphasized('Generating migration suggestions')}');
141169
Map<String, dynamic> json;
142170

143171
try {

pkg/dartfix/lib/src/migrate/options.dart

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,27 @@ import 'package:args/src/arg_parser.dart';
99
import 'package:path/path.dart' as path;
1010

1111
class MigrateOptions {
12-
static const ignoreErrorsOption = 'ignore-errors';
1312
static const applyChangesOption = 'apply-changes';
13+
static const debugOption = 'debug';
14+
static const ignoreErrorsOption = 'ignore-errors';
15+
static const sdkPathOption = 'sdk-path';
16+
static const serverPathOption = 'server-path';
17+
static const webPreviewOption = 'web-preview';
1418

15-
final String directory;
1619
final bool applyChanges;
20+
final bool debug;
21+
final String directory;
1722
final bool ignoreErrors;
23+
final String serverPath;
24+
final String sdkPath;
1825
final bool webPreview;
1926

2027
MigrateOptions(ArgResults argResults, this.directory)
2128
: applyChanges = argResults[applyChangesOption] as bool,
29+
debug = argResults[debugOption] as bool,
2230
ignoreErrors = argResults[ignoreErrorsOption] as bool,
31+
sdkPath = argResults[sdkPathOption] as String,
32+
serverPath = argResults[serverPathOption] as String,
2333
webPreview = argResults['web-preview'] as bool;
2434

2535
String get directoryAbsolute => Directory(path.canonicalize(directory)).path;
@@ -36,15 +46,33 @@ class MigrateOptions {
3646
negatable: false,
3747
help: 'Apply the proposed null safety changes to the files on disk.',
3848
);
49+
argParser.addFlag(
50+
debugOption,
51+
defaultsTo: false,
52+
hide: true,
53+
negatable: true,
54+
help: 'Show (very verbose) debugging information to stdout during '
55+
'migration',
56+
);
3957
argParser.addFlag(
4058
ignoreErrorsOption,
4159
defaultsTo: false,
4260
negatable: false,
4361
help: 'Attempt to perform null safety analysis even if there are '
4462
'analysis errors in the project.',
4563
);
64+
argParser.addOption(
65+
sdkPathOption,
66+
hide: true,
67+
help: 'Override the SDK path used for migration.',
68+
);
69+
argParser.addOption(
70+
serverPathOption,
71+
hide: true,
72+
help: 'Override the analysis server path used for migration.',
73+
);
4674
argParser.addFlag(
47-
'web-preview',
75+
webPreviewOption,
4876
defaultsTo: true,
4977
negatable: true,
5078
help: 'Show an interactive preview of the proposed null safety changes '

0 commit comments

Comments
 (0)