[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.
This commit is contained in:
Jonah Williams
2020-10-13 21:29:23 -07:00
committed by GitHub
parent 7b89af2c4f
commit 4b351ac1b4
4 changed files with 40 additions and 14 deletions

View File

@@ -54,7 +54,7 @@ import '../runner/flutter_command.dart';
/// also be provided.
class AttachCommand extends FlutterCommand {
AttachCommand({bool verboseHelp = false, this.hotRunnerFactory}) {
addBuildModeFlags(defaultToRelease: false);
addBuildModeFlags(defaultToRelease: false, excludeRelease: true);
usesTargetOption();
usesPortOptions();
usesIpv6Flag();

View File

@@ -288,7 +288,7 @@ class FlutterDevice {
}, onDone: () {
_isListeningForObservatoryUri = false;
if (!completer.isCompleted && !isWaitingForVm) {
completer.completeError('connection to device ended too early');
completer.completeError(Exception('connection to device ended too early'));
}
});
_isListeningForObservatoryUri = true;

View File

@@ -159,6 +159,7 @@ abstract class FlutterCommand extends Command<void> {
bool get hidden => deprecated;
bool _excludeDebug = false;
bool _excludeRelease = false;
BuildMode _defaultBuildMode;
@@ -451,10 +452,16 @@ abstract class FlutterCommand extends Command<void> {
}
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.
assert(defaultToRelease || !excludeDebug);
_excludeDebug = excludeDebug;
_excludeRelease = excludeRelease;
defaultBuildMode = defaultToRelease ? BuildMode.release : BuildMode.debug;
if (!excludeDebug) {
@@ -465,13 +472,15 @@ abstract class FlutterCommand extends Command<void> {
argParser.addFlag('profile',
negatable: false,
help: 'Build a version of your app specialized for performance profiling.');
argParser.addFlag('release',
negatable: false,
help: 'Build a release version of your app${defaultToRelease ? ' (default mode)' : ''}.');
argParser.addFlag('jit-release',
negatable: false,
hide: !verboseHelp,
help: 'Build a JIT release version of your app${defaultToRelease ? ' (default mode)' : ''}.');
if (!excludeRelease) {
argParser.addFlag('release',
negatable: false,
help: 'Build a release version of your app${defaultToRelease ? ' (default mode)' : ''}.');
argParser.addFlag('jit-release',
negatable: false,
hide: !verboseHelp,
help: 'Build a JIT release version of your app${defaultToRelease ? ' (default mode)' : ''}.');
}
}
void addSplitDebugInfoOption() {
@@ -628,11 +637,13 @@ abstract class FlutterCommand extends Command<void> {
// No debug when _excludeDebug is true.
// If debug is not excluded, then take the command line flag.
final bool debugResult = !_excludeDebug && boolArg('debug');
final bool jitReleaseResult = !_excludeRelease && boolArg('jit-release');
final bool releaseResult = !_excludeRelease && boolArg('release');
final List<bool> modeFlags = <bool>[
debugResult,
boolArg('jit-release'),
jitReleaseResult,
boolArg('profile'),
boolArg('release'),
releaseResult,
];
if (modeFlags.where((bool flag) => flag).length > 1) {
throw UsageException('Only one of --debug, --profile, --jit-release, '
@@ -644,10 +655,10 @@ abstract class FlutterCommand extends Command<void> {
if (boolArg('profile')) {
return BuildMode.profile;
}
if (boolArg('release')) {
if (releaseResult) {
return BuildMode.release;
}
if (boolArg('jit-release')) {
if (jitReleaseResult) {
return BuildMode.jitRelease;
}
return _defaultBuildMode;

View File

@@ -221,4 +221,19 @@ void main() {
expect(result.exitCode, 1);
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"'));
});
}