Unverified Commit 76758ef9 authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

[dap] Don't use --start-paused when running in Profile/Release mode (#98926)

parent 37a1aaf8
...@@ -85,30 +85,55 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments ...@@ -85,30 +85,55 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
/// Whether or not the user requested debugging be enabled. /// Whether or not the user requested debugging be enabled.
/// ///
/// debug/noDebug here refers to the DAP "debug" mode and not the Flutter /// For debugging to be enabled, the user must have chosen "Debug" (and not
/// debug mode (vs Profile/Release). It is provided by the client editor based /// "Run") in the editor (which maps to the DAP `noDebug` field) _and_ must
/// on whether a user chooses to "Run" or "Debug" their app. /// not have requested to run in Profile or Release mode. Profile/Release
/// modes will always disable debugging.
/// ///
/// This is always enabled for attach requests, but can be disabled for launch /// This is always `true` for attach requests.
/// requests via DAP's `noDebug` flag. If `noDebug` is not provided, will
/// default to debugging.
/// ///
/// When not debugging, we will not connect to the VM Service so some /// When not debugging, we will not connect to the VM Service so some
/// functionality (breakpoints, evaluation, etc.) will not be available. /// functionality (breakpoints, evaluation, etc.) will not be available.
/// Functionality provided via the daemon (hot reload/restart) will still be /// Functionality provided via the daemon (hot reload/restart) will still be
/// available. /// available.
bool get debug { bool get enableDebugger {
final DartCommonLaunchAttachRequestArguments args = this.args; final DartCommonLaunchAttachRequestArguments args = this.args;
if (args is FlutterLaunchRequestArguments) { if (args is FlutterLaunchRequestArguments) {
// Invert DAP's noDebug flag, treating it as false (so _do_ debug) if not // Invert DAP's noDebug flag, treating it as false (so _do_ debug) if not
// provided. // provided.
return !(args.noDebug ?? false); return !(args.noDebug ?? false) && !profileMode && !releaseMode;
} }
// Otherwise (attach), always debug. // Otherwise (attach), always debug.
return true; return true;
} }
/// Whether the launch configuration arguments specify `--profile`.
///
/// Always `false` for attach requests.
bool get profileMode {
final DartCommonLaunchAttachRequestArguments args = this.args;
if (args is FlutterLaunchRequestArguments) {
return args.toolArgs?.contains('--profile') ?? false;
}
// Otherwise (attach), always false.
return false;
}
/// Whether the launch configuration arguments specify `--release`.
///
/// Always `false` for attach requests.
bool get releaseMode {
final DartCommonLaunchAttachRequestArguments args = this.args;
if (args is FlutterLaunchRequestArguments) {
return args.toolArgs?.contains('--release') ?? false;
}
// Otherwise (attach), always false.
return false;
}
/// Called by [attachRequest] to request that we actually connect to the app to be debugged. /// Called by [attachRequest] to request that we actually connect to the app to be debugged.
@override @override
Future<void> attachImpl() async { Future<void> attachImpl() async {
...@@ -214,7 +239,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments ...@@ -214,7 +239,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
final List<String> toolArgs = <String>[ final List<String> toolArgs = <String>[
'run', 'run',
'--machine', '--machine',
if (debug) '--start-paused', if (enableDebugger) '--start-paused',
]; ];
await _startProcess( await _startProcess(
...@@ -258,7 +283,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments ...@@ -258,7 +283,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
// Delay responding until the app is launched and (optionally) the debugger // Delay responding until the app is launched and (optionally) the debugger
// is connected. // is connected.
await appStartedCompleter.future; await appStartedCompleter.future;
if (debug) { if (enableDebugger) {
await debuggerInitialized; await debuggerInitialized;
} }
} }
...@@ -363,7 +388,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments ...@@ -363,7 +388,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
void _handleDebugPort(Map<String, Object?> params) { void _handleDebugPort(Map<String, Object?> params) {
// When running in noDebug mode, Flutter may still provide us a VM Service // When running in noDebug mode, Flutter may still provide us a VM Service
// URI, but we will not connect it because we don't want to do any debugging. // URI, but we will not connect it because we don't want to do any debugging.
if (!debug) { if (!enableDebugger) {
return; return;
} }
...@@ -494,7 +519,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments ...@@ -494,7 +519,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
await sendFlutterRequest('app.restart', <String, Object?>{ await sendFlutterRequest('app.restart', <String, Object?>{
'appId': _appId, 'appId': _appId,
'fullRestart': fullRestart, 'fullRestart': fullRestart,
'pause': debug, 'pause': enableDebugger,
'reason': reason, 'reason': reason,
'debounce': true, 'debounce': true,
}); });
......
...@@ -13,9 +13,84 @@ import 'mocks.dart'; ...@@ -13,9 +13,84 @@ import 'mocks.dart';
void main() { void main() {
group('flutter adapter', () { group('flutter adapter', () {
final String expectedFlutterExecutable = globals.platform.isWindows
? r'C:\fake\flutter\bin\flutter.bat'
: '/fake/flutter/bin/flutter';
setUpAll(() { setUpAll(() {
Cache.flutterRoot = '/fake/flutter'; Cache.flutterRoot = globals.platform.isWindows
}); ? r'C:\fake\flutter'
: '/fake/flutter';
});
group('--start-paused', () {
test('is passed for debug mode', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
final Completer<void> responseCompleter = Completer<void>();
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
cwd: '/project',
program: 'foo.dart',
);
await adapter.configurationDoneRequest(MockRequest(), null, () {});
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
await responseCompleter.future;
expect(adapter.processArgs, contains('--start-paused'));
});
test('is not passed for noDebug mode', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
final Completer<void> responseCompleter = Completer<void>();
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
cwd: '/project',
program: 'foo.dart',
noDebug: true,
);
await adapter.configurationDoneRequest(MockRequest(), null, () {});
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
await responseCompleter.future;
expect(adapter.processArgs, isNot(contains('--start-paused')));
});
test('is not passed if toolArgs contains --profile', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
final Completer<void> responseCompleter = Completer<void>();
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
cwd: '/project',
program: 'foo.dart',
toolArgs: <String>['--profile'],
);
await adapter.configurationDoneRequest(MockRequest(), null, () {});
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
await responseCompleter.future;
expect(adapter.processArgs, isNot(contains('--start-paused')));
});
test('is not passed if toolArgs contains --release', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
final Completer<void> responseCompleter = Completer<void>();
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
cwd: '/project',
program: 'foo.dart',
toolArgs: <String>['--release'],
);
await adapter.configurationDoneRequest(MockRequest(), null, () {});
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
await responseCompleter.future;
expect(adapter.processArgs, isNot(contains('--start-paused')));
});
});
test('includes toolArgs', () async { test('includes toolArgs', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform); final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
...@@ -32,7 +107,7 @@ void main() { ...@@ -32,7 +107,7 @@ void main() {
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete); await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
await responseCompleter.future; await responseCompleter.future;
expect(adapter.executable, equals('/fake/flutter/bin/flutter')); expect(adapter.executable, equals(expectedFlutterExecutable));
expect(adapter.processArgs, contains('tool_arg')); expect(adapter.processArgs, contains('tool_arg'));
}); });
......
...@@ -13,9 +13,15 @@ import 'mocks.dart'; ...@@ -13,9 +13,15 @@ import 'mocks.dart';
void main() { void main() {
group('flutter test adapter', () { group('flutter test adapter', () {
final String expectedFlutterExecutable = globals.platform.isWindows
? r'C:\fake\flutter\bin\flutter.bat'
: '/fake/flutter/bin/flutter';
setUpAll(() { setUpAll(() {
Cache.flutterRoot = '/fake/flutter'; Cache.flutterRoot = globals.platform.isWindows
}); ? r'C:\fake\flutter'
: '/fake/flutter';
});
test('includes toolArgs', () async { test('includes toolArgs', () async {
final MockFlutterTestDebugAdapter adapter = MockFlutterTestDebugAdapter( final MockFlutterTestDebugAdapter adapter = MockFlutterTestDebugAdapter(
...@@ -35,7 +41,7 @@ void main() { ...@@ -35,7 +41,7 @@ void main() {
await adapter.launchRequest(request, args, responseCompleter.complete); await adapter.launchRequest(request, args, responseCompleter.complete);
await responseCompleter.future; await responseCompleter.future;
expect(adapter.executable, equals('/fake/flutter/bin/flutter')); expect(adapter.executable, equals(expectedFlutterExecutable));
expect(adapter.processArgs, contains('tool_arg')); expect(adapter.processArgs, contains('tool_arg'));
}); });
......
...@@ -52,6 +52,14 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter { ...@@ -52,6 +52,14 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
// launchRequest will complete. // launchRequest will complete.
appStartedCompleter.complete(); appStartedCompleter.complete();
} }
@override
Future<void> get debuggerInitialized {
// If we were mocking debug mode, then simulate the debugger initializing.
return enableDebugger
? Future<void>.value()
: throw StateError('Invalid attempt to wait for debuggerInitialized when not debugging');
}
} }
/// A [FlutterTestDebugAdapter] that captures what process/args will be launched. /// A [FlutterTestDebugAdapter] that captures what process/args will be launched.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment