Revert "Add ipv6 and observatory port support to the attach command." (#25288) * Revert "e5195ee47 Remove unnecessary includes of Ganesh headers (flutter/engine#7189) (#25282)" This reverts commit f198d66332f0f95f1932d35457801809b6e1d543. * Revert "Validate style in TextField (#24587)" This reverts commit 9a8e2f0c4b07d81fb3a0d3274443d26a7f34e9fe. * Revert "Allow snippets tool to be run from arbitrary CWDs (#25243)" This reverts commit 4a110b6227a10637e1671f1f7ced7faf4da45d5e. * Revert "Make doctor output consistent between VS Code/IntelliJ/Android Studio when plugins are missing (#25269)" This reverts commit e29b023a6bbbd6b106aaf8802db3192ff3d3cf9c. * Revert "Add ipv6 and observatory port support to the attach command. (#24537)" This reverts commit 9150b3f031a9b1f743e25b9516a72a0bb3064adc.
diff --git a/packages/flutter_tools/lib/src/commands/attach.dart b/packages/flutter_tools/lib/src/commands/attach.dart index 312d823..844abb0b 100644 --- a/packages/flutter_tools/lib/src/commands/attach.dart +++ b/packages/flutter_tools/lib/src/commands/attach.dart
@@ -53,9 +53,6 @@ argParser ..addOption( 'debug-port', - help: 'Device port where the observatory is listening.', - )..addOption( - 'observatory-port', help: 'Local port where the observatory is listening.', )..addOption('pid-file', help: 'Specify a file to write the process id to. ' @@ -70,12 +67,6 @@ negatable: false, help: 'Handle machine structured JSON command input and provide output ' 'and progress in machine friendly format.', - )..addFlag('ipv6', - hide: true, - negatable: false, - help: 'Binds to IPv6 localhost instead of IPv4 when the flutter tool ' - 'forwards the host port to a device port. Not used when the ' - '--debug-port flag is not set.', ); hotRunnerFactory ??= HotRunnerFactory(); } @@ -88,14 +79,6 @@ @override final String description = 'Attach to a running application.'; - // TODO(djshuckerow): this is now a confusing name. An explanation: - // The --observatory-port flag passed to `flutter run` is used to - // set up the port on the development macine that the Dart observatory - // listens to. This flag serves the same purpose in this command. - // - // The --debug-port flag passed only to `flutter attach` is used to - // set up the port on the device running a Flutter app to connect back - // to the host development machine. int get observatoryPort { if (argResults['debug-port'] == null) return null; @@ -113,12 +96,6 @@ if (await findTargetDevice() == null) throwToolExit(null); observatoryPort; - if (observatoryPort == null && argResults.wasParsed('ipv6')) { - throwToolExit( - 'When the --debug-port is unknown, this command determines ' - 'the value of --ipv6 on its own.', - ); - } } @override @@ -186,24 +163,14 @@ ); printStatus('Waiting for a connection from Flutter on ${device.name}...'); observatoryUri = await observatoryDiscovery.uri; - // Determine ipv6 status from the scanned logs. - ipv6 = observatoryDiscovery.ipv6; printStatus('Done.'); } finally { await observatoryDiscovery?.cancel(); } } } else { - ipv6 = argResults['ipv6']; - // int.tryParse will throw if it is passed null, so we need to do this. - final int argObservatoryPort = argResults['observatory-port'] == null - ? null - : int.tryParse(argResults['observatory-port']); - final int localPort = argObservatoryPort - ?? await device.portForwarder.forward(devicePort); - observatoryUri = ipv6 - ? Uri.parse('http://[$ipv6Loopback]:$localPort/') - : Uri.parse('http://$ipv4Loopback:$localPort/'); + final int localPort = await device.portForwarder.forward(devicePort); + observatoryUri = Uri.parse('http://$ipv4Loopback:$localPort/'); } try { final FlutterDevice flutterDevice = FlutterDevice(
diff --git a/packages/flutter_tools/test/commands/attach_test.dart b/packages/flutter_tools/test/commands/attach_test.dart index d2d725f..9f4e67c 100644 --- a/packages/flutter_tools/test/commands/attach_test.dart +++ b/packages/flutter_tools/test/commands/attach_test.dart
@@ -104,7 +104,6 @@ debuggingOptions: anyNamed('debuggingOptions'), packagesFilePath: anyNamed('packagesFilePath'), usesTerminalUI: anyNamed('usesTerminalUI'), - ipv6: false, ), )..thenReturn(MockHotRunner()); @@ -135,7 +134,6 @@ debuggingOptions: anyNamed('debuggingOptions'), packagesFilePath: anyNamed('packagesFilePath'), usesTerminalUI: anyNamed('usesTerminalUI'), - ipv6: false, ), )..called(1); @@ -152,21 +150,6 @@ }, overrides: <Type, Generator>{ FileSystem: () => testFileSystem, }); - - testUsingContext('exits when ipv6 is specified and debug-port is not', () async { - testDeviceManager.addDevice(device); - - final AttachCommand command = AttachCommand(); - await expectLater( - createTestCommandRunner(command).run(<String>['attach', '--ipv6']), - throwsToolExit( - message: 'When the --debug-port is unknown, this command determines ' - 'the value of --ipv6 on its own.', - ), - ); - }, overrides: <Type, Generator>{ - FileSystem: () => testFileSystem, - },); }); @@ -187,8 +170,7 @@ target: anyNamed('target'), debuggingOptions: anyNamed('debuggingOptions'), packagesFilePath: anyNamed('packagesFilePath'), - usesTerminalUI: anyNamed('usesTerminalUI'), - ipv6: false)).thenReturn( + usesTerminalUI: anyNamed('usesTerminalUI'))).thenReturn( MockHotRunner()); testDeviceManager.addDevice(device); @@ -217,92 +199,33 @@ target: foo.path, debuggingOptions: anyNamed('debuggingOptions'), packagesFilePath: anyNamed('packagesFilePath'), - usesTerminalUI: anyNamed('usesTerminalUI'), - ipv6: false)).called(1); + usesTerminalUI: anyNamed('usesTerminalUI'))).called(1); }, overrides: <Type, Generator>{ FileSystem: () => testFileSystem, },); - group('forwarding to given port', () { + testUsingContext('forwards to given port', () async { const int devicePort = 499; const int hostPort = 42; - MockPortForwarder portForwarder; - MockAndroidDevice device; + final MockPortForwarder portForwarder = MockPortForwarder(); + final MockAndroidDevice device = MockAndroidDevice(); - setUp(() { - portForwarder = MockPortForwarder(); - device = MockAndroidDevice(); + when(device.portForwarder).thenReturn(portForwarder); + when(portForwarder.forward(devicePort)).thenAnswer((_) async => hostPort); + when(portForwarder.forwardedPorts).thenReturn( + <ForwardedPort>[ForwardedPort(hostPort, devicePort)]); + when(portForwarder.unforward(any)).thenAnswer((_) async => null); + testDeviceManager.addDevice(device); - when(device.portForwarder).thenReturn(portForwarder); - when(portForwarder.forward(devicePort)).thenAnswer((_) async => hostPort); - when(portForwarder.forwardedPorts).thenReturn( - <ForwardedPort>[ForwardedPort(hostPort, devicePort)]); - when(portForwarder.unforward(any)).thenAnswer((_) async => null); - }); + final AttachCommand command = AttachCommand(); - testUsingContext('succeeds in ipv4 mode', () async { - testDeviceManager.addDevice(device); - final AttachCommand command = AttachCommand(); + await createTestCommandRunner(command).run( + <String>['attach', '--debug-port', '$devicePort']); - await createTestCommandRunner(command).run( - <String>['attach', '--debug-port', '$devicePort']); - - verify(portForwarder.forward(devicePort)).called(1); - }, overrides: <Type, Generator>{ - FileSystem: () => testFileSystem, - }); - - testUsingContext('succeeds in ipv6 mode', () async { - testDeviceManager.addDevice(device); - final AttachCommand command = AttachCommand(); - - await createTestCommandRunner(command).run( - <String>['attach', '--debug-port', '$devicePort', '--ipv6']); - - verify(portForwarder.forward(devicePort)).called(1); - }, overrides: <Type, Generator>{ - FileSystem: () => testFileSystem, - }); - - testUsingContext('skips in ipv4 mode with a provided observatory port', () async { - testDeviceManager.addDevice(device); - final AttachCommand command = AttachCommand(); - - await createTestCommandRunner(command).run( - <String>[ - 'attach', - '--debug-port', - '$devicePort', - '--observatory-port', - '$hostPort', - ], - ); - - verifyNever(portForwarder.forward(devicePort)); - }, overrides: <Type, Generator>{ - FileSystem: () => testFileSystem, - }); - - testUsingContext('skips in ipv6 mode with a provided observatory port', () async { - testDeviceManager.addDevice(device); - final AttachCommand command = AttachCommand(); - - await createTestCommandRunner(command).run( - <String>[ - 'attach', - '--debug-port', - '$devicePort', - '--observatory-port', - '$hostPort', - '--ipv6', - ], - ); - - verifyNever(portForwarder.forward(devicePort)); - }, overrides: <Type, Generator>{ - FileSystem: () => testFileSystem, - }); - }); + verify(portForwarder.forward(devicePort)).called(1); + }, overrides: <Type, Generator>{ + FileSystem: () => testFileSystem, + },); testUsingContext('exits when no device connected', () async { final AttachCommand command = AttachCommand();