Unverified Commit 4b351ac1 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] do not allow attaching in release mode (#68071)

Do not allow attach in release mode, as there is not VM Service to connect to. Observed in crash reporting as thrown string which is changed to exception below.
parent 7b89af2c
...@@ -54,7 +54,7 @@ import '../runner/flutter_command.dart'; ...@@ -54,7 +54,7 @@ import '../runner/flutter_command.dart';
/// also be provided. /// also be provided.
class AttachCommand extends FlutterCommand { class AttachCommand extends FlutterCommand {
AttachCommand({bool verboseHelp = false, this.hotRunnerFactory}) { AttachCommand({bool verboseHelp = false, this.hotRunnerFactory}) {
addBuildModeFlags(defaultToRelease: false); addBuildModeFlags(defaultToRelease: false, excludeRelease: true);
usesTargetOption(); usesTargetOption();
usesPortOptions(); usesPortOptions();
usesIpv6Flag(); usesIpv6Flag();
......
...@@ -288,7 +288,7 @@ class FlutterDevice { ...@@ -288,7 +288,7 @@ class FlutterDevice {
}, onDone: () { }, onDone: () {
_isListeningForObservatoryUri = false; _isListeningForObservatoryUri = false;
if (!completer.isCompleted && !isWaitingForVm) { if (!completer.isCompleted && !isWaitingForVm) {
completer.completeError('connection to device ended too early'); completer.completeError(Exception('connection to device ended too early'));
} }
}); });
_isListeningForObservatoryUri = true; _isListeningForObservatoryUri = true;
......
...@@ -159,6 +159,7 @@ abstract class FlutterCommand extends Command<void> { ...@@ -159,6 +159,7 @@ abstract class FlutterCommand extends Command<void> {
bool get hidden => deprecated; bool get hidden => deprecated;
bool _excludeDebug = false; bool _excludeDebug = false;
bool _excludeRelease = false;
BuildMode _defaultBuildMode; BuildMode _defaultBuildMode;
...@@ -451,10 +452,16 @@ abstract class FlutterCommand extends Command<void> { ...@@ -451,10 +452,16 @@ abstract class FlutterCommand extends Command<void> {
} }
Duration _deviceDiscoveryTimeout; Duration _deviceDiscoveryTimeout;
void addBuildModeFlags({ bool defaultToRelease = true, bool verboseHelp = false, bool excludeDebug = false }) { void addBuildModeFlags({
bool defaultToRelease = true,
bool verboseHelp = false,
bool excludeDebug = false,
bool excludeRelease = false,
}) {
// A release build must be the default if a debug build is not possible. // A release build must be the default if a debug build is not possible.
assert(defaultToRelease || !excludeDebug); assert(defaultToRelease || !excludeDebug);
_excludeDebug = excludeDebug; _excludeDebug = excludeDebug;
_excludeRelease = excludeRelease;
defaultBuildMode = defaultToRelease ? BuildMode.release : BuildMode.debug; defaultBuildMode = defaultToRelease ? BuildMode.release : BuildMode.debug;
if (!excludeDebug) { if (!excludeDebug) {
...@@ -465,13 +472,15 @@ abstract class FlutterCommand extends Command<void> { ...@@ -465,13 +472,15 @@ abstract class FlutterCommand extends Command<void> {
argParser.addFlag('profile', argParser.addFlag('profile',
negatable: false, negatable: false,
help: 'Build a version of your app specialized for performance profiling.'); help: 'Build a version of your app specialized for performance profiling.');
argParser.addFlag('release', if (!excludeRelease) {
negatable: false, argParser.addFlag('release',
help: 'Build a release version of your app${defaultToRelease ? ' (default mode)' : ''}.'); negatable: false,
argParser.addFlag('jit-release', help: 'Build a release version of your app${defaultToRelease ? ' (default mode)' : ''}.');
negatable: false, argParser.addFlag('jit-release',
hide: !verboseHelp, negatable: false,
help: 'Build a JIT release version of your app${defaultToRelease ? ' (default mode)' : ''}.'); hide: !verboseHelp,
help: 'Build a JIT release version of your app${defaultToRelease ? ' (default mode)' : ''}.');
}
} }
void addSplitDebugInfoOption() { void addSplitDebugInfoOption() {
...@@ -628,11 +637,13 @@ abstract class FlutterCommand extends Command<void> { ...@@ -628,11 +637,13 @@ abstract class FlutterCommand extends Command<void> {
// No debug when _excludeDebug is true. // No debug when _excludeDebug is true.
// If debug is not excluded, then take the command line flag. // If debug is not excluded, then take the command line flag.
final bool debugResult = !_excludeDebug && boolArg('debug'); final bool debugResult = !_excludeDebug && boolArg('debug');
final bool jitReleaseResult = !_excludeRelease && boolArg('jit-release');
final bool releaseResult = !_excludeRelease && boolArg('release');
final List<bool> modeFlags = <bool>[ final List<bool> modeFlags = <bool>[
debugResult, debugResult,
boolArg('jit-release'), jitReleaseResult,
boolArg('profile'), boolArg('profile'),
boolArg('release'), releaseResult,
]; ];
if (modeFlags.where((bool flag) => flag).length > 1) { if (modeFlags.where((bool flag) => flag).length > 1) {
throw UsageException('Only one of --debug, --profile, --jit-release, ' throw UsageException('Only one of --debug, --profile, --jit-release, '
...@@ -644,10 +655,10 @@ abstract class FlutterCommand extends Command<void> { ...@@ -644,10 +655,10 @@ abstract class FlutterCommand extends Command<void> {
if (boolArg('profile')) { if (boolArg('profile')) {
return BuildMode.profile; return BuildMode.profile;
} }
if (boolArg('release')) { if (releaseResult) {
return BuildMode.release; return BuildMode.release;
} }
if (boolArg('jit-release')) { if (jitReleaseResult) {
return BuildMode.jitRelease; return BuildMode.jitRelease;
} }
return _defaultBuildMode; return _defaultBuildMode;
......
...@@ -221,4 +221,19 @@ void main() { ...@@ -221,4 +221,19 @@ void main() {
expect(result.exitCode, 1); expect(result.exitCode, 1);
expect(result.stderr, contains('No SkSL shader bundle found at foo/bar/baz.json')); expect(result.stderr, contains('No SkSL shader bundle found at foo/bar/baz.json'));
}); });
testWithoutContext('flutter attach does not support --release', () async {
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
final String helloWorld = fileSystem.path.join(getFlutterRoot(), 'examples', 'hello_world');
final ProcessResult result = await processManager.run(<String>[
flutterBin,
...getLocalEngineArguments(),
'--show-test-device',
'attach',
'--release',
], workingDirectory: helloWorld);
expect(result.exitCode, isNot(0));
expect(result.stderr, contains('Could not find an option named "release"'));
});
} }
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