[dap] Don't use --start-paused when running in Profile/Release mode (#98926)
This commit is contained in:
parent
37a1aaf8c1
commit
76758ef960
@ -85,30 +85,55 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
|
||||
|
||||
/// Whether or not the user requested debugging be enabled.
|
||||
///
|
||||
/// debug/noDebug here refers to the DAP "debug" mode and not the Flutter
|
||||
/// debug mode (vs Profile/Release). It is provided by the client editor based
|
||||
/// on whether a user chooses to "Run" or "Debug" their app.
|
||||
/// For debugging to be enabled, the user must have chosen "Debug" (and not
|
||||
/// "Run") in the editor (which maps to the DAP `noDebug` field) _and_ must
|
||||
/// 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
|
||||
/// requests via DAP's `noDebug` flag. If `noDebug` is not provided, will
|
||||
/// default to debugging.
|
||||
/// This is always `true` for attach requests.
|
||||
///
|
||||
/// When not debugging, we will not connect to the VM Service so some
|
||||
/// functionality (breakpoints, evaluation, etc.) will not be available.
|
||||
/// Functionality provided via the daemon (hot reload/restart) will still be
|
||||
/// available.
|
||||
bool get debug {
|
||||
bool get enableDebugger {
|
||||
final DartCommonLaunchAttachRequestArguments args = this.args;
|
||||
if (args is FlutterLaunchRequestArguments) {
|
||||
// Invert DAP's noDebug flag, treating it as false (so _do_ debug) if not
|
||||
// provided.
|
||||
return !(args.noDebug ?? false);
|
||||
return !(args.noDebug ?? false) && !profileMode && !releaseMode;
|
||||
}
|
||||
|
||||
// Otherwise (attach), always debug.
|
||||
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.
|
||||
@override
|
||||
Future<void> attachImpl() async {
|
||||
@ -214,7 +239,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
|
||||
final List<String> toolArgs = <String>[
|
||||
'run',
|
||||
'--machine',
|
||||
if (debug) '--start-paused',
|
||||
if (enableDebugger) '--start-paused',
|
||||
];
|
||||
|
||||
await _startProcess(
|
||||
@ -258,7 +283,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
|
||||
// Delay responding until the app is launched and (optionally) the debugger
|
||||
// is connected.
|
||||
await appStartedCompleter.future;
|
||||
if (debug) {
|
||||
if (enableDebugger) {
|
||||
await debuggerInitialized;
|
||||
}
|
||||
}
|
||||
@ -363,7 +388,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
|
||||
void _handleDebugPort(Map<String, Object?> params) {
|
||||
// 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.
|
||||
if (!debug) {
|
||||
if (!enableDebugger) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -494,7 +519,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
|
||||
await sendFlutterRequest('app.restart', <String, Object?>{
|
||||
'appId': _appId,
|
||||
'fullRestart': fullRestart,
|
||||
'pause': debug,
|
||||
'pause': enableDebugger,
|
||||
'reason': reason,
|
||||
'debounce': true,
|
||||
});
|
||||
|
@ -0,0 +1,158 @@
|
||||
// Copyright 2014 The Flutter Authors. 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:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/debug_adapters/flutter_adapter_args.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'mocks.dart';
|
||||
|
||||
void main() {
|
||||
group('flutter adapter', () {
|
||||
final String expectedFlutterExecutable = globals.platform.isWindows
|
||||
? r'C:\fake\flutter\bin\flutter.bat'
|
||||
: '/fake/flutter/bin/flutter';
|
||||
|
||||
setUpAll(() {
|
||||
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 {
|
||||
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>['tool_arg'],
|
||||
noDebug: true,
|
||||
);
|
||||
|
||||
await adapter.configurationDoneRequest(MockRequest(), null, () {});
|
||||
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
|
||||
await responseCompleter.future;
|
||||
|
||||
expect(adapter.executable, equals(expectedFlutterExecutable));
|
||||
expect(adapter.processArgs, contains('tool_arg'));
|
||||
});
|
||||
|
||||
group('includes customTool', () {
|
||||
test('with no args replaced', () async {
|
||||
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
|
||||
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
|
||||
cwd: '/project',
|
||||
program: 'foo.dart',
|
||||
customTool: '/custom/flutter',
|
||||
noDebug: true,
|
||||
);
|
||||
|
||||
await adapter.configurationDoneRequest(MockRequest(), null, () {});
|
||||
final Completer<void> responseCompleter = Completer<void>();
|
||||
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
|
||||
await responseCompleter.future;
|
||||
|
||||
expect(adapter.executable, equals('/custom/flutter'));
|
||||
// args should be in-tact
|
||||
expect(adapter.processArgs, contains('--machine'));
|
||||
});
|
||||
|
||||
test('with all args replaced', () async {
|
||||
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
|
||||
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
|
||||
cwd: '/project',
|
||||
program: 'foo.dart',
|
||||
customTool: '/custom/flutter',
|
||||
customToolReplacesArgs: 9999, // replaces all built-in args
|
||||
noDebug: true,
|
||||
toolArgs: <String>['tool_args'], // should still be in args
|
||||
);
|
||||
|
||||
await adapter.configurationDoneRequest(MockRequest(), null, () {});
|
||||
final Completer<void> responseCompleter = Completer<void>();
|
||||
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
|
||||
await responseCompleter.future;
|
||||
|
||||
expect(adapter.executable, equals('/custom/flutter'));
|
||||
// normal built-in args are replaced by customToolReplacesArgs, but
|
||||
// user-provided toolArgs are not.
|
||||
expect(adapter.processArgs, isNot(contains('--machine')));
|
||||
expect(adapter.processArgs, contains('tool_args'));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
@ -13,9 +13,15 @@ import 'mocks.dart';
|
||||
|
||||
void main() {
|
||||
group('flutter test adapter', () {
|
||||
final String expectedFlutterExecutable = globals.platform.isWindows
|
||||
? r'C:\fake\flutter\bin\flutter.bat'
|
||||
: '/fake/flutter/bin/flutter';
|
||||
|
||||
setUpAll(() {
|
||||
Cache.flutterRoot = '/fake/flutter';
|
||||
});
|
||||
Cache.flutterRoot = globals.platform.isWindows
|
||||
? r'C:\fake\flutter'
|
||||
: '/fake/flutter';
|
||||
});
|
||||
|
||||
test('includes toolArgs', () async {
|
||||
final MockFlutterTestDebugAdapter adapter = MockFlutterTestDebugAdapter(
|
||||
@ -35,7 +41,7 @@ void main() {
|
||||
await adapter.launchRequest(request, args, responseCompleter.complete);
|
||||
await responseCompleter.future;
|
||||
|
||||
expect(adapter.executable, equals('/fake/flutter/bin/flutter'));
|
||||
expect(adapter.executable, equals(expectedFlutterExecutable));
|
||||
expect(adapter.processArgs, contains('tool_arg'));
|
||||
});
|
||||
|
@ -52,6 +52,14 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
|
||||
// launchRequest will 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.
|
@ -1,83 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. 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:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/debug_adapters/flutter_adapter_args.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'mocks.dart';
|
||||
|
||||
void main() {
|
||||
group('flutter adapter', () {
|
||||
setUpAll(() {
|
||||
Cache.flutterRoot = '/fake/flutter';
|
||||
});
|
||||
|
||||
test('includes toolArgs', () 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>['tool_arg'],
|
||||
noDebug: true,
|
||||
);
|
||||
|
||||
await adapter.configurationDoneRequest(MockRequest(), null, () {});
|
||||
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
|
||||
await responseCompleter.future;
|
||||
|
||||
expect(adapter.executable, equals('/fake/flutter/bin/flutter'));
|
||||
expect(adapter.processArgs, contains('tool_arg'));
|
||||
});
|
||||
|
||||
group('includes customTool', () {
|
||||
test('with no args replaced', () async {
|
||||
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
|
||||
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
|
||||
cwd: '/project',
|
||||
program: 'foo.dart',
|
||||
customTool: '/custom/flutter',
|
||||
noDebug: true,
|
||||
);
|
||||
|
||||
await adapter.configurationDoneRequest(MockRequest(), null, () {});
|
||||
final Completer<void> responseCompleter = Completer<void>();
|
||||
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
|
||||
await responseCompleter.future;
|
||||
|
||||
expect(adapter.executable, equals('/custom/flutter'));
|
||||
// args should be in-tact
|
||||
expect(adapter.processArgs, contains('--machine'));
|
||||
});
|
||||
|
||||
test('with all args replaced', () async {
|
||||
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
|
||||
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
|
||||
cwd: '/project',
|
||||
program: 'foo.dart',
|
||||
customTool: '/custom/flutter',
|
||||
customToolReplacesArgs: 9999, // replaces all built-in args
|
||||
noDebug: true,
|
||||
toolArgs: <String>['tool_args'], // should still be in args
|
||||
);
|
||||
|
||||
await adapter.configurationDoneRequest(MockRequest(), null, () {});
|
||||
final Completer<void> responseCompleter = Completer<void>();
|
||||
await adapter.launchRequest(MockRequest(), args, responseCompleter.complete);
|
||||
await responseCompleter.future;
|
||||
|
||||
expect(adapter.executable, equals('/custom/flutter'));
|
||||
// normal built-in args are replaced by customToolReplacesArgs, but
|
||||
// user-provided toolArgs are not.
|
||||
expect(adapter.processArgs, isNot(contains('--machine')));
|
||||
expect(adapter.processArgs, contains('tool_args'));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user